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()

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

You have the def main() left and you are not calling the main anywhere.

yea

def main()

it inactive..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.