Coerce elements to strings as fallback #264

Merged
rgbkrk merged 1 commit from str_fallback into master 2013-09-05 19:25:59 -07:00
rgbkrk commented 2013-09-05 18:52:51 -07:00 (Migrated from github.com)

Returned objects from the APIs come back as ints in some cases. For example:

from twython import Twython
import random

tw = Twython(...)
followers = tw.get_followers_ids()['ids']
sample_users = random.sample(followers, 99)
user_data = tw.lookup_user(user_id=sample_users) # Will result in a type error

One workaround is to map these ahead of time:

tw.lookup_user(user_id=map(str,lonies))

This pull request just bakes it right in. We could coerce by default (which wouldn't affect strings).

Returned objects from the APIs come back as `int`s in some cases. For example: ``` python from twython import Twython import random tw = Twython(...) followers = tw.get_followers_ids()['ids'] sample_users = random.sample(followers, 99) user_data = tw.lookup_user(user_id=sample_users) # Will result in a type error ``` One workaround is to map these ahead of time: ``` python tw.lookup_user(user_id=map(str,lonies)) ``` This pull request just bakes it right in. We could coerce by default (which wouldn't affect strings).
michaelhelmick commented 2013-09-05 19:17:01 -07:00 (Migrated from github.com)

Why is that resulting in a type error? I'm not understanding?

Why is that resulting in a type error? I'm not understanding?
rgbkrk commented 2013-09-05 19:22:52 -07:00 (Migrated from github.com)

A list of integers can't be joined directly into a string.

>>> ','.join([1,2,3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found
A list of integers can't be joined directly into a string. ``` python >>> ','.join([1,2,3]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence item 0: expected string, int found ```
michaelhelmick commented 2013-09-05 19:25:49 -07:00 (Migrated from github.com)

Ohhhh, understood! Wasn't seeing that's what was happening at first! Thanks!

Ohhhh, understood! Wasn't seeing that's what was happening at first! Thanks!
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#264
No description provided.