python

GAE AttributeError

My GAE app runs fine from my computer, but when I upload it, I start getting an AttributeError, specifically: AttributeError: 'dict' object has no attribute 'item' I am using the pylast interface (an API for last.fm--link). Specifically, I am accessing a list of variables of this type: SimilarItem = _namedtuple("SimilarItem", ["item"...

Determine cluster size of file system in Python

I would like to calculate the "size on disk" of a file in Python. Therefore I would like to determine the cluster size of the file system where the file is stored. How do I determine the cluster size in Python? Or another built-in method that calculates the "size on disk" will also work. I looked at os.path.getsize but it returns the ...

How can you do Co-routines using C#?

In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python: def coroutine(func): def start(*args,**kwargs): cr = func(*args,**kwargs) cr.next() return cr return start @corouti...

download mbox files over https using python

I was trying to find the right module for downloading kernel patches from kernel.org site For example,to download the file at https://patchwork.kernel.org/patch/62948/mbox/ I understand urlgrabber has a problem with https on debian. urllib2 seems to have problem with this url as well (says getaddrinfo failed, even though there are no ...

complex if statement in python

I need to realize a complex if-elif-else statement in Python but I don't get it working. The elif line I need has to check a variable for this conditions: 80, 443 or 1024-65535 inclusive I tried if ... # several checks ... elif (var1 > 65535) or ((var1 < 1024) and (var1 != 80) and (var1 != 443)): # fail else ... ...

Dictionaries with tuples that have lists as values.

How can i have a tuple that has a list as a value. F.x. if i want to have a structure like this. ( Somechar , Somelist[] ) And how would i iterate through a dictionary of these things? ...

How to make Twisted use Python logging?

I've got a project where I'm using Twisted for my web server. When exceptions occur (such as network errors), it's printing to the console. I've already got logging through Python's built-in log module - is there any way to tell the reactor to use that instead? What's the usual pattern for this? ...

Fixed income data online

I am looking for a resource to download fixed income data online, much like there is access to stock data from yahoo. At the very least I'd like the treasury bonds. I use python, but any help would be appreciated. ...

How to implement a hub in Python

Dear all, I need to implement a TCP server in Python which receives some data from a client and then sends this data to another client. I've tried many different implementations but no way to make it run. Any help would be really appreciated. Below is my code: import SocketServer import sys import threading buffer_size = 8182 ports = {...

How to switch position of two items in a Python list?

I haven’t been able to find a good solution for this problem on the net (probably because switch, position, list and Python are all such overloaded words). It’s rather simple – I have this list: ['title', 'email', 'password2', 'password1', 'first_name', 'last_name', 'next', 'newsletter'] I’d like to switch position of 'password2' and...

Properly using subprocess.PIPE in python?

I'm trying to use subprocess.Popen to construct a sequence to grab the duration of a video file. I've been searching for 3 days, and can't find any reason online as to why this code isn't working, but it keeps giving me a blank result: import sys import os import subprocess def main(): the_file = "/Volumes/Footage/Acura/MDX/2001/Cras...

Evaluating for loops in python, containing an array with an embedded for loop

I was looking at the following code in python: for ob in [ob for ob in context.scene.objects if ob.is_visible()]: pass Obviously, it's a for each loop, saying for each object in foo array. However, I'm having a bit of trouble reading the array. If it just had: [for ob in context.scene.objects if ob.is_visible()] that would ma...

ctypes and pointer manipulation

I am dealing with image buffers, and I want to be able to access data a few lines into my image for analysis with a c library. I have created my 8-bit pixel buffer in Python using create_string_buffer. Is there a way to get a pointer to a location within that buffer without re-creating a new buffer? My goal is to analyze and change da...

ssh-rsa public key validation using a regular expression.

What regular expression can I use (if any) to validate that a given string is a legal ssh rsa public key? I only need to validate the actual key - I don't care about the key type the precedes it or the username comment after it. Ideally, someone will also provide the python code to run the regex validation. Thanks. ...

How to create an application which embeds and runs Python code without local Python installation?

Hello fellow software developers. I want to distribute a C program which is scriptable by embedding the Python interpreter. The C program uses Py_Initialize, PyImport_Import and so on to accomplish Python embedding. I'm looking for a solution where I distribute only the following components: my program executable and its libraries ...

Modify default queryset in django

I have added a 'cancelled' field to my model, is there a way to modify the model default query to something like cancelled=False ? without having to modify all my filter/exclude queries ? ...

Recognizing language of a short text? - Python

Hi folks, I'm have a list of articles, each article has its own title and description. Unfortunately, from the sources I am using, there is no way to know what language they are written. Also, text is not entirely written in 1 language; almost always English words are present. I reckon I would need dictionary databases stored on my...

Sort a list of tuples without case sensitivity

How can I efficiently and easily sort a list of tuples without being sensitive to case? For example this: [('a', 'c'), ('A', 'b'), ('a', 'a'), ('a', 5)] Should look like this once sorted: [('a', 5), ('a', 'a'), ('A', 'b'), ('a', 'c')] The regular lexicographic sort will put 'A' before 'a' and yield this: [('A', 'b'), ('a', 5), ('...

Django URL regex question

Hey all! I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way: url(r'^env/(?P<env>\w+)/artifact/(?P<artifact>\w+)/$', 'config.views.ipview', name="bothlist"), Now, this works fine, but what I would like ...

Displaying a list of items vertically in a table instead of horizonally

I have a list of items sorted alphabetically: mylist = [a,b,c,d,e,f,g,h,i,j] I'm able to output the list in an html table horizonally like so: | a , b , c , d | | e , f , g , h | | i , j , , | What's the algorithm to create the table vertically like this: | a , d , g , j | | b , e , h , | | c , f , i , | I'm using python...