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

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 3971
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
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
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
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
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
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
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
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
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
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
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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"....

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.