Python Forum
Error when refering to class defined in 'main' in an imported module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when refering to class defined in 'main' in an imported module
#1
Hi!

In my 'main.py' I have this:

class ScalableLabel(Label):
    pass

from sharebox_ios_etc import ShareBox
And in 'sharebox_ios_etc.py' I have this:

class ShareBox(ScalableLabel):
But that line produces this error:

Error:
Traceback (most recent call last): File "/mnt/4AF15A0435E762B4/mypython/GeoESP/main.py", line 70, in <module> from sharebox_ios_etc import ShareBox File "/mnt/4AF15A0435E762B4/mypython/GeoESP/sharebox_ios_etc.py", line 15, in <module> class ShareBox(ScalableLabel): NameError: name 'ScalableLabel' is not defined
So how can I refer to a class defined in the main module in an imported module?
Do I have to but "class ScalableLabel(Label):" in a third 'common.py' module and import that in both of the others?
In that case I guess I would have to import Label in 'common.py'.
Reply


Messages In This Thread
Error when refering to class defined in 'main' in an imported module - by HeRo - Apr-13-2021, 06:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 594 Nov-23-2023, 02:53 PM
Last Post: rob101
  How to read module/class from list of strings? popular_dog 1 480 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 724 Aug-06-2023, 01:09 AM
Last Post: aupres
  "Name is not defined" when running a class lil_e 6 4,043 Jan-12-2023, 11:57 PM
Last Post: lil_e
  My code displays too much output when importing class from a module lil_e 4 1,162 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,865 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  No module found when I run a main.py tomtom 2 1,481 Jul-20-2022, 09:24 AM
Last Post: tomtom
  Can a module tell where it is being imported from? stevendaprano 3 1,190 Apr-12-2022, 12:46 AM
Last Post: stevendaprano
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,141 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,363 Mar-13-2022, 03:29 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020