Moving to Python from PHP - 3 questions

M

Michal Migurski

Hi everyone,

I've been planning to move to Python from PHP for some time now. I use
PHP extensively for web scripting, with mod_php, Apache, and a DB (I
would characterize my knowledge of PHP as advanced). Here are three
stumbling blocks I've experienced, for which I couldn't seem to find
any helpful information via Google:

1) Mod_python on OSX. I use a Mac as my primary development
environment, so I need mod_python to get anything done. Compiling
mod_python from source fails under OSX 10.3, and mod_python does not
appear to be included in Fink. I've found plenty of other questions
about this on other mailing lists, but so far no conclusive answers -
is mod_python on OSX currently a dead-end?

2) Session management. Cookie-based sessions in PHP are pretty
transparent, with a small library of basic functions that do 95% of
what anyone may need to store session data in serialized files and
associate them with cookies. I've seen python code that accomplishes
this, but so far no pre-built server-side session management modules.

3) Structured request variables. PHP has a really handy feature where
request variables with name like "foo[]", "foo[bar]", or
"foo[bar][baz]" are automatically structured into nested associative
arrays. I can see that the python cgi module will make a list of
MiniFieldStorage objects when more than one variable with the same name
is provided, but that's about the extent of it that I've seen.

2 & 3 are problems I can solve on my own, but they're so transparently
automatic in PHP that it's a real pleasure to use them. I can probably
implement my own fixes, but I'd rather not have to. Alternatively, are
these just "PHP-isms" for which python has a more native, more
appropriate response?

An "RTFM" answer with a URL for the M would be great. :)

Thank you,
-mike.
 
D

Diez B. Roggisch

Hi,
2) Session management. Cookie-based sessions in PHP are pretty
transparent, with a small library of basic functions that do 95% of
what anyone may need to store session data in serialized files and
associate them with cookies. I've seen python code that accomplishes
this, but so far no pre-built server-side session management modules.

The python-based zope application server has session management. Togther
with a built-in user and access rights management.
3) Structured request variables. PHP has a really handy feature where
request variables with name like "foo[]", "foo[bar]", or
"foo[bar][baz]" are automatically structured into nested associative
arrays. I can see that the python cgi module will make a list of
MiniFieldStorage objects when more than one variable with the same name
is provided, but that's about the extent of it that I've seen.


An "RTFM" answer with a URL for the M would be great. :)

For zope: http://www.zope.org/

But there are plenty of other python http frameworks. The mod_python is
AFAIK the most basic and primitive one. But build on top of it or fully
python-based you have plenty of options. Google is your friend - this NG
features similar discussions every other week.
 
M

Michal Migurski

The python-based zope application server has session management.
Togther
with a built-in user and access rights management.
...
This can be done in zope if you name a variable <name>:list. That then
will
give you the variable as list regardless of the number of occurences.

Thank you. My impression of Zope in the past has been that it does what
I need, along with 10,000 other things I don't (built in WebDAV
server?!), but clearly I owe it another chance. I've been initially
attracted to mod_python because of its raw simplicity and its apparent
similarity to mod_php and mod_perl, which I am familiar with. I'll give
Zope a try.
 
D

Diez B. Roggisch

Thank you. My impression of Zope in the past has been that it does what
I need, along with 10,000 other things I don't (built in WebDAV
server?!), but clearly I owe it another chance. I've been initially

The apache has a built in webdav server too - is that a reason _not_ to use
it? If you don't want a feature, don't use it. You can turn them off, btw.

But what you might not be aware of is that zope does not store its
templates, scripts and files in general in the filesystem as php does, but
as objects in the zodb database. So webdav and ftp are other views to that
objects that allow you to load and save these files using "normal" editors
and tools, not only the web-interface of zope. The advantage of this
approach is that versioning of content - regardless of it's type - is
built-in. Can be a life-saver sometimes :)
attracted to mod_python because of its raw simplicity and its apparent
similarity to mod_php and mod_perl, which I am familiar with.

It certainly is the most simple way to create dynamic content. But there is
a big difference between python and php: php started as a web-developers
tool, and it's features are a direct consequence of that. python oth is a
general purpose programming language - it is certainly suited for web
development, but not limited to. There are people who also want to use php
as general purpose programming language - but nevertheless, its design has
been influenced by its main purpose. So you e.g. get session state handling
"for free" - as more or less _all_ web-apps today need them.
 
B

Brian Beck

Michal said:
Thank you. My impression of Zope in the past has been that it does what
I need, along with 10,000 other things I don't (built in WebDAV
server?!), but clearly I owe it another chance. I've been initially
attracted to mod_python because of its raw simplicity and its apparent
similarity to mod_php and mod_perl, which I am familiar with. I'll give
Zope a try.

Personally, I'd have to say that your impression was right. Once you
start using Zope, you'll start to feel locked in. Sure, it does a lot
for you, but it's also a big investment.

I can't really help you to get mod_python working on OS X, but
concerning your other two points, did you notice these two sections in
the documentation?

http://modpython.org/live/current/doc-html/pyapi-sess.html

http://modpython.org/live/current/doc-html/pyapi-mprequest.html

mod_python and Zope are not your only options by far. In fact, they're
at completely opposite ends of the spectrum; mod_python being low-level
in that you are in control of everything and have the necessary tools to
build a framework, and Zope being the highest-level in that it does tons
of stuff for you. There are dozens of frameworks in between.

If you do manage to get mod_python working, I suggest taking a look at
Vampire as well: http://www.dscpl.com.au/projects/vampire/
I have had good experience with it. Once you start using mod_python
you'll realize you can really go anywhere you want; and that's not
necessarily a good thing. Vampire points you in a nice direction (I
don't want to say 'the right' direction).
 
J

Joe Francia

Michal said:
Thank you. My impression of Zope in the past has been that it does what
I need, along with 10,000 other things I don't (built in WebDAV
server?!), but clearly I owe it another chance. I've been initially
attracted to mod_python because of its raw simplicity and its apparent
similarity to mod_php and mod_perl, which I am familiar with. I'll give
Zope a try.

I am moving my band's website from an antiquated and horrible PHPNuke
site to a Python-based site, and so have done quite a bit of research
about this (though I never considered myself a PHP expert). Here's what
I've come up with...

Zope is excellent (especially with Plone), but if you are not building
applications that require lots of levels of access and permissions and
collaborations, as well as the 10,000 other things you speak of, you
probably would like something simpler than Zope, such as CherryPy or
Quixote. Both are excellent and light-weight frameworks that give you
session support and easy access to request variables (as well as full
access to the entire Python language). Conceptually, the two are very
close, but I am slightly more biased towards CherryPy lately. Quixote
has better built in form support, but now that I've discovered FormKit,
this seems to becoming a non-issue. Also, both are pure Python so
should run anywhere Python does (though Quixote has a C extension, it
will fallback to a somewhat slower pure-Python version if your platform
cannot compile the extension).

There are other good frameworks out there, like Nevow and Webware, but
have a somewhat larger conceptual overhead which doesn't rest as easy
with me. You'll also want to probably look at some of the templating
kits, of which Cheetah and/or ElementTree work best for me. (Well,
ElementTree isn't exactly a templating kit - it's a general-purpose XML
tookit - but it is easily used for templating.)

General Python web programming:
http://www.python.org/topics/web/

Frameworks/toolkits:
[CherryPy] http://www.cherrypy.org/
[Quixote] http://www.mems-exchange.com/software/quixote
[FormKit] http://dalchemy.com/opensource/formkit/
[Cheetah] http://www.cheetahtemplate.org/
[ElementTree] http://effbot.org/zone/element-index.htm
[Nevow] http://nevow.com/
[Webware] http://www.webwareforpython.org/

For more comparisons of some of the various frameworks:
[PyWebOff] http://pyre.third-bit.com/pyweb/index.html
[Python Web Shootout (older)] http://www.colorstudy.com/docs/shootout.html
 
M

Michal Migurski

Thank you. My impression of Zope in the past has been that it does
I am moving my band's website from an antiquated and horrible PHPNuke
site to a Python-based site, and so have done quite a bit of research
about this (though I never considered myself a PHP expert). Here's
what I've come up with...
[snip]

This is awesome, quote a bit to chew on. Thank you Joe!
 
F

Fredrik Lundh

Joe said:
You'll also want to probably look at some of the templating kits, of which Cheetah and/or
ElementTree work best for me. (Well, ElementTree isn't exactly a templating kit - it's a
general-purpose XML tookit - but it is easily used for templating.)

if you want element-based templating, see:

http://lesscode.org/projects/kid/

</F>
 
B

bruno modulix

Michal said:
Thank you. My impression of Zope in the past has been that it does what
I need, along with 10,000 other things I don't (built in WebDAV
server?!),

Our web designer just *loves* it (and ZopePageTemplates too, since they
work quite ok with it's favorite html editor...). Might not be useful to
you, but...
but clearly I owe it another chance. I've been initially
attracted to mod_python because of its raw simplicity and its apparent
similarity to mod_php and mod_perl, which I am familiar with. I'll give
Zope a try.

Zope is a great product, but hard to get into, and it's sometime just
too big and fat for some simple things. So while it may be worth giving
it a try, I would not recommend it for all and any project.

Now when it comes to session management and the like, there are many
other libs/frameworks/etc based on mod_python.

This might be a good start :
http://www.python.org/topics/web/

HTH
 
G

grahamd

Michal said:
3) Structured request variables. PHP has a really handy feature where
request variables with name like "foo[]", "foo[bar]", or
"foo[bar][baz]" are automatically structured into nested associative
arrays. I can see that the python cgi module will make a list of
MiniFieldStorage objects when more than one variable with the same
name

Someone already piped in by suggesting Vampire for mod_python, so
would add that Vampire supports structured form variables by making
use of:

http://svn.colorstudy.com/trunk/Validator/validator/variabledecode.py

Thus, if you follow the form naming conventions this code supports,
then data can be turned into lists and dictionaries as appropriate. The
only thing is the naming convention is different to what you list
above.
Read the comments in linked code to see what it does actually use.
 
G

grahamd

If you do manage to get mod_python working, I suggest taking a look
at
Vampire as well: http://www.dscpl.com.au/projects/vampire/
I have had good experience with it. Once you start using mod_python
you'll realize you can really go anywhere you want; and that's not
necessarily a good thing. Vampire points you in a nice direction (I
don't want to say 'the right' direction).

Vampire is still in a growing phase, so would be interested to hear any
comments you may have about how it can be improved. Up until now
I have mainly been focusing on making the basic features of mod_python
just that bit easier to use.

And yes I know that a lot more documentation would be a good start.
I am so snowed under with work in my real job at the moment that
progress is slow in that respect. :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top