Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] AttributeError: 'instancemethod' object has no attribute 'ongezond_SRHI_item1'

edited June 2013 in OpenSesame

In an inline scripted form I have Ratingscales named, e.g.
ratingScale1 = widgets.rating_scale(form, var='gezond_SRHI_item1',
nodes=['1', '2', '3', '4', '5', '6', '7'])

Then I want to write these variables away as exp.set.nameofvariable.
Also, I need to make the string into an int, like:
exp.set.ongezond_SRHI_item1 = int(exp.ongezond_SRHI_item1)

I get this error though. what does it mean?

traceback:
AttributeError: 'instancemethod' object has no attribute 'ongezond_SRHI_item1'

Full traceback in debug window

Comments

  • edited 10:50AM

    Hi Natalie,

    To set variables in an inline_script for future use in the graphical interface (for example, the logger item), you should indeed use the built-in experiment function exp.set().

    This function takes two parameters, namely the name of the to-be-set variable (for example, "my_var") and its current value (e.g. 1).

    So, in your case, you set this variable like so:

    exp.set("gezond_SRHI_item1", int(gezond_SRHI_item1))
    

    Does this solve the problem?

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 10:50AM

    Dear Lotje,

    I tried it, but i can't make it work. I get this error:
    Nameerror: NameError: name ongezond_SRHI_item1 is not defined.
    I tried:
    exp.set("ongezond_SRHI_item1", int(ongezond_SRHI_item1))
    and
    exp.set(self.get("ongezond_SRHI_item1"), int(ongezond_SRHI_item1))

    I also wonder WHERE I can state these lines. I have tried many different places, see my code below. I have an inline_scripted form with "run if never" + a inline_script with "run always" after that that checks if everything is filled in before continutation:

    ************ this inline script run if never:


    from libopensesame import widgets form = widgets.form(self.experiment, cols=[3,2], rows=[1,1,1,1,1,1,1,1], spacing = 10) titel = widgets.label(form, text='Ongezond snacken is iets...', center=False) vraag1 = widgets.label(form, text='1. dat ik regelmatig doe', center=False) vraag2 = widgets.label(form, text='2. dat ik automatisch doe', center=False) vraag3 = widgets.label(form, text='3. dat ik doe zonder het me bewust te herinneren', center=False) vraag4 = widgets.label(form, text='4. dat me een vreemd gevoel geeft als ik het niet doe', center=False) vraag5 = widgets.label(form, text='5. dat ik doe zonder er bij na te denken', center=False) vraag6 = widgets.label(form, text='6. dat moeite kost om niet te doen', center=False) instructie= widgets.label(form, text='1 = helemaal oneens, 7 = helemaal eens') ratingScale1 = widgets.rating_scale(form, var='ongezond_SRHI_item1', nodes=['1', '2', '3', '4', '5', '6', '7']) ratingScale2 = widgets.rating_scale(form, var='ongezond_SRHI_item2', nodes=['1', '2', '3', '4', '5', '6', '7']) ratingScale3 = widgets.rating_scale(form, var='ongezond_SRHI_item3', nodes=['1', '2', '3', '4', '5', '6', '7']) ratingScale4 = widgets.rating_scale(form, var='ongezond_SRHI_item4', nodes=['1', '2', '3', '4', '5', '6', '7']) ratingScale5 = widgets.rating_scale(form, var='ongezond_SRHI_item5', nodes=['1', '2', '3', '4', '5', '6', '7']) ratingScale6 = widgets.rating_scale(form, var='ongezond_SRHI_item6', nodes=['1', '2', '3', '4', '5', '6', '7']) nextButton = widgets.button(form, text='Verder') form.set_widget(titel, (0,0), colspan=1) form.set_widget(vraag1, (0,1)) form.set_widget(vraag2, (0,2)) form.set_widget(vraag3, (0,3)) form.set_widget(vraag4, (0,4)) form.set_widget(vraag5, (0,5)) form.set_widget(vraag6, (0,6)) form.set_widget(instructie, (1,0)) form.set_widget(ratingScale1, (1,1)) form.set_widget(ratingScale2, (1,2)) form.set_widget(ratingScale3, (1,3)) form.set_widget(ratingScale4, (1,4)) form.set_widget(ratingScale5, (1,5)) form.set_widget(ratingScale6, (1,6)) form.set_widget(nextButton, (0,7), colspan=2) form._exec() #option 1 for WHERE to put it

    **********this inline script: run if always:

    while True:
        # Make a variable storing whether the form is completely filled
        # in on or not. The starting value is False. If one of the
        # 'checks' below is not met, its set to True:
        incomplete = False
    
        # Execute the prepared inline_script item:
        # (If you placed all the Python script in the Run phase tab, only
        # executing the run phase of your item is enough here)
        exp.items["SRHI_ongezond_deel_1"].run()
    
        #option 4 where to put it:
    
    
        # Check whether your criteria are met:
    
        # The easiests way to do that here is to see whether none of your response 
        # variables are set to 'None'. 'None' indicates that no box was ticked, whereas
        # any other variable indicates that the question was not left unanswered.
        # That's all you need to know, right?
        if (self.get("ongezond_SRHI_item1") == "None" or self.get("ongezond_SRHI_item2") == "None" or           self.get("ongezond_SRHI_item3") == "None" or self.get("ongezond_SRHI_item4") == "None" or           self.get("ongezond_SRHI_item4") == "None" or self.get("ongezond_SRHI_item6") == "None"):
            incomplete = True
    
        # If incomplete is still False, break out of this while loop
        # and continue with the experiment.
        if not incomplete:
                break
    
        # If the form turns out to be incomplete, show a warning.
        else:
            exp.items["warning_message"].prepare()
            exp.items["warning_message"].run()
    
            # Next, the form_base will be executed again.
            # This continues as long as the form is incomplete.
    
    
    #option2 WHERE to put it:
    #if not (self.get("ongezond_SRHI_item1") == "None" or self.get("ongezond_SRHI_item2") == "None" or          self.get("ongezond_SRHI_item3") == "None" or self.get("ongezond_SRHI_item4") == "None" or           self.get("ongezond_SRHI_item4") == "None" or self.get("ongezond_SRHI_item6") == "None"):
    #   print self.get("ongezond_SRHI_item1") #this does print out the value I gave it!
    #   print self.get("ongezond_SRHI_item2") #this does print out the value I gave it!
    #   print self.get("ongezond_SRHI_item3") #this does print out the value I gave it!
    #   print self.get("ongezond_SRHI_item4") #this does print out the value I gave it!
    #   print self.get("ongezond_SRHI_item5") #this does print out the value I gave it!
    #   print self.get("ongezond_SRHI_item6") #this does print out the value I gave it!
    #   exp.set(self.get("ongezond_SRHI_item1"), int(ongezond_SRHI_item1)) # This line gives NameError: name 'ongezond_SRHI_item1' is not defined
    #   exp.set(self.get("ongezond_SRHI_item2"), int(ongezond_SRHI_item2))
    #   exp.set(self.get("ongezond_SRHI_item3"), int(ongezond_SRHI_item3))
    #   exp.set(self.get("ongezond_SRHI_item4"), int(ongezond_SRHI_item4))
    #   exp.set(self.get("ongezond_SRHI_item5"), int(ongezond_SRHI_item5))
    #   exp.set(self.get("ongezond_SRHI_item6"), int(ongezond_SRHI_item6))
    
    #option 3: or can I ummediately set them like this: 
    #exp.set(self.get("ongezond_SRHI_item1"), int(ongezond_SRHI_item1))
    #exp.set(self.get("ongezond_SRHI_item2"), int(ongezond_SRHI_item2))
    #exp.set(self.get("ongezond_SRHI_item3"), int(ongezond_SRHI_item3))
    #exp.set(self.get("ongezond_SRHI_item4"), int(ongezond_SRHI_item4))
    #exp.set(self.get("ongezond_SRHI_item5"), int(ongezond_SRHI_item5))
    #exp.set(self.get("ongezond_SRHI_item6"), int(ongezond_SRHI_item6))
    
    
  • edited June 2013

    Hi Natalie,

    In the first post of this thread, you wrote:

    Then I want to write these variables away

    I'm wondering what you mean exactly by this. Do you mean you want to write the variables away so that they will appear in your output file? In this case, I think everything is quite simple. You can just append a logger item after your inline_script items:

    image

    and the variables "ongezond_SRHI_item1" etc. appear as column headers in your .csv file. The columns contain the counter of the ticked box. Note that Python starts counting at zero, so if participants ticked the first box, the column (e.g. "ongezond_SRHI_item4") contains the value 0, if participants ticked the second box, the column contains the value 1. etc.

    image

    Maybe this is all you need to know? In this case you don't have to worry about setting the variables yourself using exp.set().

    Still, to answer your question about where to do this, if you wanted to do it:
    We made a while loop that keeps showing the form until all questions are answered. Thus, you are only certain that all your response variables contain the counter of a ticked box after the variable 'incomplete' is equal to False.

    As a consequence, you are sure that, on a given trial, the response variables contain their 'final' value:

    while True:
        incomplete = False
    
        exp.items["create_form"].run()
    
        if (self.get("ongezond_SRHI_item1") == "None" or self.get("ongezond_SRHI_item2") == "None" or \
            self.get("ongezond_SRHI_item3") == "None" or self.get("ongezond_SRHI_item4") == "None" or \
            self.get("ongezond_SRHI_item4") == "None" or self.get("ongezond_SRHI_item6") == "None"):
            incomplete = True
    
        if not incomplete:
            # Here
            break
    
        else:
            exp.items["warning_message"].prepare()
            exp.items["warning_message"].run()
    
    # And here (which is where Python 'jumps to' after the break
    # statement in line 13)
    
    # Or in the Run-phase of a new inline_script item that you append to your
    # trial sequence after this inline_script item.
    

    Does this make sense?

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 10:50AM

    Dear Lotje,

    thank you for your answers. I need to use the 'names'of the items later in the experiment to set a reward the participant will receive (a certain picture). That is why the 'number' is not enough. (Also, at first I didn't know a Ratingscale sets the answers as numbers. I thought they would be the names you give the nodes... ).
    I also understand the place now where to put it.. (I was so tired yesterday that I couldn;t see it anymore ;-)
    Thank you again!!

    Natalie

  • edited June 2013

    Hi Natalie,

    thank you for your answers. I need to use the 'names'of the items later in the experiment to set a reward the participant will receive

    Ahh, okay, I see what you mean.

    Maybe something like this?

    # Make a list containing your nodes as integers.
    list_of_nodes = [1,2,3,4,5,6,7]
    
    while True:
        incomplete = False
    
        exp.items["create_form"].run()
    
        if (self.get("ongezond_SRHI_item1") == "None" or self.get("ongezond_SRHI_item2") == "None" or \
            self.get("ongezond_SRHI_item3") == "None" or self.get("ongezond_SRHI_item4") == "None" or \
            self.get("ongezond_SRHI_item4") == "None" or self.get("ongezond_SRHI_item6") == "None"):
            incomplete = True
    
        if not incomplete:
            # Here
            break
    
        else:
            exp.items["warning_message"].prepare()
            exp.items["warning_message"].run()
    
    # Use the ticked box as the index to retrieve
    # the corresponding node from the node list:
    # Use the built-in self.get() function to get the
    # response variables:
    node_item1 = list_of_nodes[self.get("ongezond_SRHI_item1")]
    node_item2 = list_of_nodes[self.get("ongezond_SRHI_item2")]
    node_item3 = list_of_nodes[self.get("ongezond_SRHI_item3")]
    node_item4 = list_of_nodes[self.get("ongezond_SRHI_item4")]
    node_item5 = list_of_nodes[self.get("ongezond_SRHI_item5")]
    node_item6 = list_of_nodes[self.get("ongezond_SRHI_item6")]
    
    # Use the built-in exp.set() function
    # to set the new variables for future use in the GUI
    # (e.g. a feedback or a logger item):
    exp.set("node_item1", node_item1)
    exp.set("node_item2", node_item2)
    exp.set("node_item3", node_item3)
    exp.set("node_item4", node_item4)
    exp.set("node_item5", node_item5)
    exp.set("node_item6", node_item6)
    
    total = node_item1 + node_item2 + node_item3 + node_item4 + node_item5 + node_item6
    exp.set("total", total)
    

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 10:50AM

    Can somebody put this discussion on [solved]? It seems I can not edit the title of the discussion..
    Thank you

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games