Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

48 views
Skip to first unread message

iMath

unread,
Sep 9, 2012, 9:22:09 AM9/9/12
to
Does os.getcwd() and os.curdir have the same effect ?

Steven D'Aprano

unread,
Sep 9, 2012, 9:38:16 AM9/9/12
to
On Sun, 09 Sep 2012 06:22:09 -0700, iMath wrote:

> 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".



--
Steven

Thomas Jollans

unread,
Sep 9, 2012, 9:39:12 AM9/9/12
to pytho...@python.org
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.

iMath

unread,
Sep 27, 2012, 2:26:30 AM9/27/12
to pytho...@python.org
On Sunday, September 9, 2012 9:39:28 PM UTC+8, Thomas Jollans wrote:
> 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

iMath

unread,
Sep 27, 2012, 2:26:30 AM9/27/12
to comp.lan...@googlegroups.com, pytho...@python.org
On Sunday, September 9, 2012 9:39:28 PM UTC+8, Thomas Jollans wrote:
> 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
0 new messages