Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

mysql - Getting Error:AttributeError: 'str' object has no attribute 'set'

I am doing my school project on mysql connectivity with python and my project is on inventory managment Here I am storing all the databases and the tables of each table in dictionary ex:-'{'database1':('table1','table2')}' and so on. So whenever I need to refer a database or a list of database or tables of selected database I simply use the dictionary to get it.

global database
database = []

global data_table_dict
data_table_dict={}

def startup(): 

 conn = msc.connect(host="localhost", user="root", password="123456")
 cursor = conn.cursor()
 cursor.execute("show databases")
 databasesql_form = cursor.fetchall()
 conn.commit()
 conn.close()

 for i in databasesql_form:
     database.append(i[0])
 print("all databases", database)

 for i in database:
    tables = []
    conn = msc.connect(host="localhost", user="root", password="123456", database=i)
    cursor = conn.cursor()
    cursor.execute("show tables")
    tablesql_form = cursor.fetchall()
    print("All the tables:-", tablesql_form)
    conn.commit()
    conn.close()

    for j in tablesql_form:
        tables.append(j[0])
    print("The list is:", tables)
    data_table_dict.update({i: tables})
print("The dictionary:--", data_table_dict)

startup()

def addnew_category():             
  def add_database():
    conn1 = msc.connect(host="localhost", user="root", password="123456")
    cursor1 = conn1.cursor()
    cursor1.execute("create database {0}".format(var1.get()))
    conn1.commit()
    conn1.close()

  add_database_window = Tk()

  label2 = Label(add_database_window, text="Category Name")
  label2.grid(row=0, column=0)

  var1 = StringVar()
  var1.set(database[0])
  option_menu = OptionMenu(add_database_window, var1.get(), *database)
  option_menu.grid(row=0, column=1, padx=10, pady=20)

  btn1 = Button(add_database_window, text="Add")
  btn1.grid(row=1, column=1)

  add_database_window.mainloop()

The problem is in the options menu I refered it correctly but when I try to select another option it shows this error:

  AttributeError: 'str' object has no attribute 'set'

I don't know why it is showing error. Thank You! in advance

question from:https://stackoverflow.com/questions/65859470/getting-errorattributeerror-str-object-has-no-attribute-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...