<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic line break error in calculate field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429208#M33736</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey people!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a problem while working in the code block of the calculate field process in model builder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see in my code below, I want to add a line break in the newly created txt-file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to add it through a "\n" in the line: &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("All Postcodes \n")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But everytime I enter "\n", it ist directly changed into a strange character which looks like a square.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Purpose: I want a line break to be inserted in the textfile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What the process does: It inserts the strange square-character instead of a line break.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried the double backslash "\\n" but it doesn't work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import os, csv

def plzToFile(csvfilepath, csvfilename, plz):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = 'txt' # Defines output file extension as txt
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Join CSV file path and name, adding extension if necessary
&amp;nbsp;&amp;nbsp;&amp;nbsp; csvfile = os.path.join(csvfilepath, os.extsep.join((csvfilename, ext)) if not os.path.splitext(csvfilename)[1].lower().endswith(ext) else csvfilename)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Open text file for writing
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(csvfile, 'wb') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w = csv.writer(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = map(lambda x: x.split(';'), [plz]) # Transpose the semicolon-delimited values into rows
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("All Postcodes \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w.writerows(rows)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return csvfile&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 23 Sep 2012 12:39:02 GMT</pubDate>
    <dc:creator>PaulGoede</dc:creator>
    <dc:date>2012-09-23T12:39:02Z</dc:date>
    <item>
      <title>line break error in calculate field</title>
      <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429208#M33736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey people!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a problem while working in the code block of the calculate field process in model builder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As you can see in my code below, I want to add a line break in the newly created txt-file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to add it through a "\n" in the line: &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("All Postcodes \n")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But everytime I enter "\n", it ist directly changed into a strange character which looks like a square.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Purpose: I want a line break to be inserted in the textfile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What the process does: It inserts the strange square-character instead of a line break.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried the double backslash "\\n" but it doesn't work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import os, csv

def plzToFile(csvfilepath, csvfilename, plz):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = 'txt' # Defines output file extension as txt
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Join CSV file path and name, adding extension if necessary
&amp;nbsp;&amp;nbsp;&amp;nbsp; csvfile = os.path.join(csvfilepath, os.extsep.join((csvfilename, ext)) if not os.path.splitext(csvfilename)[1].lower().endswith(ext) else csvfilename)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Open text file for writing
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(csvfile, 'wb') as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w = csv.writer(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = map(lambda x: x.split(';'), [plz]) # Transpose the semicolon-delimited values into rows
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write("All Postcodes \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w.writerows(rows)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return csvfile&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Sep 2012 12:39:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429208#M33736</guid>
      <dc:creator>PaulGoede</dc:creator>
      <dc:date>2012-09-23T12:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: line break error in calculate field</title>
      <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429209#M33737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you viewing the text file in Notepad? Windows usually uses \r\n (and not just \n) in most places for its line break marker. Some text editors will interpret both as a new line, but they are in the minority. The solution is just &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;"Hello\r\n"&lt;/SPAN&gt;&lt;SPAN&gt; instead of &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;"Hello\n"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Sep 2012 17:41:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429209#M33737</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-09-23T17:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: line break error in calculate field</title>
      <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429210#M33738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Jscheirer,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your suggestion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I insert the code directly into the code block of the process-dialogue of "calculate field" in the model builder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Whenever I type "\n" (without the quotation marks), it is transformed to the square character &lt;/SPAN&gt;&lt;STRONG&gt;immediately&lt;/STRONG&gt;&lt;SPAN&gt;, just when I click on another part of the dialogue or close the window. That's my problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17907[/ATTACH] (see here how the \n looks like after the transformation)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any other suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought about exporting the whole model to python script. The result is a file somewhere on my disk. How do I reinsert the code of that file to ArcGIS by means of making the code an executable tool in ArcGIS?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 23 Sep 2012 18:09:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429210#M33738</guid>
      <dc:creator>PaulGoede</dc:creator>
      <dc:date>2012-09-23T18:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: line break error in calculate field</title>
      <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429211#M33739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have never, ever heard of that behavior occurring at all in the UI. What version of ArcGIS are you using?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suppose it would make sense to export your model (or at least just this part) to a Python script.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:24:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429211#M33739</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-09-24T18:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: line break error in calculate field</title>
      <link>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429212#M33740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have ArcGIS 10 installed.I also have another version (the student version) of ArcGIS 10 installed on another computer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sorry I confused "field calculater" and "calculate value"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I described above happens on both computers. Try it yourself: Open the Calculate Value (not the field calculator) in model builder, click in the code block and type "\n". Then click e.g. on "expression" above. You will see the "\n" immediately change to a square character.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;before:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17938[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;after:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]17939[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 18:49:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/line-break-error-in-calculate-field/m-p/429212#M33740</guid>
      <dc:creator>PaulGoede</dc:creator>
      <dc:date>2012-09-24T18:49:16Z</dc:date>
    </item>
  </channel>
</rss>

