cStringIO help

Hey,

I am trying to pass a string input on a single line wxTextCtrl, which is connected to a OK button, and on clicking it I wish to run a string parser module. I am trying to learn to use the cStringIO method to read the text into the memory( buffer ) and then I want to pass the string to the parser method in a separate script.

So far we have an OK button:

       self.ok = wxButton(panelB, ID_OK, ' OK ', (407,200))
       self.ok.SetDefault()

the wxTextCtrl:

      self.input = wxTextCtrl(panelB, 20, "<Enter your question here

",

                    wxPoint(340,140), wxSize(305,-1))

and an event associated to the OK button, i.e:

      EVT_BUTTON(self, self.ok.GetId(), self.BeginParse)

In defining the 'BeginParse' method, I have:

def BeginParse(self, event):
      self.input.GetValue() # get the string in the input field
      self.input = cStringIO.StringIO() # buffer the string in the text field
      self.input.read() # read the string held in memory
      parser = sys.argv[1] # parser is the parsing module

After going through many documents, I have been unable to find how I can get the string read in the wxTextCtrl in my GUI and pass it into my parser script so that I can run methods in my parser over the string, using the cStringIO method, as oppose to writing text to a file and parsing over the file.

Many thanks for any further reading recommendations or ways around this problem

Jaggy

···

_________________________________________________________________
Find a cheaper internet access deal - choose one to suit you. http://www.msn.co.uk/internetaccess

jim bob wrote:

def BeginParse(self, event):
     self.input.GetValue() # get the string in the input field
     self.input = cStringIO.StringIO() # buffer the string in the text field

I think you just reassigned self.input to a StringIO buffer instead of tying the two together. Once you do that, all references to that TextCtrl are gone.

To put the contents of your text control into the StringIO buffer:

  stBuffer = cStringIO.StringIO(self.input.GetValue())

Then you can use normal StringIO methods on it.

It's unclear from the example why you want to use StringIO, though.
  
... KPLA: Warrior's Radio! All the glory, all the time!