Join GitHub today
Change python command for the default path #122
So far we use the 'HOME' variable for the default oemof path.
import os homepath = os.environ['HOME'] oemofpath = os.path.join(homepath, '.oemof')
This does not work on Windows because by default the 'HOME' variable is not set on Windows by default. A typical variable using Windows is 'USERPROFILE'.
Another way is to use
For Linux both variables lead to the same result:
I think the first one is nicer, but the second one prevents us from using if-clauses and different default files.
@oemof/oemof-main What do you think?
So, I found an old (18.104.22.168) ActivePython version on my Windows 7 machine at work, and I get the following results:
ActivePython 22.214.171.124 (ActiveState Software Inc.) based on Python 2.7.5 (default, Sep 16 2013, 23:16:52) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import os >>> import os.path as osp >>> sys.platform 'win32' # Apparently os.envrion... and os.path.expanduser... give the same results here. >>> os.environ['USERPROFILE'] 'C:\\Users\\username-changed-to-protect-the-innocent' >>> osp.expanduser("~") 'C:\\Users\\username-changed-to-protect-the-innocent' # Just checking that the HOME environment variable is indeed not defined, so expanduser # doesn't pick up spurious stuff not existing on other machines. >>> os.environ['HOME'] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "I:\nstallation-location-changed-to-protect-the-innocent\lib\os.py", line 423, in __getitem__ return self.data[key.upper()] KeyError: 'HOME'
So at least here,
referenced this issue
Mar 23, 2016
So I checked some Python distributions on Windos 7 and they all seem to behave as expected. Thumbs up means that the correct directory, i.e.
They even all report
I don't mind the behaviour like
The only drawback would be that different oemof-users at the same windows machine might overwrite their .oemof-files.
But maybe we can circumvent this by using a user-exclusive file name.
Oh, I missed another post from @uvchik :
For me, this would be one argument more for expanduser. If Windows XP is the only OS with the behaviour