I've been doing quite a bit of simple XML-processing in python and grown to like the ElementTree way of doing things.
Is there something similar and as easy to use in Java? I find the DOM model a bit cumbersome and find myself writing much more code than I would like to do simple things.
Or am I asking the wrong thing?
Maybe my quest...
I want to generate a choicelist for all specs that inherit from imagekit.specs.ImageSpec.
The idea is to allow users of the admin interface to select an ImageSpec to add to a picture.
i.e:
class Display(ImageSpec):
pre_cache = True
increment_count = True
processors = [ResizeDisplay,]
class SingleDisplay(ImageSpec):
pr...
I messed up my IDLE shortcut. What is the way to start IDLE from the cmd.exe shell in Windows?
...
I've been messing around with Python over the weekend and find myself pretty much back at where I started.
I've specifically been having issues with easy_install and nltk giving me errors about not finding packages, etc.
I've tried both Python 2.6 and Python 3.1.
I think part of the problem may be that I'm running windows 7 in 64bi...
I need to extract data from a structure and put it into a list, but I don't know how many levels the structure has.
For each level, I can call level.children(), if there are no levels below the current one, it returns [], if there are, it returns [object, object, ...], on each of which I can call children() on again.
I need to drill do...
I am writing a GUI application using Django 1.1.1.
This is the views.py:
from django.http import HttpResponse
def mainpage(request):
f=open('pages/index.html','r').readlines()
out=''''''
for line in file:
out+=line
print out
return HttpResponse(out)
I am trying to load the contents of index.html which is...
In my source code I have:
import gtk
But when I run the script with python3 script.py command I get the following error. What package should I install to get it working?
Edit: my bad. here is the error:
ImportError: No module named gtk
Edit2:
Thanks for the answer, kaizer.se. But I'm still getting an error message. Take a loo...
Hi, I'm stuck on a simple problem. I've got a dictionary of words in the English language, and a sample text that is to be checked. I've got to check every word in the sample against the dictionary, and the code I'm using is wrong.
for word in checkList: # iterates through every word in the sample
if word not in refDict: # chec...
I'm having trouble getting an environmental variable out of apache config. (don't ask why it's being done this way, I didn't originally code it)
This is what I have in the apache config.
<Location "/var/www">
SetHandler python-program
PythonHandler mod_python.publisher
PythonOption MYSQL_PWD ###########
PythonDebug On
<...
How can I keep help strings in functions to be visible after applying a decorator?
Right now the doc string is (partially) replaced with that of the inner function of the decorator.
def deco(fn):
def x(*args, **kwargs):
return fn(*args, **kwargs)
x.func_doc = fn.func_doc
x.func_name = fn.func_name
return x
@dec...
I'm very new to Python, and am trying to learn in conjunction with using nltk.
I've been following some examples and testing things out, but it seems I am very limited in what I can do due to errors being returned by python.
I know nltk is installed and importing fine, because this code works
from nltk.sem import chat80
print chat8...
I need to send a command to a GIPB instrument and I can do it like this: power.write("volt 0.01").
This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need some sort of loop to do this for me, I ...
I'm using urllib2 to fetch a a page via HTTP. Sometimes the resource throws a HTTP error 400 (Bad Request) when my request contains an error. However, that response also contains an XML element that gives a detailed error message. It would be very handy to be able to see that error rather than just the HTTPError exception returned by ...
Possible Duplicates:
Iterate a list as tuples in python
How do I iterate over the tuples of the items of two or more lists in Python?
I have two iterables in Python and I want to go over them in pairs:
foo = (1,2,3)
bar = (4,5,6)
for (f,b) in some_iterator(foo, bar):
print "f: ", f ,"; b: ", b
should result in:
f: 1; ...
Hello,
Sorry if this is Python 101 but I don't even know what to search for to get the answer. I come from a PHP background and would like to know if there's a way to do this in Python.
In PHP you can kill 2 birds with one stone like this:
Instead of:
if(getData()){
$data = getData();
echo $data;
}
I can do this:
if($data...
I'm playing with bencoding and i would like to keep bencoded strings as java strings but they contain binary data blindly converting them to string will corrupt the data. What i am trying to accomplish is have a conversion function that will keep the ascii bytes as ascii end encode non ascii chars in a reversible way.
I have found some ...
For some reason, siginterrupt() only seems to set the behaviour for the first signal received.
In this example program, the first SIGQUIT appears to do nothing, but the second sigquit prints "SIGQUIT Handler" and s.accept() throws an Interrupted system call exception.
from signal import *
from socket import *
import sys
def sigquitHan...
A friend brought this to my attention, and after I pointed out an oddity, we're both confused.
Python's docs, say, and have said since at least 2.5.1 (haven't checked further back:
Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is ...
I'm wondering if any other C# developers would find it an improvement to have a complier directive for CSC to make whitespace significant ala Haskell or Python where the kinds of whitespace creates code blocks.
While this would certainly be a massive departure from c-style languages, it seems to me that since C# is ultimately being com...
I am looking for a decent file uploader. I'm using django, but while i don't NEED a django file uploader, python is preferable. php would also be fine.
can anyone point me in the direction of a good file uploader which is secure and efficient?
EDIT: I need the server-side handler of file uploads.
...