ruderkahn

line break error in calculate field

Discussion created by ruderkahn on Sep 23, 2012
Latest reply on Sep 24, 2012 by ruderkahn
Hey people!

I have a problem while working in the code block of the calculate field process in model builder.
As you can see in my code below, I want to add a line break in the newly created txt-file.
I tried to add it through a "\n" in the line:
        f.write("All Postcodes \n")


But everytime I enter "\n", it ist directly changed into a strange character which looks like a square.

Purpose: I want a line break to be inserted in the textfile.
What the process does: It inserts the strange square-character instead of a line break.

I've tried the double backslash "\\n" but it doesn't work.

import os, csv

def plzToFile(csvfilepath, csvfilename, plz):
    ext = 'txt' # Defines output file extension as txt
    
    # Join CSV file path and name, adding extension if necessary
    csvfile = os.path.join(csvfilepath, os.extsep.join((csvfilename, ext)) if not os.path.splitext(csvfilename)[1].lower().endswith(ext) else csvfilename)

    # Open text file for writing
    with open(csvfile, 'wb') as f:
        w = csv.writer(f)
        rows = map(lambda x: x.split(';'), [plz]) # Transpose the semicolon-delimited values into rows
        f.write("All Postcodes \n")
        w.writerows(rows)
    return csvfile


I appreciate your help!

Outcomes