Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Understanding Python from a PHP coder's perspective Date: Mon, 7 Dec 2015 14:37:23 -0700 Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de g9LtdzGDwAQ/kBZdffSTWAjGaGTpUaPRg/SngR51hZrQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'scripts': 0.09; 'abstraction': 0.09; 'appropriate.': 0.09; 'handler.': 0.09; 'meaningful': 0.09; 'php,': 0.09; 'script,': 0.09; 'tends': 0.09; 'visited': 0.09; 'python': 0.10; 'extensions': 0.13; 'apache': 0.14; 'appropriate': 0.14; '.py': 0.16; 'accesses': 0.16; 'exposes': 0.16; 'extensions,': 0.16; 'json,': 0.16; 'mapped': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'something.': 0.16; 'subject:perspective': 0.16; 'url:example': 0.16; 'url:py': 0.16; 'wrote:': 0.16; 'obviously': 0.16; '2015': 0.20; 'extension': 0.20; 'gateway': 0.22; 'code.': 0.23; 'bigger': 0.23; 'dec': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'script': 0.25; "i've": 0.25; 'command': 0.26; 'mostly': 0.27; 'message-id:@mail.gmail.com': 0.27; 'actual': 0.28; 'accidentally': 0.29; 'expose': 0.29; 'initiated': 0.29; 'loop,': 0.29; 'url:wikipedia': 0.29; 'websites.': 0.29; 'url:wiki': 0.30; 'code': 0.30; 'getting': 0.33; 'run': 0.33; 'directory,': 0.33; 'html,': 0.33; 'similar': 0.33; 'languages': 0.34; 'structure': 0.34; 'file': 0.34; 'running': 0.34; 'server': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'configured': 0.35; 'path': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'serve': 0.36; 'web,': 0.36; 'received:209.85': 0.36; 'urls': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'aspects': 0.37; 'missing': 0.37; 'seem': 0.37; 'received:209': 0.38; 'files': 0.38; 'why': 0.39; 'url:en': 0.39; 'subject:from': 0.39; 'system.': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'called': 0.40; 'some': 0.40; 'your': 0.60; 'details': 0.62; 'more': 0.63; 'excited': 0.63; 'necessarily': 0.63; 'interest': 0.64; 'between': 0.65; 'accessed': 0.66; 'lives': 0.72; 'saw': 0.77; 'browser.': 0.81; 'all!': 0.84; 'extensions.': 0.84; 'gateway,': 0.84; 'mirrors': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=b9UOMQzroMqlsFk7r75cEvrhzZG7io1VsMsoWc2OkmQ=; b=lpJmy3HhRGw0yehs5GNDS4euERcF+Kvsd0XNyGwW2v5u3iIJd3grS77SLpJqiV1i/s uIN3j6+mVmZLfsyIG3vQ6iR/TQQMd4SzahTHyDJS3a7L24JM6RpQRT27wpCaGl0BLC3E 1bPV2WDRasatt45OIeBHD9nwuPQKBSIMlDablWIyJgC9xdQ6HGjl+674NnidmV4mNzoZ +hdpqH9Q6yjKtQKlIaJgQDoV5qjdTwHK+wnFI7uGnRnN6jWz6tCYQ5GOzV2b3BEcICk7 REFaX09PqAOrCipoPDvTPkLfInCfL1D9Uccck4JFMW7wBdLya6WJb6m1Siafj2AopueK omwQ== X-Received: by 10.107.137.226 with SMTP id t95mr555795ioi.188.1449524282416; Mon, 07 Dec 2015 13:38:02 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100108 On Mon, Dec 7, 2015 at 2:07 PM, wrote: > Hello all! Just started getting into Python, and am very excited about t= he 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 i= nitiated 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 co= mmand 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 wri= tten in Python, but never saw the browser expose the .py extensions. I am = obviously missing something. > > Why don't I see the .py extension in my browser? PHP tends to be served like CGI, which is that the URL mirrors the path to a script that lives under a particular directory, which the webserver locates and executes. This has some downsides: * It exposes details about the structure of your server to the public, which is considered a security weakness. * An improperly configured webserver might accidentally serve scripts or other files that are not intended to be served over the web, which is a much bigger security risk. * It's inflexible; if you move your script, then the URL must necessarily change as well. With Python, it's more usual to have a greater abstraction between URLs and code. A set of URLs are mapped to a single Python gateway, and the gateway dispatches the request to the appropriate request handler. With this scheme there is no reason to have .py extensions in the URLs because the URL structure is unrelated to how the actual scripts are organized in the file system. This also makes it easier to create meaningful URLs: see https://en.wikipedia.org/wiki/Semantic_URL.