Does os.getcwd() and os.curdir have the same effect ?

S

Steven D'Aprano

Does os.getcwd() and os.curdir have the same effect ?

You could answer that yourself with two seconds experimentation at the
interactive prompt.


py> os.getcwd()
'/home/steve'
py> os.curdir
'.'

For more information, you can try reading the Fine Manual:

http://docs.python.org/library/os.html#os.getcwd

http://docs.python.org/library/os.html#os.curdir


In case it isn't obvious: no, they are completely different. os.getcwd is
a function which returns the path of the current working directory.
os.curdir is a string which the operating system will understand to mean
"this directory".
 
T

Thomas Jollans

Does os.getcwd() and os.curdir have the same effect ?

Python 3.2.3 (default, May 3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

No.


Both refer to the current directory, but os.curdir is not an absolute
path, so you can't chdir() to it later and expect to land it the
original directory.
 
I

iMath

On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6..3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> No. Both refer to the current directory, but os.curdir is not an absolute path, so you can't chdir() to it later and expect to land it the original directory.

get it ,thanks
 
I

iMath

On 09/09/2012 03:22 PM, iMath wrote: > Does os.getcwd() and os.curdir have the same effect ? > Python 3.2.3 (default, May 3 2012, 15:51:42) [GCC 4.6..3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.getcwd() '/home/tjol' >>> os.curdir '.' >>> No. Both refer to the current directory, but os.curdir is not an absolute path, so you can't chdir() to it later and expect to land it the original directory.

get it ,thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top