Home >Backend Development >Python Tutorial >Python reads files and simple use of time/sys module

Python reads files and simple use of time/sys module

巴扎黑
巴扎黑Original
2016-12-09 14:30:571901browse

Simple use of python to read files and time/sys module

The usage of some standard library functions also needs to be learned, such as: os/re/sets/string/queue/socket

Python code

#!/usr/bin/python  
  
print ord('a')  
print chr(97)  
#字符和整型互相转换  
  
fp = open("file.tmp")  
for line in fp.readlines():  
  print line,  
#文件操作readlines()函数一次读入多行,循环输出  
for line in fp:  
  print line,



Python code

#!/usr/bin/python  
import time  
#time模块使用  
  
print time.localtime().tm_year  
#time.struct_time(tm_year/tm_mon/tm_mday/tm_hour/tm_min/tm_sec/  
#tm_wday/tm_yday/tm_isdst)  
print time.asctime()  
#time() localtime() gmtime() ctime() strftime() strptime()   
#clock() sleep()



Python code

#!/usr/bin/python  
import sys  
  
print sys.platform  
print sys.argv[0]  
print sys.argv[1]


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:python modify filesNext article:python modify files