不错的有关Python 函数笔记(转)
2013-11-27 22:32
531 查看
原文地址:http://blog.csdn.net/oyzl68/article/details/8020982
1. os.linesep是干什么的? os.linesep字符串给出当前平台使用的行终止符。例如,Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'。 3.使用随机数 >>> import random >>> print random.uniform(1,10) 3.65089367909 4.有的IDE可以打断点,PYDEV就可以,利用pdb可以单步调试 5.print smtplib.encode_base64('yi') 6.scapy ——网络包构建分析框架,可编程的wireshark,有兴趣的google “Silver Needle in the Skype” 7.python的安装 # rm -f /usr/bin/python # ln -s ~/Desktop/python /usr/bin/python 9.查询某个导入类的方法 dir(email.generator) help(email.generator.Generator) 10.打印当前时间 print (datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')) 11.python3.0 中去掉了raw_input 函数,改用input。 12.python3.0 已经不支持了 apply(self.func,self.args) 改为 self.func(*self.args) 13.py3的encode与decode >>> print ('中国'.encode('utf-8')) b'\xe4\xb8\xad\xe5\x9b\xbd' >>> print (b'\xe4\xb8\xad\xe5\x9b\xbd'.decode('utf-8')) 中国 >>>print (b'\u8bf7\u8f93\u5165\u95ee\u9898\u7b54\u6848'.decode('unicode-escape')) 请输入问题答案 subject='\u8bf7\u8f93\u5165\u95ee\u9898\u7b54\u6848' subject = bytes(subject,'gb2312').decode('unicode-escape') >>>print subject 解决中文通用办法 froms=froms.encode('raw_unicode_escape', 'ignore').decode('GB18030', 'ignore') 14.urlencode >>> import urllib >>> urllib.unquote("myemail%40gmail.com") #py2.7 >>>urllib.parse.unquote("myemail%40gmail.com") #py3.0 15.把一个py文件编译为pyc文件了。 import py_compile py_compile.compile(r'H:\game\test.py') #windows环境下 py_compile.compile('wbm_sina.py') # Linux环境 16.时间格式化 >>> date='Wed, 11 Apr 2012 09:37:05 +0800' >>> dd=datetime.datetime.strptime(date,'%a, %d %b %Y %H:%M:%S %z') >>> dd.strftime('%Y-%m-%d %H:%M:%S') 17.html解码 #html和url解码 def HTMLDecode(html): return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '\"').replace("'", '\'') 18.文件以指定格式打开 fp = open(msgfile,encoding='gb18030')
相关文章推荐
- Python字符串格式化
- Python字符与数字的相互转换
- python视频教学笔记 中谷教育
- 用python开发android应用 【转载】
- python c
- fodera安装numpy库
- Python核心编程--学习笔记--5--数字
- Python 循环小结,写给自己的
- 简要说明python的一些基本知识(三)
- python hadoop 在streaming中获取文件名的方法 (参考java )适用: MRjob
- python Mongo环境安装,笔记
- Python 代码性能优化技巧
- python输出excel能够识别的utf-8格式csv文件
- python--流程控制语句
- python--数据类型
- Python--变量/运算符/表达式
- python--脚本语言
- python列表 字符串 转换
- Python的系统管理_07_python_自动下载图片示例
- python安全管理子进程-subprocess