Much like Java (or php), I’m use to seperating the classes to files.
Is it the same deal in Python? plus, how should I name the file?
Lowercase like classname.py or the same like ClassName.py?
Do I need to do something special if I want to create an object from this class or does the fact that it’s in the same “project” (netbeans) makes it ok to create an object from it?
Much like Java (or php), I’m use to seperating the classes to files. Is
Share
In Python, one file is called a module. A module can consist of multiple classes or functions.
As Python is not an OO language only, it does not make sense do have a rule that says, one file should only contain one class.
One file (module) should contain classes / functions that belong together, i.e. provide similar functionality or depend on each other.
Of course you should not exaggerate this. Readability really suffers if your module consist of too much classes or functions. Then it is probably time to regroup the functionality into different modules and create packages.
For naming conventions, you might want to read PEP 8 but in short:
and
To instantiate an object, you have to import the class in your file. E.g
or
or
You are asking essential basic stuff, so I recommend to read the tutorial.