[Tutor] (no subject)

2012-04-28 Thread Wei Juen Lo

here is my code for a calculator:
def menu():
print "Welcome to calculator.py"print "your options are:"print " "  
  print "1) Addition"print "2) Subtraction"print "3) Multiplication"
print "4) Division"print "5) Quit calculator.py"print " "return 
input ("Choose your option: ")
def add(a,b):print a, "+", b, "=", a + b
def sub(a,b):print b, "-", a, "=", b - a
def mul(a,b):print a, "*", b, "=", a * b
def div(a,b):print a, "/", b, "=", a / bdef main():loop = 1
choice = 0while loop == 1:choice = menu()if choice == 1:
add(input("Add this: "),input("to this: "))elif choice == 2:
sub(input("Subtract this: "),input("from this: "))elif choice 
== 3:mul(input("Multiply this: "),input("by this: "))elif 
choice == 4:div(input("Divide this: "),input("by this: "))
elif choice == 5:loop = 0
print "Thank you for using calculator.py!"


main()

Few questions:
why do i have to press enter for it to initialisewhy does it print the stuff in 
menu() again after doing the equationi am trying to understand classes if 
anyone has time to make all these functions go into a class calculator and have 
it still work and send me the code so i can have an example to refer to that 
would be great ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PIL and converting an image to and from a string value

2012-04-28 Thread Chris Hare
What I did:

self.imageBuffer = StringIO.StringIO()
image = Image.open(filename)
image = image.resize((150,150),Image.ANTIALIAS)
image.save(self.imageBuffer, format= 'PNG')
self.imageBuffer.seek(0)
image = Image.open(self.imageBuffer)

So, that is how I got around the problem


On Apr 27, 2012, at 1:22 PM, Russell Smith wrote:

> What did you do?
> 
> On Friday, April 27, 2012, Chris Hare wrote:
> 
> I got it figured out.
> 
> On Apr 27, 2012, at 12:21 AM, Chris Hare wrote:
> 
> >
> > Here is what I am trying to:
> >
> > the application user chooses an image file.  I want to store the image data 
> > in a field in a sqlite database.  My understanding from the reading I have 
> > done is that I have to convert the image data into a string , which I can 
> > then store in the database.  Additionally, I need to be able to take the 
> > stored image data and convert it back to an image  so I can display it in a 
> > canvas widget.  I am using the python imaging library
> >
> > I think I have the following parts correct:
> >
> > image = Image.open("cover.jpg")
> > image = image.resize((150,150),Image.ANTIALIAS)
> > png = image.tostring("PNG")
> >
> > I am taking the image data from the file, resizing the image, and then 
> > using the PNG coder to force it into a PNG format image and converting it 
> > to a string.
> >
> > I am stuck however, in figuring out how to take the string data and 
> > converting it back to an image that I can put into the canvas widget.  
> > Either I am not finding a good explanation of how to do this or I am just 
> > not understanding what I am finding:-)
> >
> > Any ideas are appreciated!
> >
> > Thanks,
> > Chris
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] (no subject)

2012-04-28 Thread Alan Gauld

On 28/04/12 14:08, Wei Juen Lo wrote:


def menu():

print "Welcome to calculator.py"
print "your options are:"
print " "
print "1) Addition"
print "2) Subtraction"
print "3) Multiplication"
print "4) Division"
print "5) Quit calculator.py"
print " "
return input ("Choose your option: ")




def main():
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
add(input("Add this: "),input("to this: "))
elif choice == 2:
sub(input("Subtract this: "),input("from this: "))
elif choice == 3:
mul(input("Multiply this: "),input("by this: "))
elif choice == 4:
div(input("Divide this: "),input("by this: "))
elif choice == 5:
loop = 0



Few questions:

why do i have to press enter for it to initialise


You don't, it goes straight into the menu loop.
You have to press enter after typing input to tell python you have 
finished entering data. But the initialisation is the two lines before 
the while loop starts and you don't need to press enter for that.



why does it print the stuff in menu() again after doing the equation


Because the first line inside the while loop is the call to the menu 
function:


> while loop == 1:
> choice = menu()


Every time you finish a calculation, because loop is still 1 the program 
returns to the while and repeats the body of the loop.

Starting with the call to menu() to get the next user selection.


i am trying to understand classes if anyone has time to make all these
functions go into a class calculator and have it still work and send me
the code so i can have an example to refer to that would be great


There is absolutely no point in confusing yourself with
classes if you don't understand the basics like the code above.
Figure out how the basics work first before even beginning to
worry about classes.

--
Alan G
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


[Tutor] putting an image into a canvas object

2012-04-28 Thread Chris Hare

What I am trying to do is put an image on a canvas object, which I think is 
allowed.

self.picture1 = Canvas(self.pictureFrame,width=150,height=150)

self.imageBuffer = StringIO.StringIO()

image = Image.open(filename)
image = image.resize((150,150),Image.ANTIALIAS)
image.save(self.imageBuffer, format= 'PNG')

self.imageBuffer.seek(0)
image = Image.open(self.imageBuffer)

photo = PhotoImage(image)
self.picture1.create_image(0, 0, image = photo )

However, this code results in the following exception:"
Exception in Tkinter callback
Traceback (most recent call last):
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py",
 line 1410, in __call__
return self.func(*args)
  File "z.py", line 803, in changePicture1
self.picture1.create_image(0, 0, image = photo )
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py",
 line 2198, in create_image
return self._create('image', args, kw)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py",
 line 2189, in _create
*(args + self._options(cnf, kw
TypeError: __str__ returned non-string (type instance)

What did I do wrong?

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


Re: [Tutor] Tutor Digest, Vol 98, Issue 70

2012-04-28 Thread Osemeka Osuagwu
I use 64bit Windows7 and Python 2.7.2 (upgraded from 2.6.6)

I downloaded the windows binary from the pygame site
(http://www.pygame.org/download.shtml) and ran it. During the
installation I had to choose install directory, I left it at the
default option (which created a new folder on my C: drive).

On 4/28/12, tutor-requ...@python.org  wrote:
> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   tutor-requ...@python.org
>
> You can reach the person managing the list at
>   tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. more help with vitualenv (Ivor Surveyor)
>2. Re: more help with vitualenv (Russell Smith)
>3. (no subject) (Dinesh Vadhia)
>4. Re: Pygame installation problems (Steven D'Aprano)
>5. Re: more help with vitualenv (Steven D'Aprano)
>
>
> --
>
> Message: 1
> Date: Sat, 28 Apr 2012 09:25:51 +0800
> From: Ivor Surveyor 
> To: tutor@python.org
> Subject: [Tutor] more help with vitualenv
> Message-ID: <3vfzzb6lm2z...@mail.python.org>
> Content-Type: text/plain; charset="us-ascii"; format=flowed
>
>
> As suggested I visited the site virtualenv.  However I could not find
> the files for download and to install on my machine.
> Could I please ask for further guidance on how to proceed?
>
> Ivor Surveyor
> isurve...@vianet.net.au
>
>
>
> --
>
> Message: 2
> Date: Fri, 27 Apr 2012 18:51:00 -0700
> From: Russell Smith 
> To: Ivor Surveyor 
> Cc: "tutor@python.org" 
> Subject: Re: [Tutor] more help with vitualenv
> Message-ID:
>   
> Content-Type: text/plain; charset="iso-8859-1"
>
> http://pypi.python.org/pypi/virtualenv/1.7.1.2
>
> Read the page at the link above. You will find it.
>
> On Friday, April 27, 2012, Ivor Surveyor wrote:
>
>>
>> As suggested I visited the site virtualenv.  However I could not find the
>> files for download and to install on my machine.
>> Could I please ask for further guidance on how to proceed?
>>
>> Ivor Surveyor
>> isurve...@vianet.net.au
>> __**_
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/**mailman/listinfo/tutor
>>
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> 
>
> --
>
> Message: 3
> Date: Fri, 27 Apr 2012 19:41:46 -0700
> From: Dinesh Vadhia 
> To: , ,
>   , ,
>   , , ,
>   , 
> Subject: [Tutor] (no subject)
> Message-ID: 
> Content-Type: text/plain; charset="iso-8859-1"
>
> http://revistabuenosmuchachos.com/orndkty/247274.html
>   
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> 
>
> --
>
> Message: 4
> Date: Sat, 28 Apr 2012 14:46:29 +1000
> From: Steven D'Aprano 
> To: tutor@python.org
> Subject: Re: [Tutor] Pygame installation problems
> Message-ID: <4f9b7625.9080...@pearwood.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Osemeka Osuagwu wrote:
>> Hi,
>> I started learning Python recently, having only very little programming
>> experience. I installed Pygame and tried using
>
>
> How did you install it?
>
> What operating system are you using?
>
>
>>> import pygame
>>
>> to test the installation and got the following error in return;
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> ImportError: No module named pygame
>>
>> Please does this mean I didn't install pygame correctly?
>
> Yes.
>
>
>
> --
> Steven
>
>
>
> --
>
> Message: 5
> Date: Sat, 28 Apr 2012 14:58:56 +1000
> From: Steven D'Aprano 
> To: tutor@python.org
> Subject: Re: [Tutor] more help with vitualenv
> Message-ID: <4f9b7910.8040...@pearwood.info>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Ivor Surveyor wrote:
>>
>> As suggested I visited the site virtualenv.  However I could not find
>> the files for download and to install on my machine.
>> Could I please ask for further guidance on how to proceed?
>
> Which site did you go to? "virtualenv" is not a site, it is a name.
> Precision
> of language is your friend -- when asking for help, please be precise and
> accurate in your descriptions.
>
> When I google for "virtualenv", the very first link that comes up is this:
>
> http://pypi.python.org/pypi/virtualenv
>
> Is that the site you went to? If not,

Re: [Tutor] Tutor Digest, Vol 98, Issue 70

2012-04-28 Thread Dave Angel
On 04/28/2012 11:00 AM, Osemeka Osuagwu wrote:
> I use 64bit Windows7 and Python 2.7.2 (upgraded from 2.6.6)
>
> I downloaded the windows binary from the pygame site
> (http://www.pygame.org/download.shtml) and ran it. During the
> installation I had to choose install directory, I left it at the
> default option (which created a new folder on my C: drive).
>
> On 4/28/12, tutor-requ...@python.org  wrote:
>> Send Tutor mailing list submissions to
>>  tutor@python.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>  http://mail.python.org/mailman/listinfo/tutor
>> or, via email, send a message with subject or body 'help' to
>>  tutor-requ...@python.org
>>
>> You can reach the person managing the list at
>>  tutor-ow...@python.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Tutor digest..."
>>
Like the man says, make a meaningful Subject for your message.  If it's
a reply to a previous one, you should reply to that particular message
instead of the digest.  But if you can't convince your email program to
do that, at least fix the Subject line so it looks like a reply (Stick a
Re:  in front of the previous message's subject, if it doesn't already
have one)

Also, don't include a lot of nonsense that has nothing to do with your
post.  It's possible that something meaningful was in there, but we
shouldn't have to hunt.

So, back to the question you didn't ask.  So pygame's install created a
directory?   it should be put into the existing python directory
structure if you want python to be able to find it.

-- 

DaveA

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


[Tutor] Getting started with PyGTK [Receiving Error]

2012-04-28 Thread Santosh Kumar
System Information

Ubuntu 11.10
Python 2.7.2

Problem


I think my Ubuntu has PyGTK and GTK both already installed. But
however when I am importing "gtk" in Python interactive mode then I am
getting the following warning:

(.:4126): Gtk-WARNING **: Unable to locate theme engine in
module_path: "pixmap",

(.:4126): Gtk-WARNING **: Unable to locate theme engine in
module_path: "pixmap",

(.:4126): Gtk-WARNING **: Unable to locate theme engine in
module_path: "pixmap",

(.:4126): Gtk-WARNING **: Unable to locate theme engine in
module_path: "pixmap",

On the other side, importing "PyGTK" works well. What might be error?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting started with PyGTK [Receiving Error]

2012-04-28 Thread Alan Gauld

On 28/04/12 23:48, Santosh Kumar wrote:

System Information

Ubuntu 11.10
Python 2.7.2

Problem


I think my Ubuntu has PyGTK and GTK both already installed.


You should be able to confirm that by checking in Synaptic.


however when I am importing "gtk" in Python interactive mode then I am
getting the following warning:

(.:4126): Gtk-WARNING **: Unable to locate theme engine in
module_path: "pixmap",

On the other side, importing "PyGTK" works well. What might be error?



What exactly does that mean? Do you mean yhou get no errors? Does it 
mean you can execute some sample code?


The warnings above may not be serious, does gtk work in the sense of 
executing code? What happens if youi do help(gtk) ?


However, Gtk is not a mainstream package for beginners to Python and not 
part of the standard library and that's what this list is focused on. 
You might get more detailed help on a pygtk forum, or maybe even a 
generic GTk forum since the error probably refers to some basic GTk 
feature. It certainly isn't a pure python issue.


This page has some suggestions:

http://www.pygtk.org/feedback.html



--
Alan G
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] Getting started with PyGTK [Receiving Error]

2012-04-28 Thread Russell Smith
Make sure you installed the theme engine 'pixmap' or whichever gtk package
that has the theme engine you are missing. Google search for the gtk
packages. Look here
http://askubuntu.com/questions/66356/gdk-gtk-warnings-and-errors-from-the-command-lineand
you will see a very similar problem with a solution which I bet will
help you.

Cheers

On Saturday, April 28, 2012, Alan Gauld wrote:

> On 28/04/12 23:48, Santosh Kumar wrote:
>
>> System Information
>> 
>> Ubuntu 11.10
>> Python 2.7.2
>>
>> Problem
>> 
>>
>> I think my Ubuntu has PyGTK and GTK both already installed.
>>
>
> You should be able to confirm that by checking in Synaptic.
>
>  however when I am importing "gtk" in Python interactive mode then I am
>> getting the following warning:
>>
>> (.:4126): Gtk-WARNING **: Unable to locate theme engine in
>> module_path: "pixmap",
>>
>> On the other side, importing "PyGTK" works well. What might be error?
>>
>
>
> What exactly does that mean? Do you mean yhou get no errors? Does it mean
> you can execute some sample code?
>
> The warnings above may not be serious, does gtk work in the sense of
> executing code? What happens if youi do help(gtk) ?
>
> However, Gtk is not a mainstream package for beginners to Python and not
> part of the standard library and that's what this list is focused on. You
> might get more detailed help on a pygtk forum, or maybe even a generic GTk
> forum since the error probably refers to some basic GTk feature. It
> certainly isn't a pure python issue.
>
> This page has some suggestions:
>
> http://www.pygtk.org/feedback.**html 
>
>
>
> --
> Alan G
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor