上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 59 下一页

2018年4月3日

[Python] 利用commands模块执行Linux shell命令

摘要: 用Python写运维脚本时,经常需要执行linux shell的命令,Python中的commands模块专门用于调用Linux shell命令,并返回状态和结果,下面是commands模块的3个主要函数: 1. commands.getoutput('shell command') 执行shell 阅读全文

posted @ 2018-04-03 11:48 星河赵 阅读(5158) 评论(0) 推荐(0)

Mac Terminal菜鸟篇之使用unrar解压rar文件

摘要: 在Mac上的归档工具不能够解压rar文件,这时可以使用终端中的unrar来解决问题。 步骤如下: 1.使用Homebrew安装unrar(有关Homebrew的安装和使用见Homebrew) [plain] view plain copy $ brew install unrar ==> Downl 阅读全文

posted @ 2018-04-03 09:52 星河赵 阅读(468) 评论(0) 推荐(0)

2018年4月2日

python 字典格式嵌套,相同项做叠加

摘要: all_dict = {} for tg_id in ['com.qq_a','com.qq_b','com.qq_c','com.qq_c']: tmp_dict = all_dict.get(tg_id,{'times':0}) tmp_dict['times'] += 123 all_dict[tg_id] = tmp_dict print(all_dict)... 阅读全文

posted @ 2018-04-02 21:22 星河赵 阅读(374) 评论(0) 推荐(0)

linux环境变量设置 以及 source命令 Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程 Linux 设置环境变量

摘要: 定制环境变量 环境变量是和Shell紧密相关的,用户登录系统后就启动了一个Shell。对于Linux来说一般是bash,但也可以重新设定或切换到其它的Shell。环境变量文件:/etc/profile。 环境变量是通过Shell命令来设置的,设置好的环境变量又可以被所有当前用户所运行的程序所使用。对 阅读全文

posted @ 2018-04-02 20:24 星河赵 阅读(1468) 评论(0) 推荐(0)

python URLObject url处理模块

摘要: 1、需求来源 给一个url串,例如https://github.com/zacharyvoase/urlobject?spam=eggs#foo,想要截取串中某个部分,比如传输协议(https)、服务器名称、用户名密码、路径信息、后面query等。自己能想到的主要由以下几种方法: (1)正则 (2) 阅读全文

posted @ 2018-04-02 19:09 星河赵 阅读(1396) 评论(0) 推荐(0)

python 在Unicode和普通字符串 str 之间转换

摘要: unicodestring = u"Hello world" # 将Unicode转化为普通Python字符串:"encode" utf8string = unicodestring.encode("utf-8") asciistring = unicodestring.encode("ascii") isostring = unicodestring.encode("ISO-88... 阅读全文

posted @ 2018-04-02 15:44 星河赵 阅读(10488) 评论(0) 推荐(0)

2018年3月30日

python两个字典合并,两个list合并

摘要: 1.两个字典:a={'a':1,'b':2,'c':3} b= {'aa':11,'bb':22,'cc':33} 合并1:dict(a,**b) 操作如下: 合并2:dict(a.items()+b.items()) 如下: 合并3:c = {} c.update(a) c.update(b) 输 阅读全文

posted @ 2018-03-30 11:41 星河赵 阅读(44280) 评论(0) 推荐(1)

2018年3月29日

Mac 命令行安装mysql homebrew 安装mysql后,如何配置mysql

摘要: 非常好 强力推荐 这个是我最新并且一直推崇的方法:1、安装:sunyichaodeMacBook-Pro:~ sunyichao$ brew install mysql2、开启mysql:mysql.server start2、使用mysql的配置脚本:/usr/local/opt/mysql/bi 阅读全文

posted @ 2018-03-29 18:59 星河赵 阅读(375) 评论(0) 推荐(0)

python 将字符串转换为字典

摘要: json越来越流行,通过python获取到json格式的字符串后,可以通过eval函数转换成dict格式: >>> a='{"name":"yct","age":10}' >>> eval(a) {'age': 10, 'name': 'yct'} >>> a='{"name":"yct","age 阅读全文

posted @ 2018-03-29 15:26 星河赵 阅读(226) 评论(0) 推荐(0)

python 高阶函数 map lambda filter等

摘要: map 描述 map() 会根据提供的函数对指定序列做映射。 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。 map计算两个列表各个元素的平方 提供两个列表对相同位置的元素相加 阅读全文

posted @ 2018-03-29 14:31 星河赵 阅读(156) 评论(0) 推荐(0)

上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 59 下一页

导航