python

Python library to validate Excel data

Is there any existing Python library that can validate data in Excel format? Or what kind of keyword should I use to search such an open source project? Thanks. ...

Nested WHILE loops in Python

I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact). IDLE 2.6.4 >>> a=0 >>> b=0 >>> while a < 4: a=a+1 while b < 4: b=b+1 print a, b 1 1 1 2 1 3 1 4 I am expecting the outer loop to loop through 1,2,3 and 4. And I kno...

Joining links together in a dictionary

Hi guys, I'm student here, new to python and programming in general. I have a dictionary links which holds a tuple mapped to a number. How can I join the second url in the second tuple together with the urljoin() function? What I'm trying to do is get complete links so I can run a recursive function search() which takes a complete url a...

Python optimization problem?

Alright, i had this homework recently (don't worry, i've already done it, but in c++) but I got curious how i could do it in python. The problem is about 2 light sources that emit light. I won't get into details tho. Here's the code (that I've managed to optimize a bit in the latter part): import math, array import numpy as np from PIL...

Call function in views.py from command line (django)

Hi, I'm trying to run a function defined in the views file of my django app, from the command line. Is there a way to do this? I understand view functions are supposed to be called from a request but I need this function to be called from a cron eventually. Thanks ...

have to invoke (Thread.__init__) in my overridden constructor, but why?

i saw this phrase in python 2.6 man: class threading.Thread(group=None, target=None, name=None, args=(), kwargs={}) . . . If the subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread. i just wanna know why? ...

something like a python's triple-quote in F# (or C#)?

I want to assign a xml code into a string variable. I can do this without escaping single or double-quotes by using triple-quote in python. Is there a similar way to do this in F# or C#? ...

How does git fetches commits associated to a file ?

I'm writing a simple parser of .git/* files. I covered almost everything, like objects, refs, pack files etc. But I have a problem. Let's say I have a big 300M repository (in a pack file) and I want to find out all the commits which changed /some/deep/inside/file file. What I'm doing now is: fetching last commit finding a file in it by...

Mako templates inline if statement

I have a template variable, c.is_friend, that I would like to use to determine whether or not a class is applied. For example: if c.is_friend is True <a href="#" class="friend">link</a> if c.is_friend is False <a href="#">link</a> Is there some way to do this inline, like: <a href="#" ${if c.is_friend is True}class="friend"{/if}>li...

how to encode a url with urllib or urllib2

I want a url like example.com/page.html to somthing like example.com/a$xDzf9D84qGBOeXkXNstw%3D%3D106 ...

How to display multiple images?

I'm trying to get multiple image paths from my database in order to display them, but it currently doesn't work. Here's what i'm using: def get_image(self, userid, id): image = meta.Session.query(Image).filter_by(userid=userid) permanent_file = open(image[id].image_path, 'rb') if not os.path.exists(image.image_path): ...

Compound dictionary keys

I have a particular case where using compound dictionary keys would make a task easier. I have a working solution, but feel it is inelegant. How would you do it? context = { 'database': { 'port': 9990, 'users': ['number2', 'dr_evil'] }, 'admins': ['[email protected]', '[email protected]'], 'domain....

making errorbars not clipped in matplotlib with Python

I am using matplotlib in Python to plot a line with errorbars as follows: plt.errorbar(xvalues, up_densities, yerr=ctl_sds, fmt='-^', lw=1.2, markersize=markersize, markeredgecolor=up_color, color=up_color, label="My label", clip_on=False) plt.xticks(xvalues) I set the ticks on the x-axis using "xticks". However, the error b...

RDF/XML format to JSON

I am trying to convert the RDF/XML format to JSON format. Is there any python (library) example that i can look into for this to do ? ...

how to enable a method in tamplate of google-app-engine..

the mothed is : def printa(x): return x the reponse is : self.response.out.write(template.render(path, {'printa':printa})) the html is : {{ printa 'sss'}} i want to show 'sss' in my page , so how to do this , thanks updated i create a templatetags folder, and 2 py file: templatetags |--------__init__.py |---...

How can I tell Phusion Passenger which python to use?

I'm using Phusion Passenger with a ruby app and I'd also like to set it up to work with an django appengine app I'm working on. Googling for "passenger_wsgi.py" I was able to get the following very simple non-django app working on passenger: passenger_wsgi.py: def application(environ, start_response): response_headers = [('Content-...

Error while installing dependencies for PyGTK on Mac OS 10.6.3

I tried to install the following dependencies for PyGTK 2.16.0 (the Python GIMP Tool Kit) on Mac OS 10.6.3: glib 2.25.5 gettext-0.18 libiconv-1.13.1 When I tried to install glib, I got the following error message: gconvert.c:55:2: error: #error GNU libiconv not in use but included iconv.h is from libiconv The libiconv web page tal...

Python: undefined reference to `_imp __Py_InitModule4'

I'm trying to do a debug build of the Rabbyt library using mingw's gcc to run with my MSVC built python26_d.. I got a lot of undefined references which caused me to create libpython26_d.a, however one of the undefined references remains. Googling gives me: http://www.techlists.org/archives/programming/pythonlist/2003-03/msg01035.shtml ...

how to make my method running on the template of google-app-engine..

the model is : class someModel(db.Model): name = db.StringProperty() def name_is_sss(self): return self.name=='sss' the view is : a=someModel() a.name='sss' path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'blog/a.html')) self.response.out.write(template.render(path, {'a':a})) ...

Is it possible to craft your own packets with python?

Well, I know its possible, using external libraries and modules such as scapy. But how about without external modules? Without running the script as root? No external dependencies? I've been doing a lot of googling, but haven't found much help. I'd like to be able to create my own packets, but without running as root, or installing extr...