0
I am learning Python and am following the book A byte of python. In an exercise talking about the logging module there is the following line of code:
if platform.system().startswith('Windows'):
logging_file = os.path.join(os.getenv('DIRETORIOINICIAL'), os.getenv('PATH'), 'test.log')
The script just writes inside the file teste.log
with the date and time the script was run.
I followed exactly as it is in the book but I always get the same trackback:
Traceback (most recent call last):
File "using_logging.py", line 6, in <module>
logging_file = os.path.join(os.getenv('DIRETÓRIOINICIAL'), os.getenv('PATH'), 'test.log')
File "C:\Python34\lib\ntpath.py", line 108, in join
result_drive, result_path = splitdrive(path)
File "C:\Python34\lib\ntpath.py", line 159, in splitdrive
if len(p) > 1:
TypeError: object of type 'NoneType' has no len()
It does not return or write the file.
What problem is occurring?
– rubStackOverflow
trackback returns this error but does not create the file or write. I change the
('DIRETÓRIOINICIAL')
by a complete way? But from what I understood the doc saysos.getenv
takes the environment variable so I wouldn’t need it right?– Theo Oliveira
Testing
os.getenv('DIRETÓRIOINICIAL')
and see if it returns any results.– rubStackOverflow
None
, then probably the problem is that my initial directory not this set is this?– Theo Oliveira
Right, as a matter of fact
'DIRETÓRIOINICIAL'
should exist in your Windows environment variables, review the example used is looking like a translation.– rubStackOverflow
Even though
%HomeDrive%
still showsNone
– Theo Oliveira
Let’s go continue this discussion in chat.
– Theo Oliveira