In Linux environment, I want to create a file and write text into it:
HTMLFILE: "$MYUSER/OUTPUT/myfolder/mytext.html"
f = open(HTMLFILE, 'w')
IOError: [Errno 2] No such file or directory: "$MYUSER/OUTPUT/myfolder/mytext.html"
I have read/write permission do "$MYUSER/OUTPUT/myfolder/" directories.
Why do I get this error? Why doesn't it create mytext.html file?
os.path.expandvars()
can help:
f = open(os.path.expandvars(HTMLFILE), 'w')
open
only deals with actual file names. expandvars
can expand environment variables in strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With