1. Open the file () and read it using read ().
The following example reads two files, respectively!
Reference: Exercise-14
# Coding:utf-8
From sys import ARGV # import variable parameter
script, filename = argv # unpacking variable arguments to script and filename two variables/arguments
Print u "Open File ..." # Print as Unicode output
FILE = open (filename) # is output by default in read-only form, which is open (filename, ' R ')
Print File.read () # Remember "Print" Oh!
Print U "Please enter another file name ..."
Other_file = Raw_input (">") # raw_input () for user input
Other_txt = open (Other_file)
Print Other_txt.read ()
---------------------------------------------------------------------------------
2. Another way is to create a new function with Def
# Coding:utf-8
def read (): # def: (define) definition, new function
Print U "Please enter file name:"
filename = raw_input (">")
Print u "Open file%s ..."% file
TXT = open (filename)
Print Txt.read ()
Read ()
Read ()
---------------------------------------------------------------------------------
3. Of course, we can also use the For Statement loop and DEF statements to combine
# Coding:utf-8
def read ():
For number in range (1, 3):
Print U "Please enter file%s:"% number
filename = raw_input (">")
Print U "file is open ..."
TXT = open (filename)
Print Txt.read ()
Read ()
The Art of Reading