1. read the file
file = open("README")
text = file.read()
print(text)
file.close()
2. After the file pointer will change to read the file
file = open("README")
text = file.read()
print(text)
print(len(text))
print("-" * 50)
text = file.read()
print(text)
print(len(text))
file.close()
3. Write file
file = open("README", "a")
file.write("123 hello")
file.close()
4. Branch read the file
file = open("README")
while True:
text = file.readline()
if not text:
break
print(text)
file.close()
5. Copy the file
file_read = open("README")
file_write = open("REAMDE[复件]", "w")
text = file_read.read()
file_write.write(text)
file_read.close()
file_write.close()
6. copying large files
file_read = open("README")
file_write = open("REAMDE[复件]", "w")
while True:
text = file_read.readline()
if not text:
break
file_write.write(text)
file_read.close()
file_write.close()
7.python2 string
hello_str = u"hello世界"
print(hello_str)
for c in hello_str:
print(c)
8.eval Calculator
input_str = input("请输入算术题:")
print(eval(input_str))