python

Multiple tag names in lxml's iterparse?

Is there a way to get multiple tag names from lxml's lxml.etree.iterparse? I have a file-like object with an expensive read operation and many tags, so getting all tags or doing two passes is suboptimal. Edit: It would be something like Beautiful Soup's find(['tag-1', 'tag-2]), except as an argument to iterparse. Imagine parsing an HTML...

Python ~ accessing tuple members in template class

I am new to Python - be forewarned! I have a template class that takes a list as an argument and applies the members of the list to the template. Here's the first class: class ListTemplate: def __init__(self, input_list=[]): self.input_list = input_list def __str__(self): return "\n".join([self._template % x f...

how to control LabView VI front panel switches (on/off, bar adjuster) using Python cripts ?

I have a front LabView front panel controlling switches and sensor voltage adjustors to the hardware and need to control these with Python script. I do not have much knowledge of LabView. Please explain how this could be done. Thanks in advance for your help ! ...

Why the second time I run "readlines" in Python in the same file nothing is returned?

>>> f = open('/tmp/version.txt', 'r') >>> f <open file '/tmp/version.txt', mode 'r' at 0xb788e2e0> >>> f.readlines() ['2.3.4\n'] >>> f.readlines() [] >>> I've tried this in Python's interpreter. Why does this happen? ...

Substring Comparison in python

If i have List PhoneDirectory Eg: ['John:009878788677' , 'Jefrey:67654654645' , 'Maria:8787677766'] Which is the function that can be use to compare the Presence of Substring (Eg: Joh) in each entry in the List . I have tried using if(PhoneDirectory.find(Joh) != -1) but it doesnt work kindly Help.. ...

Simplifying complex class heirarchy

With the goal of maximizing code reuse, I have created a rather complex class hierarchy for my Python code. It goes something like this: class ElectionMethod class IterativeMethod class SNTV ... class NonIterativeMethod class OrderDependent class CambridgeSTV ... class Ord...

mod_python with multiple django projects

I tried to configure my django project on a shared hosting (which supports mod_python). Following the procedures, i did make it with their proposed folder structure in the end: [folder structure] /.. /MYAPP /public_html .htaccess in .htaccess PythonPath "['/home/MYACCOUNT/' ] + sys.path" SetHandler python-program Py...

Creation of simple CRUD website using Python which framework?

I need to create a simple python website showing customer by salesman and sales by customer. No update of data at all at this time. Which framework might be best. I am not a web guru by any means can read HTML, and Understand CSS. Data is in MySQL. This is a quick and dirty. Thanks ...

Does this regex mean it has to start with A, end with Z? re.search "\A[0-9A-Za-z_-]+\Z"

Does this regex mean it has to start with A, end with Z? re.search("\A[0-9A-Za-z_-]+\Z", sometext) ...

Problems matching caret in Python regex

I have the following regular expression, which I think should match any character that is not alphanumeric, '!', '?', or '.' re.compile('[^A-z ?!.]') However, I get the following weird result in iPython: In [21]: re.sub(a, ' ', 'Hey !$%^&*.#$%^&.') Out[21]: 'Hey ! ^ . ^ .' The result is the same when I escape the '.' in the reg...

wxPython: switching text control focus on tab press

I made a frame that asks the user to put in a bunch of information in several text control fields. How can I make it so that when you hit the 'tab' key your cursor moves to the next text control? ...

In python, looking for an alternative to Shelve (too slow for large dictionaries).

I am storing a table using python, and I need persistance. Essentially I am storing the table as a dictionary string to numbers. And the whole is stored with shelve self.DB=shelve.open("%s%sMoleculeLibrary.shelve"%(directory,os.sep),writeback=True) I use writeback to true as I found the system tend to be unstable if I don't. So aft...

Python - Threaded program seems to have a Memory Leak?

I am writing a python program that seems to be leaking memory. The program takes in a list of URL's and makes sure their status code is 200. If the status code is not 200, then the script will alert me via email. The script threaded so the URL's can be checked in parallel of each other. I have set the program on a one of our server...

Python sum, why not strings?

Python has a built in function sum, which is effectively equivalent to: def sum(iterable, start): return start + reduce(operator.add, iterable) for all types of parameters except strings. It works for numbers and lists, for example. Why were strings specially left out? I seem to remember discussions in the Python list for the re...

How do I ensure data integrity for objects in google app engine without using key names?

Hi- I'm having a bit of trouble in Google App Engine ensuring that my data is correct when using an ancestor relationship without key names. Let me explain a little more: I've got a parent entity category, and I want to create a child entity item. I'd like to create a function that takes a category name and item name, and creates both ...

Python, creating a new variable from a dictionary? not as straightforward as it seems?

I'm trying to create a new variable that will consist of an existing dictionary so that I can change things in this new dictionary without it affecting the old one. When I try this below, which I think would be the obvious way to do this, it still seems to edit my original dictionary when I make edits to the new one.. I have been searchi...

passing R function arguments in rpy

I have the following two lines of code that both run fine in both R and Python (via Rpy): [R] rcut = cut(vector, brks) [Python] rcut = r.cut(vector, brks) However, if I want to add the argument of include.lowest=TRUE, it runs as expected in R: [R] rcut = cut(vector, brks, include.lowest=TRUE) But it doesn't work in Rpy: [Python] r...

String Catenation in Python

I have this code: filenames=["file1","FILE2","file3","fiLe4"] def alignfilenames(): #build a string that can be used to add labels to the R variables. #format goal: suffixes=c(".fileA",".fileB") filestring='suffixes=c(".' for filename in filenames: filestring=filestring+str(filename)+'",".' print filestrin...

How to deploy a Python/SQLAlchemy application?

Dear all: SQLAlchemy allowed me to create a powerful database utility. Now I don't know how to deploy it. Let me explain how is it built with an example: # objects.py class Item(object): def __init__(self, name): self.name = name # schema.py from sqlalchemy import * from objects import Item engine=create_engine('sqlite:///mydb.db')...

py2app: how to include modules that will be loaded by __import__ ?

I have a Python application that loads python modules dynamically at run time (using __import__). The modules to load are in a package called 'plugins' (i.e. subfolder called plugins with __init__.py etc). All works fine running from the python interpreter, and even when compiled to a windows binary using py2exe. I tried building a OSX ...