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

Ask Your Question
0

How to run two py files

asked Jun 24 '1

Nan_MX96 gravatar image

How can I first run a py file to open some files and then another py file to run a task. How to run 2 py files or more.

2 answers

Sort by » oldest newest most voted
0

answered Jun 24 '1

perolofl gravatar image

A python script can be executed by another python script with execfile. Use a main script to execute the two scripts. For example:

execfile('file1.py')
execfile('file2.py')
link

Comments

@jconto@perolofl I have not worked with codes, as it is possible to execute the two files py in PSS E 34. With a py I want to open several files and then make adjustments in parameters and with another py I want to execute the dynamic simulation. To save time.

Nan_MX96 gravatar imageNan_MX96 (Jun 24 '1)

If the second py needs data from the first py (or wait to finish), then there is no saving in time. It is still a sequential process. It is the dynamic simulation itself that takes the most time in a dynamic study. Use a single file in a parallel process. Do post-processing separate.

jconto gravatar imagejconto (Jun 25 '1)
0

answered Jun 24 '1

jconto gravatar image

Open separate CMD windows and run pythoni in windowi. The problem arises if both python scripts need to interact between them.

Another option is to use "subprocess" or "multiprocessing" (as a 'parent') to better control multiple tasks executed by different other scripts ('child' processes)

link

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: Jun 24 '1

Seen: 265 times

Last updated: Jun 24 '21