如果我将def更改为" main"我似乎无法打印任何内容。它打印正常但是当我使用def" readRecords"它似乎没有打印任何东西
import sys
import from scanner *
def readRecords():
log1 = (sys.argv[1])
log2 = (sys.argv[2])
with open(log1, 'r') as f:
print (f.readline().strip ('\n'))
for l in f:
print (l, end="")
with open(log2, 'r') as f:
print (f.readline().strip ('\n'))
for l in f:
print (l, end="")
答案 0 :(得分:1)
您需要调用该函数(并删除import语句中的语法错误)
import sys
from scanner import *
def readRecords():
log1 = (sys.argv[1])
log2 = (sys.argv[2])
with open(log1, 'r') as f:
print (f.readline().strip ('\n'))
for l in f:
print(l, end="")
with open(log2, 'r') as f:
print (f.readline().strip ('\n'))
for l in f:
print(l, end="")
readRecords()