Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't append a list of dicts with dict from another list of dicts
    primarykey
    data
    text
    <p>Been Googling hours again for answer but seems like my situation is unique, or my understanding of Py is...uh, unique.</p> <p>I have a list of dictionaries (let's call it sqlListOfDict) built from MySQLdb.cursors.DictCursor query, Py print yields this:</p> <pre><code>[{'volYtday': 18083292, 'volToday': 49395261, 'time': datetime.timedelta(0, 34800), 'priceChgPct': Decimal('1.2400'), 'volDiffPct': 173.15414140301445, 'priceNom': Decimal('6.5300'), 'date': datetime.date(2013, 4, 30), 'secCode': 'xoxoxo', 'volDiff': 31311969}] </code></pre> <p>Then I have another list of dictionaries (let's call it myListOfDict), declared empty, Py print yields this:</p> <pre><code>[{'priceChgPct': '', 'volYtday': '', 'priceNom': '', 'volDiffPct': '', 'volToday': '', 'time': '', 'date': '', 'secCode': '', 'volDiff': ''}] </code></pre> <p>I need to append myListOfDict with a specific dictionary from sqlListOfDict by index number, the code:</p> <pre><code>myListOfDict.append(sqlListOfDict[0]) </code></pre> <p>No joy, myListOfDict is still as declared (empty) and Py doesn't give any traceback.</p> <p>I did some experiments:</p> <pre><code>listDictA = [dict.fromkeys(['secCode', 'volDiff'])] listDictB = [{'secCode': 'valB1', 'volDiff': 1000}, {'secCode': 'valB2', 'volDiff': 1000}, {'secCode': 'valB3', 'volDiff': 1000}, {'secCode': 'valB4', 'volDiff': 1000}, {'secCode': 'valB5', 'volDiff': 1000}, {'secCode': 'valA1', 'volDiff': 1000}] </code></pre> <p>Ran the same command:</p> <pre><code>listDictA.append(listDictB[0]) </code></pre> <p>It worked! What did I do wrong for the first case? Thanks for helping.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload