473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Moving to Python from PHP - 3 questions

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.

------------------------------------------------------
michal migurski- contact info, blog, and pgp key:
sf/ca http://mike.teczno.com/contact.html

Jul 18 '05 #1
11 1660
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.
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.

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.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
> 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.

------------------------------------------------------
michal migurski- contact info, blog, and pgp key:
sf/ca http://mike.teczno.com/contact.html

Jul 18 '05 #3
> 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.
--
Regards,

Diez B. Roggisch
Jul 18 '05 #4
Michal Migurski wrote:
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/do...yapi-sess.html

http://modpython.org/live/current/do...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).

--
Brian Beck
Adventurer of the First Order
Jul 18 '05 #5
Maybe this can help you get it working on OS X:
http://thread.gmane.org/gmane.comp.p...od-python/4039

But as stated in my other post, you may want to take a look at your
other options first. Web development with Python is really nothing like
PHP, unless you really want it to be.

--
Brian Beck
Adventurer of the First Order
Jul 18 '05 #6
Michal Migurski wrote:
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

--
Soraia: http://www.soraia.com

Jul 18 '05 #7
>> 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...

[snip]

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

------------------------------------------------------
michal migurski- contact info, blog, and pgp key:
sf/ca http://mike.teczno.com/contact.html

Jul 18 '05 #8
Joe Francia wrote:
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>

Jul 18 '05 #9
Michal Migurski wrote:
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?!),


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
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 18 '05 #10

Michal Migurski wrote:
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/Vali...iabledecode.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.

Jul 18 '05 #11
> 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. :-(

Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
1
by: Dark Cowherd | last post by:
Hi, We program in Delphi in our shop and are generally very happy with it. We are now looking at cross-platform options especially for middle tier and web server. I have been doing a lot of...
9
by: Norm Goertzen | last post by:
I've posted a previous question about IDEs and got some good feedback, thanks, but it does seem that everyone has their own favourite IDE -- in other words, no IDE was repeatedly recommended. ...
16
by: Kenneth McDonald | last post by:
For unfortunate reasons, I'm considering switching back to Win XP (from OS X) as my "main" system. Windows has so many annoyances that I can only compare it to driving in the Bay Area at rush hour...
3
by: Just Me | last post by:
If I move the mouse cursor over a control and stop moving I get a MouseHover event. If I then move the cursor while staying within the control and then stop moving I do not get another...
2
by: 63q2o4i02 | last post by:
Hi, I'm using python 2.4 and windows XP. I have two packages in the windows version of python in site-packages. They are PyVisa and ctypes, and both live in c:\python24\lib\site-packages ...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.