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…
Tag: python-2.7
Seaborn pairplot legend – how to control position
I would like to move the Seaborn pairplot legend outside the scatter plot matrix. The official docs don’t give a keyword legend. I am trying to plot the legend outside the plot in 3 different locations simultaneously: bottom center, top center, right center I have tried this: The output of the above cod…
Python: search for a file in current directory and all it’s parents
Is there an inbuilt module to search for a file in the current directory, as well as all the super-directories? Without the module, I’ll have to list all the files in the current directory, search for the file in question, and recursively move up if the file isn’t present. Is there an easier way t…
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…
Closing a Panda3d app without shutting down the whole Process
wrote a small application which is composed of a QT GUI module which in turn initiate an object that inherits from ShowBase class. Problem is, if I close the Panda App, the ShowBase class calls finalizeExit() which in turn shuts the whole process by calling exit. If I avoid calling the finalize method by over…
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…
__init__() got an unexpected keyword argument ‘_job’
I am trying to use scrapyd with scrapy. When I use this the code below it works fine. But when I use it with selenium, it doesn’t My spider never runs. In jobs it gets listed under finished, and on error log I see exceptions.TypeError: __init__() got an unexpected keyword argument ‘_job’. He…
How to set a variable from inside a for loop that can be accessed from outside the for loop [Jinja]
When a user clicks a link, I want Jinja to set a variable called {{ contact_clicked }} that is equal to {{ contact }}. I could do <a href=”/?{% contact_clicked = contact %}”>…..</a>. However, that variable is then inaccessible outside of the for loop. I tried creating a list and …
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…
How to get the value of a selected treeview item?
I’ve looked at several posts regarding this and they’ve done the following -The output i get is blank -The output i get is the id, which is practically useless unless somebody can show me how to manipulate it -No output at all i just want to be able to click an item in treeview, and instantly be g…