Re: [Tutor] Perl equivalent of $#var

2005-05-18 Thread Blake Winton
> My current dilemma is that I've got a program that takes one argument > and needs to be run multiple times with this argument being validated > based on the previous one. So proper usage might be > myprog red > myprog blue > myprog green > where it would be wrong to do >

Re: [Tutor] Generator function question?

2005-05-09 Thread Blake Winton
Sorry for jumping in to this a little late, but... > This is (IMO) more elegant: > def neverEndingStatus(): > index = 0 > statusChars = ['|', '\\', '-', '/'] > while True: > yield statusChars[index] > index = (index + 1) % 4 Why not go a step further? def neverEn

Re: [Tutor] List comprehensions

2005-01-13 Thread Blake Winton
Kent Johnson wrote: If you mean for j to be a list of foobar(item) then use j=[foobar(item) for item in x] The first part of the list comp can be any valid expression. Does that mean that there are invalid expressions? I'd enjoy seeing an example. I suppose if it's an expression, it must be valid,

Re: [Tutor] Is there an easy way to conduct binary numbers?

2004-12-23 Thread Blake Winton
Juan Shen wrote: > Binary integer is extremely useful in my > electronic-related job. So...I need help. Is there any function to > transform between binary and decimal integers in python's library? If > not, what's the solution to binary? I can't speak for everyone, but most of the people I've met

Re: [Tutor] am I missing another simpler structure?

2004-12-16 Thread Blake Winton
Juan Shen wrote: def is_leap_year(year): is_leap = True try: datetime.date(year, 2, 29) except ValueError: is_leap = False return is_leap I would write def is_leap_year(year): try: datetime.date(year, 2, 29) return True except ValueError: