python

In Python script, how do I set PYTHONPATH?

I know how to set it in my /etc/profile and in my environment variables. But what if I want to set it during a script? Is it import os, sys? How do I do it? ...

python httplib: getting the outgoing request headers

I do: con = HTTPConnection(SERVER_NAME) con.request('GET', PATH, HEADERS) resp = con.getresponse() For debugging reasons, I want to see the request I used (it's fields, path, method,..). I would expect there to be some sort of con.getRequest() or something of the sort but didn't find anything. Ideas? ...

Best way to get xml-rpc and django working together

I have worked with django for a while but I am new to xml-rpc. I have two django servers running and 1st needs to call some functions from some modules of 2nd. I find xml-rpc easiest way to do so but don't want to run a separate server for this only. What options do I have ? Can I run django's web-server and xml-rpc server with a single ...

Lets say I have a string...how do I convert that to a datetime?

s = "June 19, 2010" How do I conver that to a datetime object? ...

Text mining: when to use parser, tagger, NER tool?

I'm doing a project on mining blog contents and I need help differentiating on which tool to uses. When do I use a parser, when do I use a tagger, and when do I need to use a NER tool? For instance, I want to find out the most talked about topics/subjects between several blogs; do I use a part-of-speech tagger to grab the nouns and do a...

Django singals file, cannot import model names

I have such file order: project/ app/ models.py signals.py I am keeping signals inside signals.py as it should be. and at the top of the signals.py file, I include myapp models as I do queries in these signals with from myproject.myapp.models import Foo However it doesnt seem to find it, as I run the server or ...

output of a python program in an XML file

Possible Duplicate: python and result in xml My program involves keystroke detection whose code is as follows: import Tkinter as tk def key(event): if event.keysym == 'Escape': root.destroy() print event.char root = tk.Tk() print "Press a key (Escape key to exit):" root.bind_all('<Key>', key) root.withdraw() root...

Using QWebPage via socks

Hello, I'm confused a bit on usage of QWebPage via socks using httplib2 (http/socks5/socks4). Is there any issues or workaround on it? ...

How can I import the enviroment variables of a completed process in python?

I need to write a python script that launches a shell script and import the environment variables AFTER a script is completed. Immagine you have a shell script "a.sh": export MYVAR="test" In python I would like to do something like: import os env={} os.spawnlpe(os.P_WAIT,'sh', 'sh', 'a.sh',env) print env and get: {'MYVAR'="test"...

How do i test django ratings in my application?

Guys, I have installed django-ratings application in my django project. Am wondering how best can i test my app voting functionality because django ratings is only allowing me to vote once for the same user, object and Ip address. Is there a way i can disable this checks so that i can just insert votes, test my application and when ...

Generate a waveform image from an audio file

Building a python application that converts raw audio files into wave using sox on a linux system. I want it to be able to generate an image (PNG or Jpeg) of the audio waveform pattern but I am unable to find a command line tool or python package that will do this. Not being an experience Python programmer my options are limited. There ...

how can python function access its own attributes?

is it possible to access the python function object attributes from within the function scope? e.g. let's have def f(): return SOMETHING f._x = "foo" f() # -> "foo" now, what SOMETHING has to be, if we want to have the _x attribute content "foo" returned? if it's even possible (simply) thanks UPDATE: i'd like the fo...

Django, creating user with add user permission

Hi All, I have gone through a strange behavior while creating a user, using Django admin interface. I have to create a user which can add other users, but for that Django requires two permissions i.e. add user and change user. But when I gave user the change permission, its even able to change the superuser of the site. What I want is...

django model subclassing: get the subclass by querying the superclass

The following code is given: class BaseMedium(models.Model): title = models.CharField(max_length=40) slug = models.SlugField() class A(BaseMedium): url = models.URLField() class B(BaseMedium): email = models.EmailField() I now want to query every BaseMedium. b = BaseMedium.objects.all() How do I print every infor...

mod_python and subpackages importing issues: ImportError: No module named...

Hello, I'm exploring mod_python and I'm having trouble with the package importing. I've a structure like this: my base dir | +- __init__.py +- index.py +- package (directory) | +- __init__.py +- package.py (file) and an Apache Virtual Host like this: <VirtualHost *:80> Serv...

C++ or Python (maybe else) to create GUI for console application in C

I have a Visual C console application (created in VC++2008EE) and I need to add GUI to it. One idea was to invoke the console app as a subprocess and communicate with it using stdin and stdout. I tried to do that with Python subprocess module - but it deadlocks (probably because my console app is running continuously). As I understood f...

pygtk - how update a gtk.liststore?

http://img824.imageshack.us/i/capturadetelag.png/ how update a gtk.liststore? i mean get a random number every second on a column just like example, such as a download manager list, i'd like to have a simple example to know how this Liststore works for update the list, because i can't find a effective way to do something like a: stor...

Django Form Display Meta

Hi I am still on Django tutorial and currently here: def display_meta(request): values = request.META.items() values.sort() html = [] for k, v in values: html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v)) return HttpResponse('<table>%s</table>' % '\n'.join(html)) I understand what it is meant to do: ...

Optimize algorithm for creating a list of items rated together, in Python.

given a list of purchase events (customer_id,item) 1-hammer 1-screwdriver 1-nails 2-hammer 2-nails 3-screws 3-screwdriver 4-nails 4-screws i'm trying to build a data structure that tells how many times an item was bought with another item. Not bought at the same time, but bought since I started saving data. the result would look like ...

Extracting semantic/stylistic features from text

Hi, I would like to know of open source tools (for java/python) which could help me extract semantic & stylistic features from text. Examples of semantic features would be adjective-noun ratio, a particular sequence of part-of-speech tags (adjective followed by a noun: adj|nn) etc. Examples of stylistic features would be number of uniqu...