First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Run multiple python files from one python file

asked Nov 20 '13

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

3 answers

Sort by » oldest newest most voted
1

answered Nov 21 '13

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

link
1

answered Nov 20 '13

nyga0082 gravatar image

updated Nov 20 '13

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.

link
0

answered Nov 21 '13

PSSEuser312 gravatar image

updated Dec 2 '13

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

link

Comments

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

nyga0082 gravatar imagenyga0082 (Nov 21 '13)

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

PSSEuser312 gravatar imagePSSEuser312 (Dec 2 '13)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Nov 20 '13

Seen: 5,143 times

Last updated: Dec 02 '13