Python to Remove a Character?

Posted on
Thu Jul 15, 2021 2:03 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Python to Remove a Character?

Hey,

I need to remove the “:” from a 24hr time variable e.g “13:48”

Appreciate any help with a script to do that.

I assume it would use these elements but have no idea how to use them correctly.
Code: Select all
s = indigo.variables["TimeNow2400"].value
print(s.translate({ord(':'): None}))
indigo.variable.updateValue("TimeNow2400")


Thanks,

Carl

Posted on
Thu Jul 15, 2021 2:33 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python to Remove a Character?

OMG...I got it working somehow.

Code: Select all
s = indigo.variables["TimeNow2400"].value
new = str(s.translate({ord(':'): None}))
indigo.variable.updateValue("TimeNow2400",new)


Waiting for hell to freeze over.

Carl

Posted on
Thu Jul 15, 2021 5:04 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python to Remove a Character?

Good job! A couple of notes. The more common way to do such things in Python is the replace() function. Like this:

Code: Select all
s = indigo.variables["TimeNow2400"].value
new = s.replace(":", "")
indigo.variable.updateValue("TimeNow2400",new)
And since this keeps the value in string format (all Indigo variables are strings), there's no need for the str() function.

Keep hacking!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Jul 15, 2021 5:22 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python to Remove a Character?

Thanks Dave.

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests