[Tutor] Calling class from another class
Peter Otten
__peter__ at web.de
Thu May 24 12:29:56 EDT 2018
aishwarya selvaraj wrote:
> Dear all,
> I have created 2 classes in 2 separate files.File 1 named atcore_py.pyx
> with class andorCameraSDK3, and file 2 with name AndorCameraGUI making
> use of TKinter.
> I was able to import andorCameraSDK3 into AndorCameraGUI, but I was not
> able to do the other way around, as I need to call the function Plot() in
> file 2 inside function acquireimage() in file 1.
> When I define self.master = master in file 1 and pass this from file 2 as
> self.camera = andorCameraSDK3(self) , I get an error saying :
>
>> Exception in Tkinter callback
>>
>
> Traceback (most recent call last):
>>
> File "/home/ravindra/anaconda2/lib/python2.7/lib-tk/Tkinter.py", line
> 1541,
>> in __call__
>>
>
> return self.func(*args)
>>
> File "/home/ravindra/PycharmProjects/LiveMode/GUI.py", line 278, in
>> getCameraStringGU
>>
>
> self.camera = AndorCameraSDK(self)
>>
> File "atcore_py.pyx", line 77, in AndorCameraDriver.
>> andorCameraSDK3.__cinit__
>>
> self.master = master
>>
> AttributeError: 'AndorCameraDriver.andorCameraSDK3' object has no
> attribute
>> 'master'
The attachments didn't make it, but it looks like you are using Cython.
According to
http://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#dynamic-attributes
you cannot add arbitrary attributes to a class written in Cython, you have
to declare them:
cdef class andorCameraSDK3:
cdef object master
...
> Process finished with exit code 0
>>
>>
>
>
> I'm attaching both the files along with this email. It would be great if
> someone could help me out here. Thanks in advance
>
>
>
More information about the Tutor
mailing list