Python return list from function

后端 未结 8 938
面向向阳花
面向向阳花 2020-12-13 08:27

I have a function that parses a file into a list. I\'m trying to return that list so I can use it in other functions.

def splitNet():
    network = []
    f         


        
8条回答
  •  北海茫月
    2020-12-13 09:19

    I assume you are not assigning the returned value to a variable in scope.

    ie. you can't do

    splitNet()
    print network
    

    instead you would

    network = splitNet()
    print network
    

    or for that matter

    my_returned_network_in_scope = splitNet()
    print my_returned_network_in_scope
    

    otherwise you could declare network outside of the splitNet function, and make it global, but that is not the recommended approach.

提交回复
热议问题