python

lxml removing <?xml ...> tags when parsing?

I'm currently working with parsing XML documents (adding elements, adding attributes, etc). So I first need to parse the XML in before working on it. However, lxml seems to be removing the element <?xml ...>. For example from lxml import etree tree = etree.fromstring('<?xml version="1.0" encoding="utf-8"?><dmodule>test</dmodule>', etr...

How do I convert a padded string to an integer while preserving padding?

I followed the great example at Python: Nicest way to pad zeroes to string (4) but now I need to turn that padded string to a padded integer. I tried: list_padded=['0001101', '1100101', '0011011', '0011011', '1101111', '0000001', '1110111', 1101111', '0111001', '0011011', '0011001'] # My padded sting list. int_l...

multiple instances of django on a single domain

Hi all, I'm looking for a good way to install multiple completely different Django projects on the same server using only a single domain name. The point is that I want to browse to something like: http://192.168.0.1/gallery/ # a Django photo gallery project http://192.168.0.1/blog/ # a blogging project This way, I can deve...

Python variable assignment confusion

Why is it that when I do the following: x = y = {} Everytime I modify, x like x[1] = 5, I also end up modifying y and vice versa? ...

How to stop SIGINT being passed to subprocess in python?

My python script intercepts the SIGINT signal with the signal process module to prevent premature exit, but this signal is passed to a subprocess that I open with Popen. is there some way to prevent passing this signal to the subprocess so that it also is not exited prematurely when the user presses ctrl-c? ...

Adding attributes to existing elements, removing elements, etc with lxml

I parse in the XML using from lxml import etree tree = etree.parse('test.xml', etree.XMLParser()) Now I want to work on the parsed XML. I'm having trouble removing elements with namespaces or just elements in general such as <rdf:description><dc:title>Example</dc:title></rdf:description> and I want to remove that entire element as...

Assist with Python script

Hi everybody, I have written a code in Python, and I want to change it. I use it when I am performing a penetration tests in my organization and I want to make my script better. The script gets a username that I entering and it connect to the SMTP server over port 25 and check if the user exists or not. Here is the script: #!/usr/bin/py...

How do I search from the bottom up using a regular expression?

Here is an example of the type of text file I am trying to search (named usefile): DOCK onomatopoeia DOCK blah blah blah DOCK blah DOCK blah blah blah onomatopoeia blah blah blah blah blah DOCK DOCK blah blah DOCK blah onomatopoeia I am using a finditer statement to find everything between DOCK and onomatopoeia as follows: re.finditer...

I want to limit how often a Tkinter callback is run

I'm writing my first GUI program with Tkinter (first program in Python too, actually). I have an Entry widget for searching, and the results go to a Listbox. I want the results to update as the user types, so I made a callback like this: search_field.bind("<KeyRelease>", update_results) The problem is that updates the search many tim...

App Engine Unique Non Numeric Code

Using an alphabet like "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" I'd like to generate 2 to 4 letter codes to identify unique datastore entries. I have a python function capable of doing this when passed an list indicating the letter positions of the last code [7,17,11] -> "7GA". the next code can be made by incrementing that right most elem...

Update value of a nested dictionary of varying depth

Hi all, I'm looking for a way to update dict dictionary1 with the contents of dict update wihout overwriting levelA dictionary1={'level1':{'level2':{'levelA':0,'levelB':1}}} update={'level1':{'level2':{'levelB':10}}} dictionary1.update(update) print dictionary1 {'level1': {'level2': {'levelB': 10}}} I know that update deletes the val...

In Python M2Crypto I cannot set the socket timeout over 30 seconds

I have tried from M2Crypto import SSL handle = url_opener.open(theurl, urllib.urlencode(data), SSL.timeout(120)) also c = SSL.Connection(ctx) c.set_socket_read_timeout(SSL.timeout(120)) also SSL.Connection.set_socket_read_timeout(c, SSL.timeout(120)) I can set the timeout less than 30 seconds but not more than 30 seconds. ...

Python: Removing spaces from list objects

I have a list of objects appended from a mysql database and contain spaces. I wish to remove the spaces such as below, but the code im using doesnt work? hello = ['999 ',' 666 '] k = [] for i in hello: str(i).replace(' ','') k.append(i) print k ...

Python: dynamic list parsing and processing

I have popened a process which is producing a list of dictionaries, something like: [{'foo': '1'},{'bar':2},...] The list takes a long time to create and could be many gigabytes, so I don't want to reconstitute it in memory and then iterate over it. How can I parse the partially completed list such that I can process each dictionary ...

view other computers on the network programatically in Python

Is it possible to view other devices that are on the same network in Python (or any programming language for that matter)? Edit: For clarification, what I'd like to do (just to start out) is to display a list of devices connected and their local IP addresses. So on my router, it'll show the info: family_pc, 192.168.1.2 work_laptop, 192...

Guide to install xampp with zope-plone on the same linux machine?

Is there a good step by step online guide to install xampp (apache server,mysql server) together with zope-plone on the same linux machine and make it play nicely or do I have to go through their confusing documentations? Or how can I install this configuration in the best way? I can install and use both seperately but in tandem is an is...

SOAP Client for Python 3

Dear Python programmers, Although this question is very popular here in StackOverflow, after spending some time here and in the Google, I still haven't find a concrete answer on what is the most appropriate way to do SOAP consuming in Python 3. I took a look at http://stackoverflow.com/questions/1534554/does-a-python-3-soap-client-mod...

Add a todo list item in SPE (Stani's Python Editor)

How do I add a todo list item in Stani's Python Editor? I think it's something you type in together with the code and it automatically shows up the the todo list panel. However, I do not know the syntax. ...

How to get accurate window information (dimensions, etc.) in Linux (X)?

How can I get accurate window information in Linux? I know that I can use wmctrl to get a window's size, but the actual size of the window can vary due to window decorations. I need the following information and methods: precise window dimensions precise available screen space (excluding panels like gnome-panel) the ability to set a wi...

How can I get the installed GDAL/OGR version from python?

How can I get the installed GDAL/OGR version from python? I aware of the gdal-config program and are currently using the following: In [3]: import commands In [4]: commands.getoutput('gdal-config --version') Out[4]: '1.7.2' However, I suspect there is a way to do this using the python API itself. Any dice? ...