Python - Script

Card Puncher Data Processing

About

Language - Script in Python are source file that can be run.

Structure

Main / Entry point

Python - 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] 

See Python - Command Line Argument

Path

Path of the script itself

import os 
script_path = os.path.realpath(__file__)
script_dir_path = os.path.dirname(script_path)

Argument

Python - Command Line Argument

Type

gui_scripts

In Python - setup.py

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

Python - Startup script for the console ( )

Management

Run

With python

If you are in a virtual environment, see virtualenv - run a script

# -m run library module as a script (terminates option list)
python -m module
  • source read from script file)
python file
python -
python -c cmd 

#Example:
python -c "print('Hello')"

Search Path

Installation of package as Scripts

Example:

  • Global: C:\Users\gerard\AppData\Roaming\Python\Python37\Scripts
  • User: UserPath\Python37\Scripts





Discover More
Card Puncher Data Processing
Python - Command Line Argument

Python provides command-line arguments through the list sys.argv (from the sys module) where: sys.argv[0] is the script name sys.argv[n] is the argument n Therefore len(sys.argv) is the number of...
Card Puncher Data Processing
Python - Engine

How Python works. Mode: or interactive via the console.
Card Puncher Data Processing
Python - Project

Project in Python as describe by The project name is specified in the name properties in the setup function of the setup.py file Project are a set of file to package a package.: one package...
Idea Python Scientific Mode
Python - Running Python Script in (Scientific|Cell) Mode with IDEA Intellij

Running Python Script in (Scientific|Cell) Mode with IDEA Intellij Intellij IDEA can using the scientific view: show plot and data run and debug cell to get the scientific module The matplotlib...
Card Puncher Data Processing
Python - Startup script for the console ( )

The environment variable named points the name of a file containing your start-up commands. This file is only read in interactive sessions, not from a script. If you want to read an additional start-up...
Card Puncher Data Processing
Python - The python interpreter

The main function of the python interpreter is to run a script. See script Global or in a virtual environment see
Card Puncher Data Processing
Python - Wheel Archive (whl - bdist_wheel)

Wheel is a compiled archive format with the .whl extension. A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster...
Card Puncher Data Processing
Python - virtualenv (Python Environment / venv)

Python Virtual Environments allow Python packages to be installed in an isolated location for a particular project, rather than being installed globally. By default (without virtual environment), all...
Card Puncher Data Processing
Python Package - Module

On a file system, package are the directories and modules are the files within this directories. A module is a file that contains structure definitions including : variables class and functions....



Share this page:
Follow us:
Task Runner