python

What is this traceback error in Python?

Traceback: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "/home/ea/ea-repos/hell/life/views.py" in linkedin_auth 137. token = oauth_linkedin.get_unauthorised_request_token() File "/home/ea/ea-repos...

Adding values in a tuple that is in a list in python

I retrieve some data from a database which returns it in a list of tuple values such as this: [(1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,), (1,)] Is there a function that can sum up the values in the list of tuples? For example, the above sample should return 18. ...

Python KMeans Orange Framework

I am planning to use orange for kmeans clustering. I have gone through the tutorials, but I still have a couple of questions which I would like to ask: I am dealing with clustering on vectors of high dimension. 1) Is there a cosine distance implemented? 2) I do not want to give zeros to empty values. I tried not having any zeros in empt...

Disassembling with python - no easy solution?

Hi, I'm trying to create a python script that will disassemble a binary (a Windows exe to be precise) and analyze its code. I need the ability to take a certain buffer, and extract some sort of struct containing information about the instructions in it. I've worked with libdisasm in C before, and I found it's interface quite intuitive a...

Mock Y of (from X import Y) in doctest (python)

I'm trying to create a doctest with mock of function that resides in a separate module and that is imported as bellow from foomodule import foo def bar(): """ >>> from minimock import mock >>> mock('foo', nsdicts=(bar.func_globals,), returns=5) >>> bar() Called foo() 10 """ return foo() * 2 import doct...

How to evaluate a matched number later in a regex? - Lexing FORTRAN 'H' edit descriptor with Ply

I am using Ply to interpret a FORTRAN format string. I am having trouble writing a regex to match the 'H' edit descriptor which is of the form xHccccc ... where x specifies the number of characters to read in after the 'H' Ply matches tokens with a single regular expression, but I am having trouble using regular expression to perform ...

How to make a relation between tables using SQLAlchemy?

Using SQLAlchemy, given tables such as these: locations_table = Table('locations', metadata, Column('id', Integer, primary_key=True), Column('name', Text), ) players_table = Table('players', metadata, Column('id', Integer, primary_key=True), Column('email', Text), Column('password', ...

Override 'in' operator in Python

If I am creating my own class in Python, what function should I define so as to allow the use of the 'in' operator, e.g. class MyClass(object): ... m = MyClass() if 54 in m: ... ...

convention to represent the exit status and actual result in XMLRPC

in the C world, a function can return error code to represent the exit status, and use INOUT/OUT parameter to carry the actual fruit of the process. when it comes to xmlrpc, no INOUT/OUT parameter, is there any best practice/conventions to represent the exit status and actual result? the context is i am trying to write an agent/daemon ...

Using a debugger and curses at the same time?

I'm calling python -m pdb myapp.py, when an exception fires, and I'd normally be thrown back to the pdb interpreter to investigate the problem. However this exception is being thrown after I've called through curses.wrapper() and entered curses mode, rendering the pdb interpreter useless. How can I work around this? ...

Django URL configuration

Hello, Assume I have 3 Models: City, Area, Entry. Each city has several Areas and each area can have several entries BUT for "now", there can be will be only one active Entry and it will be shown. So in logic: Note that each city, area, entry will be using slug variable of related model class Format will be in such: www.mysite.com/<...

Retrieving many-to-many relation properties using SQLAlchemy

I have a many-to-many relationship in which the relation-table contains more columns than only the primary key. As an example, consider a slide show system in which each image could have it's own timeout, and a different timeout depending on the slideshow. A daft example, but it will have to do for the sake of illustration ;) So I imagi...

Age from birthdate in python

How can I find an age in python from today's date and a persons birthdate? The birthdate is a from a DateField in a Django model. ...

How to convert ip address to DWORD?

Hey, how can I convert ip address to DWORD using python ? I searched a while but didn't found anything useful. Thanks for the helpers! ...

Deploying Pylons with uWSGI

Hi all, We're trying to move our intranet to Pylons. My boss is trying to set up Pylons to use uWSGI behind Apache so he can set up multiple, independent applications. However, he's having a difficult time getting it set up, with some apparent code problems in the C source code for uWSGI. Does anyone have any suggestions for how to depl...

how to implement ckeditor in django.contrib.flatpages

can any one describe how to implement the ckeditor in django.contrib.flatpages... Thanks in advance ...

Python: Retrieving only POP3 message text, no headers

I'm trying to make a Python program that retrieves only the body text of an email without passing headers or any other parameters. I'm not sure how to go about this. The goal is to be able to send basic commands to a program via message text. What I have now is this: import poplib host = "pop.gmail.com" mail = poplib.POP3_SSL(host) p...

Sort by field in ForeignKey model

I have created a Django model called Person, which has got a 'user' ForeignKey to django.contrib.auth.models.User How can I set the ordering on class Person to self.user.first_name, self.user.last_name? ...

Inserting values into specific locations in a list in python

I am trying to do print all the possible outcomes of a given list and I was wondering how to put a value into various locations in the list. For example, if my list was [A,B], I want to insert X into all possible index of the list such that it would return this [X,A,B], [A,X,B], [A,B,X]. I was thinking about using range(len()) and a for ...

SQLAlchemy INSERT IGNORE

Hi, How can I insert multiple data records into table ignoring duplicates. I am using SQLAlchemy. Thank you! ...