python - etree findall not working inside function -


i puzzled. have written little piece of code before , used somewhere else:

def testbut(p):     print(root)     items in root.findall("a/item"):         print(items.get("name")) 

and has worked fine.

but in newer project have following code:

for items in root.findall("a/item"): print(items.get("name"))  def testbut(p):     print(root)     items in root.findall("a/item"):         print(items.get("name")) 

so outside def. workes fine, , shows me items in a, inside def nothing root (because print it). can explain why?

i sorry if repost or whatever, cannot find answer, given works fine in different file exact same setup..

edit: full(ish) code.

from tkinter import * xml.etree.elementtree import elementtree xml.etree.elementtree import element import xml.etree.elementtree et  tree = et.parse("alphabet.xml") root = tree.getroot()  colour0 = "white" colour1 = "olivedrab1" colour2 = "paleturquoise1" colour3 = "rosybrown1" font1 = "arial, 24" counterrow = 1 countercolumn = 0  items in root.findall("a/item"):     print(items.get("name"))  def testbut(p):     print(root)     items in root.findall("a/item"):         print("test")         print(items.get("name"))  def setup():     letters in root:         global counterrow         global countercolumn          letters.tag = button(vindue, text=letters.tag, font=font1,                              command=lambda p=letters.tag: testbut(p))\             .grid(row=counterrow, column=countercolumn, sticky="nsew")         countercolumn += 1         if countercolumn > 7:             counterrow += 1             countercolumn = 0   def reset():     buttons in vindue.grid_slaves():         if buttons.grid_info()["row"] > 0:             buttons.grid_forget()   def showbut(input):     counter = 0     reset()     lst = []     print(input)     str = input+"/item"     print(str)     items in root.findall("a/item"):         print(items.get("name"))         print("test")         varstr = items.get("name")+"var"         varstr = intvar()         varstr2 = items.get("name")         varstr2 = button(vindue, text=items.get("name"), font="arial, 44", command=lambda varstr=varstr: (varstr.set(varstr.get() + 1), print(varstr.get())))         varstr2.grid(row=1, column=counter)         counter += 1     vindue = tk()  setup()  vindue.mainloop() 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -