Exercise18、19、20、218(自定义函数, 操作文件相关函数)

ex18.py

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)



ex19.py

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Can give function straight numbers, variable, math, combine math and variable.


ex20.py

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

ex20_test.py

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

1、current_file = open(input_file),print current_file

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

2、f.seek(0), 使文件指针回到文件头。"moves the file to the 0 byte (first byte) in the file"

3、f.read(), 读取全部文档,文件指针到最后。

4、f.readline(), 读取文件的一行,每次使用得到新的一行。"reading a line from the file and moving the read head to right after the \n that ends that line."

5、打印f.readline(), 行与行之间有空格。

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

原因: “The readline() function returns the\n thats in the file at the end of that line.”

解决办法: ”Add a end = "" at the end of“of your print function calls to avoid adding double \n to every line ”

  Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)



ex21.py

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)

Exercise18、19、20、218(自定义函数, 操作文件相关函数)