IPYTHON entry-level instance in Python

Source: Internet
Author: User
This article mainly introduces how to use IPYTHON in Python. It gives a detailed analysis of IPYTHON configuration and usage skills, which has some reference value, for more information about IPYTHON in Python, see the following example. Share it with you for your reference. The specific analysis is as follows:

1. Use the TAB complementing Function

2. Configure IPYTHON

The. ipython directory contains a file named ipy_user_conf.py. This is a simple user configuration file using Python syntax.

3. Magic Functions

Lsmagic can list all magic Functions
Or % Yes.

Magic itself can view the help of magic Functions

You can also use the magic function to directly follow the hello form, such as % page?

The starting part of % quickref is a reference to various IPython usage. The rest of % quickref is a mini summary of the % magic function, including the first line of all help information.

4. execute system commands

Embedded shell commands such as ls cd alias

alias nss netstat -lptn

Another method that can easily execute shell commands is to add an exclamation point (!) before the command (!)
You can use $ to pass variables to shell commands.

user = 'mouren'process = 'bash'!ps aux|grep $user |grep process

Who view definition Variables
Who int: int variable
Whos DISPLAY variable value
Who_ls return list
Who_ls int
Reset delete all variables

View history

Hist

5. mix and match system commands and python Variables

Convert system commands to python Variables

myfile = !ls

Directly !! Ls to list objects

The python variable in {} can be used together with system commands.

In [1]: pyvar = 'Hello world'In [2]: !echo "A python variable: {pyvar}"A python variable: Hello worldIn [3]: import mathIn [4]: x = 8In [5]: !echo {math.factorial(x)}40320

You can also use $ to identify python variables.

In [6]: !echo $sys.argv[/home/fperez/usr/bin/ipython]In [7]: !echo "A system variable: $$HOME" # Use $$ for literal $A system variable: /home/fperez

I hope this article will help you with Python programming.

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.