Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread bob gailer
Please always reply all so a copy goes to the tutor list. We all 
participate and learn.


Jason DeBord wrote:

Bob,

Thanks for the reply.

When I said I don't understand the above, that was just to give you 
guys a reference for where I am at.


At my current job I rarely touch the web server. I have just been 
using php for server side development, thus, installing python and 
mod_python was new territory for me, though I managed to get it 
working surprisingly quick. As we speak I am trying to get Django up 
and running. This is proving difficult and I think I am getting ahead 
of myself.


I'm lost with the code below because up to this point all I have ever 
had to do is type in " 


OK - line - by - line commentary:

mod_python is an apache add-on that creates a "long-running" Python 
process. This means the Python interpreter is load once (maximizing 
response time) and there is memory from one invocation by a request to 
the next.



from mod_python import apache


Here mod_python is a python module that cooperates with the add-on. 
import loads the module (once) and brings the object apache from the 
module namespace into the local namespace.  The reference to apache.OK 
is resolved by looking at the imported object for a property (attribute) 
named OK.


def handler(req):
Defines a function handler. Apache by default calls handler for each 
request, and passes the request object (here named req - arbitrarily).

   req.write("Hello World!")
calls the req object's write method passing a character string. The 
write method adds the string to the response under construction.

   return apache.OK

Terminates the function and returns apache.OK (whatever that is).

I believe that returning apache.OK from the handler call tells apache 
that the request is complete and to return the page to the browser.


--
Bob Gailer
Chapel Hill NC 
919-636-4239


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Spencer Parker
You might also want to look at Pylons...its another excellent web framework
built for Python.  The community around it, I feel, is better than Django.
People are pretty willing to answer any and all questions you have.  It
gives more control to the developer as oppiosed to Django.  I just switched
from Django to Pylons...so far it fits me better.  Not for everyone...ya
know...

On Tue, Nov 25, 2008 at 5:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

> Hello All,
>
> This is my first message on the mailing list. I am excited to get started
> developing content / backend for the web with Python.
>
> I have a background in PHP, but am convinced that Python is a better, more
> powerful language.
>
> I am on a Windows XP machine and I have been using XAMPP for server, php,
> mysql...
>
> I installed Python 2.5 and mod_python successfully. I can serve pages with
> .py extension to http://localhost .
>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.
>
> Any and all advice is extremely appreciated.
>
> Thanks for your time!
>
> Sincerely,
>
> Jason
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Spencer Parker
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread W W
On Tue, Nov 25, 2008 at 6:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.


I don't know if you did much OOP (Object Oriented Programming) in PHP, or
anything else, but that's what python does, and does well. There are some
tutorials out there that explain what objects really are... but I read
somewhere that in python /everything/ is an object, and that's pretty much
true to my experience.

The line starting with from is similar to an include statement in php.
Though what you're doing is including "apache" that happens to be inside the
"mod_python" library.

The next line:

def means you're defining a function (or method, if it's in a class, where
it would be def handler(self, req), but that's another story)

handler is the name you're calling the function and req is the name of your
argument. At this point, it really doesn't matter what req is... it's just a
name that will point to (or become a copy of) whatever you pass to it.

In this case, you're passing it a class that has the method "write".
Consider this example(I'm using the IPython active interpreter, so you see
In instead of >>>):

In [15]: class foo:
   : def write(self, mystr):
   : print mystr
   :
   :

In [17]: def handler(req):
   : req.write("Hello World!")
   :
   :

In [18]: x = foo()

In [19]: handler(x)
Hello World!

And then return apache.OK is returning... well, the object "OK" in the
apache class.

Of course, I've never used mod_python/apache, that's just me applying what I
know about python, so I may not be 100% accurate, but I don't think I'm too
far off.


> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.


If you plan on doing much command line/admin type stuff, I'd recommend
"Python for Unix and Linux System Adminstration" by Noah Gift & Jeremy M.
Jones, available through O'Reilly, at least as one resource (ISBN:
978-0-596-51582-9)

Noah spoke at our un-conference in October, and I learned a lot, hence, my
recommendation.

It does a great job of throwing you into a lot of various administration
tasks, which instruction can be applied to (and is also useful for) many
other tasks.

Definitely check out the links others have provided, they'll be packed full
of helpful information, and I hope this helped as well.

-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Kent Johnson
On Tue, Nov 25, 2008 at 7:43 AM, Jason DeBord <[EMAIL PROTECTED]> wrote:

> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web?

You might start with some general Python tutorials. Try one of these
lists, depending on your background:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
http://wiki.python.org/moin/BeginnersGuide/Programmers

Presumably you have found the mod_python docs? It has a tutorial also:
http://www.modpython.org/live/current/doc-html/

You don't say why you chose mod_python...you should know that writing
directly to mod_python is not the most popular method of writing
Python web apps. It is fine for something simple but for complex apps
you might want to look at one of the Python web frameworks such as
Django, TurboGears or web.py.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread bob gailer

Jason DeBord wrote:

Hello All,

This is my first message on the mailing list. I am excited to get 
started developing content / backend for the web with Python.


I have a background in PHP, but am convinced that Python is a better, 
more powerful language.


I am on a Windows XP machine and I have been using XAMPP for server, 
php, mysql...


I installed Python 2.5 and mod_python successfully. I can serve pages 
with .py extension to http://localhost .


The following for example:

from mod_python import apache

def handler(req):
req.write("Hello World!")
return apache.OK

Frankly, I don't understand what is going on in the above. 


Exactly what don't you understand. Or ... what DO you understand. There 
is a lot to explain here. Narrowing it down will make it easier.



--
Bob Gailer
Chapel Hill NC 
919-636-4239


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Oops, I meant to say that django "has EXCELLENT documentation"

Take care,
Don

On 11/25/08, Don Jennings <[EMAIL PROTECTED]> wrote:
> Welcome! I suggest you take a look at django [1]. You'll find that it
> has documentation [2] and an active developer community [3]. Of
> course, for your questions about learning python, you've already found
> a very helpful community : >)
>
> Take care,
> Don
>
> [1]  http://www.djangoproject.com/
> [2] http://docs.djangoproject.com/en/dev/
> [3] http://www.djangoproject.com/community/
>
> On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
>> Hello All,
>>
>> This is my first message on the mailing list. I am excited to get started
>> developing content / backend for the web with Python.
>>
>> I have a background in PHP, but am convinced that Python is a better, more
>> powerful language.
>>
>> I am on a Windows XP machine and I have been using XAMPP for server, php,
>> mysql...
>>
>> I installed Python 2.5 and mod_python successfully. I can serve pages with
>> .py extension to http://localhost .
>>
>> The following for example:
>>
>> from mod_python import apache
>>
>> def handler(req):
>> req.write("Hello World!")
>> return apache.OK
>>
>> Frankly, I don't understand what is going on in the above. This is a bit
>> different compared to what I am used to.
>>
>> So, my question, would you all please point me to some introductory
>> resources, tutorials, books, that focus on Python programming for the web?
>> I
>> am eventually going to interface with some web services, notably Amazon
>> Web
>> Services. Also, I'd like to write some server side scripts to serve as a
>> backend to some Adobe AIR apps.
>>
>> Any and all advice is extremely appreciated.
>>
>> Thanks for your time!
>>
>> Sincerely,
>>
>> Jason
>>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Leaving PHP for Python

2008-11-25 Thread Don Jennings
Welcome! I suggest you take a look at django [1]. You'll find that it
has documentation [2] and an active developer community [3]. Of
course, for your questions about learning python, you've already found
a very helpful community : >)

Take care,
Don

[1]  http://www.djangoproject.com/
[2] http://docs.djangoproject.com/en/dev/
[3] http://www.djangoproject.com/community/

On 11/25/08, Jason DeBord <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> This is my first message on the mailing list. I am excited to get started
> developing content / backend for the web with Python.
>
> I have a background in PHP, but am convinced that Python is a better, more
> powerful language.
>
> I am on a Windows XP machine and I have been using XAMPP for server, php,
> mysql...
>
> I installed Python 2.5 and mod_python successfully. I can serve pages with
> .py extension to http://localhost .
>
> The following for example:
>
> from mod_python import apache
>
> def handler(req):
> req.write("Hello World!")
> return apache.OK
>
> Frankly, I don't understand what is going on in the above. This is a bit
> different compared to what I am used to.
>
> So, my question, would you all please point me to some introductory
> resources, tutorials, books, that focus on Python programming for the web? I
> am eventually going to interface with some web services, notably Amazon Web
> Services. Also, I'd like to write some server side scripts to serve as a
> backend to some Adobe AIR apps.
>
> Any and all advice is extremely appreciated.
>
> Thanks for your time!
>
> Sincerely,
>
> Jason
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Leaving PHP for Python

2008-11-25 Thread Jason DeBord
Hello All,

This is my first message on the mailing list. I am excited to get started
developing content / backend for the web with Python.

I have a background in PHP, but am convinced that Python is a better, more
powerful language.

I am on a Windows XP machine and I have been using XAMPP for server, php,
mysql...

I installed Python 2.5 and mod_python successfully. I can serve pages with
.py extension to http://localhost .

The following for example:

from mod_python import apache

def handler(req):
req.write("Hello World!")
return apache.OK

Frankly, I don't understand what is going on in the above. This is a bit
different compared to what I am used to.

So, my question, would you all please point me to some introductory
resources, tutorials, books, that focus on Python programming for the web? I
am eventually going to interface with some web services, notably Amazon Web
Services. Also, I'd like to write some server side scripts to serve as a
backend to some Adobe AIR apps.

Any and all advice is extremely appreciated.

Thanks for your time!

Sincerely,

Jason
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor