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: 11 3889 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/
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? 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.
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!
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?
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!
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.
> 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.
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
" " """
Does Windows 98 have a %USERPROFILE% environment variable?
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% . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
by: Nagib Abi Fadel |
last post by:
Is it possible to create a session variable for each user in Postresql ??
Thx
|
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...
|
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...
|
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...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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...
| |