动态格式化字符串

1
2
3
4
5
6
= [[1,2,3], [4,5,6],[7,8], [10,11,12,13,14]]
 
for in a:
  fmt = '%s ' * len(i)
  argvs = ''.join(["i[%s], " % for in range(len(i)]) 
  print fmt % eval(argvs)


获取当前登录用户

1
2
user = subprocess.Popen('who', shell=True, stdout=subprocess.PIPE)
print list(set(user.stdout.read().split()[::5]))


Mysql查询结果显示中文。

1
MySQLdb.connect(host='192.168.1.4',user='test',passwd='test',db='test', use_unicode=True, charset="utf8")  #括号里面加入 use_unicode=True, charset="utf8" 这两句。