Coming from Perl

A

Amer Neely

Amer said:
I'm a complete newbie with Python, but have several years experience
with Perl in a web environment.

A question I have, if someone here is familiar with Perl, does Python
have something like Perl's 'here document'? I've just searched and read
some postings on generating HTML but they all seem to refer to various
template utilities. Is this the only way, or am I missing something? I'm
used to generating X/HTML by hand, which makes the here document in Perl
ideal for me. Also, many times a client already existing HTML code that
I can use in a script.

In trying to track down why this script would not run on my host, it has
to come to light that Python is installed, however the Apache module is
not. So, short story is - I was flogging a dead horse.

Sorry for raising a non-issue folks.
 
I

I V

In trying to track down why this script would not run on my host, it has
to come to light that Python is installed, however the Apache module is
not. So, short story is - I was flogging a dead horse.

Which Apache module? You don't need any special modules (just the regular
CGI one) to use python in a CGI script.
 
B

Bryan Olson

Amer said:
This seems to indicate that maybe my host needs to configure Apache to
run python scripts? But I didn't need to do anything with mine.

Another possibility: If it works on Windows but not Unix, check
the end-of-line characters. Windows ends each line with the two
character sequence carriage-return + newline, which in Python
is "\r\n". Unix uses newline alone, "\n".

Most Unixies will choke on a #! line with a carriage return.
The Python interpreter will accept source files with either
end-of-line on either system, but of course you'll not get
that far unless the operating system respects the shebang line.

Maybe you already checked that. Hmmm...other possiblities...

Do you have shell access? Can you executing it directly from
the shell? Do you get a Python error, or some other?

Did you: chmod ugo+rx <yourscript>

Is Python in /usr/bin? What does "which python" say?

Generally, most experts seem to prefer:

#!/usr/bin/env python

You might try changing the the extension of your script from .py
to .cgi. Windows uses the .py to choose the executable, but Unix
does not care; it used the shebang line.
 
A

Amer Neely

I said:
Which Apache module? You don't need any special modules (just the regular
CGI one) to use python in a CGI script.

That is an interesting observation. It does run under my Apache + Win2K
at home, with no special configuration by me. All I'm going on is what
the techs told me.

So, you think it may be something else? I've changed and even eliminated
the end-of-line chars in my print statements.

Another poster (Bryan Olson) has suggested a few things to try as well
so I will try those. I don't have shell access though, so the best I can
do is execute shell commands from a Perl script.
 
A

Amer Neely

Bryan said:
Another possibility: If it works on Windows but not Unix, check
the end-of-line characters. Windows ends each line with the two
character sequence carriage-return + newline, which in Python
is "\r\n". Unix uses newline alone, "\n".

Most Unixies will choke on a #! line with a carriage return.
The Python interpreter will accept source files with either
end-of-line on either system, but of course you'll not get
that far unless the operating system respects the shebang line.

Maybe you already checked that. Hmmm...other possiblities...

Do you have shell access? Can you executing it directly from
the shell? Do you get a Python error, or some other?

Did you: chmod ugo+rx <yourscript>

Is Python in /usr/bin? What does "which python" say?

Generally, most experts seem to prefer:

#!/usr/bin/env python

You might try changing the the extension of your script from .py
to .cgi. Windows uses the .py to choose the executable, but Unix
does not care; it used the shebang line.

Hmmm. These are interesting suggestions. Especially in light of a new
wrinkle pointed out by [IV]. That being the script runs fine under my
Apache at home with no special modules loaded.

I don't have shell access but I can run 'which python' from a Perl
script, and I will try the different shebang line you suggested.

Thanks for the suggestions.
 
A

Amer Neely

Bryan said:
Another possibility: If it works on Windows but not Unix, check
the end-of-line characters. Windows ends each line with the two
character sequence carriage-return + newline, which in Python
is "\r\n". Unix uses newline alone, "\n".

Most Unixies will choke on a #! line with a carriage return.
The Python interpreter will accept source files with either
end-of-line on either system, but of course you'll not get
that far unless the operating system respects the shebang line.

Maybe you already checked that. Hmmm...other possiblities...

Do you have shell access? Can you executing it directly from
the shell? Do you get a Python error, or some other?

Did you: chmod ugo+rx <yourscript>

Is Python in /usr/bin? What does "which python" say?

Generally, most experts seem to prefer:

#!/usr/bin/env python

You might try changing the the extension of your script from .py
to .cgi. Windows uses the .py to choose the executable, but Unix
does not care; it used the shebang line.

I tried `which python` and `whereis python` and got 0 back as a result.
So it seems Python is not installed at all.
 
B

Bryan Olson

Amer said:
I don't have shell access but I can run 'which python' from a Perl
script, and I will try the different shebang line you suggested.

And after trying it, Amer Neely reported:
I tried `which python` and `whereis python` and got 0 back as a result.
So it seems Python is not installed at all.

Probably right, but just to be thorough... Since you do not
have shell access, I'm guessing you are running these within
a Perl cgi script, and getting the results via a browser. Is
that right?

Can you backtick other commands? What do you get if you run
`which perl` the same way? How about `whoami`, `whereis sh`,
and `which nosuchthingas5748614`? Can you list /, /bin and
/usr/bin?

How did you learn that this system could run your Perl
scripts? Can that source give us anything to go on here?
If Python is not installed, do you have some avenue for
requesting it?

We're down to long shots. Still, hosts that support Perl
but will not support Python are getting to be the rare.
 
A

Amer Neely

Bryan said:
And after trying it, Amer Neely reported:


Probably right, but just to be thorough... Since you do not
have shell access, I'm guessing you are running these within
a Perl cgi script, and getting the results via a browser. Is
that right?
Yes.

Can you backtick other commands? What do you get if you run
`which perl` the same way? How about `whoami`, `whereis sh`,
and `which nosuchthingas5748614`? Can you list /, /bin and
/usr/bin?

I just looked at my code and tried something else:
@SysCmd="which python";
system(@SysCmd);

and it came back
/usr/local/bin/python
How did you learn that this system could run your Perl
scripts? Can that source give us anything to go on here?
If Python is not installed, do you have some avenue for
requesting it?

We're down to long shots. Still, hosts that support Perl
but will not support Python are getting to be the rare.

I've asked my host to put in a request for it.

So it seems python IS installed, but not where I thought it was.

I just tried my script with the new path, but still got a 500 server
error. Can I trap errors to a file locally?
 
S

Steve Holden

Amer said:
I just looked at my code and tried something else:
@SysCmd="which python";
system(@SysCmd);

and it came back
/usr/local/bin/python


I've asked my host to put in a request for it.

So it seems python IS installed, but not where I thought it was.

I just tried my script with the new path, but still got a 500 server
error. Can I trap errors to a file locally?
You could try putting an ErrorLog directive in your local .htaccess file.

http://httpd.apache.org/docs/1.3/logs.html#errorlog

regards
Steve

--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top