[Tutor] I can't know how to use the "press the enter key to exit" command

2010-07-06 Thread erinzo
Sorry, I am a beginner in the python programming language.But went I type raw 
input("\n\npress the enter key to exit.") in the last line of the program,I 
have the syntaxerror.My program can not wait the user to press the enter key.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] raw_input

2010-07-06 Thread iamroot

On Mon, 5 Jul 2010, Dipo Elegbede wrote:


Hello,

I seem to be having problems with raw_input.

i wrote something like:

raw_input('Press Enter')

it comes back to tell me raw_input is not defined, a NameError!

Is it that something about it has changed in python 3.1 or I have been writing 
the wrong thing.

Please enlighten me.

regards.

--
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise Application 
Development



In Python 3, input has replaced raw_input.

This contains info about that and other things that have changed:

  http://www.ibm.com/developerworks/linux/library/l-python3-1/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter mainloop()

2010-07-06 Thread Francesco Loffredo
Hello all, this is the first time I ask for advice but I've been lurking 
for some month and i'm sure I'll find more than I need.
I'm learning Python and Tkinter, and I chose an old board game as a 
practice field. I used a Canvas and many Polygons, one for each 
hexagonal space of the board, and I bound a mouse click to a PlacePiece 
function that handles the move. I managed to make it work for two human 
players, but when it came to let the computer play, I found a problem.
I made a slightly different function, called Auto_PlacePiece, that 
doesn't get the target hex from an Event, but from arguments given, and 
I had to figure when this function has to be called. I thought an 
obvious place is at the end of the move, whether it's a manual or auto 
one. Just after having switched from a player to the other, if the new 
current player is "COMPUTER" then an automatic move is triggered.
So, where's the problem? The problem is that the Canvas is refreshed, 
and the previous move becomes visible to the players, *only after the 
completion of the automatic move!* This is, I think, a consequence of 
the binding and a feature of Tk's mainloop(): the loop waits for the 
bound routine to end before redrawing the graphics, and unfortunately I 
call the automatic move inside (albeit at the very end) of the previous 
move. And now for the (long awaited) question:
How can I ask a Canvas to redraw itself at my command? And if i can't, 
when should I call the auto move?

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


Re: [Tutor] I can't know how to use the "press the enter key to exit"command

2010-07-06 Thread Alan Gauld


"erinzo"  wrote 


Sorry, I am a beginner in the python programming language.
But went I type raw input("\n\npress the enter key to exit.") 
in the last line of the program,I have the syntaxerror.


If you are using Python v2 use

raw_input()  # note the underscore

If you are using Python v3 use

input()

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] I can't know how to use the "press the enter key to exit" command

2010-07-06 Thread Camillo Pereira
On 6 July 2010 17:27, Camillo Pereira  wrote:

> Hi,
>
> Can the error message be posted along with the Python code please.
>
> Regards,
>
> Camillo
>
> On 5 July 2010 23:52, erinzo  wrote:
>
>>  Sorry, I am a beginner in the python programming language.But went I
>> type raw input("\n\npress the enter key to exit.") in the last line of the
>> program,I have the syntaxerror.My program can not wait the user to press the
>> enter key.
>>
>> ___
>> 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] Sorting the Dictionary Set?

2010-07-06 Thread Ken G.

Is there a way to sort a dictionary?

Assuming I have a dictionary set containing the following:

{'02': 1, '03': 1, '12': 1, '15': 2, '14': 2, '04': 3, '05': 1, '19': 1, 
'32': 1, '28': 1, '27': 1, '17': 2, '25': 1}


and using the following code:

print ('Printing the result of numbers that are repeated:')
print
for x, y in counted.items():
if y > 1:
print "Number %s was found %s times." % (x,y)
# else:
# print "Number %s was found %s times." % (x,y)
print

and the result are:

Printing the result of numbers that are repeated:

Number 15 was found 2 times.
Number 14 was found 2 times.
Number 04 was found 3 times.
Number 17 was found 2 times.

and the question is:

How do I sort the dictionary so the numbers listed (15, 14, 04, 17) are 
listed in sorted ascending order such as:


Number 04 was found 3 times.
Number 14 was found 2 times.
Number 15 was found 2 times.
Number 17 was found 2 times.

I would appreciate any help, suggestion or hint on how to do achieved 
the desired result.


Thanks,

Ken

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


Re: [Tutor] Sorting the Dictionary Set?

2010-07-06 Thread Shashwat Anand
On Tue, Jul 6, 2010 at 8:08 PM, Ken G.  wrote:

> Is there a way to sort a dictionary?
>
> Assuming I have a dictionary set containing the following:
>
> {'02': 1, '03': 1, '12': 1, '15': 2, '14': 2, '04': 3, '05': 1, '19': 1,
> '32': 1, '28': 1, '27': 1, '17': 2, '25': 1}
>
> and using the following code:
>
>print ('Printing the result of numbers that are repeated:')
>print
>for x, y in counted.items():
>if y > 1:
>print "Number %s was found %s times." % (x,y)
># else:
># print "Number %s was found %s times." % (x,y)
>print
>
> and the result are:
>
>Printing the result of numbers that are repeated:
>
>Number 15 was found 2 times.
>Number 14 was found 2 times.
>Number 04 was found 3 times.
>Number 17 was found 2 times.
>
> and the question is:
>
> How do I sort the dictionary so the numbers listed (15, 14, 04, 17) are
> listed in sorted ascending order such as:
>
> Number 04 was found 3 times.
>Number 14 was found 2 times.
>Number 15 was found 2 times.
>Number 17 was found 2 times.
>

>>> d = {'02': 1, '03': 1, '12': 1, '15': 2, '14': 2, '04': 3, '05': 1,
'19': 1, '32': 1, '28': 1, '27': 1, '17': 2, '25': 1}
>>> import operator
>>> sorted(d.items(), key=operator.itemgetter(1), reverse = True)
[('04', 3), ('17', 2), ('15', 2), ('14', 2), ('25', 1), ('27', 1), ('02',
1), ('03', 1), ('12', 1), ('05', 1), ('19', 1), ('32', 1), ('28', 1)]

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


Re: [Tutor] Sorting the Dictionary Set?

2010-07-06 Thread Steven D'Aprano
On Wed, 7 Jul 2010 12:38:55 am Ken G. wrote:
> Is there a way to sort a dictionary?

Not directly, dictionaries are unsorted and unsortable. They print in an 
arbitrary order.

If you need to operate on dictionaries in a specific, non-arbitrary 
order, you need to extract the keys, sort them, and then work from 
them. Example:

keys = mydict.keys()
keys.sort()
for key in keys:
value = mydict[key]
print "the value of key %s is %s" (key, value)

I'm sure you can adapt that example to what you're trying to do :)


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


Re: [Tutor] Tkinter mainloop()

2010-07-06 Thread Alan Gauld


"Francesco Loffredo"  wrote

How can I ask a Canvas to redraw itself at my command? And if i 
can't, when should I call the auto move?


You can ask the canvas to repaint itself by calling 
update_idle_tasks()
method. But in general you shouldn't need to. It's usually better to 
keep
your event handlers short enough that they return to the mainloop 
which

will then redraw as necessary for you.

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


[Tutor] newbie to gui programming

2010-07-06 Thread Payal
Hi all,
Some background before the actual query.
A friend of mine, an electronics engineer has a
small co. He had a computer engg. with him who used to design GUI
front-ends
for his products in Visual Basic. These apps used to take data from
serial port, store it on disk put and show it in excel also plot graphs. 
Now the engg has left. So my friend has asked me to help him out till 
he finds a replacement. I don't know a word of electronics and know Python to
extend of understanding almost 90% of "Learning Python" and 70-75% of
"Core Python programming" books.
Now my real query, do you think it is possible for me to try my hand at
gui programming? There seems to be many ways to do gui programming in
Python namely wxpython, tkinter, gtk, qt etc. Which is the easiest and
nice looking one and works on both windows and Linux? The interfaces
will be used by other electronics enggs. so they do not expect real
swell gui, but it should be bearable and more importantly easy for me to
learn, cos' I have a day time job and I am doing this just as a help and
eagerness to learn.
Looking  for advice.

Thanks a lot.
With warm regards,
-Payal
-- 



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


Re: [Tutor] the ball needs a kick...

2010-07-06 Thread Dave Angel

Schoap D wrote:

Hi,

I'm doing the exercises here: chapter 8
http://www.openbookproject.net/thinkCSpy/ch08.html

Now I have added another paddle to the pong game. So far so good, but the
ball isn't moving anymore and I am not able to fix it...
Any comments, tips, feedback?

Thanks in advance,

http://paste.pocoo.org/show/233739/


Dirk

  
First thing to do is a file diff with the last version that worked 
properly.  You do that by going into your version control system.  
Chances are you made one more change than you realized you were making.


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


Re: [Tutor] newbie to gui programming

2010-07-06 Thread Adam Bark
On 6 July 2010 18:09, Payal  wrote:

> Hi all,
> Some background before the actual query.
> A friend of mine, an electronics engineer has a
> small co. He had a computer engg. with him who used to design GUI
> front-ends
> for his products in Visual Basic. These apps used to take data from
> serial port, store it on disk put and show it in excel also plot graphs.
> Now the engg has left. So my friend has asked me to help him out till
> he finds a replacement. I don't know a word of electronics and know Python
> to
> extend of understanding almost 90% of "Learning Python" and 70-75% of
> "Core Python programming" books.
> Now my real query, do you think it is possible for me to try my hand at
> gui programming?


Of course you can, it depends on how complex the GUI has to be on how far
you'll get most likely.


> There seems to be many ways to do gui programming in
> Python namely wxpython, tkinter, gtk, qt etc. Which is the easiest and
> nice looking one and works on both windows and Linux?


Any of those toolkits are available on windows and linux, as to the nicest
looking, that's up to you and your friend to decide. wxPython does a good
job of blending in with other applications on the same system though.
Tkinter comes with python which may swing it for you.


> The interfaces
> will be used by other electronics enggs. so they do not expect real
> swell gui, but it should be bearable and more importantly easy for me to
> learn, cos' I have a day time job and I am doing this just as a help and
> eagerness to learn.
> Looking  for advice.
>
>
Once you've picked your toolkit you'll probably want to get on the relevant
mailing list to get some help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie to gui programming

2010-07-06 Thread Alan Gauld

"Payal"  wrote

gui programming? There seems to be many ways to do gui programming 
in

Python namely wxpython, tkinter, gtk, qt etc. Which is the easiest


There are many toolkits but these have as many similarities as 
differences.

But none of them will be easy to learn if you have not done GUI work
before because GUI programming is a whole new style and that's what
takes the time. Once you learn one framework picking up another is
not that hard - just a lot of new API names to learn!


nice looking one and works on both windows and Linux?


Nowadays they are all acceptable looking but wxPython would
be my recommendation, mainly for its support for printing, which
sounds easy but in Guis is surprisingly difficult. wxPython makes
it about as easy as it can be.

Don't underestimate the learning curve and use the toolset as much
as possible, also look at things like plotting libraries if you need 
to

display graphs etc.

You can compare very simple GUIs in Tkinter and wxPython
in the GUI topic of my tutor, and a slightly more complex
GUI in the Case Study topic.

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] newbie to gui programming

2010-07-06 Thread Eric Hamiter
If you decide to run with wxPython there is a pretty handy video series you
could watch:

http://showmedo.com/videotutorials/series?name=PythonWxPythonBeginnersSeries

Eric


On Tue, Jul 6, 2010 at 1:48 PM, Alan Gauld wrote:

> "Payal"  wrote
>
>  gui programming? There seems to be many ways to do gui programming in
>> Python namely wxpython, tkinter, gtk, qt etc. Which is the easiest
>>
>
> There are many toolkits but these have as many similarities as differences.
> But none of them will be easy to learn if you have not done GUI work
> before because GUI programming is a whole new style and that's what
> takes the time. Once you learn one framework picking up another is
> not that hard - just a lot of new API names to learn!
>
>
>  nice looking one and works on both windows and Linux?
>>
>
> Nowadays they are all acceptable looking but wxPython would
> be my recommendation, mainly for its support for printing, which
> sounds easy but in Guis is surprisingly difficult. wxPython makes
> it about as easy as it can be.
>
> Don't underestimate the learning curve and use the toolset as much
> as possible, also look at things like plotting libraries if you need to
> display graphs etc.
>
> You can compare very simple GUIs in Tkinter and wxPython
> in the GUI topic of my tutor, and a slightly more complex
> GUI in the Case Study topic.
>
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie to gui programming

2010-07-06 Thread Nick Raptis
Please excuse if I'm jumping on the topic. Haven't done any GUI work so 
this interests me too.


wxPython always seemed a great choice as it works on all platforms, and 
uses GTK+ for linux.
Well, what mainly bugs me about wxPython is that most of it's API names 
come from the wx C library, you almost can feel the C code underneath.

I would really love a more pythonic wrapper around it.

Really good news is that on this very list on another thread, someone 
suggested Dabo http://dabodev.com/
It's a python library on top of wxPython and it's database-logic-GUI 
separation looks a lot like the MVP of django, which I'm familiar with.


Of course, a bit not that easy to install if you're just starting out 
and there are no books for it. It's also database oriented, but I 
consider this a plus.


I'd like to hear your views on whether you think it might be a good 
choice for a new python programmer, exactly for the above reasons.

I think it might be worth the hurdles and pay off in the end.

Nick


On 07/06/2010 09:48 PM, Alan Gauld wrote:
There are many toolkits but these have as many similarities as 
differences.

But none of them will be easy to learn if you have not done GUI work
before because GUI programming is a whole new style and that's what
takes the time. Once you learn one framework picking up another is
not that hard - just a lot of new API names to learn!


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


Re: [Tutor] newbie to gui programming

2010-07-06 Thread John
On Tuesday 06 July 2010 05:35:34 pm Nick Raptis wrote:
> Please excuse if I'm jumping on the topic. Haven't done any GUI work so
> this interests me too.
>
> wxPython always seemed a great choice as it works on all platforms, and
> uses GTK+ for linux.
> Well, what mainly bugs me about wxPython is that most of it's API names
> come from the wx C library, you almost can feel the C code underneath.
> I would really love a more pythonic wrapper around it.
>
> Really good news is that on this very list on another thread, someone
> suggested Dabo http://dabodev.com/
> It's a python library on top of wxPython and it's database-logic-GUI
> separation looks a lot like the MVP of django, which I'm familiar with.
>
> Of course, a bit not that easy to install if you're just starting out
> and there are no books for it. It's also database oriented, but I
> consider this a plus.
>
> I'd like to hear your views on whether you think it might be a good
> choice for a new python programmer, exactly for the above reasons.
> I think it might be worth the hurdles and pay off in the end.
>
> Nick

I really enjoy Dabo and I feel it is very easy to use and learn.  Best of all 
there plenty of support.

Johnf

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


Re: [Tutor] Tkinter mainloop()

2010-07-06 Thread Francesco Loffredo
RTFM I happened to find the answer just a couple of hours after 
having sent this message. How could I miss the update method of the Canvas?


Now my game works as expected, maybe I'll post it when it's complete.

Thanks to all!
Francesco

Il 05/07/2010 21.00, Francesco Loffredo ha scritto:

Hello all, this is the first time I ask for advice but I've been lurking
for some month and i'm sure I'll find more than I need.
I'm learning Python and Tkinter, and I chose an old board game as a
practice field. I used a Canvas and many Polygons, one for each
hexagonal space of the board, and I bound a mouse click to a PlacePiece
function that handles the move. I managed to make it work for two human
players, but when it came to let the computer play, I found a problem.
I made a slightly different function, called Auto_PlacePiece, that
doesn't get the target hex from an Event, but from arguments given, and
I had to figure when this function has to be called. I thought an
obvious place is at the end of the move, whether it's a manual or auto
one. Just after having switched from a player to the other, if the new
current player is "COMPUTER" then an automatic move is triggered.
So, where's the problem? The problem is that the Canvas is refreshed,
and the previous move becomes visible to the players, *only after the
completion of the automatic move!* This is, I think, a consequence of
the binding and a feature of Tk's mainloop(): the loop waits for the
bound routine to end before redrawing the graphics, and unfortunately I
call the automatic move inside (albeit at the very end) of the previous
move. And now for the (long awaited) question:
How can I ask a Canvas to redraw itself at my command? And if i can't,
when should I call the auto move?
TIA
Francesco
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




Nessun virus nel messaggio in arrivo.
Controllato da AVG - www.avg.com
Versione: 9.0.830 / Database dei virus: 271.1.1/2984 -  Data di rilascio: 
07/05/10 20:36:00


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


Re: [Tutor] Tkinter mainloop()

2010-07-06 Thread Francesco Loffredo

Il 06/07/2010 17.32, Alan Gauld wrote:


"Francesco Loffredo"  wrote


How can I ask a Canvas to redraw itself at my command? And if i can't,
when should I call the auto move?


You can ask the canvas to repaint itself by calling update_idle_tasks()
method.
Thank you, Alan. As many answers, this poses me a new question: why 
should I call update_idle_tasks() instead of update() ? What's the 
difference between the two methods?



But in general you shouldn't need to. It's usually better to keep
your event handlers short enough that they return to the mainloop which
will then redraw as necessary for you.
In general, I do agree. But I explained rather verbosely the peculiar 
situation I'm facing in my practice project: where would you put the 
automatic move call, if not where I did? I need an automatic move be 
performed at the proper moment, when it's the computer player turn.



HTH,

  SID!  (sure it did!)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor