python

How do I use a Django custom template tag in a template?

I’ve written a custom template tag: def mytag(para): return something In my template I am getting a value {{value}}. Now I am using {{value|mytag}} to apply the tag to the value, and it is throwing a syntax error. ...

weird problem with urllib2.proxyhandler in python 2.5

in windows XP, python 2.5 and 2.6 I tested the following code: import urllib2 proxy= urllib2.ProxyHandler({'http': '127.0.0.1:8080'}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) urllib2.urlopen('http://www.google.com/') I have a proxy running at 127.0.0.1:8080 which works (I can use it in proxyswitchy and can s...

how to compare two arrays in python?

How to compare two arrays in python? date = "Thu Sep 16 13:14:15 CDT 2010" sdate = "Thu Sep 16 14:14:15 CDT 2010" dateArr = [] dateArr = date.split() sdateArr = [] sdateArr = sdate.split() Now I want to compare these two array I guess split returns array. We can do simple comparision in Java like dateArr[i] == sdateArr[i] but how ...

What's the recommended way to return a boolean for a collection being non-empty in python ?

I came across the question Python: What is the best way to check if a list is empty? on SO. Now if I wanted to return a True (False) depending on whether a collection coll is non-empty (empty) from a function, what's the recommended way of doing this ? return not not coll ? ...

Django: What is `sys.path` supposed to be?

When developing a Django application, what is sys.path supposed to contain? The directory which contains the project, or the directory of the project, or both? ...

Get Active Directory group members using PyWin32

Hello, I need to list all Active Directory group's members - can I do this without using LDAP queries with PyWin's win32security, for instance? I can lookup accounts' sids and names using it (LookupAccountSid and LookupAccountName), but how about getting all group members? For now I cannot figure out what functions I should use. I ...

Problems for parse POST json message Django/GAE

When I send a POST message to the GAE with a json parameters using POST the QueryDict parsed by the server is not parsed like a json ... I found a similar problem in this issue: http://stackoverflow.com/questions/2579235/iphone-json-post-request-to-django-server-creates-querydict-within-querydict Maybe is a problem with the GAE configu...

specify dtype of each object in a python numpy array

This is a similar question using dtypes in a list The following snippet creates a "typical test array", the purpose of this array is to test an assortment of things in my program. Is there a way or is it even possible to change the type of elements in an array? import numpy as np import random from random import uniform, randrange, c...

Printing Attribute Values in python-amara

Hi, I'm trying to parse an xml file with using python-amara. doc = amara.parse('h.xml') assert doc.xml_type == tree.entity.xml_type m = doc.xml_children[0] print m When I do this it gives amara.tree.element at 0x94c864c: name u'HOP', 0 namespaces, 0 attributes, 93 children However when I try this : print doc.HOP.A.D it says...

BeautifulSoup or regex HTML table to data structure?

Hi, I've got an HTML table that I'm trying to parse the information from. However, some of the tables span multiple rows/columns, so what I would like to do is use something like BeautifulSoup to parse the table into some type of Python structure. I'm thinking of just using a list of lists so I would turn something like <tr> <td>1,1</...

Is there a good tutorial on setting up the Augustus PMML scoring engine as a web service?

I know it is possible, but the provided documentation here: http://code.google.com/p/augustus/ is thin. The documentation for setting up the web service states: "Configuring the Augustus PMML consumer is covered in great detail elsewhere so we will limit our discussion to what is needed to get the consumer to accept data via HTTP, ...

[python] xldate_as_tuple

im not quite sure how to use the following function: xldate_as_tuple for the following data xldate:39274.0 xldate:39839.0 could someone please give me an example on usage of the function for the data? ...

Python USSD via com port

Hello all, I am new to python. Is there anyway i can use python to send ussd with a phone via at+cusd commands. i can do that using hyperterminal. i want to automate using python. thanks. ...

Sorting while preserving order in python

What is the best way to sort a list of floats by their value, whiles still keeping record of the initial order. I.e. sorting a: a=[2.3, 1.23, 3.4, 0.4] returns something like a_sorted = [0.4, 1.23, 2.3, 3.4] a_order = [4, 2, 1, 3] If you catch my drift. ...

python: multiple inheritance and __add__() in base class

I've got a base class where I want to handle __add__() and want to support when __add__ing two subclass instances - that is have the methods of both subclasses in the resulting instance. import copy class Base(dict): def __init__(self, **data): self.update(data) def __add__(self, other): result = copy.deepcopy(...

python re: r'\b \$ \d+ \b' won't match 'aug 12, 2010 abc $123'

Hi, so i'm just making a script to collect $ values from a transaction log type file for line in sys.stdin: match = re.match( r'\b \$ (\d+) \b', line) if match is not None: for value in match.groups(): print value right now I'm just trying to print those values it would match a line containing $...

Using Python in Netbeans

Hi, I have x64 Windows XP machine. I use Netbeans to code Java. I am now trying to use it for Python, but I get this error: \NetBeans was unexpected at this time. Any idea how to fix it? ...

nosetest deprecation warnings

I am getting deprecation warnings from nosetest for 3rd party modules imported by my code. Does anybody know how to silence these warnings? I know of the following flag which works for arbitrary python runs of the same code: python -W ignore::DeprecationWarning But, calling nosetest does not appear to offer me a similar flag to...

Testing email sending - Django

Hi folks, any tips on testing email sending? Other than maybe creating a gmail account, especially for receiving those emails? I would like to maybe store the emails locally, within a folder as they are sent. Tips would be great! Thanks :) ...

How to quickly fail a python script if it is called from wrong interpreter?

I have inherited a few Python scripts from someone who has left my employer. Some are meant to be run from Jython, others are not. I'd like to add them to svn, but before I do I want to modify these files so that if a "requires Jython" file is run from python, the user gets a message like "please run with Jython" and the program exits....