Console window copy pastes into a single cell in excel

Brett_SpenceBrett_Spence Posts: 11
edited March 2017 in FAQs

I'm trying to get some of the backtest results into Excel. I have tried writing a comma delimited string to the console and copying that (Text to columns) into Excel, but it doesn't recognize the end of the string (even if I add \r\n or \n to the end of the string) and just makes one long row in Excel. Is there a way to get the data into Excel easily? Can I write the output of the script into a file and use that?

Tagged:

Comments

  • My code to write to the console:
    print(self.symbol + "," + str(md.L1.last) + "," + str(md.nyse_imb.imbalance_quantity) + "," + str(self.cnt) + "," + str(self.perc) + "," + str(md.nyse_imb.price_diff_from_last) + "," + self.side + "," + str(md.nyse_imb.high_imbalance) + "," + str(md.nyse_imb.clearing_price) + "," + self.message + "," + service.time_to_string(event.timestamp) + "\r\n")

  • I think you have multiple paths ... use the console or service.write_file()

  • as an FYI, there are easier ways to format your "line". I recommend either

    • print "%s\t%s" % ("item 1", "item 2") # goes away in python 3.0
    • print("{}\t{}\t{1}\t{2}".format("item 1", "item 2"))

    google/stackover flow for more info

  • if you copy/paste from the console - you need to separate your items with tab "\t" rather than commas. You might have to paste in notepad (or other app) before copy/pasting into excel.

Sign In or Register to comment.