Help...how to filter "}"

A forum for general discussion of the Python programming language.

Help...how to filter "}"

Postby alabview » Tue Oct 29, 2013 9:30 am

Hi there,

I have no idea how to remove "}". My code is below,

Code: Select all
INPUTSCRIPT="CLOSEDLOOP{DCSOURCE1|VOLTAGE|0.1|-1|5|1000}"
TEMPSCRIPT=INPUTSCRIPT.split('|')
STR_SETTELING=TEMPSCRIPT[5]


When I perform querying....
Code: Select all
>>> STR_SETTELING
'1000}'
>>>


So, I would like to remove "}" after "1000" and no idea how to do.

Many Thanks.
alabview
 
Posts: 22
Joined: Mon Sep 16, 2013 1:48 pm

Re: Help...how to filter "}"

Postby metulburr » Tue Oct 29, 2013 9:45 am

Code: Select all
print(STR_SETTELING[:-1])
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
metulburr
 
Posts: 2243
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Help...how to filter "}"

Postby micseydel » Tue Oct 29, 2013 4:35 pm

How about str.rstrip?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Help...how to filter "}"

Postby ochichinyezaboombwa » Tue Oct 29, 2013 5:59 pm

And could you please stop CAPITALIZING EVERYTHING? It hurts my eyes.
ochichinyezaboombwa
 
Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

Re: Help...how to filter "}"

Postby bunburya » Fri Nov 08, 2013 1:41 am

If the variables are to be used as constants, then PEP8 says they should be given names in ALL_CAPS.

Micseydel's rstrip idea seems better to me than [:-1], with the caveat that it will not work correctly if the final value contained in the curly braces also ends with a '}'.
http://www.bunburya.eu | https://github.com/bunburya

Join the #python-forum IRC channel on irc.freenode.net!
bunburya
 
Posts: 9
Joined: Sat Feb 09, 2013 7:28 pm
Location: Dublin, Ireland


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 3 guests