打印记录有问题

时间:2014-03-13 20:11:28

标签: python loops printing

如果我将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="")

1 个答案:

答案 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()