22
07年05月
特殊符号,星号(*)的作用
* unpacking argument lists
分解开list类型的参数
** unpacking argument dicts
分解开dict类型的参数
iteritems()
retrieved the key and value of dict
上述函数可以得到dict的key和value
python怎么取得系统环境变量的值?
os.environ.get(’path’)
python中导入模块搜索的顺序
1当前目录
2pythonpath
3,path
4install dir
怎么修改python的提示符用
修改sys.ps1,sys.ps2的值
添加搜索模块的目录
sys.path.append
看对象都有什么方法和属性
dir以及dir(__builtin__)
repr
repr函数用来取得对象的规范字符串表示。反引号(也称转换符)可以完成相同的功能。
格式化输出的函数
ljust,rjust,center,zfile
for,while loop 可以和else组合使用
try…except可以后边加上else
else必须在所有的excep后边,当try里面没有异常的时候,执行else的语句,可以避免截获不属于保护代码里面的异常。
确保关闭文件的读文件方法
with open("mf.txt") as f:
for l in f:
print l
贝贝爸 发表在 原创技术文章 |
7
07年03月
时间转换
- import time
- print time.strftime('%Y年%m月%d日',time.localtime())
- 2007年03月07日
- time.strptime("2002年2月2","%Y年%m月%d")
- (2002, 2, 2, 0, 0, 0, 5, 33, -1)
- a=time.strptime("2002年2月2","%Y年%m月%d")
- print time.strftime('%Y年%m月%d日',a)
- 2002年02月02日
让idle使用utf-8编码
设定Options/General/Default Source Encoding/UTF-8 来支持
python怎么copy文件
>>> import shutil
>>> dir(shutil)
['Error', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '_samefi
le', 'abspath', 'copy', 'copy2', 'copyfile', 'copyfileobj', 'copymode', 'copysta
t', 'copytree', 'destinsrc', 'move', 'os', 'rmtree', 'stat', 'sys']
>>> shutil.copyfile('d:/c.sql','d:/cc.sql')
>>>
python怎么copy目录
>>> import shutil
>>> shutil.copytree('d:/test','d:/testd')
>>>
贝贝爸 发表在 原创技术文章 |
6
07年03月
#!/usr/bin/python
# -*- coding: utf-8 -*-
print "中文"
输出
涓枃
看了一下帮助,eclipse console default的encoding是GBK,需要设置console的encoding为utf-8方法
Console encoding
The console can be configured to display output using a character encoding different from the default encoding. To set the console encoding for an application, use the Console Encoding settings on the Common tab of a launch configuration.
贝贝爸 发表在 原创技术文章 |