Take the 2-minute tour ×

This has been driving me nuts for days... Any help would be appreciated.

I have the following class set up:

class tutor:
    anzahlmitarbeiter = 0

    def __init__(self, name):
        self.name = name
        self.aerzte = []
        self.beobachter = []
        QuicklytestWindow.tutor.anzahlmitarbeiter += 1

    def __del__(self):
        QuicklytestWindow.tutor.anzahlmitarbeiter -= 1

All instances of the class are being held inside a dictionary.

The if self.tutor_number_vorhanden == 1 checks to see if that object has been instantiated. I have a function that istantiates these objects only if needed and then sets the appropriate variable to 1.

    self.mitarbeiter_dict = {}
    if self.tutor_1_vorhanden == 1:
        self.mitarbeiter_dict[1] = self.tutor_1 # the names of the instantiated objects
    if self.tutor_2_vorhanden == 1:
        self.mitarbeiter_dict[2] = self.tutor_2 # the names of the instantiated objects
    if self.tutor_3_vorhanden == 1:
        self.mitarbeiter_dict[3] = self.tutor_3 # the names of the instantiated objects
    if self.tutor_4_vorhanden == 1:
        self.mitarbeiter_dict[4] = self.tutor_4 # the names of the instantiated objects

I am now trying to access a specific self.aerzte list item from a specific tutor object. My code:


the context:


while i <= self.tutor.anzahlmitarbeiter: 

       self.textview.get_buffer().insert(self.textview.get_buffer().get_end_iter(), "\n" + "Arzt: " + self.mitarbeiter_dict[i].aerzte[j])

i += 1
j += 1

This program is running in a PYGTK Window. self.textview.get_buffer() gets the contents of a textview object and appends(prints) my string at the end.

The problem I am getting is that


for some reason returns the entire self.mitarbeiter_dict[i].aerzte list instead of the one string item (a name) that I want which then cannot be printed because it cannot concantenate list and string items.

Again, thank you for your time and help in advance.

share|improve this question
You need to show how you are manipulating the aerzte list. You only show one line where you initialize it to [], but how do you add to it? It sounds like maybe you're not adding what you think you are. –  BrenBarn Jul 14 '12 at 5:30
Any variables called x_1, x_2, etc... are the sign of a common anti-pattern - You are having to write the same code again and again for each of them. Use a list or tuple and a for loop. –  Lattyware Jul 14 '12 at 8:37
I have another function which holds a list of names i want to distribute to the tutor objects. I do somethin like self.tutor_1.aerzte.append(self.a[0::2]) where self.a is the list of names. I want to put every second name into self.tutor_1.aerzte –  user1525082 Jul 14 '12 at 10:22
add comment


Your Answer



Browse other questions tagged or ask your own question.