Skip to content

Tag: python-2.7

Implement packing/unpacking in an object

I have a class that only contains attributes and I would like packing/unpacking to work on it. What collections.abc should I implement to get this behaviour? I would like to avoid using a namedtuple. Answer You can unpack any Iterable. This means you need to implement the __iter__ method, and return an iterat…

How to convert CRLF to LF on a Windows machine in Python

So I got those template, they are all ending in LF and I can fill some terms inside with format and still get LF files by opening with “wb”. Those templates are used in a deployment script on a windows machine to deploy on a unix server. Problem is, a lot of people are going to mess with those tem…

Module imports and __init__.py

I am trying to understand what the best practices are with regards to Python’s (v2.7) import mechanics. I have a project that has started to grow a bit and lets say my code is organized as follows: The package name is foo and underneath it I have module Foo.py which contains code for the class Foo. Henc…

Getting WebViewLinks with Google Drive

I’ve just started trying to use the Google Drive API. Using the quickstart guide I set up the authentication, I can print a list of my files and I can even make copies. All that works great, however I’m having trouble trying to access data from a file on Drive. In particular, I’m trying to g…