python

How to sort all possible words out of a string?

Howdy! I'm wondering how to proceed with this task, take this string for example "thingsandstuff". How could I generate all possible strings out of this string as to look them up individually against an english dictionary? The goal is to find valid english words in a string that does not contain space. Thanks ...

HTTP Download very Big File

I'm working at a web application in Python/Twisted. I want the user to be able to download a very big file (> 100 Mb). I don't want to load all the file in memory (of the server), of course. server side I have this idea: ... request.setHeader('Content-Type', 'text/plain') fp = open(fileName, 'rb') try: r = None while r != '': ...

newbie question: why are python strings and tuples are made immutable?

a newbie question. i am not sure why strings and tuples were made to be immutable; what are the advantages and disadvantage of making them immutable? please be gentle as it is a newbie question ;-) thanks & wish you a good day!! ...

can't import gdal in python?

Hi, I have gdal installed and running on Ubuntu Jaunty but I can't run gdal2tiles because I get the error: Traceback (most recent call last): File "/usr/local/bin/gdal2tiles.py", line 42, in <module> import gdal ImportError: No module named gdal When I open python and type import gdal I get the same error. I've set LD_LIBRARY...

Is this single underscore a built-in variable in Python?

I don't understand what this single underscore means. Is it a magic variable? I can't see it in locals() and globals(). >>> 'abc' 'abc' >>> len(_) 3 >>> ...

Caesar's Cipher using python, could use a little help.

I'm trying to make a "Caesar's Cipher" while using python..this is what I have so far. Could anyone tell me how this is looking? Am I going in the right direction? What am I missing? When I run the program to say for example (josh is cool) I don't get the cipher on the same line. It looks like this when I do main(3) m r v k l v f r r o ...

Perform an action and redirecting to the same URL doesn't refresh the page

We are working on a new web site using Apache, Python and Django. In the development phase, no problem but once binding to Apache, using Firefox 3.5.3, we got a strange problem. We stand on : http://website.fr/search/ When we want to change the ordering of the research, we are sending the user to : http://website.fr/search/order/pri...

Using Python's xml.dom.minidom

I'm trying to use Python's xml.dom.minidom, and I'm getting the following error: >>> from xml.dom import minidom >>> xdocument = minidom.Document() >>> xrss = minidom.Element("rss") >>> xdocument.appendChild(xrss) <DOM Element: rss at 0xc1d0f8> >>> xchannel = minidom.Element("channel") >>> xrss.appendChild(xchannel) Traceback (most rece...

Weird behaviour with two Trac instances under Apache + mod_wsgi

I am trying to configure two Trac instances in order to access them via browser each one with a different url: http://trac.domain.com/trac1 http://trac.domain.com/trac2 First time I access them Apache response is fine, I get the first Trac with /trac1, then the second one in /trac2. But when I access /trac1 again, it keeps giving me t...

Python client library for WebDAV

I'd like to implement a piece of functionality in my application that uploads and manipulates files on a WebDAV server. I'm looking for a mature Python library that would give an interface similar to the os.* modules for working with the remote files. Googling has turned up a smattering of options for WebDAV in Python, but I'd like to kn...

Django Reuseable Apps

I came across many resources about the difference between Django projects and reusable apps, most prominently the DjangoCon talk, and Pinax Project. However, being a newbie, writing my own projects and reusable software seems to a bit challenging. I don't quite understand how where models go (and how apps can be flexible and permissive...

Changing document's attributes in Python's xml.dom.minidom

I created a xml.dom.minidom.Document. How do I give it attributes so that when I do .toprettyxml() it will show like this: <?xml version="1.0" encoding="iso-8859-2"?> ...

Determine which button was pressed with tkinter in Python?

I'm making a simple little utility while learning Python. It dynamically generates a list of buttons: for method in methods: button = Button(self.methodFrame, text=method, command=self.populateMethod) button.pack({'fill': 'x', 'expand': 1, 'padx': 5, 'pady': 3}) That part works fine. However, I need to know which of the butt...

Python HTTP server with XML-RPC

I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port. I think it should be possible to modify the CGIXMLRPCRequestHandler...

Python: Replace values in list

Hello Stack Overflow Community, I have a list where I want to replace values with None where condition() returns True. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] For example, if condition checks bool(item%2) should return: [None, 1, None, 3, None, 5, None, 7, None, 9, None] What is the most efficient way to do this? ...

How to print the function name as a string in Python.

def applejuice(q): print THE FUNCTION NAME! It should result in "applejuice" as a string. ...

Can Python be used for client side web development?

If yes are there any frameworks/Tutorials/tips/etc recommended? N00b at Python but I have tons of PHP experience and wanted to expand my skill set. I know Python is great at server side execution, just wanted to know about client side as well. ...

Why isn't getopt working if sys.argv is passed fully?

If I'm using this with getopt: import getopt import sys opts,args = getopt.getopt(sys.argv,"a:bc") print opts print args opts will be empty. No tuples will be created. If however, I'll use sys.argv[1:], everything works as expected. I don't understand why that is. Anyone care to explain? ...

Recurrence sequence in Java / Python / Mathematica

How can you write the following statement in the given languages? a(0) = 1 a_(n+1) = 1 - 1 / ( a_n + 3) I need to find the smallest value of n when a_n -> 0.732050.... My attempt in Mathematica a[(x+1)_] = 1 - 1/(a[x_] + 3) The problem is apparently in this a[(x+1)_]. However, I do not know how to do it iteratively in Mathematica....

Java Equivalent to Python Dictionaries

I am a long time user of Python and really like the way that the dictionaries are used. They are very intuitive and easy to use. Is there a good Java equivalent to python's dictionaries? I have heard of people using hashmaps and hashtables. Could someone explain the similarities and differences of using hashtables and hashmaps versus pyt...