Working with classes

Chris Angelico rosuav at
Tue Dec 4 04:27:16 CET 2012

On Tue, Dec 4, 2012 at 9:47 AM,  <laila at> wrote:
> Hello, I've been working on this program for a long time but can't seem to get it to work.. The first array is the input file, then a class, another class and the actual program. Could anyone see what is wrong? I'm sorry if the program doesn't make any sense at all  I'm just starting to learn this..
> The exercise wants us to do the following:

Hi! Thanks for being up-front about it being homework :)

In what way does your code not work? Is it giving an exception? Paste
the exception and traceback to us - it'll be a lot easier to see
what's going on.

> file_input=file('pirateinvoer','r')

No idea if it's your issue or not, but this is an unusual way to read
files. Normally you'll want to use the open() function, and probably
use 'with' to ensure it's closed promptly.

Note that Python is not Java. You don't have to put one class in one
file. Instead of importing classes from other files, just have them
all in your main file - it makes a lot more sense, usually. In Python,
a file usually is a module, on par with the modules in the standard
library. It can contain lots of (related) classes and functions.


More information about the Python-list mailing list