Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100107

Re: Understanding Python from a PHP coder's perspective

From Cameron Simpson <cs@zip.com.au>
Newsgroups comp.lang.python
Subject Re: Understanding Python from a PHP coder's perspective
Date 2015-12-08 08:33 +1100
Message-ID <mailman.29.1449524055.12405.python-list@python.org> (permalink)
References <f39f97f5-d7a1-4d7c-a7ac-527c2ffff76b@googlegroups.com>

Show all headers | View raw


On 07Dec2015 13:07, villascape@gmail.com <villascape@gmail.com> wrote:
>Hello all!  Just started getting into Python, and am very excited about the prospect.
>
>I am struggling on some general concepts.  My past experience with server-side code is mostly limited to PHP and websites.  I have some file called "whatever.php", the browser accesses it, and PHP parses it and returns HTML, JSON, etc.  Every now and then, I need to run some background PHP script, or have some PHP script initiated by a CRON job, or have some PHP script initiated by the command line running in an endless loop, and while it works, feel other languages might be more appropriate.
>
>So, my interest in Python...
>
>I've read up on Python, and while some aspects seem similar to PHP, some don't.  I have learned how to create Python script, have run it from the command line, and have even accessed it with Apache by placing http://example.com/myscript.py in the browser.  I am used to seeing .php extensions, but never .py extentions, and even visited multiple sites which I knew were written in Python, but never saw the browser expose the .py extensions.  I am obviously missing something.

The most obvious thing is: a well produced website does not expose its 
implementation language in the URL. All those .php URLs? Sloppy! Suppose you 
wanted to change the implementation and switched languages? All your users' 
bookmarks would break!

>Why don't I see the .py extension in my browser?

Usually Python is used in a web server via a WSGI plugin and a framework of 
some kind (Django, Flask, CheryPy etc). All of these allow you to associate any 
URL with any piece of Python code. So you don't have that simple but also 
inflexible "map this URL to a specific .php file" model that you have with 
typical PHP.

>Is Python event driven like PHP, or is it somehow different?

Depends what you mean by "event driven". I suspect you mean "accessing a web 
page runs a python program".

A .php file is a kind of macro file: it is ostensibly HTML until one hits the 
<?php tag, and then a snippet of PHP runs and usually writes some output into 
the HTML stream going back to the browser. You very rarely see PHP 
"standalone", used to write command line tools or other things - it is almost 
only ever used to generate web page output.

Python is a general purpose language and all manner of things are written in 
it. When used in a web server there is usually:

  - a WGSI hook into the web server configuration, which causes certain URLs to 
    be passed to a running Python program for implementation

  - a Python program which maps those URLs to particular pieces of code, which 
    return HTML or other suitable content

>How should I view Python differently than PHP?

It is more useful and nicer to work in. For a quick and dirty web page PHP is a 
handy tool, but almost entirely for the web. Python is not targeted specificly 
at web output.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 13:07 -0800
  Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 13:21 -0800
    Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 09:00 +1100
      Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 14:27 -0800
        Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 10:09 +1100
          Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 17:00 -0800
            Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 14:26 +1100
        Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 16:10 -0700
        Re: Understanding Python from a PHP coder's perspective Cameron Simpson <cs@zip.com.au> - 2015-12-08 10:07 +1100
        Re: Understanding Python from a PHP coder's perspective Tim Chase <python.list@tim.thechases.com> - 2015-12-07 21:11 -0600
        Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 14:47 +1100
  Re: Understanding Python from a PHP coder's perspective Cameron Simpson <cs@zip.com.au> - 2015-12-08 08:33 +1100
  Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 14:37 -0700
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 08:40 +1100
  Re: Understanding Python from a PHP coder's perspective Terry Reedy <tjreedy@udel.edu> - 2015-12-07 16:53 -0500
  Re: Understanding Python from a PHP coder's perspective Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 14:59 -0700
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 09:03 +1100
  Re: Understanding Python from a PHP coder's perspective Tim Chase <python.list@tim.thechases.com> - 2015-12-07 16:28 -0600
  Re: Understanding Python from a PHP coder's perspective villascape@gmail.com - 2015-12-07 20:11 -0800
  Re: Understanding Python from a PHP coder's perspective Peter Otten <__peter__@web.de> - 2015-12-08 10:24 +0100
  Re: Understanding Python from a PHP coder's perspective Chris Angelico <rosuav@gmail.com> - 2015-12-08 20:40 +1100

csiph-web