【发布时间】:2013-10-09 05:41:48
【问题描述】:
这是程序:
import sys
def IndexSearchString():
'''
This function search a string in a password file through index and gives the result.
:return: none
:return type: none
:author: Neeraj
'''
fieldindex = int(sys.argv[1])-1
stringsrch = sys.argv[2]
file_name = open("passwd", "r")
for store_file in file_name:
temp = store_file.split(":")
search = temp[fieldindex]
#print search
if stringsrch in search:
print store_file
#print sys.stdout.write(store_file)
return
#IndexSearchString()
【问题讨论】:
-
很抱歉,您必须更具体地说明您的问题。
-
如果我删除最后一行 IndexSearchStrind() 并运行程序,它会被执行。
-
我的意思是如果不定义函数,程序甚至会被执行。我是python的新手。
-
请,告诉我们“正常工作”是什么意思。如果我执行上面的代码,并注释最后一行,它将运行但什么也不做。在我看来,这工作正常。如果您有其他定义,则需要说明。
-
然后发生了三件事之一。 1)您的缩进不正确(如建议但 DanielB 的回答)。 2)在添加评论(如@Bakuriu 建议)后,您实际上并没有保存它,或者 3)您在其他地方调用该函数。因为你是对的,如果你不调用函数,函数体就无法运行。
标签: python function python-2.6