python - Python3/SQLite3 | How to create multiple tables from a list or list of tuples? -


i have list of tuples so:

>>> all_names = c.execute("""select name fb_friends""") >>> name in all_names: ...     print(name) ('jody ann elizabeth lill',) ('georgia gee smith',) ...(282 more)... ('josh firth',) ('danny hallas',) 

and want create table each individual person. first need replace spaces underscore in order sqlite3 table names, so:

>>> all_names = c.execute("""select name fb_friends""") >>> name in all_names: ...     friends_name = name[0].replace(" ", "_") ...     print(friends_name) jody_ann_elizabeth_lill georgia_gee_smith ...(282 more)... josh_firth danny_hallas 

so if understand correctly have list, not list of tuples..? should simple create tables list so:

>>> all_names = c.execute("""select name fb_friends""") >>> name in all_names: ...     friends_name = name[0].replace(" ", "_") ...     c.execute("""create table {0} (`id` integer not null primary key autoincrement, `work` text not null, `education` text, `current_city` text, `phone_number` text, `dob` text, `gender` text, `sexual_orientation` text, `religion` text, `relationship_status` text, `about_me` text )""".format(friends_name)) 

but create table first name in list, have thought for loop iterate on list of names , create table each one, want, can people please advise me on few things:

  1. is using .replace method best way underscores in names? if no is?
  2. why for loop not iterating on each name create tables? , how make that?
  3. are methods correct @ all? if not methods better?

so after continually playing around various methods managed figure out how this. in order the code work had done convert list, so:

>>> all_names = c.execute("""select name fb_friends""") >>> names = list(all_names) # added line , changed variable names below >>> name in names: ...     friends_name = name[0].replace(" ", "_") ...     c.execute("""create table {0} (`id` integer not null primary key autoincrement, `work` text not null, `education` text, `current_city` text, `phone_number` text, `dob` text, `gender` text, `sexual_orientation` text, `religion` text, `relationship_status` text, `about_me` text )""".format(name)) 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -