Nathan McCorkle
2014-10-03 17:16:35 UTC
I am using configobj to save colour tuples (tuples with 4 values) to a
config file, this saves the tuple as a string like '(1,2,3,4)'
Upon loading this file with configobj on GUI startup, I've found I need to
convert the configobj data from a string (configobj doesn't give me a
Python tuple object), and I am doing it like so:
def stringTo4Tuple(self, st):
sp = st.split(',')
if len(sp)==4:
if sp[0][0]=='(' and sp[3][-1]==')':
try:
#chop off the '(' and convert to int
val1 = int(sp[0][1:])
val2 = int(sp[1])
val3 = int(sp[2])
#chop off the ')' and convert to int
val4 = int(sp[3][0:-1])
#return values as a tuple
return (val1, val2, val3, val4)
except ValueError:
return None
I'm wondering if there's a better way to do this... I might try converting
the colour tuple to a list before storing with configobj to see if it will
load it as a Python list, which would get around the string operations at
least.
Is there some magic string-tuple-to-colour function I'm not seeing in the
docs?
config file, this saves the tuple as a string like '(1,2,3,4)'
Upon loading this file with configobj on GUI startup, I've found I need to
convert the configobj data from a string (configobj doesn't give me a
Python tuple object), and I am doing it like so:
def stringTo4Tuple(self, st):
sp = st.split(',')
if len(sp)==4:
if sp[0][0]=='(' and sp[3][-1]==')':
try:
#chop off the '(' and convert to int
val1 = int(sp[0][1:])
val2 = int(sp[1])
val3 = int(sp[2])
#chop off the ')' and convert to int
val4 = int(sp[3][0:-1])
#return values as a tuple
return (val1, val2, val3, val4)
except ValueError:
return None
I'm wondering if there's a better way to do this... I might try converting
the colour tuple to a list before storing with configobj to see if it will
load it as a Python list, which would get around the string operations at
least.
Is there some magic string-tuple-to-colour function I'm not seeing in the
docs?
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.