Implement packing/unpacking in an object

You can unpack any Iterable. This means you need to implement the __iter__ method, and return an iterator. In your case, this could simply be: def __iter__(self): return iter((self.name, self.age, self.gender)) Alternatively you could make your class an Iterator, then __iter__ would return self and you’d need to implement __next__; this is more work, and … Read more

Parse a Pandas column to Datetime when importing table from SQL database and filtering rows by date

Pandas is aware of the object datetime but when you use some of the import functions it is taken as a string. So what you need to do is make sure the column is set as the datetime type not as a string. Then you can make your query. df[‘date’] = pd.to_datetime(df[‘date’]) df_masked = df[(df[‘date’] … Read more

Avoid Twitter API limitation with Tweepy

For anyone who stumbles upon this on Google, tweepy 3.2+ has additional parameters for the tweepy.api class, in particular: wait_on_rate_limit – Whether or not to automatically wait for rate limits to replenish wait_on_rate_limit_notify – Whether or not to print a notification when Tweepy is waiting for rate limits to replenish Setting these flags to True … Read more

How to handle IncompleteRead: in python

The link you included in your question is simply a wrapper that executes urllib’s read() function, which catches any incomplete read exceptions for you. If you don’t want to implement this entire patch, you could always just throw in a try/catch loop where you read your links. For example: try: page = urllib2.urlopen(urls).read() except httplib.IncompleteRead, … Read more