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: https://hastebin.com/haruhacohe.py To call the objects I am using the following: https://hastebin.com/oxatumuyep.coffeescript (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 ( https://stackoverflow.com/questions/3434581/accessing-a-class-member-variables-in-python ) 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 PMrfPeixoto
2 AnswersNew Answer
what do you think about this code? #page one.py 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 two.py 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?