473,406 Members | 2,710 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,406 software developers and data experts.

Running Win XP application programs.or Python .py file from script

From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

I have tried a lot of things, including importing a python.py file
such as, CooperPairs.py, which only has print statements.
This module is not a function, and should not be compiled.

import CooperPairs
( Runs one time).

Also, I have used import os to start Windows applications.

import os
os.startfile(r'C:\Bk2CDNFS\Test.xls')

When I try this for Python modules, I get this error,

"Not a valid Win32 application"
Sep 16 '06 #1
2 2465
I found a partial answer from the built-in function,
execfile('CooperPair.py', globals() )

This does execute in a new shell, which behaviour I do want sometimes,

but my shell is already open when I respond to an input prompt, and I want the file to execute in this same shell, so that all variables will still be defined.

From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

I have tried a lot of things, including importing a python.py file
such as, CooperPairs.py, which only has print statements.
This module is not a function, and should not be compiled.

import CooperPairs
( Runs one time).

Also, I have used import os to start Windows applications.

import os
os.startfile(r'C:\Bk2CDNFS\Test.xls')

When I try this for Python modules, I get this error,

"Not a valid Win32 application"
Sep 17 '06 #2
bartonc
6,596 Expert 4TB
1) The best way to re-run code is to start thinking about "scripts" as modules of your program. Then in your module define a function like this:

In MyModule.py you would write:

def MyFunc():
[put the code that is in the "script" here]

Then you can either:

import MyModule
MyModule.MyFunc()

or:

from MyModule import *
MyFunc()

2) I can't reproduce the error message that you are getting from os.startfile().

What version of Python are you running? Does Python (command line) show up in your Start menu?

From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

I have tried a lot of things, including importing a python.py file
such as, CooperPairs.py, which only has print statements.
This module is not a function, and should not be compiled.

import CooperPairs
( Runs one time).

Also, I have used import os to start Windows applications.

import os
os.startfile(r'C:\Bk2CDNFS\Test.xls')

When I try this for Python modules, I get this error,

"Not a valid Win32 application"
Sep 19 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Crose, Carol | last post by:
I need to test some lsof source code and have loaded Flawfinder 1.22 to test it. Flawfinder required Python 1.5 or better so I loaded Python 2.2.3. This is all running on an HPUX 11.11 server. ...
2
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
8
by: Darren Dale | last post by:
Is there a place to put python programs so I dont have to refer to the absolute path everytime I want to call them? For example: if I am in /home/me and want to execute: python...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
2
by: Benjamin Rutt | last post by:
I often execute a long-running python script which is a "driver" for my application; it may run for several hours on a large input. Under CPython, is it safe for me to modify the Python script...
13
by: John Salerno | last post by:
If I want to write my code in a separate text editor (I like UltraEdit) but then press a single button to have that code run in the IDLE environment, is that possible? I know that you can configure...
2
by: Heikki Toivonen | last post by:
We have successfully used a script to run external programs for several years. Now we upgraded our Python to 2.5, and are hitting a mysterious error. The expected output from the sample script...
9
by: Jimmy | last post by:
Well, i know it may be a little non-python thing, however, I can think of no place better to post this question :) can anyone tell me, in python, how to obtain some information of a running...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.