1

I'm trying to split a string returned from the Python implementation of Interactive Broker's API, but I keep getting a:

AttributeError: 'TickPrice' object has no attribute 'split'

def my_price_handler(msg):
    fields=msg.split()
    print fields[0]

Checked the API code and (1) msg is a string and (2) 'split' is not redefined elsewhere. Msg string looks like this <Tick Price tickerId=1, field=1, price=74.0, canAutoExecute=1> and can be printed to console directly. Same error message when using syntax:

def my_price_handler(msg):
    fields=string.split(msg)
    print fields[0]

I have imported string at the top of the program.

Is this a variable scope issue?

1
  • 1
    Did you check whether isinstance(msg, basestring) or type(msg) in [str, unicode]? What you have pasted as value of msg could very well be a __str__ representation of a class (the TickPrice mentioned in error message, most likely). Commented Jan 20, 2012 at 0:15

2 Answers 2

4

Clearly, msg is not a string when it enters my_price_handler; it's a TickPrice. Put

print(type(msg))

before the split call to convince yourself of this fact.

(The fact that msg can be printed does not mean it's a string, if that's what you thought.)

Sign up to request clarification or add additional context in comments.

Comments

1

TickPrice appears to be a Class. msg is an Instance of said class, which has a __repr__ method which allows you to print it to the console, producing:

<Tick Price tickerId=1, field=1, price=74.0, canAutoExecute=1>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.