22 07年05月

python读书笔记-1

关键字:

特殊符号,星号(*)的作用

* 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月

python tips

关键字:,

时间转换

  1. import time 
  2. print time.strftime('%Y年%m月%d日',time.localtime()) 
  3. 20070307日 
  4. time.strptime("2002年2月2","%Y年%m月%d") 
  5. (2002, 2, 2, 0, 0, 0, 5, 33, -1) 
  6. a=time.strptime("2002年2月2","%Y年%m月%d") 
  7. print time.strftime('%Y年%m月%d日',a) 
  8. 20020202

让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月

改写地一个python利用Queue多线程干活的脚本


python用Queue多线程干活的脚本

阅读全部»

贝贝爸 发表在 原创技术文章 | 等您写评论

6 07年03月

pydev在eclipse里面的输出中文乱码的解决方案


#!/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.

贝贝爸 发表在 原创技术文章 | 等您写评论

美体小铺急救棒 the bodyshop body shop 美体小铺茶树精油 美体小铺接骨木花眼胶 美体小铺VE眼霜
11Q.0.654Ss.