Python函数参数

use*_*041 0 python

我的代码有两个问题 - 我不知道如何将我的populateArray函数与我的main函数链接; 我不确定我需要传递什么参数另外,我一直在打开要打开的文件的文件路径 - 路径是正确的,文件存在数据.这是我的代码:

network = []  

def populateArray():
    file = open('theroute.txt', 'r')
    network = []  

    for line in file:

        network.append(line)

    print "Network = "
    print network

    file.close()

def main():    
    if __name__ == "__main__":
       populateArray()
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

感谢您的回复 - 我的代码现在看起来像上面,但当我删除def main()时:我收到以下错误:

File "populateArray.py", line 18
    if __name__ == "__main__":
                             ^
IndentationError: unindent does not match any outer indentation level
Run Code Online (Sandbox Code Playgroud)

Sen*_*ran 5

删除def main():,只需将其作为:

if __name__ == "__main__":
   populateArray()
Run Code Online (Sandbox Code Playgroud)

删除def stmt后,请确保正确缩进程序.

如果您在同一目录中,也可以直接引用文件名.