Importing Objects from a Class | Sololearn: Learn to code for FREE!


Importing Objects from a Class

Hello people good night. I have the following problem: to make it easier to maintain / translate an application, I created a class called ProgramVocab to store all the strings used. However, when I try to import these strings to use them in the project, I get the AttributeError, saying that they are undefined attributes. For example: How the class is: To call the objects I am using the following: (Please ignore the .coffeescript extension that Hastebin generated above) Well, when I try to modify the calling mode of the class - using an instance - as explained in this link ( ) I get theTypeError: 'module' object is not callable. So, what am I doing wrong? Sounds like a simple problem, but I can not figure it out.

8/1/2018 11:59:29 PM


2 Answers

New Answer


what do you think about this code? #page class ProgramVocab: def __init__(self, text_1, text_2, text_3): self.text_1 = text_1 self.text_2 = text_2 self.text_3 = text_3 #page from page_one import ProgramVocab as vocab #instance variable x = vocab("attack", "defend", "hide") print("Skill 1: ", x.text_1) #attack print("Skill 2: ", x.text_2) #defend print("Skill 3: ", x.text_3) #hide


Mohamed :) It would work perfectly, but I would need to type the texts outside the 'ProgramVocab' file. Would not there be a more practical way to leave all strings in a single file?