[Tutor] Nested list access?
I've got a bit of code here that's giving me some trouble. I am trying to make a 2 dimensional array with nested lists, but when I try to change one element, it changes all the elements in that "column". --begin code-- width = 7 depth = 6 board = [['.']*width]*depth def printBoard(board): 'Prints out the 6 x 7 board' for i in board: #print board for j in i: print j, print return printBoard(board) print board[0][4]='X' #I think this is the line I'm having trouble with print board printBoard(board) --end code-- Here's some of the output in question: . . . . X . . . . . . X . . . . . . X . . . . . . X . . . . . . X . . . . . . X . . I'm trying to get it to make only one 'X'. Any hints? it feels kind of like a syntax error on my part... -- chuk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Getting a binary value from a file
Okay, I actually can load the value fine, but then I'm not sure how to do anything with it. I have a file full of "integers". If I get a file handle (e.g. file1) and then read something in, I get back some hex value. How can I go on to use that in my program? For example, in interactive mode, file1.read(4) gets me an output of '/x00/x00/x00/x1c' (might not be exact, I'm at a different computer right now). Can I just store that in a variable and then somehow convert it to decimal? Sorry if this is too newbish. -- chuk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor