Hello,
I'm working my way through some code examples and I stumbled upon this:
endings = ['st', 'nd', 'rd'] + 17 * ['th'] + ['st', 'nd', 'rd'] + 7 * ['th']
+ ['st']
I understand that for numbers after 4 and until 20 they end in 'th' and I can see that we are adding 17 more items to the list, and I understand that '17 * ['th'] is addi...
Hello, I am developing a Math application which can be extended by writing python scripts.
I am using QT 4.6.3 (build as static library, debug and release versions) and Boost 1.43.0 (build as static library, runtime-link also set to static, multi-threaded version, debug and release). Everything is build with MSVC++2008. The boost build ...
I'm trying to calculate the coefficient of determination (R^2) in Python, but I'm getting a negative value in certain cases. Is this a sign that there's an error in my calculation? I thought R^2 should be bounded between 0 and 1.
Here's my Python code for doing the calculation, adapted straight from the WP article:
>>> yi_list = [1, 1,...
I'm working on a web app (using Python & Bottle) and building a decorator for validating HTTP parameters sent in GET or POST. The early version takes callables, so this:
@params(user_id=int, user_name=unicode)
... ensures that user_id is an int, user_name is a string, and both fields exist.
But that's not enough. I want to be able to ...
This is a apache/mod_wsgi/virtualenv/django stack. In the virtualenv site-packages dir I've got a virtualenv_path_extensions.pth file. The apache conf has a
WSGIScriptAlias / /path/to/my.wsgi
my.wsgi has
site.addsitedir('/path/to/virtualenv/site-packages')
Now, if I start up a python shell, import site, and call the line above, my ...
I'm playing with twitter statuses rss feed on Google AppEngine (in python). I perform a urlfetch and I systematically get a
DownloadError: ApplicationError: 5
when I deploy the app whereas everything is fine when I test it locally on my dev server.
I guess it's a timeout issue due to AppEngine limitations. I already extended urlfetc...
I am using SWIG to create a Python wrapper around a piece of C++ code which returns an object like this:
TH1F*GetHist();
(The class TH1F has not been written by me.)
Now under Python this results in an
<Swig Object of type 'TH1F *' at 0x12da820>
My problem is that I would like to use methods of this object which SWIG does not know ...
Hi,
I have written a Ruby gem named 'this'. Get it here http://rubygems.org/gems/this. Purpose of 'this' is to show quotes of 'The Zen of Ruby' whenever you "require 'this'". As I could not find any equivalent zen quotes for Ruby, currently I am using 'The Zen of Python' (PEP 20). Extremely sorry for using it :)
Can you guys suggest me...
I am interested in taking an arbitrary dict and copying it into a new dict, mutating it along the way.
One mutation I would like to do is swap keys and value. Unfortunately, some values are dicts in their own right. However, this generates a "unhashable type: 'dict'" error. I don't really mind just stringifying the value and giving it t...
Hi,
I have a database where one field gives spatial coordinates. I have learned the field is a serialised MSDN geometry Data Type (http://msdn.microsoft.com/en-us/library/bb933973.aspx).
I want to access this database from Python and was wandering if anyone knew the format of the Geometry Data Type, or any libraries capable of parsing ...
I am plotting some weather data for a research project. The plot consists of 18 timesteps. I decided the best way to accomplish this was to make a new plot for each timestep, save it a file, and create a new plot for the next timestep (using a for loop).
For example:
map_init #[Basemap Instance]
extra_shapes #[Basemap.readshapefil...
I am trying to use Tarek Ziadé's Trac buildout recipe from PyPi (and his book 'Expert Python Programming', which I don't have access to.)
It worked fine the first time round, however upon creating a new (Python 2.6 virtualenv) environment I got the following error on buildout.
File "/usr/local/Plone/buildout-cache/eggs/pbp.recipe.trac-...
Is it feasible to store data for a web application inside the program itself, e.g. as a large dictionary? The data would mostly be just a few hundred short-ish text blocks (roughly blog post size), and it will not be altered/added to at all by the users (although I would want to be able to update it myself every so often).
Up until now...
I've got a file, constants.py, that contains a bunch of global constants. Is there a way I can grab all of them as dict, for just this file?
...
So I have a file that looks like so:
#!/usr/bin/python
import MySQLdb
import subprocess
from subprocess import call
import re
conx = MySQLdb.connect (user = 'root', passwd = '******', db = 'vaxijen_antigens')
cursor = conx.cursor()
cursor.execute('select * from sequence')
row = cursor.fetchall()
f = open('/home/rv/ncbi-blast-2.2.23+/d...
I have an issue where I need to pass in query parameters for a GET request, but Django is not resolving the URL correctly to the view.
My urls.py looks like this:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(r'^confirm_cancel',
'myapp.views.confirm_cancel_method',
name='myapp...
Seems like it should be simple enough but it's driving me up the wall. I've looked at the python date formatting strings and it still doesn't make too much sense.
Here's what I'm trying to do: <Full day>, <Day of month><Ordinal> <Month>
Where <Ordinal> is st, nd, rd, th, etc depending on the day.
...
Hi, I'm writing a script to generate a CSR in Python. The script is very simple. I generate an RSA private key by using the following:
keycmd = "openssl genrsa -out mykey.pem 2048"
keyprocess = Popen(keycmd, shell=True, stdout=PIPE)
csrcmd = "openssl req -new -key mykey.pem -subj "+ subj + " -out mycsr.csr"
reqprocess = Popen(csrcmd, s...
Hi,
I'm newbie with python. I want to write a class with two keys as indexer. also need to be able to use them inside of class like this:
a = Cartesian(-10,-10,10,10) # Cartesian is the name of my class
a[-5][-1]=10
and in the Cartesian class:
def fill(self,value):
self[x][y] = x*y-value
I try with
def __getitem__(self,x,y):
...
In order to keep my code clean and organized, I split my classes up into a bunch of different files and folders, here is what a typical project structure will look like for me:
> Project
__init__.py
main.py
ui.py
> lib
foo.py
bar.py
In my ui.py file, I usually define some sort of info function if the ap...