Migrating from PHP to Python...

Joal Heagney s713221 at student.gu.edu.au
Tue Sep 4 02:19:55 EDT 2001


Ignacio Vazquez-Abrams wrote:
> 
> On Tue, 4 Sep 2001, Joal Heagney wrote:
> 
> > Rick Shin wrote:
> > >
> > > >
> > > > All variables in python are dynamic type. Is that what you were asking?
> > > >
> > > > >>> a=1
> > > > >>> a
> > > > 1
> > > > >>> a = 'hello'
> > > > >>> a
> > > > 'hello'
> > >
> > > Actually, I was referring to PHP's ability to assign names dynamically to
> > > variables. For example:
> > >
> > > $var = 'hello';
> > > $$var = 'world!';
> > > echo $var . ' ' . $$var;    // prints 'hello world!'
> > > echo $var . ' ' . $hello;    // prints 'hello world!' too
> >
> > You mean like this?
> >
> >  [snip]
> >
> 
> Sorry Joal, Rick meant exactly what he wrote.
> 
> It's just that the concept of a variable variable name usually isn't used in
> programming, so when most people encounter it, they feel that there's
> something wrong with the code.
> 
> You can simulate it in Python using globals():
> 
> ---
> >>> var='hello'
> >>> globals()[var]='world!'
> >>> print '%s %s' % (var, globals()[var])
> hello world!
> >>> print '%s %s' % (var, hello)
> hello world!
> >>>

Yeah. I sorted that out oh, about three seconds after I pushed the
"Send" button. Then I spent the next half hour trying a variety of ways
to get a python phpvar before deciding to wait until I had some lunch.
--
      Joal Heagney is: _____           _____
   /\ _     __   __ _    |     | _  ___  |
  /__\|\  ||   ||__ |\  || |___|/_\|___] |
 /    \ \_||__ ||___| \_|! |   |   \   \ !



More information about the Python-list mailing list