[Tutor] mistake naming class

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jan 1 05:33:40 EST 2004


> class open(object):
>         def __init__(world, person, animal):
>                 open('foo.txt', 'r')
>
> Any solutions other then renaming my class, because going through
the
> code looking for calls to class open is not going to be fun

It might not be fun but you really should do it. Naming a class
after a system name is a big problem(unless you really want to
hide the system name and provide alternative functionality. Even
then its probably better to do it with an alias.

Conventionally class names start with an uppercase letter. If
you had followed the convention this problem would not have
arisen. As to changing it, use a search tool like grep to find
all of the occurences. You will have to manually validate whether
it should be a call to your class or to the system open()

Incidentally its very unusualy to name a class after a verb.
Objects are things so the class name is usually a noun. Are
you sure you need a class and not just a function? Just a
thought...

[BTW there are several modules with an open function in them,
but they are doing so deliberately, usualky with 'file-like'
objects and are a good example of why you should never use
the from foo import * style...]

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list