python

Change process priority in Python, cross-platform

I've got a Python program that does time-consuming computations. Since it uses high CPU, and I want my system to remain responsive, I'd like the program to change its priority to below-normal. I found this: Set Process Priority In Windows - ActiveState But I'm looking for a cross-platform solution. ...

Connecting C# (frontend) to an apache/php/python (backend)

Overview: We are looking to write a C# user interface to select parts of our web applications. This is for a very captive audience (internally, for example). Our web applications are written in PHP and/or Python using Apache as the web server. Why? A well thought out native Windows interface can at times be far more effective than li...

How to pickle a CookieJar?

I have an object with a CookieJar that I want to pickle. However as you all probably know, pickle chokes on objects that contain lock objects. And for some horrible reason, a CookieJar has a lock object. from cPickle import dumps from cookielib import CookieJar class Person(object): def __init__(self, name): self.name = n...

[Django/Python] Why does mass importing not work but importing definition individually works?

Hi. So I just met a strange so-called bug. Because this work on my other .py files, but just on this file it suddenly stopped working. from tuttobelo.management.models import * The above used to work, but it stopped working all of a sudden, and I had to replace it with the bottom. from tuttobelo.management.models import Preferences,...

working with django and sqlalchemy but backend mysql

i am working with python django framework but in model part is sqlalchemy and back end data base is mysql how i will configure them??? ...

smoothing irregularly sampled time data

Given a table where the first column is seconds past a certain reference point and the second one is an arbitrary measurement: 6 0.738158581 21 0.801697222 39 1.797224596 49 2.77920469 54 2.839757536 79 3.832232283 91 4.676794376 97 5.18244704 100 5.521878863 118 6.316630137 131 6.778507504 147 7.020395216 157 7.331607129 176 7.63749222...

How can I have variable assertions in Perl?

How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of it's variables? I wonder if I can use the Pythonic practice of inserting: assert 0, (foo, bar) to debug scripts in a debuger-less way? ...

It is possible to match a character repetition with regex? How?

Question: Is is possible, with regex, to match a word that contains the same character in different positions? Condition: All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't know what is it. Examples: using lowercase 6char words I'd like to match w...

Is it pythonic to import inside functions?

PEP 8 says: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. On occation, I violate PEP 8. Some times I import stuff inside functions. As a general rule, I do this if there is an import that is only used within a single function. Any opin...

What's a good beginner setup for C++/Python on OSX?

I'm looking for a good setup for learning C++ and eventually Python on Mac OSX. As I'm going use C++ I don't want to use XCode, as (I understand) this is primarily used with Objective-C. I have a small bit of experience in Java and MATLAB programming, and math is probably not going to be my main problem. I was thinking on an approach loo...

How to stop Python parse_qs from parsing single values into lists?

In python 2.6, the following code: import urlparse qsdata = "test=test&test2=test2&test2=test3" qs = urlparse.parse_qs(qsdata) print qs Gives the following output: {'test': ['test'], 'test2': ['test2', 'test3']} Which means that even though there is only one value for test, it is still being parsed into a list. Is there a way to en...

Looping Fget with fsockopen in PHP 5.x

Hello, I have a Python Server finally working and responding to multiple command's with the output's, however I'm now having problem's with PHP receiving the full output. I have tried commands such as fgets, fread, the only command that seems to work is "fgets". However this only recieve's on line of data, I then created a while statem...

Can python doctest ignore some output lines?

Hi! I'd like to write a doctest like this: """ >>> print a.string() foo : a bar : b date : <I don't care about the date output> baz : c """ Is there any way to do this? I think it would make more sense to switch to unittest, but I'm curious whether it's possible to specify a range of output tha...

HOWTO: Fix Python Indentation

I have some python code that have inconsistent indentation, there is a lot of mixture of tabs and spaces to make the matter even worse even space indentation is not preserve. The code works as expected but its difficult to maintain. I'm looking for a tool that will fix the indentation (like html tidy but for python) and won't break the ...

Python newbie: What does this code do?

This is a snippet from Google AppEngine tutorial. application = webapp.WSGIApplication([('/', MainPage)], debug=True) I'm not quite sure what debug=True does inside the constructor call. Does it create a local variable with name debug, assign True to it, and pass it to constructor, or is this a way to set a class instance member vari...

Autoload in Python

In the past I've used perl's AUTOLOAD facility for implementing lazy loading of symbols into a namespace, and wanted the same functionality in python. Traditionally the closest you appear to be able to get is to use a class and a __getattr__ class to achieve this sort of thing. However I've also tried rummaging around in sys.modules, a...

Resolving a relative path from py:match in a genshi template

<py:match path="foo"> <?python import os href = select('@href').render() SOMEWHERE = ... # what file contained the foo tag? path = os.path.abspath(os.path.join(os.path.dirname(SOMEWHERE), href) f = file(path,'r') # (do something interesting with f) ?> </py:match> ... <foo href="../...

How to test a Python script with an input file filled with testcases?

I'm participating in online judge contests and I want to test my code with a .in file full of testcases to time my algorithm. How can I get my script to take input from this .in file? ...

Django - alternative to subclassing User?

I am using the standard User model (django.contrib.auth) which comes with Django. I have made some of my own models in a Django application and created a relationship between like this: from django.db import models from django.contrib.auth.models import User class GroupMembership(models.Model): user = models.ForeignKey(User, null =...

Add to a dictionary in python?

Hi, Is it possible to add a key to a python dictionary after it has been created? It doesn't seem to have an .add() method... ...