Aug-30-2017, 12:14 PM
Quote:ratiofile.write( tradingSymbol + "," + entityRegistrantName + "," + entityCentralIndexKey + "," + currentFiscalYearEndDate + "," + docType + "," + documentPeriodEndDate + "," + documentFiscalYearFocus + "," + documentFiscalPeriodFocus + "," + entityCommonStockSharesOutstanding + "," + documentCreationDate + "," + commonStockSharesIssued + "," + treasuryStockShares + "," + commonStockSharesOutstanding + "\n")I would also write this as Larz suggested (most likely the first one since the latter is newer). The author looks like they came from C/C++ and not much python.
Anyways, this line is all concatenating strings and values that are strings. So now that it returns a list, one (or many) of those now might be a list. I can see at least one of them is as one is the return value of the function printFacts *docType"
docType = printFacts( documentType ) entityName = printFacts( entityRegistrantName ) entityCIK = printFacts( entityCentralIndexKey )doctype would now be a list, not a string anymore as printFacts returns lists now
Its going to mess up the layout of the csv file. Im not sure what way you want it. The following would convert the list values to a string joined by a comma , via the first line in the code below. For every value that is now a list would have to be done such as this. Now sure how many as they are all on the same line.
docType = ','.join(docType) with open("ratios.csv", "a") as ratiofile: buff = '{},{},{},{},{},{},{},{},{},{},{},{},{}\n'.format(tradingSymbol, entityRegistrantName, entityCentralIndexKey, currentFiscalYearEndDate, docType, documentPeriodEndDate, documentFiscalYearFocus, documentFiscalPeriodFocus, entityCommonStockSharesOutstanding, documentCreationDate, commonStockSharesIssued, treasuryStockShares, commonStockSharesOutstanding) ratiofile.write(buff)
Recommended Tutorials: