954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Read file into 2-D List

I need to read a file that contains this:
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 2 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1

... into a 2-Dimensional python list. This list has already been built in the main function of my program. Here is the code:

def main():
        old = [ [" "]*COLUMN  for i in range(ROW)]
        user_file = input("blah blah blah: ")
        getfromfile(old,user_file)

def getfromfile(old,user_file):
      old = open(user_file, 'r')
      old = old.read()


- COLUMN is a global variable with a value of 10, the same for ROW

...When I return old to the main function and print old it just prints an empty 10x10 array. I know in this piece of code I dont return it at all, that is because I have tried multiple ways of changing the getfromfile function and for some reason I can't figure out how to actually read the file INTO the 2-D list. Any help would be greatly appreciated!

gnik2009
Newbie Poster
2 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This post is the same as http://www.daniweb.com/software-development/python/threads/398951 Take a look at it first, and then post any further questions.

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

Nice.. Chances are that post was created by one of my classmates. Thanks for the help.

gnik2009
Newbie Poster
2 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: