472,111 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

os.path.expanduser('~/foo') and MSWindows "My Documents"

On *nix, ~/foo refers to a file in a user's home directory. On
MSWindows, users normally look at "My Documents" in their home
directory. ISTM that a file that my program would put in ~/. on Linux
should be put in "~/My Documents/" (modulo os.path.normpath()) on
MSWindows, where a user would expect it. How do you guys cope with this
issue?
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #1
8 2189
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...

Regards,

jim

Nov 22 '05 #2
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...

Regards,

jim

Nov 22 '05 #3
In article <11**********************@o13g2000cwo.googlegroups .com>,
ji*******@gmail.com wrote:
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...


Sounds good, thanks. I'll read up on it all tomorrow.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #4
In article <11**********************@o13g2000cwo.googlegroups .com>,
ji*******@gmail.com wrote:
Try this:
from win32com.shell import shell, shellcon
HOMEDIR = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_PERSONAL)
myfile_location = os.path.join(HOMEDIR, myfile_name)

Define a HOMEDIR for your various platforms (use sys.platform to figure
out what choice to make) and the rest of your code should not need to
care where "home" is...


Sounds good, thanks. I'll read up on it all tomorrow.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #5
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


:-)

Dalius

Nov 22 '05 #6
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


:-)

Dalius

Nov 22 '05 #7
In article <11**********************@g44g2000cwa.googlegroups .com>,
da*****************@gmail.com wrote:
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


platform looks good.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #8
In article <11**********************@g44g2000cwa.googlegroups .com>,
da*****************@gmail.com wrote:
python
import os
help(os.path.expanduser)
import platform
platform.system() 'Windows' platform.release() 'XP'


platform looks good.
__________________________________________________ ______________________
TonyN.:' *firstname*nlsnews@georgea*lastname*.com
' <http://www.georgeanelson.com/>
Nov 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jonas Auken | last post: by
9 posts views Thread by Clinton Frankland | last post: by
reply views Thread by Tony Nelson | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.