I have this code in template, which I would like to printout number of votes that each choice got. votes is just dictionary while choices are model object.
{% for choice in choices %}
{{choice.choice}} - {{votes[choice.id]}} <br />
{% endfor %}
it raises an exception with this message "Could not parse the remainder"
I googled it a...
My python script executes fine in Jail shell, putting out html which I can pipe to an html file. When I look at the file, it's exactly what I want. However when I try to run the file from a browser I get a 500 error. According to the instructions at http://imgseekweb.sourceforge.net/install.html the cgi-bin should be in suEXEC mode. M...
A PIL.Image.grab() takes about 0.5 seconds. That's just to get data from the screen to my app, without any processing on my part. FRAPS, on the other hand, can take screenshots up to 30 FPS. Is there any way for me to do the same from a Python program? If not, how about from a C program? (I could interface it w/ the Python program, pot...
What is the best way to strip all non alphanumeric characters from a string, using Python?
The solutions presented in the PHP variant of this question will probably work with some minor adjustments, but don't seem very 'pythonic' to me.
For the record, I don't just want to strip periods and commas (and other punctuation), but also quo...
I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?
Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.
...
Is there a built-in function that works like zip() but that will pad the results so that the length of the resultant list is the length of the longest input rather than the shortest input?
>>> a=['a1']
>>> b=['b1','b2','b3']
>>> c=['c1','c2']
>>> zip(a,b,c)
[('a1', 'b1', 'c1')]
>>> What command goes here?
[('a1', 'b1', 'c1'), (None, '...
i have stored my public key on the public key server .now i have to fetch/retrieve public key from that public key server using the python script/programme .how can i do this?
also want to know the way how to execute gpg commands within my programme.
...
Let's say I have this :
def a(dict):
locals().update(dict)
print size
def b():
size = 20
f(locals())
What do I have to do to access the size variable directly from the a function? I know of :
size = dict["size"]
but I think there should be a more direct way. I tried using locals().update(dict) but it didn't work. Is ther...
I have some commands which I am running using the subprocess module. I then want to loop over the lines of the output. The documentation says do not do data_stream.stdout.read which I am not but I may be doing something which calls that. I am looping over the output like this:
for line in data_stream.stdout:
#do stuff here
.
...
I currently toying with Python 3.1 and I need a deep update function for dictionaries (a function that willl recursively update child dictionaries that are inside a parent dictionary).
But I think, in the future, my function could have to deal with objects that behave like dictionaries but aren't. And furthermore isinstance and type are...
Simple Question:
list_1 = [ 'asdada', 1, 123131.131, 'blaa adaraerada', 0.000001, 34.12451235265, 'stackoverflow is awesome' ]
I want to create a list_2 such that it only contains the numbers:
list_2 = [ 1, 123131.131, 0.000001, 34.12451235265 ]
Is there simplistic way of doing this, or do I have to resort to checking the variable ...
I am trying to update my Profile info via python-twitter module.
>>> api = twitter.Api(username="username", password="password")
>>> user = api.GetUser(user="username")
>>> user.SetLocation('New Location')
The problem is that it is not getting updated and the documentation is unclear if there's another step I need to do - is there a "...
Hi all. I have a file.
>Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA
ATATTATAGCGCGCGCGCGGATATATATATATATATATATT
>Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG
ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT
>Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG
NOW,I would like to remove the last digit from each of the line that starts with '>'. Fo...
Catching an exception that would print like this:
Traceback (most recent call last):
File "c:/tmp.py", line 1, in <module>
4 / 0
ZeroDivisionError: integer division or modulo by zero
I want to format it into:
ZeroDivisonError, tmp.py, 1
...
I'm trying to parse a CSV file using Python's csv module (specifically, the DictReader class). Is there a Pythonic way to detect empty or missing fields and throw an error?
Here's a sample file using the following headers: NAME, LABEL, VALUE
foo,bar,baz
yes,no
x,y,z
When parsing, I'd like the second line to throw an error since it's...
Hi all. I have a file.
Sequence 1.1.1 ATGCGCGCGATAAGGCGCTA
ATATTATAGCGCGCGCGCGGATATATATATATATATATATT
Sequence 1.2.2 ATATGCGCGCGCGCGCGGCG
ACCCCGCGCGCGCGCGGCGCGATATATATATATATATATATT
Sequence 2.1.1 ATTCGCGCGAGTATAGCGGCG
NOW,I would like to remove the last digit from each of the line that starts with '>'. For example, in thi...
Few times while browsing tests dir in various Django apps I stumbled across models.py and settings.py files (in django-tagging for example).
But there's no code to be found that syncs test models or applies custom test settings - but tests make use of them just as if django would auto-magically load them. However if I try to run django...
Hi guys, i have to parse need string.
Here is command I execute in Linux console:
amixer get Master |grep Mono:
And get, for example,
Mono: Playback 61 [95%] [-3.00dB] [on]
Then i test it from python-console:
import re,os
print re.search( ur"(?<=\[)[0-9]{1,3}", u" Mono: Playback 61 [95%] [-3.00dB] [on]" ).group()[0]
And get re...
I want to remove dots in acronyms but not in domain names in a python string. For example,
I want the string
'a.b.c. [email protected] http://www.test.com'
to become
'abc [email protected] http://www.test.com'
The closest regex I made so far is
re.sub('(?:\s|\A).{1}\.',lambda s: s.group()[0:2], s)
which results to
'ab.c. [email protected]...
I've got a Model in Django, example code below (not my actual code):
class Department(models.Model):
name = models.CharField(max_length=100)
abbreviation = models.CharField(max_length=4)
Let's say I do the following in the Django shell:
>>> Department(name='Computer Science',abbreviation='C S ').save()
>>> Department(name='Ma...