Re: [Tutor] Visual and audible system bell

2011-12-12 Thread Alan Gauld

On 12/12/11 07:57, David Smith wrote:


In a terminal window

print ("\a")


triggers a visual and audible bell as set in Terminal window preferences.

However


print ("\a")

and pressing Enter in a Python Shell window
results in neither a visible nor an audible system bell.


I assume the second case means an IDLE window?
If so then its not surprising because IDLE does not use the Terminal 
settings. It is its own Terminal. And IDLE intercepts many of the 
standard control keys etc. In general this is a good thing since IDLE is 
trying to make  debugging and testing code as easy as possible so it 
prevents premature exit from IDLE. But occasionally it stops things 
happening the way you want. In this case no bell. (It is worth perusing 
the IDLE config settings, it may be possible to change this, but I 
suspect its more deeply embedded in the code than that)


The only way round it is probably to just test your code by running it 
in a Terminal and just use IDLE for editing and debugging.


--
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] best book for OOP

2011-12-12 Thread Sarma Tangirala
> Object Oriented Analysis and Design with Applications
> by Grady Booch (1st edition)
> Classic text on OO Design with code and case studies realized in 5
different OOP languages (Smalltalk, Object Pascal, C++, Lisp, ADA)
> Explains why OOP is important and how to ise it effectively. Also
introsduces Booch's OOD notation which was paret of the core that evolved
into UML.
>

+1
Used this book in an OOAD course and was very good.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2011-12-12 Thread Hugo Arts
On Mon, Dec 12, 2011 at 3:56 AM, shawn taylor  wrote:
> firstname = raw_input ("Enter your first name ")
> lastname = raw_input ("Enter your last name ")
> idnumber = raw_input ("Enter your id number ")
> birthday = raw_input ("Enter your birthday mm/dd/ ")
> username1 = firstname[0] + lastname[0] + idnumber
>
> print ("Your username is ") + username1
>
> midltr = firstname[len(firstname) / 2]
> midltrlastnm = lastname[len(lastname)  / 2]
>
> on = int (birthday[0])
> tw = int (birthday[1])
> th = int (birthday[3])
> fr = int (birthday[4])
> fv = int (birthday[6])
> sx = int (birthday[7])
> sv = int (birthday[8])
> eg = int (birthday[9])
>
> num = str (on + tw + th + fr + fv + sx + sv + et)
>
> while num > 10:
>
>
> print num
>
> I'm trying to add all the digits in the birthday and keep adding till i get
> a single digit and I'm stuck
> anything would help thanks

alright, well, you've got all the basic ideas that you need in there,
it's just a matter of combining them in the right way. The basic
component is the while loop you have, you want to keep adding the
digits while there's more than two of them:

while num > 10:
#add digits

there is a slight error in there (what happens if the number comes out
to exactly ten? is that what should happen?), but I'll leave it in for
you to find. Another problem is that the while loop wants to check the
num variable, but it doesn't actually exist until the bottom of the
loop. What we do have at the top of the loop is the birthday variable,
but that has some pesky '/' characters in there that we don't really
want. I suggest the first thing you do is remove those slashes. (hint:
the str class has a replace() method. Google it and see if you can
figure out how to use it for this purpose).

no_slashes_birthday = # use replace here in someway on the birthday?
num = int(no_slashes_birthday)
while num > 10:
#add digits

that's enough for basic setup of the while loop. Now, to add the
digits. First thing we'll need to do is separate our number out into
digits. There's a nifty trick with the division and modulo operators
that can get us individual digits[1], but I don't want to convolute
the essence of this example with math. So here's a simpler way: leave
your number as a string! As you've already figured out, it's easy to
get characters in a string, and you can convert them to integers
individually again.

Ok, so we don't do num = int(no_slashes_birthday), but just num =
no_slashes_birthday. Now we can get at the digits. All we need to do
now is convert them all into integers and add them together inside the
loop, and the loop will repeat it as necessary. The general structure
is "for every digit in num, convert digit to integer and add digit to
total." If you learn to state problems in this way, the necessary code
should flow out from it almost automatically. We can already see that
we'll need a for loop here, and a variable called total with a
sensible starting value[2]. See if you can figure it out.

We're almost done here. at the end of the loop we've got a variable
called total, with our added digits. But the point of a loop is to run
multiple times, and our loop wants to have this total in a variable
called num, and it wants it to be a string so we can get at the
individual digits again. So we want to take the integer from total,
convert it back to a string, and put it in the num variable, right at
the end of the loop. That way it can run over and over until we have
only one digit left:

no_slashes_birthday = # use replace here in someway on the birthday?
num = no_slashes_birthday
while num > 10:
# for every digit, convert digit to int and add to total
# convert total back to string and put it in num for the next iteration

if you fill in the blanks you'll be almost done. There is one problem
though, and it's in the condition of the while loop. The statement
"while num > 10" makes no sense at all, because num, despite its name,
is not a number but a string. Now *we* know that there are characters
representing a number inside the string, but the computer doesn't care
which characters represent a number and it shouldn't, because you've
chosen to store it as a string. So for all it cares you might as well
be asking if "hello" > 10, which very obviously doesn't make sense.
See if you can find a way around this (hint: the requirement was "keep
going while we have more than 1 digit." strings can't be compared to
numbers, but they do have a length).

And with that, you should be able to get it working. Good luck, and if
you have any trouble come back here.

Hugo

P.S.: I wrote this as soon as I woke up. Hopefully this reaches you in
time for you finals, though I fear the worst. In any case, (stating
the obvious) it might be a good idea to start studying a little
earlier next time ;) Programming isn't learned in a day.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://ma

Re: [Tutor] Tutor Digest, Vol 94, Issue 44

2011-12-12 Thread Bulent Arikan
Thank you Dax! That was it! Now I can run the script.

Cheers,
Bulent

On Mon, Dec 12, 2011 at 12:57 PM,  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. Running a script! (Bulent Arikan)
>   2. Re: Running a script! (David Smith)
>   3. Re: best book for OOP (wesley chun)
>   4. Visual and audible system bell (David Smith)
>   5. Re: Visual and audible system bell (Alan Gauld)
>   6. Re: best book for OOP (Sarma Tangirala)
>   7. Re: (no subject) (Hugo Arts)
>
>
> --
>
> Message: 1
> Date: Mon, 12 Dec 2011 08:00:51 +0200
> From: Bulent Arikan 
> To: tutor@python.org
> Subject: [Tutor] Running a script!
> Message-ID:
> >
> Content-Type: text/plain; charset="windows-1252"
>
> Dear List,
>
> I am an absolute beginner to programming and Python. I have Python 2.6.5
> and 3.2 running on Mac OS 10.6.8 Snow Leopard. I have self-help books but
> the problem I am having is not described in any of them. The answer may be
> too obvious though. I am using IDLE: I figured that I could call Idle by
> typing its name on the Terminal instead of launching it from the
> Applications ?WOW! big step ;)) When I save a script as (.py) document, I
> do not know how to 'run' it since the IDLE (2.6 or 3.2) menus do not have
> RUN option (as they describe in the books I have). I understand that I may
> have to type a command to run the script on the Terminal but I could not
> find a specific command. It also seemed strange to me that there was not a
> shortcut in Mac OS to run scripts unlike Windows.
>
> Thank you for your time and help,
>
> --
> B?LENT
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20111212/c0d85f7e/attachment-0001.html
> >
>
> --
>
> Message: 2
> Date: Mon, 12 Dec 2011 06:26:28 +
> From: David Smith 
> To: tutor@python.org
> Subject: Re: [Tutor] Running a script!
> Message-ID: <6f440ed4-bc58-4310-b0c4-61dc48379...@gmail.com>
> Content-Type: text/plain; charset=windows-1252
>
>
> If I have understood you correctly you are looking at the Python Shell.
>
> On this window choose File then New Window this will open a script window
> albeit without any code. This window will have a Run menu and within this
> menu there is a Run Module item which is what I think you are looking for.
> I hope this helps.
>
> Dax
>
> On 12 Dec 2011, at 06:00, Bulent Arikan wrote:
>
> > Dear List,
> >
> > I am an absolute beginner to programming and Python. I have Python 2.6.5
> and 3.2 running on Mac OS 10.6.8 Snow Leopard. I have self-help books but
> the problem I am having is not described in any of them. The answer may be
> too obvious though. I am using IDLE: I figured that I could call Idle by
> typing its name on the Terminal instead of launching it from the
> Applications ?WOW! big step ;)) When I save a script as (.py) document, I
> do not know how to 'run' it since the IDLE (2.6 or 3.2) menus do not have
> RUN option (as they describe in the books I have). I understand that I may
> have to type a command to run the script on the Terminal but I could not
> find a specific command. It also seemed strange to me that there was not a
> shortcut in Mac OS to run scripts unlike Windows.
> >
> > Thank you for your time and help,
> >
> > --
> > B?LENT
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
>
> Message: 3
> Date: Sun, 11 Dec 2011 22:54:50 -0800
> From: wesley chun 
> To: surya k 
> Cc: Python Tutor 
> Subject: Re: [Tutor] best book for OOP
> Message-ID:
> >
> Content-Type: text/plain; charset=ISO-8859-1
>
> what do you think you are missing? is there something in the book that
> you don't/can't understand? those of us on the list may be able to
> help you out... sometimes humans are better at explainin

Re: [Tutor] Running a script!

2011-12-12 Thread Robert Sjoblom
On 12 December 2011 11:59, Bulent Arikan  wrote:
> Thank you Dax! That was it! Now I can run the script.
>
> Cheers,
> Bulent

You don't have to submit the entire digest when you're replying; trim
it down to what you're actually replying to. Also, please avoid
posting your reply on top -- it makes it difficult to find (and to
keep track of who says what when).

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


Re: [Tutor] Need Explanation...

2011-12-12 Thread Homme, James
Hi,
Alan said:
Because app() returns the result of append().
But append() returns None, since it modifies the list in place.

This is one of the few features of Python I dislike. It would not have been 
difficult to make these modifier methods return the thing modified.
This style would then allow chained methods.

We do it with strings:

"foobar is a string".rstrip('ing').upper()

because strings are immutable. But we could have done it with other sequence 
types too. Sadly we didn't and history/tradition leaves us with these 
counterintuitive modifiers that return None. It catches everybody out at some 
point...


Is that the same problem with using the len function on sequences and open on 
files, or is it different?

Thanks.

Jim

-Original Message-
From: tutor-bounces+james.homme=highmark@python.org 
[mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Alan 
Gauld
Sent: Saturday, December 10, 2011 4:16 AM
To: tutor@python.org
Subject: Re: [Tutor] Need Explanation...

On 10/12/11 07:41, sunil tech wrote:

> /def app(x):/
> / return x.append(100)/
> /
> /p = app(a)/
> /
> /now list holds appended value [1,2,3,100]/
> /but p is empty... why it is?/

Because app() returns the result of append().
But append() returns None, since it modifies the list in place.

This is one of the few features of Python I dislike. It would not have
been difficult to make these modifier methods return the thing modified.
This style would then allow chained methods.

We do it with strings:

"foobar is a string".rstrip('ing').upper()

because strings are immutable. But we could have done it with other
sequence types too. Sadly we didn't and history/tradition leaves us with
these counterintuitive modifiers that return None. It catches everybody
out at some point...


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



This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Explanation...

2011-12-12 Thread James Reynolds


Sent from my iPad

On Dec 12, 2011, at 7:08 AM, "Homme, James"  wrote:

> Hi,
> Alan said:
> Because app() returns the result of append().
> But append() returns None, since it modifies the list in place.
> 
> This is one of the few features of Python I dislike. It would not have been 
> difficult to make these modifier methods return the thing modified.
> This style would then allow chained methods.
> 
> We do it with strings:
> 
> "foobar is a string".rstrip('ing').upper()
> 
> because strings are immutable. But we could have done it with other sequence 
> types too. Sadly we didn't and history/tradition leaves us with these 
> counterintuitive modifiers that return None. It catches everybody out at some 
> point...
> 
> 
> Is that the same problem with using the len function on sequences and open on 
> files, or is it different?
> 
> Thanks.
> 
> Jim


But a python list is mutable. I'm hardly an expert, but the idea is you are 
modifying the list. Why would you create another copy of the same list via a 
return statement?

At it's fundamentals python is really an object oriented language. When you use 
append, extend, pop, sort, etc on the list you retain the object but change 
some of the attributes stored in the object. Your string example isn't 
analogous because they are, as you noted, immutable.

I don't see this as a weakness but a strength. It cuts back on confusion and 
extraneous variables. 

Your example of Len also doesn't apply. It isn't modifying anything. It's 
returning the length of the list, in this case. You change nothing.

Open, if I recall, creates a file object in the same way class A:  a = A() 
creates an instance of A.

But like I said I'm not an expert.







> -Original Message-
> From: tutor-bounces+james.homme=highmark@python.org 
> [mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Alan 
> Gauld
> Sent: Saturday, December 10, 2011 4:16 AM
> To: tutor@python.org
> Subject: Re: [Tutor] Need Explanation...
> 
> On 10/12/11 07:41, sunil tech wrote:
> 
>> /def app(x):/
>> / return x.append(100)/
>> /
>> /p = app(a)/
>> /
>> /now list holds appended value [1,2,3,100]/
>> /but p is empty... why it is?/
> 
> Because app() returns the result of append().
> But append() returns None, since it modifies the list in place.
> 
> This is one of the few features of Python I dislike. It would not have
> been difficult to make these modifier methods return the thing modified.
> This style would then allow chained methods.
> 
> We do it with strings:
> 
> "foobar is a string".rstrip('ing').upper()
> 
> because strings are immutable. But we could have done it with other
> sequence types too. Sadly we didn't and history/tradition leaves us with
> these counterintuitive modifiers that return None. It catches everybody
> out at some point...
> 
> 
> --
> 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
> 
> 
> 
> This e-mail and any attachments to it are confidential and are intended 
> solely for use of the individual or entity to whom they are addressed. If you 
> have received this e-mail in error, please notify the sender immediately and 
> then delete it. If you are not the intended recipient, you must not keep, 
> use, disclose, copy or distribute this e-mail without the author's prior 
> permission. The views expressed in this e-mail message do not necessarily 
> represent the views of Highmark Inc., its subsidiaries, or affiliates.
> ___
> 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] Remove python modules

2011-12-12 Thread John De

Hi,
I want to build python-2.7.2 and omit some modules that I don't need in order 
to create a smaller Python interpreter.
Am I able to do this?
Any recommendations?

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


[Tutor] pygame blinking text

2011-12-12 Thread Cranky Frankie
My Python presentation is just about complete. As a nice ending I want
to do a pygame program that displays the group's .jpg, with the words
"Thank You!" blinking, say on for a second and off for a second.
Unfortunatley, I can't get the works to blink, but I can get them to
appear for a short time:

from livewires import games, color

games.init(screen_width = 640, screen_height = 480, fps = 50)

bg_image = games.load_image("AEMUG640x480.JPG", transparent = False)
games.screen.background = bg_image


ty_message = games.Message(value = "Thank You!",
 size = 100,
 color = color.red,
 x = games.screen.width/2,
 y = games.screen.height/2,
 lifetime = 100,
 after_death = 0)

games.screen.add(ty_message)

games.screen.mainloop()



I tried putting the ty_message block in a WHILE TRUE loop, and that
didn't work. Then I tried the same with the
games.screen.add(ty_message) line and that didn't work either. I think
what might work is if I can find a way to delete the ty_message and
readd it, over and over in a loop with a delay, bu:

games.screen.delete(ty_message)

doesn't work - delete is not a valid method.

Is there any way to get blinking text with pygame? This is not a deal
breaker, but I thought the blinking text would be neat.

-- 
Frank L. "Cranky Frankie" Palmeri
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] return, why do I need it?

2011-12-12 Thread Prasad, Ramit
>No one has mentioned it so far, but the interactive interpreter is what you 
>should use for debugging short code snippets.  I always program with two 
>windows open - one with my editor and one with the interpreter. This lets me 
>try out short bits of code without running my whole program.
+1

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygame blinking text

2011-12-12 Thread Timo

Op 12-12-11 15:01, Cranky Frankie schreef:

My Python presentation is just about complete. As a nice ending I want
to do a pygame program that displays the group's .jpg, with the words
"Thank You!" blinking, say on for a second and off for a second.
Unfortunatley, I can't get the works to blink, but I can get them to
appear for a short time:

from livewires import games, color
Looks like you're not using pygame, but livewires. Why not try their 
mailinglist, I bet their knowledge is better than this *Python 
beginners* list.


Cheers,
Timo



games.init(screen_width = 640, screen_height = 480, fps = 50)

bg_image = games.load_image("AEMUG640x480.JPG", transparent = False)
games.screen.background = bg_image


ty_message = games.Message(value = "Thank You!",
  size = 100,
  color = color.red,
  x = games.screen.width/2,
  y = games.screen.height/2,
  lifetime = 100,
  after_death = 0)

games.screen.add(ty_message)

games.screen.mainloop()



I tried putting the ty_message block in a WHILE TRUE loop, and that
didn't work. Then I tried the same with the
games.screen.add(ty_message) line and that didn't work either. I think
what might work is if I can find a way to delete the ty_message and
readd it, over and over in a loop with a delay, bu:

games.screen.delete(ty_message)

doesn't work - delete is not a valid method.

Is there any way to get blinking text with pygame? This is not a deal
breaker, but I thought the blinking text would be neat.



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


[Tutor] timedelta, difference calculation

2011-12-12 Thread rail shafigulin
i found something interesting during the timedate difference calculation

import datetime
import time

def main():
  mydatetime = datetime.datetime.now()
  time.sleep(1)
  mydatetime2 = datetime.datetime.now()
  diff = mydatetime - mydatetime2

  print(diff)

if __name__ == '__main__':
  main()

if you run this code the result you get will be
-1 day, 23:59:59

at least that is what i'm getting.

i was expecting to get -1 second. diff object is of type timedelta. this
kind of objects represent duration, at least that is what i understood from
the documentation (
http://docs.python.org/release/3.1.3/library/datetime.html#timedelta-objects).
so, is this a bug in the timedelta implementation or is it me not
understanding documentation properly?

any help is appreciated.

ps. i'm using python 3.1 on a windows xp machine.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Explanation...

2011-12-12 Thread Alan Gauld

James H wrote:

Is that the same problem with using the len function on sequences

> and open on files, or is it different?

I don't think so. I'm not sure which problem you are referring to with 
these?


Neither return None...


But a python list is mutable. I'm hardly an expert, but the idea is
you are modifying the list. Why would you create another copy of
the same list via a return statement?


You wouldn't you'd return the same, now-modified, object.

James R wrote:

I don't see this as a weakness but a strength.
It cuts back on confusion and extraneous variables.


It creates confusion too. Look at how many posts we get
because people try to do things like:

mylist = mylist.sort()

Actually it can introduce extraneous variables because
you need a temp to hold the modified list while you perform the extra 
operations. With method chaining you do it all on one line.
Now the good news is that in Python you can use one variable to hold 
both the intermediate list and the final result, so its not often a new 
variable just a double use of a single one.


I suspect the value of this is only apparent if you have
used Smalltalk :-)

--
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] Need Explanation...

2011-12-12 Thread Homme, James
Hi Alan,
I'm sorry. I'm coming pretty much from Cobol and freaking out about OO, so my 
questions may not be coming from a familiar place. I think I was referring 
partly to the idea that, for example, len and open are built in functions, 
whereas append is part of a list. I just am now to the place in Python where I 
understand some things about making classes and using them, but not a lot more. 
If I'm unintentionally implying anything else, I'm unaware of what it might be.

I've used classes on purpose when I was working with LotusScript in my Lotus 
Notes development work, and I know that I have used them in other programming 
areas, but I've only recently purposely begun to get over the hump of learning 
to make them and really try to understand how they work. My programming 
knowledge is all over the place, since I have no formal computer science 
training.

Thanks for your patience.

Jim

-Original Message-
From: tutor-bounces+james.homme=highmark@python.org 
[mailto:tutor-bounces+james.homme=highmark@python.org] On Behalf Of Alan 
Gauld
Sent: Monday, December 12, 2011 2:58 PM
To: tutor@python.org
Subject: Re: [Tutor] Need Explanation...

James H wrote:
>> Is that the same problem with using the len function on sequences
 > and open on files, or is it different?

I don't think so. I'm not sure which problem you are referring to with
these?

Neither return None...

> But a python list is mutable. I'm hardly an expert, but the idea is
> you are modifying the list. Why would you create another copy of
> the same list via a return statement?

You wouldn't you'd return the same, now-modified, object.

James R wrote:
> I don't see this as a weakness but a strength.
> It cuts back on confusion and extraneous variables.

It creates confusion too. Look at how many posts we get
because people try to do things like:

mylist = mylist.sort()

Actually it can introduce extraneous variables because
you need a temp to hold the modified list while you perform the extra
operations. With method chaining you do it all on one line.
Now the good news is that in Python you can use one variable to hold
both the intermediate list and the final result, so its not often a new
variable just a double use of a single one.

I suspect the value of this is only apparent if you have
used Smalltalk :-)

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



This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pygame blinking text

2011-12-12 Thread Steven D'Aprano

Cranky Frankie wrote:
[...]

Is there any way to get blinking text with pygame? This is not a deal
breaker, but I thought the blinking text would be neat.


To punish your users for completing the game?


Ha ha only serious.



--
Steven


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


Re: [Tutor] timedelta, difference calculation

2011-12-12 Thread Lie Ryan

On 12/13/2011 06:46 AM, rail shafigulin wrote:

i found something interesting during the timedate difference calculation

import datetime
import time

def main():
   mydatetime = datetime.datetime.now()
   time.sleep(1)
   mydatetime2 = datetime.datetime.now()
   diff = mydatetime - mydatetime2

   print(diff)

if __name__ == '__main__':
   main()

if you run this code the result you get will be
-1 day, 23:59:59

at least that is what i'm getting.

i was expecting to get -1 second. diff object is of type timedelta. this
kind of objects represent duration, at least that is what i understood
from the documentation
(http://docs.python.org/release/3.1.3/library/datetime.html#timedelta-objects).
so, is this a bug in the timedelta implementation or is it me not
understanding documentation properly?


It's due to timedelta normalization; in timedelta object only the day 
part is ever negative, you never had negative hour, minute, or second. 
The `-1 day, 23:59:59` means to subtract 1 day, then add 23:59:59; 
therefore giving us -1 second.


It is documented behavior, although perhaps hinted too subtly, from the 
docs:


"""
Note that normalization of negative values may be surprising at first. 
For example,


>>> from datetime import timedelta
>>> d = timedelta(microseconds=-1)
>>> (d.days, d.seconds, d.microseconds)
(-1, 86399, 99)
"""

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


Re: [Tutor] pygame blinking text

2011-12-12 Thread Lie Ryan

On 12/13/2011 01:01 AM, Cranky Frankie wrote:

I tried putting the ty_message block in a WHILE TRUE loop, and that
didn't work. Then I tried the same with the
games.screen.add(ty_message) line and that didn't work either. I think
what might work is if I can find a way to delete the ty_message and
readd it, over and over in a loop with a delay, bu:


This is a common problem when people start GUI/graphics programming; 
once you enter the GUI mainloop, you're no longer in control of the 
program flow. Instead the mainloop will process events and callbacks; 
therefore if you want a blinking text, you had to arrange such that your 
blinker function will be called every second.


In pygame, you can do the following:

#!/usr/bin/env python

import pygame

# initialize pygame, this must be called before
# doing anything with pygame
pygame.init()

# create a screen
screen = pygame.display.set_mode((400, 400))

# setup the text
font = pygame.font.Font(None, 36)
text = font.render("Hello World", True, (100, 100, 100))

display = True

# the main loop
while pygame.time.get_ticks() < 1: # run the program for 10 seconds
# empty the screen
screen.fill((255, 255, 255))

display = not display

# draw the text to the screen only if display is True
if display:
screen.blit(text, (100, 100))

# update the actual screen
pygame.display.flip()

# wait for half second
pygame.time.wait(500)


You can do this in pygame since pygame do not provide a mainloop.

I took a quick glance at livewires, their main loop implementation is 
very simple; however it discards all events except for mouse, keyboard, 
and the quit event. In typical game engine, you usually will register an 
event to the event handler to be executed every second that will 
draw/undraw the text. However, in livewires event handling system you 
can't do that. Therefore, if you want to do it, you'd have to override 
the event handling method in the Screen class.


However, for a quick hack, I think you can abuse the after_death= 
parameter; you can register a function that will games.screen.add() a 
Message, then after_death, it registers an invisible message which 
registers a Message after its death which registers the visible message 
after death which ... . In short, the following (I haven't tested it, 
although I think it should work):


stop = False
def add_visible_ty():
if stop: return
message = games.Message(
value = "Thank You!",
size = 100,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 500,
after_death = add_invisible_ty
)
games.screen.add(message)

def add_invisible_ty():
if stop: return
message = games.Message(
value = "",
size = 100,
color = color.red,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 500,
after_death = add_visible_ty
)
games.screen.add(message)




games.screen.delete(ty_message)

doesn't work - delete is not a valid method.


There are two rendering style for graphics programming; one is called 
the "retained mode", in which the libraries retain a complete model of 
the objects to be rendered and graphic calls do not directly cause 
actual rendering but instead update an internal model, the other is the 
"immediate mode" in which graphic calls directly cause rendering of 
graphics objects to the display.


pygame falls into the latter; pygame do not keep track of objects that 
it has drawn on screen, therefore if you need to "delete" an object from 
the screen, you'd need to redraw the whole screen except the object you 
had deleted. At the very least, you'd need to redraw the part of the 
screen that had changed due to the deletion.


livewires falls into the former; in livewires there is an internal 
object that represent each screen object and it keep tracks of which 
objects and which part of the screen that are "dirty".


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


Re: [Tutor] pygame blinking text

2011-12-12 Thread Prasad, Ramit
>This is a common problem when people start GUI/graphics programming; 
>once you enter the GUI mainloop, you're no longer in control of the 
>program flow. Instead the mainloop will process events and callbacks; 
>therefore if you want a blinking text, you had to arrange such that your 
>blinker function will be called every second.

Since you are using livewires, you can subclass games.Timer 
and then create an instance of that subclass at the end and then have 
the tick function check for some Boolean value and either hide or 
show the text. I am not familiar with livewires or pygame, so I hope that helps.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor