osx - Executable Python Program with Multiple Functions (MacOS) -
i seek advise regarding python.
i created main.py using python calls multiple functions, located in separate python script files. i'd create executable files in macos , found command:
chmod +x main.py
however, since main.py calls function, can't run gave me error. kindly advise how link function scripts main script.
thanks.
i'm not sure issue , since there isn't lot of detail i'm going start beginning:
the command chmod +x main.py
indicating system file main.py
executable file. since main.py
isn't program can executed, going have tell osx how run script have created. shebang comes in shebang (unix).
at top of script going need put following line:
#!/usr/bin/env python
this tell computer pass main.py
script python execution.
now onto import stuff. python going in following locations when use import
statement see python docs more info:
the directory containing input script (or current directory when no file specified).
pythonpath
(a list of directory names, same syntax shell variablepath
).the installation-dependent default.
so if had module foo.py
function bar
, place foo.py
in same directory main.py
, can following in main.py
script.
#!/usr/bin/env python import foo foo.bar() <-- run bar function defined in foo.py
alternatively following in main.py:
#!/usr/bin/env python foo import bar bar() <-- run bar function defined in foo.py
Comments
Post a Comment