Deleting directory in Python
shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain? ...
shutil.rmtree will not delete read-only files on Windows. Is there a python equivalent of "rm -rf" ? Why oh why is this such a pain? ...
I have a simple django app that is using only the admin. This is the model as is now in the server: from django.db import models class School(models.Model): school = models.CharField(max_length=200) def __unicode__(self): return self.school class Lawyer(models.Model): first = models.CharField(max_length=20) ...
I have many dll files and I would like to select them into two different folders (PC and PPC). For this I need to know the target platform of the dll file or any other details about its platform. I use Python 3.1.1. I have tried the win32api which does not compatible with this Python version. So, I tried to use the ctypes.windll with tr...
It would not be my intention to put a link on my blog, but I don't have any other method to clarify what I really mean. The article is quite long, and it's in three parts (1,2,3), but if you are curious, it's worth the reading. A long time ago (5 years, at least) I programmed a python program which generated "mathematical bacteria". The...
I have asked this question here about a Python command that fetches a URL of a web page and stores it in a variable. The first thing that I wanted to know then was whether or not the variable in this code contains the HTML code of a web-page: from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetc...
I am developing a library and an application that uses the library in Python 2.6. I've placed a "mylib.pth" file in "site-packages" so that I can import mylib from within my application. I am using a DVCS so when I want to fix a bug or add a feature to the library I make a branch of the repository and work within that branch. To tes...
Specifically, I got a form that calls a Django service (written using Piston, but I don't think that's relevant), sending via POST something like this: edu_type[3][name] => a edu_type[3][spec] => b edu_type[3][start_year] => c edu_type[3][end_year] => d edu_type[4][0][name] => Cisco edu_type[4][0][spec] => CCNA edu_type[4][0][start_year...
I'm working with an API which I post files to. However, when I receive the response, the HTTP status code is a 202. This is to be expected, but in addition the API will also respond with XML content. So in my try/except block urllib2.urlopen will result in a raised urllib2.HTTPError and destroying the XML content. try: response = u...
Eclipse templates can automatically insert text and variables as you are coding. When variables are used with the ${variable} form, the value is inserted automatically. My question is whether you can add sections to these templates conditionally. Can you have a method definition template that will fill in multiple variables and add loca...
I have PDF forms that I want to autopopulate with data from my Django web application and then offer to the user to download. What python library would let me easily pre-populate PDF forms? These forms are intended to be printed out. ...
In memcached (appengine api implementation), how does expiration interact with incr()? There isn't a time argument for incr(), but what happens if I add the key with another call rather than using the initial_value param, like so: memcache.add('testcounter', 0, time=60*90) newcnt = memcache.incr('testcounter') will testcounter stil...
My intention was to use pyGTK's main loop to create a function that blocks while it waits for the user's input. The problem I've encountered is best explained in code: #! /usr/bin/python import gtk def test(): retval = True def cb(widget): retval = False gtk.main_quit() window = gtk.Window(gtk.WINDOW_TOPLE...
I have an interactive program that runs stdin and stdout. I need to create wrapper that will send X to it's stdin, check that it prints Y and then redirects wrapper's stdin and stdout to program's stdin and stdout just like program would be executed directly. How to implement this ? X and Y can be hardcoded. Bash? Python? Edit: I can't...
I'm creating a Django app that uses some inheritance in it's model, mainly because I need to assign everything a UUID and a reference so I know what class it was. Here's a simplified version of the base class: class BaseElement(models.Model): uuid = models.CharField(max_length=64, editable=False, blank=True, default=lambda:unicode(...
The use case is the following: Given a (fixed, not changeable) DLL implemented in C Wanted: a wrapper to this DLL implemented in python (chosen method: ctypes) Some of the functions in the DLL need synchronization primitives. To aim for maximum flexibility, the designers of the DLL completely rely on client-provided callbacks. More p...
How can you have model declarations at two different directories in Django? I have the model at the directory Code which contains "init.py", "models.py" and "admin.py". It is working properly alone. I want to have the directory History which has the model of the revisions of the given questions. I have the similar files in the director...
Hi, I am looking for a few pointers, I got pointed to this site. My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing wit...
I'm building a tool where as exceptions propagate upwards, new data about the context of the exception gets added to the exception. The issue is, by the time the exception gets to the top level, all of the extra context data is there, but only the very latest stack trace is shown. Is there an easy way to have an exception show the origin...
My Django templates use a lot of related stuff: images, style sheets, etc. Where should I put these file, or how should I refer to them in the template itself? For now I'm using the development server. I know it's a really common thing, but I can't really figure it out. ...
My primary interest is network programming. I have done quite a bit of reading and experimenting and am familiar with mechanisms of most protocols. Now I want to start writing code. I read introductory stuff on python and grasped it well too. I had just started playing with the python modules, when I met somebody (with a tall reputation)...