0

I got several values in my list [Me, You, He, She, it] I loop over my list. In each iteration, I want to set up a global var with the value of the list-item.

while ls_ddictab in gt_ddic_table:
    lv_create_gl_tab = ls_ddictab['TABLA']
    lv_create_gl_tab_old = lv_create_gl_ta
    if lv_create_gl_tab is not lv_create_gl_tab_old:
        global lv_create_gl_tab

SyntaxError: name lv_create_gl_tab is used prior to global declaration

Edit

Overall target is to create a global data dictionary. All global-variables are maintained an an excel-file. From time to time I add additional variables in my excel. These variables I want to make global in a runtime

Bill P
  • 3,622
  • 10
  • 20
  • 32
Lui
  • 1
  • 2
  • it is Python. Dont be confused because of the declation. – Lui Dec 21 '18 at 09:58
  • 1
    I think you might have misunderstood how `global` works. It is something you use when you want multiple functions to have access to the same (mutable) variable. In other words, access to the variable is not limit to the scope of the function. I don't think that is what you want here. But, actually, I don't really know what you want. What is your expected outcome? What do you want to store in `lv_create_gl_tab`? – Karl Dec 21 '18 at 10:11
  • Overall target is to create a global data dictionary. All global-variables are maintained an an excel-file. From time to time I add additional variables in my excel. These variables I want to make global in a runtime. – Lui Dec 21 '18 at 10:17
  • in lv_create_gl_tab I have all lines of my excel-file. for each line i have a cell with the name of the variable that I want to make to become a global var – Lui Dec 21 '18 at 10:18
  • have a look here [https://stackoverflow.com/questions/423379/using-global-variables-in-a-function] to understand how `global` works in pyhton. In your case, I think it is enough to read you excel file at the top of your code and store the values in a list or a dict. That list or dict can be read from anywhere in your code, no need to loop over it to declare its elements global. – Valentino Dec 21 '18 at 13:58

0 Answers0