473,473 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

2.4->2.5 current directory change?

This appears to be a change in behavior from Python 2.4 to Python 2.5,
which I can't find documented anywhere. It may be windows only, or
related to Windows behavior.

In 2.4, the current directory (os.curdir) was on sys.path. In 2.5, it
appears to be the base directory of the running script. For example,
if you execute the file testme.py in your current working directory,
'' is on sys.path. If you execute c:\Python25\Scripts\testme.py, '' is
*not* on sys.path, and C:\Python25\Scripts is.

That means if you run a Python script located in another directory,
modules/etc in your current working directory will not be found. This
makes .py scripts in the PYTHONHOME\Scripts file moderately useless,
because they won't find anything in the current working directory.
I first noticed this because it breaks Trial, but I'm sure there are
other scripts affected by it. Is this desirable behavior? Is there
anything to work around it except by pushing os.curdir onto sys.path?
Feb 26 '07 #1
3 3175
On Feb 26, 7:44 pm, "Chris Mellon" <arka...@gmail.comwrote:
This appears to be a change in behavior from Python 2.4 to Python 2.5,
which I can't find documented anywhere. It may be windows only, or
related to Windows behavior.

In 2.4, the current directory (os.curdir) was on sys.path. In 2.5, it
appears to be the base directory of the running script. For example,
if you execute the file testme.py in your current working directory,
'' is on sys.path. If you execute c:\Python25\Scripts\testme.py, '' is
*not* on sys.path, and C:\Python25\Scripts is.

That means if you run a Python script located in another directory,
modules/etc in your current working directory will not be found. This
makes .py scripts in the PYTHONHOME\Scripts file moderately useless,
because they won't find anything in the current working directory.

I first noticed this because it breaks Trial, but I'm sure there are
other scripts affected by it. Is this desirable behavior? Is there
anything to work around it except by pushing os.curdir onto sys.path?

The change was intentional and is mentioned in the NEWS file:

- Patch #1232023: Stop including current directory in search path
on Windows.

This unifies Python's behaviour across different platforms; the
docs always said that the current directory is inserted *only*
if the script directory is unavailable:

As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or
if the script is read from standard input), path[0] is the empty
string, which directs Python to search modules in the current
directory first. Notice that the script directory is inserted
before the entries inserted as a result of PYTHONPATH.

The old behaviour was never intentional and wasn't desired,
because users could break an application simply by running it
from a directory that contained inappropriately named files.

For details see the bug report and patch submission:
http://www.python.org/sf/1526785
http://www.python.org/sf/1232023

Ziga

Feb 26 '07 #2
On 26 Feb 2007 13:00:55 -0800, Ziga Seilnacht <zi************@gmail.comwrote:
On Feb 26, 7:44 pm, "Chris Mellon" <arka...@gmail.comwrote:
This appears to be a change in behavior from Python 2.4 to Python 2.5,
which I can't find documented anywhere. It may be windows only, or
related to Windows behavior.

In 2.4, the current directory (os.curdir) was on sys.path. In 2.5, it
appears to be the base directory of the running script. For example,
if you execute the file testme.py in your current working directory,
'' is on sys.path. If you execute c:\Python25\Scripts\testme.py, '' is
*not* on sys.path, and C:\Python25\Scripts is.

That means if you run a Python script located in another directory,
modules/etc in your current working directory will not be found. This
makes .py scripts in the PYTHONHOME\Scripts file moderately useless,
because they won't find anything in the current working directory.

I first noticed this because it breaks Trial, but I'm sure there are
other scripts affected by it. Is this desirable behavior? Is there
anything to work around it except by pushing os.curdir onto sys.path?


The change was intentional and is mentioned in the NEWS file:

- Patch #1232023: Stop including current directory in search path
on Windows.

This unifies Python's behaviour across different platforms; the
docs always said that the current directory is inserted *only*
if the script directory is unavailable:

As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to
invoke the Python interpreter. If the script directory is not
available (e.g. if the interpreter is invoked interactively or
if the script is read from standard input), path[0] is the empty
string, which directs Python to search modules in the current
directory first. Notice that the script directory is inserted
before the entries inserted as a result of PYTHONPATH.

The old behaviour was never intentional and wasn't desired,
because users could break an application simply by running it
from a directory that contained inappropriately named files.

For details see the bug report and patch submission:
http://www.python.org/sf/1526785
http://www.python.org/sf/1232023

Ziga
Considering that it's a backwards incompatible breaking change
(although I understand why it was done), you'd think it deserved
mention in the more prominent "Whats new in Python 2.5" section on the
website, in addition to a one-liner in the NEWS file. Ah well, while
I'm sure I'm not the only one who ran into it, it doesn't seem to be
causing mass calamity and I know now.
Feb 26 '07 #3
Chris Mellon wrote:
Considering that it's a backwards incompatible breaking change
(although I understand why it was done), you'd think it deserved
mention in the more prominent "Whats new in Python 2.5" section on the
website, in addition to a one-liner in the NEWS file. Ah well, while
I'm sure I'm not the only one who ran into it, it doesn't seem to be
causing mass calamity and I know now.
I guess that most of the scripts that want curdir on path and work
on different platforms already have to include current directory
manualy. Twisted's preamble in Trial does that too, but it is too
cautious to work on Windows (line 15 in the trial script):

if hasattr(os, "getuid") and os.getuid() != 0:
sys.path.insert(0, os.curdir)

Maybe that can be changed to:

if not hasattr(os, "getuid") or os.getuid() != 0:
sys.path.insert(0, os.curdir)

I'm no security expert, and I don't know if there are other
operating systems that don't have getuid() function but have
a superuser, but this doesn't look that less secure to me.

Ziga

Feb 26 '07 #4

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

Similar topics

3
by: Daniel | last post by:
How do you get the current directory of the actual .exe file (not the file name but the directory it is in) ? These do not work: System.IO.Directory.GetCurrentDirectory() - returns system...
1
by: Philip | last post by:
what controls the "current directory" path just prior to loading a aspx DLL ?.... and can it be changed via web.config ? -- Philip
3
by: Alur | last post by:
Changing the current directory with the help of dialog window(MFC app) We can change directory with the help of the following code: CFileDialog m_ldFile(TRUE);...
2
by: Andy B. | last post by:
I've got a python utility that I want to change my shell's current directory based on criteria it finds. I've scoured google and the python cookbook and can't seem to figure out if this is even...
3
by: Progman | last post by:
I use Visual Studio 2005 When I run msgbox Curdir(), I get the visual studio directory. This problem seems to be only in the VB part. In the ASP, we use ~/etc... to access files. Why I...
4
by: Wayne | last post by:
about href links to other html pages in current directory: w3c seems to recommond using ./pagename and just pagename works too. Is there any actual difference in these two? I think no in...
2
by: mhwang111 | last post by:
I have a Java application which is interfacing with a Windows ActiveX control (using a third party tool named JacoZoom). The problem I'm encountering is that the ActiveX control is writing out to a...
6
by: titan.nyquist | last post by:
The WebBrowser control won't load a css file written in the same directory as the program. If I put an absolute path to it, it will load it. Thus, the current directory of the WebBrowser control...
8
by: Mateusz Viste | last post by:
Hi, I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)... ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.