python

RW - Primary/Secondary DNS Address In Python

I want to read the primary and secondary dns addresses from the system and want to change it to any user given address. Is this possible through some library. An alternative approach is that I read the /etc/resolv.conf and do the changes, which is what I've done. BTW the current solution I have is for Ubuntu OS, and for now if I get ...

related to list and file handling?

I have file with contents in list form such as [1,'ab','fgf','ssd'] [2,'eb','ghf','hhsd'] [3,'ag','rtf','ssfdd'] I want to read that file line by line using f.readline and assign each line to a list. I tried doing this: k=[ ] k=f.readline() print k[1] I expected a result to show 2nd element in the list in first line, but it showe...

Forms generated through admin in Django

I need to be able to create forms from admin panel. Process would look like this: I click on "Add form" then I enter email to which the form should be sent and of course several fields (probably thanks to inlines) consisting of field name, type and if it is required. User should be able to view and fill the form and submit it and the dat...

Maintaining file permissions across SVN updates?

I have a series of python scripts with execute permissions in Linux. They are stored in SVN. If I then run svn up to update them, the overwritten files are back to 644 - ie no execute permissions for anyone. Yes I could just script it to chmod +x * afterwards, but surely there's a way to store permissions in SVN or to maintain them wh...

Strange (atleast for me) behavior in Django template

The following code snippet in a Django template (v 1.1) doesn't work. {{ item.vendors.all.0 }} ==> returns "Test" but the following code snippet, doesn't hide the paragraph! {% ifnotequal item.vendors.all.0 "Test" %} <p class="view_vendor">Vendor(s): {{item.vendors.all.0}} </p><br /> {% endifnotequal %} Any tips on what's wrong...

How do I splice a python string programmatically?

Very simple question, hopefully. So, in Python you can split up strings using indices as follows: >>> a="abcdefg" >>> print a[2:4] cd but how do you do this if the indices are based on variables? E.g. >>> j=2 >>> h=4 >>> print a[j,h] Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: string indices must be i...

Difference between list, sequence and slice in Python?

What are the differences between these built-in Python data types: list, sequence and slice? As I see it, all three essentially represent what C++ and Java call array. ...

Draw and move a point over an image in python

Hi all I have to do a little script in Python. In this script I have a variable (that represents a coordinate) that is continuously updated to a new value. So I have to draw a red point over a image and update the point position every time the variable that contains the coordinate is updated. I tried to explain what I need doing somethi...

Python 2.6 does not like appending to existing archives in zip files

Hello, In some Python unit tests of a program I'm working on we use in-memory zipfiles for end to end tests. In SetUp() we create a simple zip file, but in some tests we want to overwrite some archives. For this we do "zip.writestr(archive_name, zip.read(archive_name) + new_content)". Something like import zipfile from StringIO import ...

Converting human readable date into integer values

Hello all, I am looking to do something really simple. Merely convert a string, such as 'december' into something I can use with MySQL (such as '12'). At the moment I use a dict, month_map = { 'december': '12', 'november': '11', 'october': '10', 'september': '09', 'august': '08', 'july': '07', 'june': '06',...

Is there anything for Python that is like readability.js?

Hi, I'm looking for a package / module / function etc. that is approximately the Python equivalent of Arc90's readability.js http://lab.arc90.com/experiments/readability http://lab.arc90.com/experiments/readability/js/readability.js so that I can give it some input.html and the result is cleaned up version of that html page's "main t...

How to prevent lxml prom compacting elements?

Having following Python code: >>> from lxml import etree >>> root = etree.XML("<a><b></b></a>") >>> etree.tostring(root) '<a><b/></a>' How can I force lxml to use "long" version? Like >>> etree.tostring(root) '<a><b></b></a>' ...

Program structure in long running data processing python script

For my current job I am writing some long-running (think hours to days) scripts that do CPU intensive data-processing. The program flow is very simple - it proceeds into the main loop, completes the main loop, saves output and terminates: The basic structure of my programs tends to be like so: <import statements> <constant declaration...

Django context processor gets AnonymousUser

instead of User. def myview(request): return render_to_response('tmpl.html', {'user': User.objects.get(id=1}) works fine and passes User to template. But def myview(request): return render_to_response('tmpl.html', {}, context_instance=RequestContext(request)) with a context processor def user(request): from djang...

mySQL Trigger works after console insert, but not after script insert.

Hello, I have a strange wird problem with a trigger: I set up a trigger for update other tables after an insert in a table. If i make an insert from mysql console, all works fine, but if i do inserts from external python script, trigger does nothing, as you can see bellow. When i insert from console, works fine, but insert THE SAME D...

standard geographic tilizing/binning method?

I'm trying to learn and understand more about mapping and displaying values on a map. (GIS) At the moment I'M looking to take some values and apply those values to a tile or bin on a map. Ideally I'd like the tile sizes to be uniform, like 100 meters, 500 meters, etc. Is there a standard method for creating uniform tile sizes? Or Are ...

Fast matrix transposition in Python

Is there any fast method to make a transposition of a rectangular 2D matrix in Python (non-involving any library import).? Say, if I have an array X=[[1,2,3], [4,5,6]] I need an array Y which should be a transposed version of X, so Y=[[1,4],[2,5],[3,6]]. ...

Include a text file *as is* in (Python) Sphinx Docs

(using Python-Sphinx Documentation tool) I have a .txt log file I'd like to build into _build/html unaltered. What do I need to alter in conf.py, index.rst, etc. Here is the layout: src/ index.rst some_doc.rst somefile.txt How do I get somefile.txt into the html build? I tried adding a line like this to index.rst: Con...

Help Replacing Non-ASCII character in Python

I have a bunch of HTML files I downloaded using HTTPLIB2 package in Python. ' ' are showing as 'Â '. <font color="#ff0000">02/12/2004Â </font> is showing while <font color="#ff0000">02/12/2004&nbsp;</font> is the desired format. How do I replace the 'Â ' with '&nbsp;' in Python? Thanks a lot! ...

Python: Once and for all. What does the Star operator mean in Python?

Possible Duplicate: What does *args and **kwargs mean? What does the * operator mean in Python, such as in code like zip(*x) or f(**k)? How does it work internally in the interpretor? Is it fast or not? When is it useful and when is it not? Should it be used in a function declaration or in a call? ...