0

Run multiple python files from one python file

Hi there, I am wondering if anyone knows how you can run multiple python scripts from a main one. I know you can do what I am trying to do with idevs by using the "@Input" command followed by the idev you want to run in the main idev. ( Example @Input File.idv will run the idev File.idv on the basecase). Thanks for your help

anonymous user
asked 2013-11-20 11:16:58 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

3 Answers

1

Use the 'import' statement.

For example, if I have prog1.py that contains:

print 'test 1'

and I run prog2.py which contains:

import prog1
print 'test 2'

My output would be:

test 1

test 2

Importing a module or another program will automatically execute that program upon import.

nyga0082's avatar
106
nyga0082
answered 2013-11-20 14:55:18 -0500, updated 2013-11-20 14:55:48 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
1

You can try to use 'exec' statement in Python. This statement supports dynamic execution of Python code. The first expression should evaluate to either a string, an open file object, or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). [1] If it is an open file, the file is parsed until EOF and executed. If it is a code object, it is simply executed.

Example:

fid = open(r'C:\xxx\yyy.py'); exec(fid); fid.close();

yfwing's avatar
436
yfwing
answered 2013-11-21 10:17:56 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

Thanks nyga0082 I did this exact same procedure but i am still getting the same error. It is as if PSSE can no longer access the psspy library for python. Please let me know if you have ever encounter this and what the fix is. Thanks again,

Edited to add: The exec statement works well. Thanks all for answering

PSSEuser312's avatar
3
PSSEuser312
answered 2013-11-21 09:08:25 -0500, updated 2013-12-02 11:08:17 -0500
edit flag offensive 0 remove flag delete link

Comments

Are you actually able to import PSSPY? What's the error message you're getting?

nyga0082's avatar nyga0082 (2013-11-21 15:22:34 -0500) edit

Thanks nyga0082. I have been able to do it with the exec statement as mentionned by yfwing. Thanks again

PSSEuser312's avatar PSSEuser312 (2013-12-02 11:07:08 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer