---
title: "python读入文件和time/sys模块的简单使用"
author: "polyahu"
date: "2013-02-12T17:11:47Z"
tags: []
categories: ["编程语言"]
slug: "python-time-sys"
draft: false
lastmod: "2013-02-12T17:11:47Z"
id: 1797954
url: "https://polyahu.iteye.com/blog/1797954"
---

python读入文件和time/sys模块的简单使用

一些标准库函数的用法也待学习，如：os/re/sets/string/queue/socket


```python

#!/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

#!/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

#!/usr/bin/python
import sys

print sys.platform
print sys.argv[0]
print sys.argv[1]

```