473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.jo in(envHome, ".pdbrc"))
except IOError:

Oct 29 '05 #1
11 3915
ji***********@g mail.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***********@g mail.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*****@fiedzi a.prv.pl> wrote:
ji***********@g mail.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*****@fiedzi a.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.p y
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***********@g mail.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***********@g mail.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.expandu ser('~') 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.ellio tt.name
" " """
Nov 1 '05 #10

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

Similar topics

2
2016
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 make design the GUI. I'd be satisfied if the GUI is automatically generated from the config file (or config file specification). Is there some...
1
1674
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 rows and variable number of columns(see example below). The start of each row has a document reference which is the same for every line of one invoice....
3
7508
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 the due date that a particular hire is due. I have used microsoft's automated appointment code to do this, what I would also like the code to do...
2
2649
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 stamps, and one with details of covers/envelopes the stamps are fixed to. Each indivdual stamp has a specific reference number (not an auto-number). ...
5
3727
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 these specifications in place. I'd like to have it automatic somehow, possibly through a button. Thanks
13
13299
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
0
1055
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 such machines, the HOME envvar may not be set at all, and the HOMEPATH envvar may be set to '\\'!! Here's an implementation of getHomeDir which tries...
19
19235
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 things a bit easier. What I need to do is create a playlist and play it using JavaScript. I keep on getting close but not close enough to play the dang...
6
6514
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 help me with this? Can i put the application in System tray or something, or is there any other way?
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7979
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.