Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

1.10. Input/Output

1.10.1. Standard

1.10.1.1. Standard Input

sys.stdin.readline().strip()
			

1.10.1.2. Standard Output

sys.stdout.write("输出的字串")
			

1.10.2. File

		
f = open('/tmp/workfile', 'r+')
f.write('0123456789abcdef')
f.seek(5)     # Go to the 6th byte in the file
f.read(1)
f.seek(-3, 2) # Go to the 3rd byte before the end
f.read(1)
f.readline()
f.close()
		
			
for line in open("myfile.txt"):
    print line

with open("myfile.txt") as f:
    for line in f:
        print line
		

		
with open('beak', 'rb+') as f:
    content = f.read()
    f.seek(0)
    f.write(content.replace(b'\r', b''))
    f.truncate()