<?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 Re: Get parameters as file path without baslashes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171560#M64515</link>
    <description>&lt;P&gt;Haven't worked with python toolbox's here, but you could try something like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;path = "r'" + parameters[0].valueAsText + "'"&lt;/LI-CODE&gt;&lt;P&gt;and see if the output looks like either of these:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;r'C:\Users\xxx\FileName.txt'
or
'C:\\Users\\xxx\\FileName.txt'&lt;/LI-CODE&gt;&lt;P&gt;Both of which would be valid python filepaths.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Fri, 06 May 2022 17:24:59 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2022-05-06T17:24:59Z</dc:date>
    <item>
      <title>Get parameters as file path without baslashes</title>
      <link>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171547#M64514</link>
      <description>&lt;P&gt;I am fairly new to python toolbox and I am trying to input a text file path into my script to further use with pandas (pd.read_csv()). However, everytime I extract my parameter, the file path returned uses '\' as separator. If I've learn one thing in Python, is that you never want to use backslashes. How do I get rid of those or how can I get my parameter to know that the string is a file path and read it appropriately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;def getParameterInfo(self):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; param0 = arcpy.Parameter(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; displayName="File path to enter",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name="path",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; datatype="DETextfile",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parameterType="Required",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; direction="Input")&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; params = [param0]&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; return params&lt;/P&gt;&lt;P&gt;def execute(self, parameters, messages):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; path = parameters[0].valueAsText&lt;BR /&gt;&amp;nbsp; &amp;nbsp; arcpy.AddMessage(path)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Output :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;C:\Users\xxx\FileName.txt&lt;/PRE&gt;&lt;P&gt;The pd.read_csv function does not accept this file path format.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 17:00:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171547#M64514</guid>
      <dc:creator>AntoinePrince</dc:creator>
      <dc:date>2022-05-06T17:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get parameters as file path without baslashes</title>
      <link>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171560#M64515</link>
      <description>&lt;P&gt;Haven't worked with python toolbox's here, but you could try something like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;path = "r'" + parameters[0].valueAsText + "'"&lt;/LI-CODE&gt;&lt;P&gt;and see if the output looks like either of these:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;r'C:\Users\xxx\FileName.txt'
or
'C:\\Users\\xxx\\FileName.txt'&lt;/LI-CODE&gt;&lt;P&gt;Both of which would be valid python filepaths.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 17:24:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171560#M64515</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-05-06T17:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get parameters as file path without baslashes</title>
      <link>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171818#M64519</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/584730"&gt;@AntoinePrince&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;If I've learn one thing in Python, is that you never want to use backslashes.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I've been using python for a very long time and can confidently say that backslashes are fine to use.&amp;nbsp; The only issue is that new users don't realise that when you have a string literal in your code you need to escape backslashes or use raw string syntax (neither of which are applicable when you're passing a string in as a parameter).&lt;/P&gt;&lt;P&gt;The backslashes used in the path in your parameter will be understood just fine by pandas. I have just tested and pd.read_csv worked as expected with backslashes.&lt;/P&gt;&lt;P&gt;There's something else going on.&amp;nbsp; Please paste in the error message you are getting.&lt;/P&gt;</description>
      <pubDate>Sun, 08 May 2022 22:07:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-parameters-as-file-path-without-baslashes/m-p/1171818#M64519</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2022-05-08T22:07:27Z</dc:date>
    </item>
  </channel>
</rss>

