Python3 - How do I import a class from another file

R.Wieser address at not.available
Tue Dec 10 03:45:01 EST 2019


DL,

> I went through this cycle of thinking, first using if __name__... to 
> 'hide' testing, then adding test functions within the module, and now keep 
> test code quite separate from 'the real thing'.

:-) The normal newbie progression, off of which I'm in phase #1.   Having a 
working program (riddeled with debugging output) is still (way) more 
important than having the best code I'm afraid.   But reading about how 
others handle it definitily makes it easier for me to progress.

> Expanding on 'names' and del(): the first point is that there is seldom 
> much to be gained by using del(), ie becoming your own 'garbage 
> collector'.

In my case deleting the instance was needed to release its hold on something 
that was taken when the instance was initialised (in my case a GPIO pin on a 
Raspberry Pi).   I did not even think of garbage collection.

> Python enables you to play fast-and-loose, eg

I know (similar to VBScript which uses Variants for everything).   Its all 
about wnat I /intend/ to have inside it, and the type prefix character 
keeping myself aware of where (not) to use the variable.  Also, silent type 
conversions can work against you.    I normally prefix an instanciated class 
(having methods) with an "o".

Than again, I normally camel-case my variable and function names (to make 
them stand out from the build-in commands), as I normally do not use editors 
with syntax highlighting.

> A Python-list will handle the former (wow, that's a bit of 'rocket 
> science'!?) whereas a Python-set will only contain unique values. So, 
> rather than using a somewhat-bland varNM such as "letters", I would choose 
> to be more explicit:

:-) Always start with a descriptive* name for the variable, regardless of if 
it is a compounded one or not.   As said, the type prefix is just a 
reminder.

*though not /too/ descriptive.   Languages which can easily have 
40-character names for variables, functions and such are simply the pits, 
especially when they start to differ only for a single/few character(s) 
somewhere in the middle. :-(

> rudy = Man( etc ) #rudy probably does have class, in this instance

You almost owed me a new keyboard there. :-p

Regards,
Rudy Wieser




More information about the Python-list mailing list