[nSLUG] Python and HTML

Frank Geitzler frank.geitzler at ns.sympatico.ca
Mon Jan 12 17:32:51 AST 2015


On Sun, 2015-01-11 at 09:37 -0400, George N. White III wrote:
> On Sun, Jan 11, 2015 at 12:38 AM, Hatem Nassrat <hnassrat at gmail.com>
> wrote:
>         On linux systems the best way to make it generic, is to use
>         the env command, making the hash bang line read:
>         
>         
>         #!/usr/bin/env python3
>         
>  
> My scientific linux 7 (RHEL7-based) system has both /bin/env
> and /usr/bin/env (from coreutils). I have encountered scripts with
> "#! /bin/env ...".  I assume RedHat provides /bin/env for
> compatibility with some legacy systems (Sun, SGI, etc) or maybe some
> systems that use busybox.  OS X generally follows BSD and has
> only /usr/bin/env.

Thanks, George (and everyone else who provided comments, suggestions,
and assistance).  I can now report success with this application.  I
went with "!# /usr/bin/env python3", including the space in the third
position (I notice both George and Hatem have suggested  "!#/usr/bin/env
python3", eliminating the space in position 3, but including the space
between 'env' and 'Python3'.
As a matter of interest, while I was struggling to get this application
to work, I first thought that the problem might have been with my PATH.
I first set up the application in several development sub-directories
deep within my /home directory:  /frank/Documents/SourceCode/... webapp
and /frank/Documents/SourceCode/.../webapp/cgi-bin,  .../SourceCode/.../webapp/data, .../SourceCode/.../webapp/images, and ,... /SourceCode/.../webapp/templates.  The python script to start the simple local server, "simple_httpd.py", together with the file "index.html" and several other files referenced by that file ("coach.css" and "favicon.ico"), are in the webapp subdirectory, which is NOT IN MY PATH.  

When the application consistently failed to find the first ".py" file
which was supposed to be in the cgi-bin subdirectory, I first copied the
all the files in the webapp subdirectory (index.html, simple_httdp.py,
etc.) and and all its other files and subdirectories (but not the
"/webapp" directory itself), to my /home directory, (so that I had
"/home/cgi-bin", "/home/data", etc. but not "/home/webapp".  

When that gave the same error, I tried something similar by determining
that "/usr/games" was at the end of my PATH, and copied the same files
and subdirectories to the "/usr/games" directory.  When it was suggested
that "!#/usr/bin/env python3" might resolve my difficulty, I first
modified that header in three ".py" files -the one which started the
server, and two others which were referenced in cgi scripts.  When that
worked, I realized that the PATH was not the problem.  I made the same
change to the files in my "/home" directory, and again the application
worked.

I ruled out the possibility that one part of the application was being
referenced from the root directory (/usr/games...) and another from
the /home directory or the development sub-directory by renaming the
relevant files and sub-directories for each of the two versions which
were not being tested (z_simple_httpd.py, z_index.html, z_cgi-bin,
z_templates, etc.).  when the 'root' version worked, I renamed it to
'z_...', and removed the 'z_...' from version in the '/home' directory.
When that version worked, I again repeated the process with the version
in the development sub-directory.  Incidentally, before each test, I
restarted Firefox and selected Tools -> Clear Recent History... to be
sure that I wasn't picking up the same version of the application for
each test.

Sorry for being so verbose, but I thought some of you might find it
interesting, or possibly even helpful in some similar situation.
Thanks again for your support (ant patience).
Frank Geitzler
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug




More information about the nSLUG mailing list