python

Stuck in a while loop, can you please help?

I am currently writing a program that reads records from a txt file and prints the data on the screen as such: GRADE REPORT NAME COURSE GRADE ----------------------------------------------------------- JOE FRITZ AMERICAN GOVERNMENT B ...

Responding to httpRequest after using threading.Timer to delay response

Hey everyone, I'm trying to patch a testing framework built in python for javascript called mootools-test-runner (i'm a front end developer by day, so my python skills are pretty weak... really weak.) The use case is we want to be able to make a json request to the server and have it delay x amount of time before it returns -- original...

Registry Entries for all users in Python

I wrote an application that stores several things in the registry. When I first started, I added them to HKEY_LOCAL_MACHINE, but kept getting permission errors writing to the. So, it was suggested that I use HKEY_CURRENT_USER, that worked until I realized that I am not able to access them from another account. How can I write to the regi...

Bash Script for MythTV which requires Python Dependencies

I wrote a bash script which renames MythTV files based upon data it receives. I wrote it in bash because bash has the strong points of textual data manipulation and ease of use. You can see the script itself here: http://code.google.com/p/mythicallibrarian/source/browse/trunk/mythicalLibrarian I have several users which are first time ...

comparing two lists, python

I should define a function overlapping() that takes two lists and returns True if they have at least one member in common, False otherwise. For the sake of the exercise, I should write it using two nested for-loops. What am I doing wrong? def overlapping(a,b): for char in a: for char2 in b: return char in char2 ...

Chi Square Test using Frequencies, Bins, CDF, Python

Hi, I am trying to write a chi square goodness-of-fit test for Beta distribution from scratch, without using any external functions. The code below reports '1' for a fit, even though kstest from scipy.stats returns a zero. Data is distributed normally, so my function should also return zero. import numpy as np from scipy.stats import ch...

Simplify the changing of this binary variable.

When I am writing my code, I find the following situation many times: def Mwindow_stayontop(self, event): if CFG["AlwOnTop"] == 1: self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE) CFG["AlwOnTop"] = 0 else: self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE | wx.STAY_ON_TOP) CFG["AlwOnTop"] = 1 Can anybody th...

Sort a list of Class Instances Python

I have a list of class instances - x = [<iteminstance1>,...] among other attributes the class has score attribute. How can I sort the items in ascending order based on this parameter? EDIT: The list in python has something called sort. Could I use this here? How do I direct this function to use my score attribute? ...

Django development version vs stable release

I am about to start ramping up on Django and develop a web app that I want to deploy on Google App Engine. I learn that Google has Django 0.96 already installed on the APP engine, but the latest "official" version of Django I see is at 1.2.3 and its a bit of an effort to install it there. I am curious which version of Django is most wid...

Ackermann function versus n nested loops

Hi everyone, I'm working my way thorugh a book on computation (Minksy 1967) and am having a hard time with relating a recursive function to a function defined in terms of loops. Specifically he asks to find the relationship between two functions: The Ackermann function (all code in python): def a(n,m): if n==0: return m+1...

How do I forcefully clean a field and redisplay it in Django?

How can I clean the data in a form and have the cleaned data redisplayed instead of the submitted data? There are several fields in my form, and every time the user submits it, it should be redisplayed with the values the user entered. However, some of the fields I would like to clean and update for the user. More specifically, I have ...

Why do people say that Java is more scalable than python?

I've seen this argument in a few places, and now, recently i saw it again on a reddit post. This is by no means a flame against any of these two languages. I am just puzzled why there is this bad reputation about python not being scalable. I'm a python guy and now I'm getting started with Java and i just want to understand what makes Jav...

Having a problem getting my output to look a certain way.

Hello all! Thanks for viewing my question and thanks in advance for any help you may provide. I am writing a program that reads lines from a txt file and then prints the output in a certain fashion. Here they both are Here is the txt file I am reading from JOE FRITZ AMERICAN GOVERNMENT B JOE FRITZ CALCUL...

generating variable names on fly in python

Hi, Is there a way I can generate variable names in python in a loop and assign values to them? For example, if I have prices = [5, 12, 45] I want price1 = 5 price2 = 12 price3 = 45 Can I do this in a loop or something instead of manually assigning price1 = prices[0], price2 = prices[1] etc. Thank you. EDIT Many people suggest...

Python 2.7 cannot import PyQt4

I've upgraded to Python 2.7 from Python 2.6 on Ubuntu Maverick Meerkat (10.10) and I'm unable to import PyQt4. austin@gerald:~$ python2.7 Python 2.7.0+ (r27:82500, Sep 15 2010, 18:04:55) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import PyQt4 Traceback (most recent call last): Fil...

smallest value of hash() function?

in python (3), what is the smallest value that hash(x) can return? i want to use hashes to give a quick 'fingerprint' to database values (basically making it easy to see whether two longish, similar texts are actually equal or not), and want to get rid of negative numbers (for simplicity), so i thought i'd just add the smallest possibl...

Registry Startup Entry with runas argument?

Is it possible to add a startup entry in the windows registry with a runas argument? So when it launches, it runs with the user specified? ...

django ModelMultipleChoiceField (default values)

I`ve been searching and trying to get this to work for the past few hours and I cant ... I have a list of skills that I take from the database forms.ModelMultipleChoiceField( skills.objects.all(), required=True, widget=forms.CheckboxSelectMulti...

unable to help(exec)

Ok, this is funny. >>> exec("print") >>> help(exec) File "<stdin>", line 1 help(exec) ^ SyntaxError: invalid syntax >>> looks like exec is a statement, not a function, hence you cannot help() it. Is this expected or a bug? if expected, why? can you reproduce it on python3 ? I have Python 2.6.1 here. ...

Laplacian smoothing to Biopython

Hi, I am trying to add Laplacian smoothing support to Biopython's Naive Bayes code 1 for my Bioinformatics project. I have read many documents about Naive Bayes algorithm and Laplacian smoothing and I think I got the basic idea but I just can't integrate this with that code (actually I cannot see which part I will add 1 -laplacian num...