python

Django: separate template dir for model

What's the point of using template structure like this: templates/ app/ article_view.html # or view_article.html category_view.html vs templates/ app/ article/ view.html category/ view.html It's easier to find particular template with second approach, but I almost don'...

Error from pip install: "RuntimeError: maximum recursion depth exceeded while calling a Python object"

I get an error when running pip install datapkg The error is this: "RuntimeError: maximum recursion depth exceeded while calling a Python object" Partial traceback: RuntimeError: maximum recursion depth exceeded while calling a Python object ---------------------------------------- Command /usr/bin/python -c "import setuptools;...

What does this code do in Python?

I'm learning Python and ran into some code that has this line... self.clear() I am curious as to what it would do and why would someone need to do this? ...

First Python Tkinter window works, but the rest are blank.

I think I'm missing something basic about Tkinter. What would be the correct way to create several windows with the same hidden root window? I can get one window to open, but once it's closed subsequent ones show up blank, without any widgets in them. I've also noticed if I leave the root window visible, it disappears when I close the f...

Why is executemany slow in Python MySQLdb?

I am developing a program in Python that accesses a MySQL database using MySQLdb. In certain situations, I have to run an INSERT or REPLACE command on many rows. I am currently doing it like this: db.execute("REPLACE INTO " + table + " (" + ",".join(cols) + ") VALUES" + ",".join(["(" + ",".join(["%s"] * len(cols)) + ")"] * len(data)...

Find a specific tag with BeautifulSoup

I can traverse generic tags easily with BS, but I don't know how to find specific tags. For example, how can I find all occurances of <div style="width=300px;">? Is this possible with BS? ...

Python - Iterate throuhg 2 lists at the same time

Possible Duplicate: how can I iterate through two lists in parallel in Python? I have 2 lists: l = ["a", "b", "c"] m = ["x", "y", "z"] And I want to iterate throught both at the same time, something like this: for e, f in l, m: print e, f Must show: a x b y c z The thing is that is totally illegal. How can I do so...

Encoding JSON in Mako?

Im having trouble with json in mako. I do this: ${ to_json( dict( a = 1, b = 2 ) ) } where to_json is: <%! import simplejson as json def to_json( d ): return json.dumps( d ) %> however, instead of giving me {"a": "1", "b": "2"} its giving me {&quot;a&quot;: 1, &quot;b&quot;: 2} so mako changes the " to " som...

csvreader.fieldnames not recognized as an attribute of a csv reader object in python

I am trying to extract the header of a CSV file in Python by using the CSV module. The CSV file is quite flat, and looks something like: This, That, The Other 1, 2, 3 I am doing the following: Read in the CSV file and make the reader object push the reader's iterator to the next line to force it to access the first line at...

Converting string to tuple and adding to tuple

I have a config file like this. [rects] rect1=(2,2,10,10) rect2=(12,8,2,10) I need to loop through the values and convert them to tuples. I then need to make a tuple of the tuples like ((2,2,10,10), (12,8,2,10)) ...

Passing self into a constructor in python

I recently was working on a little python project and came to a situation where I wanted to pass self into the constructor of another object. I'm not sure why, but I had to look up whether this was legal in python. I've done this many times in C++ and Java but I don't remember ever having to do this with python. Is passing references to...

What to consider before subclassing list?

Hi, I was recently going over a coding problem I was having and someone looking at the code said that subclassing list was bad (my problem was unrelated to that class). He said that you shouldn't do it and that it came with a bunch of bad side effects. Is this true? I'm asking if list is generally bad to subclass and if so, what are th...

How do I update an instance of a Django Model with request.POST if POST is a nested array?

I have a form that submits the following data: question[priority] = "3" question[effort] = "5" question[question] = "A question" That data is submitted to the URL /questions/1/save where 1 is the question.id. What I'd love to do is get question #1 and update it based on the POST data. I've got some of it working, but I don't know how ...

Python to C++ function conversion using Boost.Python

Hi, I have a bunch of classes and APIs written in C++ and exposed to Python with help of Boost.Python I am currently investigating the possibilities of creating the following architecture. In python: from boostPythonModule import * AddFunction( boostPythonObject.Method1, args ) AddFunction( boostPythonObject.Method2, args ) AddFuncti...

Eclipse PyDev now shows all references to Tkinter as errors

I've been using Eclipse with PyDev (on Windows, mind you) for my Python Tkinter project for about a month now, and up until recently I've had no complaints. I start the source for one module (my GUI) like so: from Tkinter import * Now, ever since I updated Eclipse to 3.6.1, it shows an error for every call to the Tkinter module(Frame(...

Python equivalent to Java's BitSet

Is there a Python class or module that implements a structure that is similar to the BitSet? ...

How to use refresh_access_token in the Yahoo Social Python SDK

I'm trying to use the Yahoo Social Python SDK to get a users contacts through oAuth. This is for a webapp running on App Engine. SO, I have everything set up to run through the oAuth dance, exchanging consumer keys and verifiers and all that jazz. I store the token and can reuse it to retrieve a users contacts until the token the expires...

Migrating from Stata to Python

Some coworkers who have been struggling with STATA 11 are asking for my help to try to automate their laborious work. they mainly use 3 commands in stata: tsset (sets a time series analysis) as in: tsset year_column, yeary varsoc (Obtain lag-order selection statistics for VARs) as in: varsoc column_a column_b vec (vecto...

What are the implications of using mutable types as default arguments in Python?

Possible Duplicates: Why the mutable default argument fix syntax is so ugly, asks python newbie least astonishment in python: the mutable default argument The title says it all. Here is an example. def list_as_default(arg = []): pass ...

A little help needed in code translation (Python to C#)

Good night everyone, This question leaves me a little embarassed because, of couse, I know I should be able to get the answer alone. However, my knowledge about Python is just a little bit more than nothing, so I need help from someone more experienced with it than me... The following code comes from Norvig's "Natural Language Corpus D...