<?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: Trying to use rstrip in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745221#M57617</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The easiest ways to do this are to slice, or split by period.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
outFile = r"C:\GIS\output\" + lname[:-4] + ".pdf" 

# OR
 outFile = r"C:\GIS\output\" + lname.split('.')[0] + ".pdf" 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you do not need to have the double backslash when you use the r'' (raw string method)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Sorry, I just realized I had a typo in here.&amp;nbsp; The colon was supposed to be &lt;/SPAN&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;SPAN&gt; the -4 to get everything before the period in the path name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would be best to use one of the two methods above.&amp;nbsp; Sometimes, for some reason, when you try to use strip or rstrip() it will cut off an extra character.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; test = r'C:\Users\Caleb\Desktop\EucDistTools\ascii\polys.shp'
&amp;gt;&amp;gt;&amp;gt; print test.rstrip('.shp')
C:\Users\Caleb\Desktop\EucDistTools\ascii\poly
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above was done in the interactive window of Python.&amp;nbsp; See where it cut off the "s" in polys?&amp;nbsp; This is why it is better to use split or slicing.&amp;nbsp; Another method is the os.path.splitext().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; print os.path.splitext(test)[0] # 0 index to grab everything before the period
C:\Users\Caleb\Desktop\EucDistTools\ascii\polys
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 07:42:41 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-12T07:42:41Z</dc:date>
    <item>
      <title>Trying to use rstrip</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745219#M57615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to strip off the last 4 characters of a layer name that is in my mxd. It is the only layer. It is a MrSid file. I want to &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;export this image to pdf using the layer name without the .sid part. This code exports the map to PDF but it is not stripping off the .sid part. Ex: J-228-01-W-2013.sid.pdf&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used 4 as the number of characters to strip off because I assumed that the dot needs to be removed also.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy,os

mxd = arcpy.mapping.MapDocument(r"C:\GIS\designsheet.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.rotation = 0
lname = arcpy.mapping.ListLayers(mxd)[0].name
outFile = r"C:\GIS\output\\" + lname.rstrip('4') + ".pdf" 
arcpy.mapping.ExportToPDF(mxd, outFile)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 18:18:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745219#M57615</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2013-08-20T18:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use rstrip</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745220#M57616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I misread the example I was following about how to use rstrip. Instead of using the number of characters I want removed I should use the actual characters! In my example I should have used '.sid' and it works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Aug 2013 18:22:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745220#M57616</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2013-08-20T18:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to use rstrip</title>
      <link>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745221#M57617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The easiest ways to do this are to slice, or split by period.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
outFile = r"C:\GIS\output\" + lname[:-4] + ".pdf" 

# OR
 outFile = r"C:\GIS\output\" + lname.split('.')[0] + ".pdf" 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you do not need to have the double backslash when you use the r'' (raw string method)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&amp;nbsp; Sorry, I just realized I had a typo in here.&amp;nbsp; The colon was supposed to be &lt;/SPAN&gt;&lt;STRONG&gt;before&lt;/STRONG&gt;&lt;SPAN&gt; the -4 to get everything before the period in the path name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It would be best to use one of the two methods above.&amp;nbsp; Sometimes, for some reason, when you try to use strip or rstrip() it will cut off an extra character.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; test = r'C:\Users\Caleb\Desktop\EucDistTools\ascii\polys.shp'
&amp;gt;&amp;gt;&amp;gt; print test.rstrip('.shp')
C:\Users\Caleb\Desktop\EucDistTools\ascii\poly
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above was done in the interactive window of Python.&amp;nbsp; See where it cut off the "s" in polys?&amp;nbsp; This is why it is better to use split or slicing.&amp;nbsp; Another method is the os.path.splitext().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; print os.path.splitext(test)[0] # 0 index to grab everything before the period
C:\Users\Caleb\Desktop\EucDistTools\ascii\polys
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:42:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trying-to-use-rstrip/m-p/745221#M57617</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T07:42:41Z</dc:date>
    </item>
  </channel>
</rss>

