Since an assignment problem can be posed in the form of a single matrix, I am wondering if NumPy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if NumPy/SciPy has an assignment-problem-solve function? Edit: In the meanwhile I have found a Python (not NumPy/SciPy) implementation at http://software.clapper.org/munkres/. Still
Calculating a directory’s size using Python?
Before I re-invent this particular wheel, has anybody got a nice routine for calculating the size of a directory using Python? It would be very nice if the routine would format the size nicely in Mb/Gb etc. Answer This walks all sub-directories; summing file sizes: And a oneliner for fun using os.listdir (Does not include sub-directories): Reference: os.path.getsize – Gives
How can I compare two lists in python and return matches [duplicate]
This question already has answers here: How do I iterate through two lists in parallel? (8 answers) How to find list intersection? (16 answers) Closed 5 months ago. I want to take two lists and find the values that appear in both. would return [5], for instance. Answer Not the most efficient one, but by far the most obvious way
String formatting
I have a list filter = [‘a’, ‘b’, ‘c’]. I need to frame the following string out of the list “item -a item -b item -c”. Which is the most efficient way to do this? Usually the list filter contains 100 to 200 items and each would be of length 100 – 150. Wouldn’t that lead to overflow? And what
Add variables to tuple
I am creating a database connection. While trying to add to the DB, I am thinking of creating tuples out of information and then add them to the DB. I am taking information from the user and store it in variables. Can I add these variables into a tuple? Can you please help me with the syntax? I only need
Python dicts in sqlalchemy
I would like to load/save a dict to/from my sqlite DB, but am having some problems figuring out a simple way to do it. I don’t really need to be able to filter, etc., based on the contents so a simple conversion to/from string is fine. The next-best thing would be foreign keys. Please don’t post links to huge examples,
virtualenv in PowerShell?
There seems to be a problem when virtualenv is used in PowerShell. When I try to activate my environment in PowerShell like… .. nothing happens. (the shell prompt should have changed as well as the PATH env. variable .) I guess the problem is that PowerShell spawns a new cmd. process just for running the activate.bat thus rendering the changes
AttributeError: ‘NoneType’ object has no attribute ‘GetDataStore’
I guys, I developing a utility in python and i have 2 object the main class and an database helper for get sqlserver data. database.py gaemodel.py My problem is when i try run code return me this error What is wrong ?? Answer First of all: The __new__ method should be named __init__. Remove the global _host etc. line Then
Extract part of a regex match
I want a regular expression to extract the title from a HTML page. Currently I have this: Is there a regular expression to extract just the contents of <title> so I don’t have to remove the tags? Answer Use ( ) in regexp and group(1) in python to retrieve the captured string (re.search will return None if it doesn’t find
Python unit test with base and sub class
I currently have a few unit tests which share a common set of tests. Here’s an example: The output of the above is: Is there a way to rewrite the above so that the very first testCommon is not called? EDIT: Instead of running 5 tests above, I want it to run only 4 tests, 2 from the SubTest1 and