python

Problem opening berkeley db in python

I have problems opening a berkeley db in python using bdtables. As bdtables is used by the library I am using to access the database, I need it to work. The problem seems to be that the db environment I am trying to open (I got a copy of the database to open), is version 4.4 while libdb is version 4.6. I get the following error using bs...

When to use the Python debugger

Since Python is a dynamic, interpreted language you don't have to compile your code before running it. Hence, it's very easy to simply write your code, run it, see what problems occur, and fix them. Using hotkeys or macros can make this incredibly quick. So, because it's so easy to immediately see the output of your program and any erro...

How do I turn an RSS feed back into RSS?

According to the feedparser documentation, I can turn an RSS feed into a parsed object like this: import feedparser d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml') but I can't find anything showing how to go the other way; I'd like to be able do manipulate 'd' and then output the result as XML: print d.toXML() ...

Code to verify updates from the Google Safe Browsing API

In order to verify the data coming from the Google Safe Browsing API, you can calculate a Message Authentication Code (MAC) for each update. The instructions to do this (from Google) are: The MAC is computed from an MD5 Digest over the following information: client_key|separator|table data|separator|client_key. The separator...

Setup Python enviroment on windows

How do I setup a Python enviroment on windows computer so I can start writing and running Python scripts, is there an install bundle? Also which database should i use? Thanks Sorry I should of mentioned that I am using this for web based applications. Does it require apache? or does it use another http server? What is the standard s...

How do I watch a file for changes using Python?

I have a log file being written by another process which I want to watch for changes. Each time a change occurrs I'd like to read the new data in to do some processing on it. What's the best way to do this? I was hoping there'd be some sort of hook from the PyWin32 library. I've found the win32file.FindNextChangeNotification function bu...

What do I need to import to gain access to my models?

I'd like to run a script to populate my database. I'd like to access it through the Django database API. The only problem is that I don't know what I would need to import to gain access to this. How can this be achieved? ...

Os.path : can you explain this behavior ?

I love Python because it comes batteries included, and I use built-in functions, a lot, to do the dirty job for me. I have always been using happily the os.path module to deal with file path but recently I ended up with unexpected results on Python 2.5 under Ubuntu linux, while dealing with string that represent windows file paths : fi...

How can I use UUIDs in SQLAlchemy?

Is there a way to define a column (primary key) as uuid in sqlalchemy if using postgresql? ...

Is this the best way to get unique version of filename w/ Python?

Still 'diving in' to Python, and want to make sure I'm not overlooking something. I wrote a script that extracts files from several zip files, and saves the extracted files together in one directory. To prevent duplicate filenames from being over-written, I wrote this little function - and I'm just wondering if there is a better way to d...

In Python, what is the difference between '/' and '//' when used for division?

Is there a benefit to using one over the other? They both seem to return the same results. >>> 6/3 2 >>> 6//3 2 ...

Framework/Language for new web 2.0 sites (2008 and 2009)

I know I'll get a thousand "Depends on what you're trying to do" answers, but seriously, there really is no solid information about this online yet. Here are my assumptions - I think they're similar for alot of people right now: It is now October 2008. I want to start writing an application for January 2009. I am willing to use beta...

How do I check out a file from perforce in python?

I would like to write some scripts in python that do some automated changes to source code. If the script determines it needs to change the file I would like to first check it out of perforce. I don't care about checking in because I will always want to build and test first. ...

What is the best way to copy a list in Python?

lst1 = ['one', 2, 3] // What is the best way of the following -- or is there another way? lst2 = list(lst1) lst2 = lst1[:] import copy lst2 = copy.copy(lst1) ...

What is a good CMS written in Python (and not Plone)?

I've been doing CMS sites for clients using Joomla for a while now, but I've been migrating a lot of my coding over to Python and have been looking for a good CMS solution that's written in Python. Most of what I've seen so far is either Zope based (Plone) or Django based. I'm not totally opposed to something written in a Python framewo...

Regular expression to match start of filename and filename extension

What is the regex to match filenames that start with 'Run' and have a filename extension of '.py'? It should match any of the following: RunFoo.py RunBar.py Run42.py It should not match: myRunFoo.py RunBar.py1 Run42.txt (I am a regex novice and am more familiar with sql wildcards so the equivalent of what I am searching for would ...

MVC model structure in Python

Hi all, I'm having problems structuring classes in the Model part of an MVC pattern in my Python app. No matter how I turn things, I keep running into circular imports. Here's what I have: Model/__init__p.y should hold all Model class names so I can do a "from Model import User" e.g. from a Controller or a unit test case Model/Data...

Delete Folder Contents in Python

How can I delete the contents of a local folder in Python. The current project is for Windows but I would like to see *nix also. ...

Extracting unique items from a list of mappings

Hello, He're an interesting problem that looks for the most Pythonic solution. Suppose I have a list of mappings {'id': id, 'url': url}. Some ids in the list are duplicate, and I want to create a new list, with all the duplicates removed. I came up with the following function: def unique_mapping(map): d = {} for res in map: ...

What is the best way to open a file for exclusive access in Python?

What is the most elegant way to solve this: open a file for reading, but only if it is not already opened for writing open a file for writing, but only if it is not already opened for reading or writing The built-in functions work like this >>> path = r"c:\scr.txt" >>> file1 = open(path, "w") >>> print file1 <open file 'c:\scr.txt',...