I encountered a problem today. It happened when I was creating a map for one of my 2d engines and I had something that looked like:
return[[08,07,07,07,07,07,16,07,07,07,07,07,07,07,07,06],
_______ ^
invalid token
Upon further study, I found that Octal numbers are represented by 0 then a number from 0 - 7. Since the symbol 8 and 9 don't represent anything in an octal numbering system python returns a SyntaxError: invalid token. This causes a headache for me because I need to have my maps line up under one another:
[08,07,07,07,07,07,16,07,07,07,07,07,07,07,07,06],
[01,00,00,00,14,10,22,00,00,00,00,00,00,00,00,05],
[01,19,07,06,09,00,00,00,00,00,00,08,00,00,00,05],
[01,00,00,01,09,00,00,00,00,00,00,08,00,00,00,05],
[01,00,00,01,11,10,10,19,12,00,00,09,09,09,00,05],
But to omit the leading "0" causes this:
[8,07,07,07,07,07,16,07,07,07,07,07,07,07,07,06],
[01,00,00,00,14,10,22,00,00,00,00,00,00,00,00,05],
[01,19,07,06,9,00,00,00,00,00,00,8,00,00,00,05],
[01,00,00,01,9,00,00,00,00,00,00,8,00,00,00,05],
[01,00,00,01,11,10,10,19,12,00,00,9,9,9,00,05],
messy, hunh?
To rectify the problem, I used a "." after 8 and 9 to fill up the spaces. It lines up well and if you wanted to be consistent, all your single digits can be done that way.
[8. ,07,07,07,07,07,16,07,07,07,07,07,07,07,07,06],
[01,00,00,00,14,10,22,00,00,00,00,00,00,00,00,05],
[01,19,07,06,9. ,00,00,00,00,00,00,8. ,00,00,00,05],
[01,00,00,01,9. ,00,00,00,00,00,00,8. ,00,00,00,05],
[01,00,00,01,11,10,10,19,12,00,00,9. ,9. ,9. ,00,05],
*NOTE* this "." fills up the spaces only on the Python Editor and basic textpad files. in Word or some other higher level format the "." is significantly smaller widthwise and will not line up with other items vertically. I've never used Word to make something like this, but I'm just sayin'.
So for those who have run into this exception and it's driving you nuts, I hope this was a help!
Cheers!
.:Sween:.
Sunday, December 30, 2007
Subscribe to:
Post Comments (Atom)
2 comments:
you can just use blank space.
[
1, 2, 3, 4, 5, 6, 7, 8, 9,
11, 12, 13, 14, 15, 16, 17, 18, 19,
]
Using . changes the number into floating point number, which might be undesirable for speed and representation accuracy.
[quote=
*NOTE* this "." fills up the spaces only on the Python Editor and basic textpad files. in Word or some other higher level format the "." is significantly smaller widthwise and will not line up with other items vertically. I've never used Word to make something like this, but I'm just sayin'.
]
it's not the fault of Word or Python Editor. It's the choice of fonts. Most code editors use fixed-width font as default font, the rest of the world use proportional-width font.
If you want, you could set python editor to use Times New Roman or set Word to use Courier New.
Post a Comment