Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Modifying selected column of Python 2D list

Posted on 2015-02-04
1
Medium Priority
?
158 Views
Last Modified: 2015-02-16
I have a 2D list 'sorted_list' and need to modify selected elements of the list. The list consists of a variable number of sub lists, each - with 3 elements.  I need to modify the 3rd element of each sub list.  For example :

[[2, 25, 1], [1, 26, 2], [1, 27, 3], [1, 29, 4]]  .... I need to replace elements 1, 2, 3 and 4 with their corresponding names obtained by looking up a mysql table. The revised list could look something like
[[2, 25, NAME1], [1, 26, NAME2], [1, 27, NAME3], [1, 29, NAME4]]

I have made the attached Function 'convertPizzaNameCOMBO(sorted_list)' which should produce the modified list (attached). It gives however  the attached error message indicating SQL syntax problem (see attached error message)
 

The function seems to be working correctly from a looping standpoint. For example, if I replace sorted_list[][col] with 20 (which is a legitimate ID for looking up the table)  - all the targeted elements in the list will be changed to the name corresponding to 20.   So it appear to be some mysql syntax problem ?

Hopefully you can spot the error - or if my basic approach is incorrect, maybe you can point me in the right direction

Thanks
combo.jpg
ErrorMessage.jpg
0
Comment
Question by:jameskane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
jameskane earned 0 total points
ID: 40611803
 cursor.execute("select PizzaName from pizzafill where PizzaID=%s", (sorted_list[i][2],))

Open in new window

turns out that the sql was incorrect. FYI I have attached the correct sql.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question