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])
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1512
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?
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1443
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: 200
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: No registered users and 2 guests