python

Append Row(s) to a NumPy Record Array

Hi Everyone, Is there a way to append a row to a NumPy rec.array()? For example, x1=np.array([1,2,3,4]) x2=np.array(['a','dd','xyz','12']) x3=np.array([1.1,2,3,4]) r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c') append(r,(5,'cc',43.0),axis=0) The easiest way would to extract all the column as nd.array() types, add the sepa...

list management python

I have extracted some url list and want to manipulate this list. Following is extracted list sample: http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http://www.naver.com/rules/disclaimer.htm...

Eclipse smart quotes - like in Textmate

Hey all, Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I'm a newbie here so be gentle. FWIW - I'm using pydev in Eclipse. Thanks Rephrase What I am looking for is given I have a word or phrase selected on...

How to find where a function was imported from in Python?

I have a Python module with a function in it: == bar.py == def foo(): pass == EOF == And then I import it into the global namespace like so: from bar import * So now the function foo is available to me. If I print it: print foo The interpreter happily tells me: <function foo at 0xb7eef10c> Is there a way for me to find...

Principal component analysis in Python

I'd like to use principal component analysis (PCA) for dimensionality reduction. Does numpy or scipy already have it, or do I have to roll my own using numpy.linalg.eigh? I don't just want to use singular value decomposition (SVD) because my input data are quite high-dimensional (~460 dimensions), so I think SVD will be slower than com...

Alternatives to wx.lib.masked.NumCtrl

Hi everyone! In a wxPython application I'm developing I need a lot of input fields for numbers (integers and floats), so I tried using wx.lib.masked.NumCtrl, but my users now tell me that it's quite uncomfortable to use (and I agree with them). Is there an alternative widget implementation I can use, or should I just roll my own, start...

More pythonic way of skipping header lines

Is there a shorter (perhaps more pythonic) way of opening a text file and reading past the lines that start with a comment character? In other words, a neater way of doing this fin = open("data.txt") line = fin.readline() while line.startswith("#"): line = fin.readline() ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") returns an object containing the keys: <google.appengine.ext.db.GqlQuery object at 0x0415E210> I need to compare it to an array of keys t...

Pack program *and* dynamically loaded files into single executable? (python + pygame, or language agnostic)

There are plenty of great answers to questions about making a standalone executable, but I can't figure out how to pack art assets (or dynamically loaded files) into it as well. Why would I want to do this? Because it would be great to distribute a simple (throw away) game that lives entirely in a single executable with no installer. ...

Is there an existing Python class that can hold any user attributes?

I can use this when I need multiple objects with different attributes: class struct(object): def __init__(self,*args,**kwargs): for key,val in kwargs.items(): setattr(self,key,val) But I'm wondering if there isn't a built-in already? ...

Nonblocking webserver on .Net for Comet applications

I am trying to implement a Comet style (e.g. chat) application using IronPython. While I don't need to scale to twitter like dimensions, it is vital that the response time is lightening fast. All the possibilities in Python (Twisted, Tornado, Magnum-Py) do not work with IronPython, often because of epoll support. Is there a default ch...

Python code to accept many different formats of US phone numbers?

I'm reading in lots of user entered data that represent phone numbers from files. They are all slightly entered in differently: 5555555555 555-555-5555 555-555/5555 1555-555-5555 etc... How could I easily parse in all of these phone numbers in Python and produce a canonical output like: 555-555-5555? ...

Process two files at the same time in Python

Hi, I have information about 12340 cars. This info is stored sequentially in two different files: car_names.txt, which contains one line for the name of each car car_descriptions.txt, which contains the descriptions of each car. So 40 lines for each one, where the 6th line reads @CAR_NAME I would like to do in python: to add for eac...

Getting only one dimension of indexes from the getSelectedIndexes function in QT?

I'm working on a small project in QT (well, pyQT4 actually, but it shouldn't matter too much) and I've run into the following problem. I have a QTableView with several rows and columns. I have set the selection mode to be rows only. When I call getSelectedIndexes() on my QTableView, I get an index for every row and column, which in the c...

How do I check the HTTP status code of an object without downloading it?

>>> a=urllib.urlopen('http://www.domain.com/bigvideo.avi') >>> a.getcode() 404 >>> a=urllib.urlopen('http://www.google.com/') >>> a.getcode() 200 My question is...bigvideo.avi is 500MB. Does my script first download the file, then check it? Or, can it immediately check the error code without saving the file? ...

How to get two random records with Django

How do I get two distinct random records using Django? I've seen questions about how to get one but I need to get two random records and they must differ. ...

httplib in Python to get the status code...but it is too tricky?

>>> import httplib >>> conn = httplib.HTTPConnection("www.google.com") >>> conn.request("HEAD", "/index.html") >>> res = conn.getresponse() >>> print res.status, res.reason 200 OK This code will get the HTTP status code. However, notice that I split up "google.com" and "/index.html" on 2 lines. And it's confusing. What if I want to ...

Where can I find a Python lib documentation??!!

Hello again. Am looking for a full and official Python standard lib reference. I can't seem to find proper documentation for Python's built-in library anywhere, similar to javadocs. Perhaps I'm not looking hard enough. Thanks ...

Is there 'multimap' implementation in python?

hi i am a newbie to Python I need to use multi-map to store my data, i.e., a = multidict() a[1] = 'a' a[1] = 'b' a[2] = 'c' print(a[1]) # prints: ['a', 'b'] print(a[2]) # prints: ['c'] is there any suggestions? can anyone provide some keywords so that i can google? ...

How to play sound till the user hits a key?

First thought of implementing this using threads but python doesnt have a way for killing threads. I have read the other topic on killing threads. Is there any proper platform independent way of doing this? ...