随笔分类 -  Python笔记

摘要:>>> import sys>>> logfile = open('e:/python/test.txt', 'a')>>> print >> logfile, 'tester logfile...'>>> logfile.close()print 语句支持将输出重定向到文件,从 pyhton2.0开始增加。 符号 >> 用来重定向输出。 阅读全文
posted @ 2013-05-11 13:31 Roger| 阅读(152) 评论(0) 推荐(0)
摘要:>>> print str(1000L)1000>>> print str('hello,world')hello,world>>> print str(1000L)1000>>> print repr('hello,world')'hello,world'>>> print repr('1000L')'1000L'str()函数:把值转换为合理形式的字符串,方便用户理解repr()函数:创建一个字符串,以合法的 python 阅读全文
posted @ 2013-05-11 11:17 Roger| 阅读(194) 评论(0) 推荐(0)
摘要:如:希望获得系统当前时间,按指定格式显示:2013-05-11 10:20:35time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())以上2行代码输出的结果一致.time.strftime():格式化字符串time.localtime():获取当前系统时间time.time():当前时间,新纪元开始后的描述,以UTC为准python中时间日期格式化符号:%y 两位数的年份表示(00-99)% 阅读全文
posted @ 2013-05-11 10:27 Roger| 阅读(195) 评论(0) 推荐(0)