471,348 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Baffled on Windows.

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
4 1020
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
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
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
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.

Similar topics

4 posts views Thread by Mark Thomas | last post: by
10 posts views Thread by Damien | last post: by
5 posts views Thread by =?Utf-8?B?Q2hhcmxlc0E=?= | last post: by

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.