python

Probability distribution in Python

I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module that I could use, else I...

pycurl cancel a transfer and try & except

How do i cancel a transfer in pycurl? i use to return -1 in libcurl but pycurl doesnt seem to like that ("pycurl.error: invalid return value for write callback -1 17") return 0 doesnt work either, i get "error: (23, 'Failed writing body')" . Also how do i do a try/except with pycurl? i dont see any examples online nor the pycurl examples...

python time to age part 2, timezones

Following on from my previous question: http://stackoverflow.com/questions/508727/python-time-to-age I have now come across a problem regarding the timezone, turns out that its not always going to be "+0200". So when strptime tries to parse it as such, it throws up an exception. I thought about just chopping off the +0200 with [:-6] or...

Django form fails validation on a unique field

I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) and the form: class ArticleForm(ModelForm): class Meta: model = Article The validation here fails when I try to update an existing row...

Practical examples of NLTK use

I'm playing about with the Natural Language Toolkit (NLTK). The documentation (Book and HOWTO) and is a little heavy going. Are there any good but basic examples of the use of NLTK? I'm thinking of things like the NTLK articles on the Stream Hacker blog. ...

subprocess.Popen

I am running an msi installer in silent mode and caching logs in the specific file. the following is the command i need to execute. C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log" I used: subprocess.Popen(['C:\Program Files\ My Installer\Setup.exe', '/s /v "/qn /lv %TEMP%\log_silent.log"'],stdout=subpro...

How to add custom fields to InlineFormsets?

I'm trying to add custom fields to an InlineFormset using the following code, but the fields won't show up in the Django Admin. Is the InlineFormset too locked down to allow this? My print "ding" test fires as expected, I can print out the form.fields and see them all there, but the actual fields are never rendered in the admin. admin...

python console intrupt? and cross platform threads

I want my app to loop in python but have a way to quit. Is there a way to get input from the console, scan it for letter q and quick when my app is ready to quit? in C i would just create a pthread that waits for cin, scans, locks a global quit var, change, unlock and exit the thread allowing my app to quit when its done dumping a file o...

Dynamic data in postgresql

Hi world, I intend to have a python script do many UPDATEs per second on 2,433,000 rows. I am currently trying to keep the dynamic column in python as a value in a python dict. Yet to keep my python dict synchronized with changes in the other columns is becoming more and more difficult or nonviable. I know I could put the autovacuum on...

Python or java which language will exposed a self taught programmer to more computer science concept?

Of the two which one would exposed someone just learning to program to more computer science concept/problems? ...

intercepting stdout of a subprocess while it is running

if this is my subprocess: import time, sys for i in range(200): sys.stdout.write( 'reading %i\n'%i ) time.sleep(.02) And this is the script controlling and modifying the output of the subprocess: import subprocess, time, sys print 'starting' proc = subprocess.Popen( 'c:/test_apps/testcr.py', shell=True, stdin=su...

How to debug deadlock with python?

I am developing a multi-threading application, which is deadlocking. I am using Visual C++ Express 2008 to trace the program. Once the deadlock occurs, I just pause the program and trace. I found that when deadlock occurs, there will be two threads called python from my C++ extension. All of them use Queue in python code, so I guess ...

How to modify existing panels in Maya using MEL or Python?

I've been writing tools in Maya for years using MEL and Python. I'd consider myself an expert in custom window/gui design in Maya except for one area; modifying existing panels and editors. Typically, I'm building tools that need totally custom UIs, so its customary for me to build them from scratch. However, recently I've found mysel...

input and thread problem, python

I am doing something like this in python class MyThread ( threading.Thread ): def run (s): try: s.wantQuit = 0 while(not s.wantQuit): button = raw_input() if button == "q": s.wantQuit=1 except KeyboardInterrupt: s.wantQuit = 1 my...

How to deploy a Python application with libraries as source with no further dependencies?

Background: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directory from SVN. The program has about 6 di...

How to embed p tag inside some text using Beautifulsoup?

I wanted to embed <p> tag where ever there is a \r\n\r\n. u"Finally Sri Lanka showed up, prevented their first 5-0 series whitewash, and stopped India at nine ODI wins in a row. \r\n\r\nFor 62 balls Yuvraj Singh played a dream knock, keeping India in the game despite wickets falling around him. \r\n\r\nPerhaps the toss played a big par...

Can I instatiate a subclass object from the superclass

I have the following example code: class A(object): def __init__(self, id): self.myid = id def foo(self, x): print 'foo', self.myid*x class B(A): def __init__(self, id): self.myid = id self.mybid = id*2 def bar(self, x): print 'bar', self.myid, self.mybid, x When used, the follo...

How to properly organize a package/module dependency tree ?

Good morning, I am currently writing a python library. At the moment, modules and classes are deployed in an unorganized way, with no reasoned design. As I approach a more official release, I would like to reorganize classes and modules so that they have a better overall design. I drew a diagram of the import dependencies, and I was pla...

TypeError: 'NoneType' object is not iterable

I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above. what does this mean and how do I go about it? ...

Is there a better way (besides COM) to remote-control Excel?

I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks: For example, the slightest upset seems to be able to break the c...