Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Bt "Crash", I mean the browser displays:


 Internal Server Error

The server encountered an internal error or misconfiguration and was 
unable to complete your request.



The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.
I can print a single key.  I can iterate over the keys, just printing 
out "hello" for each iteration.
But I can't figure out how to iterate over all the keys printing out 
somethinf sensible.


#!C:\python25\python.exe

import cgi, sys
# import cgitb; cgitb.enable()

#Send errors to browser
sys.stderr = sys.stdout

#Parse data from form
data = cgi.FieldStorage()

#Send response to browser
print "Content-type: text/html\n"
print "CGI Form Response\n"
print "This is the data passed to the cgi script"

# This next bit works and I can see a list of keys displayed in the browser
print "Version 4: data.keys()\n"
print ""
print data.keys()

# This next bit also works and I can see the value of the variable 
"JQuiz_q01_score"

print "-"
print "JQuiz_q01_score = ", data["JQuiz_q01_score"].value

# However, whenever I try to iterate over all the keys, I get the 
"Internal Server error"

print "-"
for k in data.keys():
   print ""data[k].key

#  I have also tried data[k]
#data.key[k]
#data[k].value
#  and many other random combinations.


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


Re: [Tutor] cgi scripts

2008-11-08 Thread Alan Gauld


"Jim Morcombe" <[EMAIL PROTECTED]> wrote

The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.


Look at what you are doing in the two examples

# This next bit also works and I can see the value of the variable 
print "JQuiz_q01_score = ", data["JQuiz_q01_score"].value


# However, whenever I try to iterate over all the keys, I get the 
print ""data[k].key


Can you see what you are doing differently whwen accessing
the data?

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Thanks guys,

This works :)

field_list = '\n'
for field in data.keys():
   field_list = field_list + '%s : %s\n' % (field, 
data[field].value)

field_list = field_list + '\n'
print field_list

I think the problem wasn't in getting the keys and values, but I might 
have been producing illegal HTML code before.

I think I'd better brush up on my HTML skills.

Jim





Alan Gauld wrote:


"Jim Morcombe" <[EMAIL PROTECTED]> wrote

The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.


Look at what you are doing in the two examples

# This next bit also works and I can see the value of the variable 
print "JQuiz_q01_score = ", data["JQuiz_q01_score"].value


# However, whenever I try to iterate over all the keys, I get the 
print ""data[k].key


Can you see what you are doing differently whwen accessing
the data?

HTH,





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


Re: [Tutor] cgi scripts

2008-11-08 Thread Kent Johnson
On Sat, Nov 8, 2008 at 3:38 AM, Jim Morcombe <[EMAIL PROTECTED]> wrote:

> I think the problem wasn't in getting the keys and values, but I might have
> been producing illegal HTML code before.
> I think I'd better brush up on my HTML skills.

Poorly formed HTML won't give an internal server error. That is due to
something more serious such as a syntax error in your program.

With bad HTML you will see *something* in the browser, even if only a
blank page, and you can view source to see the actual code.

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


Re: [Tutor] cgi scripts

2008-11-08 Thread Don Jennings
(Oops! Forgot to include tutor in recipient.)

On 11/8/08, Don Jennings <[EMAIL PROTECTED]> wrote:
> Hi, Jim. Actually, improper HTML would cause a problem with the
> browser and what it may or may not display. An "Internal Server Error"
> does indicate that you had a problem with your code. I suggest
> referring back to Alan's post again.
>
> Take care,
> Don
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] gnuplot from a python gui

2008-11-08 Thread spir

[EMAIL PROTECTED] a écrit :

Hello tutors,

I'm trying to generate a plot using gnuplot from within a python gui. In 
Windows, if after the plot is drawn I use a raw_input string demanding a 
'RETURN' be hit, the plot will persist on the screen until the 'RETURN' is 
pressed. In  *nix, one can use the 'persist' switch to easily and much more 
elegantly accomplish the same.

My question is, is there a better way IN WINDOWS to keep the plot on the screen 
rather than having to leave the gui and find the console window in which a 
'RETURN' must be pressed to continue? My gui will not 'quit' until I enter the 
'RETURN' in the console window. Kind of a chintzy way to end the gui, really.

There must be a better way than using raw_input???

Daniel B.


Maybe a stupid question: as your application has a GUI, why do you use this 
raw_input() trick? As far as I know, this is a way to let the console open at 
the end of execution so that the user can watch results (otherwise it's autom. 
closed). What's the point in doing that in a GUI app?

Denis

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


[Tutor] Upgrading from Python 2.5 to Python 2.6 - IDLE not working...

2008-11-08 Thread Dan
Hi All,

This is my first post, so I apologize in advance for any etiquette
violations.

I am interested in learning Python, and to that end, I undertook to upgrade
my current version of Python 2.5 (available via openSUSE repositories and
YaST) to Python 2.6.  I have Python 2.6 running (compiled from source [I'm
not a total bonehead]) but idle gives me the following when I invoke it in
bash:

[EMAIL PROTECTED]:~> idle
Traceback (most recent call last):
  File "/usr/local/bin/idle", line 3, in 
  from idlelib.PyShell import main
  File "/usr/local/lib/python2.6/idlelib/PyShell.py", line 14, in 
  import macosxSupport
  File "/usr/local/lib/python2.6/idlelib/macosxSupport.py", line 6, in

  import Tkinter
  File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 39, in 
  import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
[EMAIL PROTECTED]:~>

I thought of unistalling and reinstalling (using YaST) the associated Python
packages to make them aware of the version change, but the Idle package says
it requires Python 2.5.2, nothing more or less, so I didn't attempt it.

Thanks in advance for your patience.

Dan

-- 
-=-=-=-=-=-=-=-=-
Science is what we have learned about how not to fool ourselves about the
way the world is.
- Richard Feynman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question

2008-11-08 Thread Bap

Can I use notepad++ for Python?

Thank you! ;-)

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


Re: [Tutor] Upgrading from Python 2.5 to Python 2.6 - IDLE not working...

2008-11-08 Thread Kent Johnson
On Sat, Nov 8, 2008 at 6:34 PM, Dan <[EMAIL PROTECTED]> wrote:
> I am interested in learning Python, and to that end, I undertook to upgrade
> my current version of Python 2.5 (available via openSUSE repositories and
> YaST) to Python 2.6.  I have Python 2.6 running (compiled from source [I'm
> not a total bonehead]) but idle gives me the following when I invoke it in
> bash:
>
> [EMAIL PROTECTED]:~> idle
> Traceback (most recent call last):
>   File "/usr/local/bin/idle", line 3, in 
>   from idlelib.PyShell import main
>   File "/usr/local/lib/python2.6/idlelib/PyShell.py", line 14, in 
>   import macosxSupport
>   File "/usr/local/lib/python2.6/idlelib/macosxSupport.py", line 6, in
> 
>   import Tkinter
>   File "/usr/local/lib/python2.6/lib-tk/Tkinter.py", line 39, in 
>   import _tkinter # If this fails your Python may not be configured for Tk
> ImportError: No module named _tkinter
> [EMAIL PROTECTED]:~>

Are you running on MacOS or Linux? I'm confused by the import
macosxSupport. There is a known problem with IDLE on MacOSX:
http://bugs.python.org/issue4017

For linux I think there is a build option to include tkinter but
someone else will have to answer that one.

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


Re: [Tutor] Question

2008-11-08 Thread Nick Scholtes
Last I checked, Notepad ++ works with Python. I've never used it for Python,
so I don't know how it works.
Nick



On Sat, Nov 8, 2008 at 9:22 PM, Bap <[EMAIL PROTECTED]> wrote:

> Can I use notepad++ for Python?
>
> Thank you! ;-)
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Art: http://www.coroflot.com/bellsoffreedom
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor