[Tutor] Array indexing

Joe Abbey joe.abbey at gmail.com
Tue Jan 16 17:28:49 CET 2007


I'm using Active Python v2.4.3.11 on a Windows XP machine.

Probably more relevant is that I'm just learning Python, as in I've been
writing Python for less than 24 hours.

While trying to implement a PE parser, I ran into the following problem:

#************** START CODE*******************
data = file.read(128);
directoryTable = struct.unpack('LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL', data);
print "Export table           0x%08X + 0x%08x" % (directoryTable[i+=1],
print "Import table           0x%08X + 0x%08x" % (directoryTable[i+=1],
#************** END CODE*******************

This code throws a syntax error at the first i+=1 on "line 4".

Why is this the case?

It seems like it would be very useful to be able to increment an index after
referencing into an array.

Is my approach busted?  Is there a better way to reference elements?

The "fix" I'm currently using is to write the index I want:

(directoryTable[0], directoryTable[1])

I was hoping someone on this list could point me in the right direction.

Thanks in advance!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070116/2c03f3b3/attachment.html 

More information about the Tutor mailing list