Encapsulating conditional execution based on list membership - how do you do it?

Gabriel Genellina gagsl-py at yahoo.com.ar
Mon Dec 11 19:37:46 EST 2006


At Monday 11/12/2006 12:23, metaperl wrote:

>ok, so I'm thinking of adding a method to the storage class so I can do
>this:
>
>self.storage.archive_has(f, print_msg=True) and sys.exit()
>
>but really there is no need to hardcode which storage directory. So I'm
>thinking:
>
>self.storage.memberof('archive', f, print_msg=Tree) and sys.exit()
>
>
>Is that the best solution you can think of?

This is just _my_ opinion, of course.
I don't like the construct "blablabla() and sys.exit()" or 
"blablabla() or sys.exit()", I prefer an explicit check "if not 
blablabla(): exit()"
I'm not sure what you mean by "archive" but instead of a string, make 
it an object so you can write self.storage.archive.has_file(f). The 
check should do just *that*, return a boolean without side effects; 
if you want to print a message, make the caller print it.
If you alias .has_file as .__contains__, you could also write: if f 
in self.storage.archive, which looks even better.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list