0

I've been following along in Automate the Boring Stuff.

This question follows my two previous questions here:

Iterate a Nested Dictionary in Python

Iterate Dictionary in Python and Sum Totals by Category

I've been using the methods used in ATBS to print out some data from my python code to a word document. The following is a snippet of how this is setup:

dataFile = open('stocks.py', 'w')
wordFile = open('stocks.doc', 'w')
dataFile.write('allData = ' + pprint.pformat(stockData))

wordFile.write(pprint.pformat(sectors))
My question is two fold. First, i have a dictionary called 'sectors' that holds a key 'sector' with a 'percentage' value. I want to output this to a table in word like so:

Technology 30% Health Care 20% Financials 30%

but i'm not finding it easy via the pprint method. Is there a good way to do this?

my second question--is--is there a better way to be doing this? i know ATBS is sort of the beginners way of using python but i'm open to trying a better way of using python to analyze my data in excel and then generate an automated report in Word.

Community
  • 1
  • 1
John Rogerson
  • 1,153
  • 2
  • 19
  • 51

0 Answers0