我对 python 有点陌生,我正在尝试编写这个脚本来取消超过 1 mb 的打印作业。(它检查大小的行设置为 1 mb 只是为了确保它正常工作)。出于某种原因,我最后一个 else 语句一直说它的语法无效。我检查了是否所有括号都关闭了,我找不到一对不匹配的。有人可以告诉我为什么它说它无效吗?你也可以看看我的第 24 行 (fullname = ...grep...) 以确保上面的语法是正确的吗?
#! /usr/bin/python
import os
infile = open ('test.pl', 'r')
outfile = open('print.reportpython', 'w+')
newfile = infile.readlines()
newfile.pop(0)
count = 0
firstline = newfile[0]
splitline = firstline.split()
currentuser = splitline[1]
currentuser = str(currentuser)
for line in newfile:
newline = line.split()
names = newline[1]
size = int(newline[2])
names = str(names)
print names
if names is currentuser:
if size >= 1:
os.popen ("cancel lab01-10292")
fullname = os.popen("cat /etc/passwd |grep " + newline[1] + "cut -d':' -f5")
count += 1
print count
else:
print outfile.write ("(" + currentuser + ")")
print outfile.write (" ")
count = 0
currentuser = names