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.