-1

Hello,

I am stuck on how I have pass function arguments to the main method of my program. Here is my code:

network = []  

def populateArray():
      
        file = open('C:\\My Documents\\route.txt', 'r')
        for line in file:
            network.append(line)
            
        print "Network = "
        print network
        
        
def main():

    if __name__ == "__main__":
       main()

I am not sure how I link the two functions together

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by richieking
Featured Replies
  • 1

    [QUOTE=kinto;1476758]Hello, I am stuck on how I have pass function arguments to the main method of my program. Here is my code: [CODE]network = [] def populateArray(): file = open('C:\\My Documents\\route.txt', 'r') for line in file: network.append(line) print "Network = " print network def main(): if __name__ == "__main__": main() … Read More

1

Hello,

I am stuck on how I have pass function arguments to the main method of my program. Here is my code:

network = []  

def populateArray():
      
        file = open('C:\\My Documents\\route.txt', 'r')
        for line in file:
            network.append(line)
            
        print "Network = "
        print network
        
        
def main():

    if __name__ == "__main__":
       main()

I am not sure how I link the two functions together

network = []  

def populate_array():
      
    file_ = open('C:\\My Documents\\route.txt')
    for line in file_:
        network.append(line)
          
    print "Network = "
    print network

    file_.close()
        

if __name__ == "__main__":
    populate_array()

Edited by pyTony: n/a

-1

Thanks for replying - I have an additional question regarding Linux
I want to open a file on my Linux desktop, but when I run my program nothing works:

network = []  



def populateArray():

      

        file = open('/home/harvey/Desktop/theroute.txt', 'r')

        for line in file:

            network.append(line)

            

        print "Network = "

        print network



        file.close()

        

        

def main():



    if __name__ == "__main__":

       populateArray()

I have entered the correct path but alas, nothing happens when I run

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.