Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting dict.items() for wxPython
    text
    copied!<p>I have a text box in wxPython that takes the output of dictionary.items() and displays it to the user as items are added to the dictionary. However, the raw data is very ugly, looking like </p> <pre><code>[(u'BC',45) (u'CHM',25) (u'CPM',30)] </code></pre> <p>I know dictionary.items() is a list of tuples, but I can't seem to figure out how to make a nice format that is also compatible with the SetValue() method of wxPython.</p> <p>I've tried iterating through the list and tuples. If I use a <em>print</em> statement, the output is fine. But when I replace the <em>print</em> statement with SetValue(), it only seems to get the last value of each tuple, rather than both items in the tuple.</p> <p>I've also tried creating a string and passing that string to SetValue() but, again, I can only get one item in the tuple or the other, not both.</p> <p>Any suggestions?</p> <hr> <p><strong>Edit:</strong> Yes, I am passing the results of the dictionary.items() to a text field in a wxPython application. Rather than having the results like above, I'm simply looking for something like:</p> <pre><code>BC 45 CHM 25 CMP 30 </code></pre> <p>Nothing special, just simply pulling each value from each tuple and making a visual list.</p> <p>I have tried making a string format and passing that to SetValue() but it gets hung up on the two values in the tuple. It will either double print each string and add the integers together or it simply returns the integer, depending on how I format it.</p>
 

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