|
2008-12-16
, 20:20
|
|
Posts: 2,853 |
Thanked: 968 times |
Joined on Nov 2005
|
#42
|
I hate to be a nit-picker here, but... daperl: from my understanding of python (and I could be wrong, I'm still learning), items in parentheses () are a tuple, while items in brackets [] are a list. So, in this case, the items need to be in a tuple, not a list. Not a big deal here, but the terminology changes what you can do with the items. (Reference Link)
values = {'name':'Joe', 'score':10, 'rank':'first'} print "%(name)s scored %(score)d and ranked %(rank)s, congrats %(name)s !" % values
The Following 2 Users Say Thank You to fpp For This Useful Post: | ||
|
2008-12-16
, 20:35
|
Posts: 2 |
Thanked: 3 times |
Joined on Dec 2008
|
#43
|
The Following User Says Thank You to plop For This Useful Post: | ||
|
2008-12-16
, 20:53
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#44
|
You're quite right. Although tuples are, in effect, like immutable lists, they're not equivalent in this case.
The other data structure commonly used for string formatting is the Python 'dictionary', especially when there are many variables and/or some of them are used multiple times. The placeholders are then named after the dict keys and their type, as in :
A commonly used dict is the one returned by locals(), which contains all local variables in context.Code:values = {'name':'Joe', 'score':10, 'rank':'first'} print "%(name)s scored %(score)d and ranked %(rank)s, congrats %(name)s !" % values
|
2008-12-16
, 21:56
|
|
Posts: 334 |
Thanked: 366 times |
Joined on Nov 2008
@ Italy
|
#45
|
ciao ciroip =) (and first post, btw).
Nice little clock and very useful. Looking in your code, I've noticed quite a bit of redundant code, so, I did a little bit of cleaning (too much loop unrolling ): http://python.pastebin.com/f6bdc2e1d .
EDIT: now with a more flexible event handling, you could even save a little bit of battery life increasing the delay for the redraw of the clock : http://python.pastebin.com/m363e32c .
The Following User Says Thank You to ciroip For This Useful Post: | ||
|
2008-12-16
, 22:01
|
|
Moderator |
Posts: 7,109 |
Thanked: 8,820 times |
Joined on Oct 2007
@ Vancouver, BC, Canada
|
#46
|
|
2008-12-17
, 00:09
|
|
Posts: 1,635 |
Thanked: 1,816 times |
Joined on Apr 2008
@ Manchester, England
|
#47
|
|
2008-12-17
, 01:15
|
|
Posts: 334 |
Thanked: 366 times |
Joined on Nov 2008
@ Italy
|
#48
|
Don't be ashamed, ciroip!
You asked developers to write the code for you, but nobody did, so you wrote it yourself! Excellent!
Now your achievement has motivated developers to fix your code. Everybody wins!
Especially me!
ciroip,
do not be ashamed, when a diamond comes out of the ground it is uneven and dull.
its easier to spot a mistake than come up with the rough draft
thanks for starting this
The Following User Says Thank You to ciroip For This Useful Post: | ||
|
2008-12-17
, 20:02
|
Posts: 1,097 |
Thanked: 650 times |
Joined on Nov 2007
|
#49
|
The Following User Says Thank You to nilchak For This Useful Post: | ||
|
2008-12-17
, 20:47
|
|
Posts: 2,853 |
Thanked: 968 times |
Joined on Nov 2005
|
#50
|
Indeed, sure I can . I'm making a package now of ciroip's new version (thank you ciroip for the path modification!) and will relax the versions.
I've lowered it to 2.5.1, should be fine for both diablo and chinook. Pygame version is the same so no changes there.
it ould also be displaying internet time, @0000 was the format...