简体   繁体   中英

run PY script from another python script

me again with another noob question as I go along my path of learning python.

I have a py script....it runs fine...but now i want to call another one I have written and execute that during a try/catch block. The other script runs alone, but just importing it isnt going to do anything to execute whats in the external script....

how do I go about that?

I think I just need to go about battling it and suck it up, but wondered if anyone had some tips or pointers to some examples.

Importing a.py file into another will not execute the code from the imported file; it will only make the functions and variables from the imported file available for use by the importing file, but the functions still need to be called.

So your importing file could look like this:

import imported_file 

imported_file.foo()

(Assuming the imported_file has a function called foo() ).

If you want to avoid typing imported_file over and over again each time you want to call one of its functions, you can give it an abbreviation:

import imported_file as if

if.foo()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM