python read single file operation

Python reads a single file, refer to Section 15 of "The Stupid Method of Python".

 

The operation mode is to use: python python file name The file name to be read

in code

script, filename = argv

agrv is to get parameters, to understand the usage of sys.argv.

 

Code example to read a file:

 1 from sys import argv
 2 
 3 script, filename = argv
 4 
 5 txt = open(filename)
 6 print("Here's your file %r:" % filename)
 7 print(txt.read())
 8 
 9 print("Type the file again:")
10 file_again = input("> ")
11 
12 txt_again = open(file_again)
13 print(txt_again.read())

Running steps:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324776030&siteId=291194637