[wingide-users] How to instantiate a class defined in a separate file?

Werner wernerfbd at gmx.ch
Wed Dec 9 06:11:17 EST 2015


Hi Brad,

Not really a wingide question, you might want to read one of the many 
tutorials on Python, e.g.:
https://www.python.org/about/gettingstarted/

On 12/9/2015 2:46, Brad Stiritz via wingide-users wrote:
...
> Question : Does Perceptron have to be imported somehow into the Test 
> harness?
Yes
>
> 2) I then tried explicitly importing the class into the same test 
> harness file, as follows:
> import Perceptron
> p = Perceptron(2)
> Traceback (most recent call last):
>   File "w:\Python-work\Perceptron\Test harness.py", line 2, in <module>
>     p = Perceptron(2)
> TypeError: 'module' object is not callable
> Process terminated with an exit code of 1
> Question : How do we import a class defined in an external .py file?
I would do it like this:

import Perceptron as PM
p = PM.Perceptron(2)

"PM" is the module which can contain multiple classes, functions etc.

You could also do:
import Perceptron
p = Perceptron.Perceptron(2)

Werner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://wingware.com/pipermail/wingide-users/attachments/20151209/4816f32a/attachment.html>


More information about the wingide-users mailing list