Is it bad practise to write __all__ like that
Ben Finney
ben+python at benfinney.id.au
Thu Jul 28 07:52:36 EDT 2011
Karim <karim.liateni at free.fr> writes:
> Hello,
>
> __all__ = 'api db input output tcl'.split()
>
> or
>
> __all__ = """
> api
> db
> input
> output
> tcl
> """.split()
Maybe this:
__all__ = [x.__name__ for x in [
api,
db,
input,
output,
tcl,
]]
presuming these are all objects with an accurate ‘__name__’ attribute.
I'm starting to yearn for the ability in Python to get a string
representation of a name itself, by using the name and not writing it as
a string literal. That would make the above more robust.
But really, this is all obfuscatory. Why not:
__all__ = [
'api',
'db',
'input',
'output',
'tcl',
]
It's clear and explicit and really not difficult to type or maintain.
--
\ “I do not believe in forgiveness as it is preached by the |
`\ church. We do not need the forgiveness of God, but of each |
_o__) other and of ourselves.” —Robert G. Ingersoll |
Ben Finney
More information about the Python-list
mailing list