[Pythonmac-SIG] Question on user's directory ( ~ )

Kent Quirk kquirk at solidworks.com
Sun Mar 19 01:35:01 CET 2006


Try this:

import os.path
os.path.expanduser('~')

You might also find a use for
os.path.expandvars()

	Kent


-----Original Message-----
From: pythonmac-sig-bounces at python.org
[mailto:pythonmac-sig-bounces at python.org] On Behalf Of Stewart Midwinter
Sent: Saturday, March 18, 2006 7:22 PM
To: pythonmac-sig at python.org
Subject: [Pythonmac-SIG] Question on user's directory ( ~ )

I have a question on use of the tilde symbol (~) to access the current
user's home directory.

If you are in a bash shell, you can "cd ~" and be in the default
user's home directory.

I want my python app to be able to switch to the user's directory. 
But I can't use os.chdir('~') since Python doesn't understand the
tilde.   Nor can I do this:
file = os.path.join('~', filename)

What options do I have?

thanks
S
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


More information about the Pythonmac-SIG mailing list