from os.path import expanduser

510
2
Jump to solution
06-17-2014 10:48 AM
JohnLay
Occasional Contributor
I am trying to identify the current user folder as part of a larger process. I am using the code

from os.path import expanduser HOME = expanduser("~")


If I run the script in the foreground the result is:
print HOME 'C:\Users\jlay'


However if I enable background processing the result is
print HOME 'H:\'


Can someone tell me why that is? And how to correct it?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MattEiben
Occasional Contributor
I'm not entirely sure about that behavior, but here's an alternative approach. 

# Get your current user name usrName = os.getenv('USERNAME') Home = r'C:\Users\%s' % usrName


Though this will only be useful if your path is constant and you just need to adjust for user name.

View solution in original post

0 Kudos
2 Replies
MattEiben
Occasional Contributor
I'm not entirely sure about that behavior, but here's an alternative approach. 

# Get your current user name usrName = os.getenv('USERNAME') Home = r'C:\Users\%s' % usrName


Though this will only be useful if your path is constant and you just need to adjust for user name.
0 Kudos
JohnLay
Occasional Contributor
That worked. Thanks.
0 Kudos