About
Language - Script in Python are source file that can be run.
Articles Related
Structure
Main / Entry point
Shebang
On Linux, begin your scripts with your interpreter. See How to write a Linux Script (Shebang)?
#! /usr/local/bin/python
or
#! /usr/bin/python
You can find them by executing the whereis commando:
$ whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
Properties
Name
sys.argv[0] is the script name
sys.argv[0]
Path
Path of the script itself
import os
script_path = os.path.realpath(__file__)
script_dir_path = os.path.dirname(script_path)
Argument
Type
gui_scripts
Example: declaration of a GUI script called baz
setup(
# other arguments here...
entry_points={
'gui_scripts': [
'baz = my_package_gui:start_func',
]
}
)
console_scripts
setuptools generates scripts for you with the correct extension (on Windows an .exe file, no need to create an file association)
Distributions can specify console_scripts entry points in Python - setup.py, each referring to a function which can be used as a command
When a console_scripts aware installer such as pip installs the distribution, it will create a command-line wrapper for each entry point.
Example: declaration of two console scripts called foo and bar,
setup(
# other arguments here...
entry_points={
'console_scripts': [
'foo = my_package.some_module:main_func',
'bar = other_module:some_func',
]
}
)
More … automatic-script-creation
startup
Management
Run
With python
If you are in a virtual environment, see virtualenv - run a script
- source read from a Python Package - Module
# -m run library module as a script (terminates option list)
python -m module
- source read from script file)
python file
python -
- source read from a string
python -c cmd
#Example:
python -c "print('Hello')"
Search Path
Installation of package as Scripts
Example: