[Tutor] os.getcwd() confusion
spangled spanner
bentbakwards at gmail.com
Mon May 20 08:31:32 CEST 2013
G'day,
I have a comprehension issue here! I have made two simple scripts:
## script1
import os
print os.getcwd()
-----------------------------
## script 2
import os
f = open('test', 'wb')
f.write(os.getcwd())
f.close()
_________________
Both scripts are in my home directory.
Using bash I cd to some other directory and call script 1:
> python ../../script1.py
and I get this result printed to the screen:
> users/scriptdir/dir1/dir2
i.e. the script returns the name of the directory that I'm currently
working in.
However if I call script2:
> python ../../script2.py
I get a result that to me seems inconsistent: the script writes the
directory
that IT is in (i.e., NOT the name of the directory I'm currently working
in),
to the file 'test' in the home directory.
I don't quite understand what is happening here! Any explanation would be
much appreciated.
Cheers,
CSS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130520/cbe11ff1/attachment.html>
More information about the Tutor
mailing list