[Tutor] POST request using httplib2

2011-06-29 Thread naheed arafat
On the way of learning " handling POST request in php" i tried to make a
simple python http client using httplib2 & urllib module.. what i wanted to
do was submitting username & password field to a php script (which just
echo's the username & password)  & prints the response in python,not in
html/php..

import httplib2
import urllib
url="http://localhost/form_process.php";
body={'username':'xyz','password':'abc'}
h=httplib2.Http()
response,content=h.request(url,'POST',urllib.urlencode(body))
print content

I got the following content:

*
Form processing

: 
*


instead of:

*
Form processing

xyz: abc
*

attachments:
form.php # takes username,password from the user,pass those to
  # form_process.php as GET parameter
form_process.php # echo username,password.

sorry for my long email.
<>
<>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GUI

2011-06-29 Thread Alan Gauld


"Walter Prins"  wrote

Just to add to what Alan's said:  A key thing you will need to wrap 
your
head around when transitioning to GUI applications is the fact that 
the

application is then not linear (or as linear) as a console/text
application.


Thanks for the extra detail Walter, I was in a hurry this morning :-)


So conceptually, in a console application, you write the "main" loop
...In a GUI application, you can imagine this loop is somewhere
inside the operating system


And if you want to compare the two approaches the Event Driven
Programming topic in my tutorial has essentially the same
application implemented as both a console and GUI app.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GUI

2011-06-29 Thread Walter Prins
Just to add to what Alan's said:  A key thing you will need to wrap your
head around when transitioning to GUI applications is the fact that the
application is then not linear (or as linear) as a console/text
application.

In a console application you basically control everything, and if there
needs to be a loop in the application to repeatedly collect user actions or
events (such as menu selections and so on) etc, then it's up to you to write
this yourself.

GUI applications are however different, in that the entire GUI system is
"event driven".  Conceptually what this means is that operating system is
ultimately responsible for collecting events (such as mouse clicks, keyboard
input, and so on) and it delivers these events/actions to your application
by sending it messages (which ultimately translates into functions and
methods in your application being called, as if by magic, from the
outside.)

The upshot of this is, as Alan said, that in most GUI applications you don't
write loops to "wait for input" yourself, you instead hand this off to the
operating system.   And it knows to call your methods by the fact that in
some part of your application you "register your interest" in receiving
various events, typically by providing an event handler (a method to be
called when that event happens.)

So conceptually, in a console application, you write the "main" loop
yourself, and directly call other methods/functions when certain "events"
happen (such as the user selecting a menu option.)  In a GUI application,
you can imagine this loop is somewhere inside the operating system (not
inside your application), and so your application doesn't provide one
itself, instead your application collaborates with the operating system to
make your application happen.  Object orientation conceptually is all about
objects collaborating with other objects by sending and receiving messages,
collectively working towards a solution.

Hope that helps.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python GUI

2011-06-29 Thread Alan Gauld


"David Merrick"  wrote 


Others have answered the immediate issue.
But...


   def testNumber(self):
   guess = int(self.numberEnt.get())
   tries = 1

   while guess != the_number:
   if guess > the_number:
 number += "Lower..."
   else:
 number += "Higher..."
   guess = int(self.numberEnt.get())
   tries += 1


This is all wrong for a GUI appluication. 
You should not use loops in an event handler.
Instead let the event loop in Tkinter do the looping. 
You respond to the user clicking the submit button 
and evaluate that single value. You then wait for 
the next button press to signal that there is a new 
value to check.


Any time you see a loop inside a GUI event 
handler you should stop and check that it belongs there.

Usually it doesn't!


number += "You guessed it!  The number was" + the_number
number += "And it only took you " + tries + " tries!\n"
self.numberTxt.delete(0.0, END)
self.numberTxt.insert(0.0, number)


It may just be mail but this appears to be outside 
the method definition and indeed outside the class.
Is that correct? Or just a mail glitch? Since they refer 
to self they should be inside a method so I'll assume 
its a mail thing.



# main
number = ""
the_number = random.randint(1, 100)


If you are using classes its normal to put most of 
the variables inside the classes. There is no reason 
for the_number to be a global value, it would be 
better as part of  the Application.


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor