473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Automatically creating a HOME environ variable on Windows?

Windows doesn't have a HOME environment variable, but it does have
HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically
populate os.environ with HOME, where HOME =
os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])?

If this was done, then modules such as pdb, which load resource files
from HOME, would work under Windows.

Alternatively, here is a patch to make pdb.py read .pdbrc under
Windows.

*** pdb_orig.py Mon Jun 16 01:26:30 2003
--- pdb.py Sat Oct 29 11:11:07 2005
***************
*** 65,72 ****
--- 65,76 ----

# Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
+ envHome = ''
if 'HOME' in os.environ:
envHome = os.environ['HOME']
+ elif 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ:
+ envHome = os.path.join(os.environ['HOMEDRIVE'],
os.environ['HOMEPATH'])
+ if envHome:
try:
rcFile = open(os.path.join(envHome, ".pdbrc"))
except IOError:

Oct 29 '05 #1
11 3892
ji***********@gmail.com napisa(a):
Windows doesn't have a HOME environment variable, but it does have
HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically
populate os.environ with HOME, where HOME =
os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH'])?


MS recommends using %USERPROFILE%, as the above in many cases returns
"C:\", which is wrong.

--
Jarek Zgoda
http://jpa.berlios.de/
Oct 29 '05 #2
Cool, even better. So what's best, having code to add HOME
(=USERPROFILE) to os.environ, or change the various places that HOME is
used to check for USERPROFILE?

Oct 29 '05 #3
ji***********@gmail.com wrote:
Cool, even better. So what's best, having code to add HOME
(=USERPROFILE) to os.environ, or change the various places that HOME is
used to check for USERPROFILE?


Best solution would be to have portable function that returns
user home directory and knows about all platfom quirks.

--
Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)
www.fiedzia.prv.pl

If you lost your left arm, your right arm would be left.

Oct 29 '05 #4
On Sat, 29 Oct 2005 18:43:44 +0200, Maciej Dziardziel <fi*****@fiedzia.prv.pl> wrote:
ji***********@gmail.com wrote:
Cool, even better. So what's best, having code to add HOME
(=USERPROFILE) to os.environ, or change the various places that HOME is
used to check for USERPROFILE?


Best solution would be to have portable function that returns
user home directory and knows about all platfom quirks.


Why is that better than Python creating a HOME in os.environ, if it doesn't
already exist? I can think of a few reasons it's better, and a few reasons
it's worse.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 31 '05 #5
Jorgen Grahn wrote:
Best solution would be to have portable function that returns
user home directory and knows about all platfom quirks.


Why is that better than Python creating a HOME in os.environ, if it
doesn't
already exist? I can think of a few reasons it's better, and a few
reasons it's worse.


First, it is possible that HOME viariable already exists and has different
meaning, (if python is used as embedded scripting language it can be
defined by application), Second, there is a group of path related functions
in os.path (or ntpath), including expanduser, and its better to use
function than relay on some interpreter behaviour that may be different on
jython or ironpython.

--
Maciej "Fiedzia" Dziardziel (fiedzia (at) fiedzia (dot) prv (dot) pl)
www.fiedzia.prv.pl

How come in Scooby Doo Fred and Daphne were always on the same team and
Velma, Scooby and Shaggy were always on the same team? Doesn't seem quite
right now that you think about it, does it?
Oct 31 '05 #6
On Mon, 31 Oct 2005 12:26:30 +0100, Maciej Dziardziel <fi*****@fiedzia.prv.pl> wrote:
Jorgen Grahn wrote:
Best solution would be to have portable function that returns
user home directory and knows about all platfom quirks.


Why is that better than Python creating a HOME in os.environ, if it
doesn't
already exist? I can think of a few reasons it's better, and a few
reasons it's worse.


First, it is possible that HOME viariable already exists and has different
meaning, (if python is used as embedded scripting language it can be
defined by application),


And on systems where $HOME exists, that's what this new abstraction would
have to use internally anyway, so us Unix users won't lose anything. OK, I
accept the reasoning.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 31 '05 #7
Having a function is definitely cleaner. Creating a HOME environment
variable where one does not exist in the calling shell is misleading.

There are 10 modules in the python 2.3 lib directory that contain
os.environ['HOME']:

lib\ftplib.py
lib\mailbox.py
lib\mailcap.py
lib\netrc.py
lib\ntpath.py
lib\os2emxpath.py
lib\pdb.py
lib\posixpath.py
lib\rfc822.py
lib\user.py

It's probably not a huge effort to change these (but that's easy for me
to say ...) It would be nice to start of with having a standard way to
find out what the home directory is.

Nov 1 '05 #8
> ji***********@gmail.com napisa(a):

MS recommends using %USERPROFILE%, as the above in many cases returns
"C:\", which is wrong.


I'm guessing this is why IDLE creates a directory in the root of my
Win98 system whenever I use it. It would be great if this could be
fixed for the next version.

--
Ben Sizer.

Nov 1 '05 #9
Maciej Dziardziel wrote:
...there is a group of path related functions in os.path (or
ntpath), including expanduser, and its better to use function...

On Nov 01, ji***********@gmail.com wrote: Having a function is definitely cleaner. Creating a HOME environment
variable where one does not exist in the calling shell is
misleading.
...
It would be nice to start of with having a standard way to find out
what the home directory is.


I think that is what Maciej has already pointed out.

Just to clarify then:

os.path.expanduser('~') is the universal/portable means to find a
user's home directory, regardless of platform. So use of HOME or
USERPROFILE or whatever in scripts should be discouraged.

Someone please correct me if the above is wrong. I haven't tried on a
mac, but linux and windows seem to behave well; i.e., linux looks for
HOME, and windows appears to combine HOMEDRIVE and HOMEPATH if HOME is
not set. Details are in the 2.4.2 sources' "Python24/Lib/posixpath.py"
if you're curious.

--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
Nov 1 '05 #10
Does Windows 98 have a %USERPROFILE% environment variable?

Nov 1 '05 #11
os.path.expanduser('~') is a bit cryptic for non-unix people.
os.path.gethome() or something like that would be nicer. expanduser()
should then call gethome() so the logic is in one place.

It looks like the existing logic in expanduser() is out of date anyway.
It should be updated to use %USERPROFILE% before %HOMEDRIVE% +
%HOMEPATH% .

Nov 1 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Дамјан Георгиевски | last post by:
Hi, I'm making a small PyQT app, and it will also have a config file (any type is ok) for several options. I would also like to add a gui for changing the config options but I don't want to...
1
by: Steve Wathen | last post by:
I need to create a database where each record is an invoice originally stored as a csv file. Currently these csv files are loaded in excel to display them. Each invoice has a variable number of...
3
by: Sam | last post by:
My db looks after the hiring and lending of equipment, the form which books out equipment hired prints a signout sheet and automatically inserts an appointment into outlook advising the operator on...
2
by: Phil Longworth | last post by:
Im very new to Access 97 and Im sure I should be able to do this but cant work out how. Im bulding a database for my stamp collection. I have two tables; one with details of all the individual...
5
by: Scott Simonson | last post by:
Does anyone know of a way to create import/export specifications via code? I want my users to able to create a table when needed but in order to allow importing into and exporting out of I need...
13
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
0
by: K.S.Sreeram | last post by:
Hi everybody, I'm having trouble using os.path.expanduser('~') on windows. It uses $HOME or ($HOMEDRIVE+$HOMEPATH), but this doesn't work with windows machines which are part of a domain. On...
19
by: Tony | last post by:
I'm working on project that plays movies using Windows Media Player and I'm controlling everything with JavaScript. Per the client I only need to support IE 6 or greater which happens to make...
6
siddnair54
by: siddnair54 | last post by:
Hey Guys, i have created a windows application in c#. I want to create a setup in such a way that once the application is installed, it should start automatically when the windows starts up. Can you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.