Index error when passing a list to a class

I have the following code: class TestClass: def __init__(self, myint, mylist=None): if mylist == None: mylist = [] self.myint = myint self.mylist = mylist[:] theList = [[1,3,4,5,6],[1,2,3],[1],[1,2,3,4,5,6,7,8,9]] myOb = [] for i in range(len(theList

Pandas read_csv: Ignore the second line of the header

I have data files like this: # comment # comment Header1;Header2 Unit1;Unit2 0;123 1;231 2;512 I'd like to read them with Pandas.read_csv using the line Header1;Header2 as headers but ignoring Unit1;Unit2. What I have so far is pd.read_csv(datafile,

Check if a directory contains a file with a given extension

I need to check the current directory and see if a file with an extension exists. My setup will (usually) only have one file with this extension. I need to check if that file exists, and if it does, run a command. However, it runs the else multiple t

Numpy: returns a Boolean array after checking the condition

Simple question: I know that stuff like import numpy as np a = np.array([1, 2]) (a < 2) will return a boolean array where the condition (elem < 2) was checked: array([True, False], dtype=bool) Is this a native numpy method? I searched for the docume

Python programming for the new

I am using the book "Learn Python In A Day" by Acodemy. It seems this book has several typos (though I think so). I have installed Selenium IDE, Python 2.7.10 and NotePad++ on my Windows 7 64-bit. So from the book I was seeing this code: ls = [&

Python (rospy) in C ++ (roscpp) struct.unpack

I am currently translating a rospy IMU-driver to roscpp and have difficulites figuring out what this piece of code does and how I can translate it. def ReqConfiguration(self): """Ask for the current configuration of the MT device. Assume th

Django's tests waste too much time on creating a test database

We are try to cover tests on an old, big project which has more than 500 tables in database, and that waste too much time on database creating(more than 1 hour on my RMBP) and db migrations. We are using PostgreSQL as the Database, cause some GIS abo

Multiplication with int and str

I am completely baffled at this seemingly simple problem that I have. I want to define a function that will take the input, which can be a str or int and double it. For example, if the input is 'foo', then the output will be 'foofoo'. Likewise, if th

Break outside two loops

I'm writing a code with a while loop inside a while loop and am wondering how to break out of the outer loop if I meet the necessary conditions in the inner loop. while N <= 8: while i < 60: if this: that elif this: that other thing else: break i +=

Search by Python XML attribute

SO I am running a third party program that outputs in XML .... here is the XML section I am interested in: <something> <process> <iteration number="0" value="186.88" delta="0.5" nu="0.5" rho="0.1

strange F1 score result using scikit learn

I am doing some classification and I was looking at the f1 score and noticed something strange. When I do: "f1:" + str(f1_score(y_test_bin, target, average="weighted")) I get : f1:0.444444444444 When I do: print "f1:" + str(f

Project Euler 240: number of ways to roll the dice

I 'm trying to solve Project Euler problem 240: In how many ways can twenty 12-sided dice (sides numbered 1 to 12) be rolled so that the top ten sum to 70? I've come up with code to solve this. But it really takes a lot of time to compute. I know thi

Copying files with the native file manager in python

Okay, so I'm developing an application that will allow users to select file objects in a menu and will allow them to copy said selections to another location. I have so far managed to use the pywin32 module to allow me to copy files using Windows' na

Thermal map of binary data using R or Python

I have a binary data set of 0 and 1, where 0 is an absence and 1 is a presence of an event. A sample of the data set looks like this: events germany Italy Rain 0 1 hail 1 0 sunny 0 0 I'd like to get a red and white picture of this data in the form of

remove the item from the list in a dictionary

In a big dictionary, similar to d = {} d['a']=[1,2,3,4] d['b']=[1,2,3,4,5,6] d['c']=[1,2] d['d']=[1,4] how can I quickly remove the 'four' in the lists ? EDIT Is there a way to link the fours in the lists? As in, eliminating one eliminates the others

read Colander Schema from a configuration file or database

I googled for a while but I could not find reference on how to retrieve a Colander Schema from a config file or from a database. I think this is not difficult to implement but I might have overlooked something. Maybe somebody has done or seen somethi

Convert SVG to PNG to Python

How do I convert an svg to png, in Python? I am storing the svg in an instance of StringIO. Should I use the pyCairo library? How do I write that code?The answer is "pyrsvg" - a Python binding for librsvg. There is an Ubuntu python-rsvg package

Web.py todo list using invalid sqlite literal for int ()

I was following the tutorial here http://webpy.org/docs/0.3/tutorial then looked around the webs to find out how to use the todo list part with sqlite and found this http://kzar.co.uk/blog/view/web.py-tutorial-sqlite I cannot get passed this error. I

Scope of objects passed in arguments - Python

I want to send a session object of sqlalchemy to a function of another class . From class OraDialog's function oraconnect to class oraconn's assign function . Actually My need is to use the session object in oraconn's another function map I can't sen

Recursive deletion in Google Apps Engine

I'm using google app engine with django 1.0.2 (and the django-helper) and wonder how people go about doing recursive delete. Suppose you have a model that's something like this: class Top(BaseModel): pass class Bottom(BaseModel): daddy = db.Reference

How can I delete a cookie that I placed on someone's computer?

I've got a web system where users log in, and it stores a cookie of their session. When they log in as someone else or log out I want to remove that original cookie that I stored. What's the best way to do that? I'm using Python and Apache, though I