Linux中关于ipython

安装:

pip install ipython
获取mysql binlog 日志中的关键值:
mysql slave binlog position:master host '10.173.33.35' ,filename 'mysql-bin.000002',position '524993060'
ipython
line = "mysql slave binlog position:master host '10.173.33.35' ,filename 'mysql-bin.000002',position '524993060'"
In [7]: line.split("'")
Out[7]:
['mysql slave binlog position:master host ',
'10.173.33.35',
' ,filename ',
'mysql-bin.000002',
',position ',
'524993060',
'']
In [11]: host=line.split("'")[1]
In [12]: filename=line.split("'")[3]
In [13]: position=line.split("'")[5]
In [14]: print(host,filename,position)
10.173.33.35 mysql-bin.000002 524993060

查看模块函数及查看帮助:

import os
?os.path.is*
In [16]: ?os.path.is*
os.path.isabs
os.path.isdir
os.path.isfile
os.path.islink
os.path.ismount

In [17]: os.path.isfile?
Signature: os.path.isfile(path)
Docstring: Test whether a path is a regular file
File:      /usr/lib64/python3.6/genericpath.py
Type:      function

字典转换json

In [23]: d=dict(a=1,b=2,c=3)
In [24]: json.dumps(d)
Out[24]: '{"a": 1, "b": 2, "c": 3}'

查看所有magic函数:

In [25]: %lsmagic
Out[25]:
Available line magics:
%alias  %alias_magic  %autoawait  %autocall  %autoindent  %automagic  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %cp  %cpaste  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %paste  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode
Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile	

与操作系统交互

!cmd 形式可以执行任何linux命令
也可以通过这种方式捕获命令的输出:
In [41]: data = !df
In [42]: data
Out[42]: ['文件系统          1K-块    已用     可用 已用% 挂载点', 'devtmpfs        1897860       0  1897860    0% /dev', 'tmpfs           1913168      24  1913144    1% /dev/shm', 'tmpfs           1913168     416  1912752    1% /run', 'tmpfs           1913168       0  1913168    0% /sys/fs/cgroup', '/dev/vda1      61860632 4048436 55195532    7% /', 'tmpfs            382632       0   382632    0% /run/user/0']
data[1].split()[4]
Out[45]: '0%'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值