By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Baffled on Windows.

P: n/a
I have the following Python program:

import win32com.client
print 'Huh?' # Actually, it says something profain.
Running this program with 2.5.1 causes another Python script in
the same directory to be loaded and run (specifically the import
causes it), and a .pyc file is created from that list.

The 'other' program is called 'new.py'. Is that what's causing
my problem?

--
Neil Cerutti
Jun 7 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Neil Cerutti wrote:
I have the following Python program:

import win32com.client
print 'Huh?' # Actually, it says something profain.
Running this program with 2.5.1 causes another Python script in
the same directory to be loaded and run (specifically the import
causes it), and a .pyc file is created from that list.

The 'other' program is called 'new.py'. Is that what's causing
my problem?
A useful technique on these occasions is to use the -v
switch when starting python. If I do nothing more than
import win32com.client, watch what happens:

python -v -c "import win32com.client" 2python-startup.txt
grep "new" python-startup.txt
..
..
# c:\python24\lib\new.pyc matches c:\python24\lib\new.py
import new # precompiled from c:\python24\lib\new.pyc
# cleanup[2] new

So somewhere in there a module called "new" is being
imported from standard library and, yes, you are
shadowing that module by your own one of the same
name.

http://docs.python.org/lib/module-new.html

TJG
Jun 7 '07 #2

P: n/a
On Jun 7, 8:17 am, Neil Cerutti <horp...@yahoo.comwrote:
I have the following Python program:

Running this program with 2.5.1 causes another Python script in
the same directory to be loaded . . . 'new.py'
A good habit for naming your scripts: If you have a script and you
want to name it text.py, or list.py or new.py or old.py or some common
name that might be found in the thousand and one other modules and
programs in your various installations, just use my_text.py or
my_list.py or neil_new.py or something to reduce the chances that
you'll be shadowing without knowing it.

rick
Jun 7 '07 #3

P: n/a
BartlebyScrivener wrote:
On Jun 7, 8:17 am, Neil Cerutti <horp...@yahoo.comwrote:
.........
A good habit for naming your scripts: If you have a script and you
want to name it text.py, or list.py or new.py or old.py or some common
name that might be found in the thousand and one other modules and
programs in your various installations, just use my_text.py or
my_list.py or neil_new.py or something to reduce the chances that
you'll be shadowing without knowing it.

rick
using your advice we will start getting problems where my_new is shadowed so
then we start having to recur and we'll have names like

my_my_new.py my_my_list.py ...... my_my_my_new.py .....

I leave as an exercise the algorithm which chooses the appropriate version of
new/list to use :)
--
Robin Becker

Jun 7 '07 #4

P: n/a
On 2007-06-07, Robin Becker <ro***@reportlab.comwrote:
BartlebyScrivener wrote:
>On Jun 7, 8:17 am, Neil Cerutti <horp...@yahoo.comwrote:
........
>A good habit for naming your scripts: If you have a script and you
want to name it text.py, or list.py or new.py or old.py or some common
name that might be found in the thousand and one other modules and
programs in your various installations, just use my_text.py or
my_list.py or neil_new.py or something to reduce the chances that
you'll be shadowing without knowing it.

rick

using your advice we will start getting problems where my_new
is shadowed so then we start having to recur and we'll have
names like

my_my_new.py my_my_list.py ...... my_my_my_new.py .....

I leave as an exercise the algorithm which chooses the
appropriate version of new/list to use :)
Thanks all for the helpful replies.

I'll just memorize the names of all the Python modules in
existence to eliminate this source of errors once and for all.

Or possibly I'll just rename my scripts things whenever this
happens. ;)

--
Neil Cerutti
Jun 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.