473,507 Members | 6,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run another .py file w/o exec command?

Hi everybody,

I'm sure there's a way to do this, but I can't find it. How can I execute
another .py file from my first .py file without using an exec* command?
They're both in the same directory, and it would be nice to have some
run("another.py") type statement as opposed to a big exec with absolute
pathnames and garbage like that.

It works the way I have it, but it just seems like a bad way in general to
do it. I'm runnning Python 2.3.3 on win32.

Thanks!
CaptainN

Jul 18 '05 #1
3 3985
Ca******@altel.net wrote:
Hi everybody,

I'm sure there's a way to do this, but I can't find it. How can I execute
another .py file from my first .py file without using an exec* command?
They're both in the same directory, and it would be nice to have some
run("another.py") type statement as opposed to a big exec with absolute
pathnames and garbage like that.

It works the way I have it, but it just seems like a bad way in general to
do it. I'm runnning Python 2.3.3 on win32.

Thanks!
CaptainN

I'm really new to python, but there are several ways with the import
statement:
1) If the code you want to execute is not in a class but just like this:
File: other.py
class A:
pass

print "You've called me!"

then you can just import it with "import other" and the print statement
gets executed, like any other thing at column 0
2) If 1) is not the case i.e.
File: other.py
class A:
pass

def method():
print "You've called me!"

you can import it with "import other", too and just do "other.method()"
or "from other import *" and "method()"

Christian von Essen
Jul 18 '05 #2
Hello CaptainN,
I'm sure there's a way to do this, but I can't find it. How can I execute
another .py file from my first .py file without using an exec* command?
They're both in the same directory, and it would be nice to have some
run("another.py") type statement as opposed to a big exec with absolute
pathnames and garbage like that.

http://www.python.org/doc/current/li...built-in-funcs
Search for execfile

HTH.
Miki
Jul 18 '05 #3
you can try this

import os
os.system("python example.py")
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3061
by: Andrew Crowe | last post by:
Hi guys, I'm having trouble executing commands using exec() or system() that need to write files. I've set the permissions on CMD.EXE but I can't use exec() to write any files, even if the...
0
10158
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
1
3416
by: Bego?a | last post by:
Is it possible to access a file (for example, to write in a text file) with transact-sql?. I've create a stored procedure and I'd like to write in a log file some traces depends on the result of...
3
7476
by: phantom | last post by:
Greetings, I have a sp that dumps text into a textfile but I am having trouble creating the textfile. EXEC master.dbo.xp_cmdShell '\\servername\d$\The File\sub\filename.dat' The directory...
9
3014
by: Casanova | last post by:
Hello! How can I execute other exe files from within a executable file in GCC. In TurboC 3, the spawn command executes a file and returns command to the calling file. whereas in GCC, the exec...
11
5757
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
27
5085
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
21
7796
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
4
12574
by: Tom | last post by:
I have a script which allows a user to upload a file. The script does some filename editing, mimetype checking, etc., and it's then supposed to send the file to a remote server, without any...
15
2788
by: tmp123 | last post by:
Hello, Thanks for your time. We have very big files with python commands (more or less, 500000 commands each file). It is possible to execute them command by command, like if the commands...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7314
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
7372
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...
1
7030
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
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
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,...
1
5041
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.