Re: Case Statements

2016-03-16 Thread Mark Lawrence
On 16/03/2016 10:52, Antoon Pardon wrote: Op 16-03-16 om 10:51 schreef Mark Lawrence: On 16/03/2016 09:35, Antoon Pardon wrote: Op 16-03-16 om 09:47 schreef Mark Lawrence: Same with switch. You can use a hash table etc. to simulate switches, but only if the codeblocks are independent. Other

Re: Case Statements

2016-03-16 Thread Antoon Pardon
Op 16-03-16 om 10:51 schreef Mark Lawrence: > On 16/03/2016 09:35, Antoon Pardon wrote: >> Op 16-03-16 om 09:47 schreef Mark Lawrence: >>> Same with switch. You can use a hash table etc. to simulate switches, but only if the codeblocks are independent. Otherwise, if-elif chains

Re: empty clause of for loops

2016-03-16 Thread Peter Otten
Sven R. Kunze wrote: > Hi, > > a colleague of mine (I write this mail because I am on the list) has the > following issue: > > > for x in my_iterable: > # do > empty: > # do something else > > > What's the most Pythonic way of doing this? What would you expect? >>> class Empty(Exc

Re: empty clause of for loops

2016-03-16 Thread Sven R. Kunze
On 16.03.2016 11:28, Joaquin Alzola wrote: If len(my_iterable) is not 0: for x in my_iterable: # do else: # do something else I am sorry, I should have been more precise here. my_iterable is an iterator that's exhausted after a complete iteration and cannot be restored. I

Re: Case Statements

2016-03-16 Thread BartC
On 16/03/2016 04:06, Mario R. Osorio wrote: On Tuesday, March 15, 2016 at 9:55:27 PM UTC-4, jj0ge...@gmail.com wrote: You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other la

RE: empty clause of for loops

2016-03-16 Thread Joaquin Alzola
You could do something like ... If len(my_iterable) is not 0: for x in my_iterable: # do else: # do something else There should be a more code efficient way to do this. -Original Message- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Be

empty clause of for loops

2016-03-16 Thread Sven R. Kunze
Hi, a colleague of mine (I write this mail because I am on the list) has the following issue: for x in my_iterable: # do empty: # do something else What's the most Pythonic way of doing this? Best, Sven -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-16 Thread Mark Lawrence
On 16/03/2016 09:35, Antoon Pardon wrote: Op 16-03-16 om 09:47 schreef Mark Lawrence: Same with switch. You can use a hash table etc. to simulate switches, but only if the codeblocks are independent. Otherwise, if-elif chains are the way to go. Command line parsing is a case where switch stat

Re: Case Statements

2016-03-16 Thread Antoon Pardon
Op 16-03-16 om 09:47 schreef Mark Lawrence: > >> >> Same with switch. You can use a hash table etc. to simulate switches, >> but only if the codeblocks are independent. Otherwise, if-elif chains >> are the way to go. Command line parsing is a case where switch >> statements are often used, e.g. in

Re: Case Statements

2016-03-16 Thread Marko Rauhamaa
Christian Gollwitzer : > That happens indeed if one were to simulate polymorphism using switch > statements, but not for other cases. There are not many other cases. Decoding is the only generally valid case I can think of. > In Python, you need to go the other way round, you don't have a > swit

Re: Case Statements

2016-03-16 Thread Mark Lawrence
On 16/03/2016 08:13, Christian Gollwitzer wrote: Am 16.03.16 um 05:26 schrieb Mark Lawrence: So you would rather write something like:- switch (x): case COW: moo() break case DUCK: quack() break default IDUNNO: panic() than:- x.makeNoise() No sane person

Re: Case Statements

2016-03-16 Thread Christian Gollwitzer
Am 16.03.16 um 05:26 schrieb Mark Lawrence: So you would rather write something like:- switch (x): case COW: moo() break case DUCK: quack() break default IDUNNO: panic() than:- x.makeNoise() No sane person would do that. But just because you selected the w

Re: Obfuscating Python code

2016-03-16 Thread Steven D'Aprano
On Wednesday 16 March 2016 05:59, Thomas 'PointedEars' Lahn wrote: > On a more constructive note, python(1) (CPython) creates a binary (byte- > code) “.pyc” file from “.py” files when it runs them. To be precise, it creates a .pyc file when the file is imported, not run. Just running a Python