What's in a name?
Edward S. Vinyard
vinyard at arlut.utexas.edu
Thu May 25 16:19:09 EDT 2000
Ouch! Your questions might be the death knell for my suggestions. For
example, I can legally write:
class f:
value = 1
def f():
return 2
f = 3
Perhaps I was thinking too "statically-typed". Thanks for the specific
questions. Some of these didn't occur to me, and they've got me thinking
about more practical matters.
Ed
On Thu, 25 May 2000, Andrew Dalke wrote:
>Edward S. Vinyard wrote:
>>For example, forcing the first letter of class names to be capitalized
>>makes it visually clear which names are classes. I enjoy Python's lack of
>>block delimiters and I think I would enjoy the lack of implicitness here,
>>too.
>
>Will the following be allowed?
>
>import UserList
>x = UserList.UserList
>
>or will all assignment have to preserve case?
>
>What about:
>
>def f():
> return UserList.UserList
>x = f()
>
>or will f() have to be capitalized if it returns classes, thus making
>x by capitalized because it gets something from F()?
>
>Sometimes you use factory functions instead of a constructor. Consider
>the following common idiom:
>
>try:
> from cStringIO import StringIO # function
>except ImportError:
> from StringIO import StringIO # constructor
>
>f = StringIO("This is some text")
>
>Would you prevent the first from occuring? Similarly, any sort of
>dispatch function will likely need to allow both functions and constructors
>to be used interchangeably:
>
>table = {
> "i", int,
> "sf", StringIO,
> ...
>}
>def unpack_object(s):
> datatype, data = string.split(s)
> f = table.get(datatype, None)
> if f is None:
> raise TypeError("unknown datatype", datatype)
> return f(data)
>
> Andrew
> dalke at acm.org
>
>
>
>
>
More information about the Python-list
mailing list