473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 1067
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Thomas | last post by:
Hi I do not understand why the following does not compile under Visual C++ 7.1. It is just a simple "Hello, World" program. // Hello World Application. Why does this fail? #include <iostream>...
13
by: s_m_b | last post by:
I'm building a suite of online forms for insurance. These have been stripped down from messy MS Word templates, and two of the six, substantially identical, are misbehaving with the .js page that...
2
by: Bob Graham | last post by:
When my applications hit certain types of errors, it shows me a box that says if I enable JIT debugging in the machine.config file, the code will break into a debugger instead of showing me the...
10
by: Damien | last post by:
I am a complete newbie to .net. I have just built a simple Stopwatch Application but when I F5 to get things going I get this message popping up. An unhandled exception of type...
5
by: =?Utf-8?B?Q2hhcmxlc0E=?= | last post by:
Hi folks, I will try my best to clarify what should be a simple thing to solve: I've got XP pro sp2 VS 2005 Team system and .Net 2.0 with ASP.net and C# I've got the compilation...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.