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

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 5 Years Ago by pyTony: n/a

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.