Pascal int()

Jeff Pinyan jeffp at
Fri Mar 17 15:33:36 CET 2000

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().

  def inc(var,i=1):
    globals()[var] = globals()[var] + i

  foo = 20
  print foo  # 21
  print foo  # 31

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        
PerlMonth - An Online Perl Magazine  
The Perl Archive - Articles, Forums, etc.

More information about the Python-list mailing list