Change the method of the Python command line Interactive prompt.

Source: Internet
Author: User

Change the method of the Python command line Interactive prompt.

I. Customize the Python interactive prompt

The default interactive prompt of Python is ">>>", but it can be customized.

After Python is started, find the PYTHONSTARTUP environment variable and then execute the Execution Code specified by the variable in this file.

Some Linux release packages provide the default startup script, which is generally stored in the home directory named. pythonstartup. The "Tab complete" and "command history" functions enhance the prompt application, both of which are based on the readline module.

If you do not have the. pythonstartup file, you can create one by yourself.

Simple Example:
Copy codeThe Code is as follows:
# Python startup file
Import readline
Import rlcompleter
Import atexit
Import OS
# Tab completion
Readline. parse_and_bind ('tab: complete ')
# History file
Histfile = OS. path. join (OS. environ ['home'], '. pythonhistory ')
Try:
Readline. read_history_file (histfile)
Handle t IOError:
Pass
Atexit. register (readline. write_history_file, histfile)
Del OS, histfile, readline, rlcompleter

You can set it to .pythonstartupat http://pypi.python.org/pypi/pbp.scripts.

Set the PYTHONSTARTUP environment variable

If you are running Python in Linux or Mac OS X, the easiest way is to create a STARTUP script and save it to the home directory.
Connect to the environment variable PYTHONSTARTUP and set it to the system startup script. For example, in Bash and Korn shell, you can use the. profile file. You can insert rows, for example:
Export PYTHONSTARTUP = ~ /. Pythonstartup
In windows, you can easily set the PYTHONSTARTUP gold variable.

Ii. iPython

See iPython: http://ipython.scipy.org
IPython aims to create a comprehensive environment for interactive applications and research and computing. IPython has two main components:

1) An enhanced Python Interactive shell
2) interactive parallel computing architecture

IPython open-source, current version: 0.9.1. It is an enhanced shell of Python. Features:

-Dynamic Object check
-Access the system shell from the prompt
-Direct support for Profiling
-Convenient debugging

Iii. Python distutils

Python comes with a set of tools distutils for publishing Python applications. It provides:

1. a skeleton
Provides standard metadata domains, such as the author name and License type.

2. A set of Helper
Understand how to create a release package.

Distutils does not provide the ability to define other dependent packages, which is enhanced by the setuptools tool.

Setuptools framework, which is a sub-project of Python Enterprise Application Kit (PEAK. Setuptools replaces the standard distutils library and adds version-based packages and dependency management for Python.

Perl users are familiar with CPAN, while Ruby users are familiar with Gems. The ez_setup tool of setuptools and the extended easy_install and Cheeseshop (Python Package Index, also known as "PyPI. In addition, setuptools also allows us to package our library into a package called "egg", which is similar to Java? The JAR file is similar, but it is used in Python.

To install setuptools, use EasyInstall.
EasyInstall is a package download tool and installer. EasyInstall is a supplement to the setuptools tool because it knows how to process build a package.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.