Migrating from PHP to Python...

Joal Heagney s713221 at student.gu.edu.au
Mon Sep 3 23:24:45 EDT 2001


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?

>>> var = 'hello'
>>> print var 'world'
  File "<stdin>", line 1
    print var 'world'
                    ^
SyntaxError: invalid syntax

The above is to demonstrate that you neet to use apostrophes. *hoping
people think that was a deliberate mistake*
>>> print var
hello
>>> print var, "world"
hello world
>>> var2 = "I'm Joal"
>>> print var, 'world', var2
hello world I'm Joal

Also, if var can be cooerced into a string, you can print it as well.
>>> var = 1
>>> str(var)
'1'
>>> print var2, "I'm no.", var, ".... Not!!!"
I'm Joal I'm no. 1 .... Not!!!
>>>

Additionally, others have pointed out the use of the % operator.

> In any case, you've made some pretty compelling arguments. I'm strongly
> leaning towards Python for my next major web app. The only thing holding me
> back really is questions I have about it's performance and scaleability. Is
> it true that Google and Yahoo Mail is built on Python?

I've heard that Google is built on python. You made a comment later on
about serverlets. As somebody pointed out, you can drop Jython into
serverlets, but I think Zope also has a server philosophy. I don't
actually know what Zope is for - something about a Network Application
Server or something. The Zope fanatics will straighten me out but will
also point out that it has a steep learning curve.
-- 
      Joal Heagney is: _____           _____
   /\ _     __   __ _    |     | _  ___  |
  /__\|\  ||   ||__ |\  || |___|/_\|___] |
 /    \ \_||__ ||___| \_|! |   |   \   \ !



More information about the Python-list mailing list