python

Spaceship objects

I'm trying to make a program which creates a spaceship and I'm using the status() method to display the ship's name and fuel values. However, it doesn't seem to be working. I think I may have messed something up with the status() method. I'm also trying to make it so that I can change the fuel values, but I don't want to create a new met...

Defining the context of a word - Python

Hi folks, I think this is an interesting question, at least for me. I have a list of words, let's say: photo, free, search, image, css3, css, tutorials, webdesign, tutorial, google, china, censorship, politics, internet and I have a list of contexts: Programming World news Technology Web Design I need to try and match wo...

Globally accessible object across all Celery workers / memory cache in Django

Hi everyone, I have pretty standard Django+Rabbitmq+Celery setup with 1 Celery task and 5 workers. Task uploads the same (I simplify a bit) big file (~100MB) asynchronously to a number of remote PCs. All is working fine at the expense of using lots of memory, since every task/worker load that big file into memory separatelly. What I ...

How to step through debug twisted?

I'd like to be able to debug Punjab, a twisted python application, in Netbeans so that I can step through the code. How can I do that? Alternatively, how could I do it in a different debugger? ...

'module' object has no attribute 'pcapObject'

I have the following sample code which doesn't seem to want to run. import pcap pc = pcap.pcapObject() dev = sys.argv[1] pc.open_live(dev, 1600, 0, 100) pc.setfilter("udp port 53", 0, 0) while 1: pc.dispatch(1, p.pcap_dispatch) I'm really not sure why. I'm using pypcap. I'm running this on both 2.5.1 and 2.6 versions of python (...

Programmatically specifying Django model attributes

Hi! I would like to add attributes to a Django models programmatically. At class creation time (the time of the definition of the model class). The model is not going to change after that in run time. For instance, lets say I want to define a Car model class and want to add one price attribute (database column) per currency, given a lis...

Copy and pasting code into the Python interpreter

There is a snippet of code that I would like to copy and paste into my Python interpreter. Unfortunately due to Python's sensitivity to whitespace it is not straightforward to copy and paste it a way that makes sense. (I think the whitespace gets mangled) Is there a better way? Maybe I can load the snippet from a file. This is just an ...

String comparison in Numpy

In the following example In [8]: import numpy as np In [9]: strings = np.array(['hello ', 'world '], dtype='|S10') In [10]: strings == 'hello' Out[10]: array([False, False], dtype=bool) The comparison fails because of the whitespace. Is there a Numpy built-in function that does the equivalent of In [12]: np.array([x.strip()==...

Google App Engine Datastore Faceted Search

Has any one implemented Faceted Search using Google App Engine Datastore? ...

What do I use for a max-heap implementation in Python?

Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python? ...

What can be done in Cpython that can not be done in IronPython?

What can be done in Cpython that can not be done in IronPython? ...

matplotlib: How to adjust ticks at the corner of a 3Dplot with mplot3d

Hey hello, the problem I'm facing at the moment is the lack of ticks at the corners of the 3D-plots from matplotlib.mplot3d. Say the xaxis ranges from 0 to 10, then only the ticks 2,4,6 and 8 will be displayed. What I'm looking for is a way to format the ticks similiar to pylab: from pylab import * plot([1,2,3]) xticks([0, 1, 2], ['a',...

add a decorate function to a class

I have a decorated function (simplified version): class Memoize: def __init__(self, function): self.function = function self.memoized = {} def __call__(self, *args, **kwds): hash = args try: return self.memoized[hash] except KeyError: self.memoized[hash] = self.func...

Printing elements out of list

Hi, I have a certain check to be done and if the check satisfies, I want the result to be printed. Below is the code: import string import codecs import sys y=sys.argv[1] list_1=[] f=1.0 x=0.05 write_in = open ("new_file.txt", "w") write_in_1 = open ("new_file_1.txt", "w") ligand_file=open( y, "r" ) #Open the receptor.txt file ligand_l...

Deleting python modules?

Hi, Can you delete python modules? I've installed one that I would like to remove, and can't seem to figure out how. Thanks ...

Scraping landing pages of a list of domains

I have a reasonably long list of websites that I want to download the landing (index.html or equivalent) pages for. I am currently using Scrapy (much love to the guys behind it -- this is a fabulous framework). Scrapy is slower on this particular task than I'd like and I am wondering if wget or an other alternative would be faster given ...

Reading UDP Packets

I am having some trouble dissecting a UDP packet. I am receiving the packets and storing the data and sender-address in variables 'data' and 'addr' with: data,addr = UDPSock.recvfrom(buf) This parses the data as a string, that I am now unable to turn into bytes. I know the structure of the datagram packet which is a total of 28 bytes,...

Trying to grab just absolute links from a webpage using BeautifulSoup

I am reading the contents of a webpage using BeautifulSoup. What I want is to just grab the <a href> that start with http://. I know in beautifulsoup you can search by the attributes. I guess I am just having a syntax issue. I would imagine it would go something like. page = urllib2.urlopen("http://www.linkpages.com") soup = BeautifulSo...

Python 2.5 fails on a datetime.strptime format

I have seen several questions with people asking about the same problem but none of the answers are helping me. I'm receiving this error: pydev debugger: starting Traceback (most recent call last): >>> File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <module> userConnDate = datetime.strptime(data[1] + ' ' +...

Reducing size of a character array in Numpy

Given a character array: In [21]: x = np.array(['a ','bb ','cccc ']) One can remove the whitespace using: In [22]: np.char.strip(x) Out[22]: array(['a', 'bb', 'cccc'], dtype='|S8') but is there a way to also shrink the width of the column to the minimum required size, in the above case |S4? ...