473,242 Members | 1,808 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,242 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 1065
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
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"....
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
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 =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...

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.