[Tutor] Writing an "Alt-Enter"

URBAN LANDREMAN ulandreman at msn.com
Tue Jun 20 06:57:03 CEST 2006


I'm trying to write a .csv file which I can subsequently load into Excel.
The part that's tripping me up is I want to include an "Alt-Enter" between 
two of the fields so that when Excel reads the file, it will enter the two 
fields into the same cell, but on separate lines.

Is there a way to do it with chr(x) or \nnn or something similar?

My close-to-working code is listed below.
Thanks.

states = {}
states["MN"] = ("Minnesota","St. Paul")
states["WI"] = ("Wisconsin","Madison")
states["OH"] = ("Ohio","Columbus")

oFileName = "c:\PythonExport.csv"
ofile = open(oFileName,"w")
ofile.write("State Code,State info"+"\n")
for stateCode in states.keys():
    stateInfo=states[stateCode]
    ofile.write(stateCode+","+stateInfo[0]+"???"+stateInfo[1]+"\n")

ofile.close()


Urban Landreman




More information about the Tutor mailing list