Newbie Req: Integer Handling
scarblac-spamtrap at pino.selwerd.nl
Mon Mar 20 02:30:36 CET 2000
Aesop wrote in comp.lang.python:
> Been looking for an alternative way to handle integers, such that say in
> a 3 digit number, any digit making up the number can be examined
> individually. Up until now been converting the integers to strings, then
> handling the strings, then converting back to numbers if the need be... long
> and laborious.
> What other ways are there of handling such issues? the need is for a
> crossword puzzle based around mathematical clues. Such that the second digit
> of one answer may be the first digit of another answer. Or whatever.
Well, you'll need some sort of conversion between the two (strings and ints)
anyway. Ints are mathematical, and don't care about 'digits'; you can
express ints decimally, but you could express them in another base as well.
You should make a class, so that you can still add the strings, and look at
their digits as well.
I don't have time to show the details of such a class right now.
> is it possible to set up direct pointers and indirection operators as in C
> that could be used to examine integer variables on the fly?
> as in;
> int x = 1, y = 2, z;
> int *ip;
> ip= &x; /* ip points to x */
> y= *ip; /* y = 1 */
> *ip = 0; /* x = 0 */
> ip = &z; /* ip now points to z */
> can this sort of thing be done in Python?
This questions shows that you don't really grok what a Python variable
really is, how lists work, and what assignment does. I think this is
explained well in "Learning Python" (at least, there's where I picked it up)
but you should read the thread "Pointers?" from the last week. Many people
gave an explanation of Python behavior.
Key point: everything is a reference. In other words: everything is a pointer.
But you can't always *change* the thing it points to.
Remco Gerlich, scarblac at pino.selwerd.nl
"This gubblick contains many nonsklarkish English flutzpahs, but the
overall pluggandisp can be glorked from context" (David Moser)
More information about the Python-list