Python "with"

Laurent Pointal laurent.pointal at limsi.fr
Mon Sep 17 04:44:12 EDT 2007


Ivan Voras a écrit :
<zip>
> I know it can be almost always done by using a temporary variable:
> 
> tmp = some.big.structure.or.nested.objects.element
> tmp.member1 = something
> tmp.member2 = something
> 
> but this looks ugly to me.)

The ugly part is the 'tmp' name, try to choose a name with a proper 
meaning about what it is really, and it become clean and readable:

filerefs = some.big.structure.or.nested.object.with.file.references
filerefs.encoding = "utf-8"
filerefs.name = "MyFileName.txt"
filerefs.use_quotes = True

Isn't it ?




More information about the Python-list mailing list