简体   繁体   中英

How can I write python code in a shell script such that it imports a module and runs a test on it?

How can I run python code in a shell script that imports a python module and tests that specific module?

For example: from _some_path_ import File_We_Want_To_Test

if(File_We_Want_To_Test.Function_We_Want_To_Test(a, b) == True):
   print("great!")
else:
   print("bad!")

You can use Python in your shell like this:

python -c command

Where command is a small Python program (a quoted string).

Example:

python -c "import my_module; my_module.function()"

See the page Command line and environment

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