答:
1.可以指定open(file, mode=‘r’, buffering=None, encoding=None, errors=None, newline=None, closefd=True),其中encoding: 一般使用utf8。
2.
"""
Input file
test.txt
Output file
['general-purpose,', 'object-oriented,']
"""
def longest_word(filename):
f=open(filename)
a=f.read()
a=a.split()
print(a)
long=''
for line in a:
if len(line)>len(long):
long=line
for line in a:
if len(line)==len(long):
print(line)
pass