[Tutor] Everything in one file?

Shall, Sydney sydney.shall at kcl.ac.uk
Wed Jul 18 09:46:20 EDT 2018


On 24/05/2018 03:27, Steven D'Aprano wrote:
 > On Tue, May 22, 2018 at 03:46:50PM +0530, aishwarya selvaraj wrote:
 >>   Dear all,
 >>   I have created 2 classes in 2 separate files.
 >
 > If you have learned the bad habit from Java of putting every class in a
 > separate file, you should unlearn that habit for your Python code. There
 > is no need to put every class in a separate file, and it usually leads
 > to complicated dependencies and circular imports.
 >
 >

I am an slightly more than a beginner.
I have not met this advice from Steven D'Aprano before, so I have some 
questions.

I have constructed a program which has a parent class and a child class 
and I have them in two different files. I import the parent class into 
the child class and create instances with the child class. This works fine.
But, would it be better to have both classes in one file? Would then the 
child class 'know' that the parent class is in the file?

And further. I have a function which sets up all the suitable data 
structures into which this function will put the information supplied by 
the user. I import this file too into both the parent and the child class.
Would the instances with which I actually work, 'know' that this 
function is there if it is simply present in the same file?

-- 
Sydney





More information about the Tutor mailing list