|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Spilt string into its arguments
Hi All,
I am creating objects using eval. For instance: class MyClass(): def __init__(self,stringField,integerField,sequenceField): self.stringField = stringField self.integerField = integerField self.sequenceField = sequenceField theString = 'MyClass("foo",32,["foo","bar"])' theMyClass = eval(stripPackage(theEventString)) This works fine. I am in the situation where i would like to modify some of the parameters. Is there a way to spit the parameter string i.e. ("foo",32,["foo","bar"]) into an array or list that contains the parameters. So that the string ("foo",32,["foo","bar"]) would be split into an array of three strings the first being "foo" second being 32 and third being ["foo","bar"]. I would appreciate any help on this as I am completelly stuck. |
|
#2
|
|||
|
|||
|
Sounds like a badly designed system to me. The two key indicators are:
1) Using eval() full stop. 2) Getting to a stage where you need to manually parse a string containing Python code into running Python so you can modify it before converting it back to a string so you can feed it into the function that parses strings containing Python code into running Python. Whatever you're doing (it's not clear), take a couple of steps back and rethink, I say. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Spilt string into its arguments |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|