Python Function Argument -


i having 2 issues code - not sure how link populatearray function main function; i'm not sure argument need pass also, have been having trouble file path of file opened - path correct , file exists data in. here code:

network = []    def populatearray():     file = open('theroute.txt', 'r')     network = []        line in file:          network.append(line)      print "network = "     print network      file.close()  def main():         if __name__ == "__main__":        populatearray() 

any appreciated!

thanks replies - code looks above, when remove def main(): following error:

file "populatearray.py", line 18     if __name__ == "__main__":                              ^ indentationerror: unindent not match outer indentation level 

remove line 5 (the "network=[]") , def main() don't need. , pass network argument populatearray function , work.

network = []    def populatearray(network):     file = open('theroute.txt', 'r')      line in file:         network.append(line)         file.close()   if __name__ == "__main__":         print "start"         populatearray(network)         print "network = "         print network 

for file path: no path, pointing @ python home directory (e.g. c:\python27 python 2.7)

if use / points root directory. point home directory point directory (e.g /home/myuserid/theroute.txt or /users/myuserid/theroute.txt)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -