Ask Your Question
0

Run multiple python files from one python file

asked 2013-11-20 11:16:58 -0500

anonymous user

Anonymous

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

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
1

answered 2013-11-21 10:17:56 -0500

yfwing gravatar image

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();

edit flag offensive delete link more
1

answered 2013-11-20 14:55:18 -0500

nyga0082 gravatar image

updated 2013-11-20 14:55:48 -0500

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.

edit flag offensive delete link more
0

answered 2013-11-21 09:08:25 -0500

PSSEuser312 gravatar image

updated 2013-12-02 11:08:17 -0500

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

edit flag offensive delete link more

Comments

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

nyga0082 gravatar imagenyga0082 ( 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 gravatar imagePSSEuser312 ( 2013-12-02 11:07:08 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2013-11-20 11:16:58 -0500

Seen: 5,079 times

Last updated: Dec 02 '13