What's in a name?

Andrew Dalke dalke at acm.org
Thu May 25 17:52:28 CEST 2000

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,

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:

  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)

                    dalke at acm.org

More information about the Python-list mailing list