Pascal int()

Michal Bozon bozon at natur.cuni.cz
Fri Mar 17 15:43:58 CET 2000


On Fri, 17 Mar 2000, Jeff Pinyan wrote:

> On Mar 17, Michal Bozon said:
> 
> >I want to have a function (of course in Python) equivalent to Pascal
> >function int(). (It increments an integer stored in argument by 1).
> >
> >>>> int(i)
> >>>> int(i, 2)
> 
> First, you'd better not call it int(), because that'd cause some sillyness
> -- there's a builtin int().  For sake of argument, I'll call it inc().
> 

Im sorry, it was mistake. Of course it should be inc, not int.


>   def inc(var,i=1):
>     globals()[var] = globals()[var] + i
> 
>   foo = 20
>   inc('foo')
>   print foo  # 21
>   inc('foo',10)
>   print foo  # 31
> 

But this is not exactly what I want. I want tou use in function a variable
itself, not its name in quotes. I know that it is not simple, but I think
that there should be a better way than that you suggersted.


Michal


> Notice I passed the variable's NAME in a string.  That's the only way I've
> figured out so far to muck with a global object like a string or number
> inside a function.  I can't even assure that it's bug-free.
> 
> -- 
> MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy at pobox.com
> http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
> PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
> The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
> 




More information about the Python-list mailing list