Python os.chdir () and os.getcwd () errors when using tempfile.mkdtemp () on Mac OSX Lion

I'm not sure if this is an error or a function, but when I change the directory with the help os.chdir()to the one generated with the help tempfile.mkdtemp(), then os.getcwd()it reports the directory with a prefix /private.

The following code illustrates this:

In [1]: import os, tempfile

In [2]: d = tempfile.mkdtemp()

In [3]: d
Out[3]: '/var/folders/s4/grpfgn297hjgnfws3tl_gnt80000gn/T/tmpmfNUYz'

In [4]: os.chdir( d )

In [5]: os.getcwd()
Out[5]: '/private/var/folders/s4/grpfgn297hjgnfws3tl_gnt80000gn/T/tmpmfNUYz'

Can someone explain why this is so?

+5
source share
1 answer

/var is a symbolic link to /private/var

$ ls -l /var
lrwxr-xr-x@ 1 root  wheel  11 Dec  2  2011 /var -> private/var

tempfilejust uses the environment variable TMPDIRto prefix the location of the path, so its just a string. But os.getcwd()allows absolute location:

$ echo $TMPDIR
/var/folders/04/kc575q1n6x9drkwxyfljg5zw0000gn/T/
+7
source

All Articles