python

Would python be an appropriate choice for a video library for home use software

Hi, I am thinking of creating a video library software which keep track of all my videos and keep track of videos that I already haven't watched and stats like this. The stats will be specific to each user using the software. My question is, is python appropriate to create this software or do I need something like c++. ...

Python chat : delete variables to clean memory in functions?

I'm creating a chat daemon in python and twisted framework. And I'm wondering if I have to delete every variable create in my functions to save memory in the long run when multiple users are connected, or are those variable automatically clear?. Here's a strip down version of my code to illustrate my point: class Chat(LineOnlyReceiver...

Python type inference for autocompletion

Is it possible to use Ocaml/Haskell algorithm of type inference to suggest better autocompletions for Python? The idea is to propose autocompletion for example in the following cases: class A: def m1(self): pass def m2(self): pass a = A() a. <--- suggest here 'm1' and 'm2' fun1(a) def fun1(b): b. <--- suggest here...

Django autoreload for development on every request?

Can a Django app be reloaded on every request ? This is very useful for development. Ruby on Rails does just this. runserver reloads, but it reloads slow, and still sometime one has to stop and start it again for some changes to show up. (For example changes in admin.) mod_wsgi can autoreload on Linux by touching *.wsgi files. On Wi...

To do RegEx, what are the advantages/disadvantages to use UTF-8 string instead of unicode?

Usually, the best practice in python, when using international languages, is to use unicode and to convert early any input to unicode and to convert late to a string encoding (UTF-8 most of the times). But when I need to do RegEx on unicode I don't find the process really friendly. For example, if I need to find the 'é' character follow...

What's the life-time of a thread-local value in Python?

import threading mydata = threading.local() def run(): # When will the garbage collector be able to destroy the object created # here? After the thread exits from ``run()``? After ``join()`` is called? # Or will it survive the thread in which it was created, and live until # ``mydata`` is garbage-collected? mydata.f...

Build failure during install py25-gtk on Mac OS X 10.6 using MacPorts 1.8

When I do this command : sudo port clean py25-gtk sudo port install py25-gtk I get this error : ---> Computing dependencies for py25-gtk ---> Building getopt Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_sysutils_getopt/w...

How to import bookmarks from users web browsers using python?

I am working on an RSS Reader type program and I would like it to be able to automatically import RSS feeds from the users browser bookmarks. I assume different browsers use different methods to store bookmarks. Is there any library out there just for this purpose? I only need it to work on Linux so I don't care about Windows or Mac o...

Why my python does not see pysqlite?

I would like to have an interface between Python and sqlite. Both are installed on the machine. I had an old version of Python (2.4.3). So, pysqlite was not included by default. First, I tried to solve this problem by installing pysqlite but I did not succeed in this direction. My second attempt to solve the problem was to install a new ...

for line in open(filename)

I frequently see python code similar to for line in open(filename): do_something(line) When does filename get closed with this code? Would it be better to write with open(filename) as f: for line in f.readlines(): do_something(line) ...

Python: "1-2-3-4" to [1, 2, 3, 4]

What is the best way to convert a string on the format "1-2-3-4" to a list [1, 2, 3, 4]? The string may also be empty, in which case the conversion should return an empty list []. This is what I have: map(lambda x: int(x), filter(lambda x: x != '', "1-2-3-4".split('-'))) EDIT: Sorry all of those who answered before I c...

Python: undo write to file

What is the best way to undo the writing to a file? If I'm going through a loop and writing one line at a time, and I want to undo the previous write and replace it with something else, how do I go about doing that? Any ideas? Thanks in advance! ...

How to build from the source?

I cannot use sqlite3 (build python package). The reason of the is missing _sqlite3.so. I found that peoples had the same problem and they resolved it here. The solutions is given in one sentence: By building from source and moving the library to /usr/lib/python2.5/lib-dynload/ I resolved the issue. However, I do t understand...

IronPython - How to prevent CLR (and other modules) from being imported

I'm setting up a web application to use IronPython for scripting various user actions and I'll be exposing various business objects ready for accessing by the script. I want to make it impossible for the user to import the CLR or other assemblies in order to keep the script's capabilities simple and restricted to the functionality I expo...

Making a string the name of an instance/object

I've been struggling for a couple of days now with the following... I'm trying to find a way to instantiate a number of objects which I can name via a raw_input call, and then, when I need to, look at its attributes via the 'print VARIABLE NAME' command in conjunction with the str() method. So, to give an example. Let's say I want to ...

What is Python's Fabric equivalent in other languages?

Can someone tell me what's the equivalent of Python's Fabric in Python itself, other languages or third party tools? I am still a bit fuzzy on what it is trying to accomplish and it's usage. ...

Readably print out a python dict() sorted by key

I would like to print a python dictionary to a file using PrettyPrinter (for human readability) but have the dictionary be sorted by key in the output file to further improve readability. So: mydict = {'a':1, 'b':2, 'c':3} pprint(mydict) currently prints to {'b':2, 'c':3, 'a':1} I would like to PrettyPrint the dictionary but have...

How to bind a TextField to an IBOutlet()?

I'm trying to figure out how to update an NSTextField programatically. I've figured out how to get the current value of the Text Field from Python: myVar = objc.IBOutlet() .... self.myVar.stringValue() How do I set the value of myVar from the Python side and have the GUI update? I'd like some sort of two way binding (like {myVAR} in...

"Too many values to unpack" Exception

I'm working on a project in Django and I've just started trying to extend the User model in order to make user profiles. Unfortunately, I've run into a problem: Every time I try to get the user's profile inside of a template (user.get_template.lastIP, for example), I get the following error: Environment: Request Method: GET Request ...

Case-insensitive comparison of sets in Python

I have two sets (although I can do lists, or whatever): a = frozenset(('Today','I','am','fine')) b = frozenset(('hello','how','are','you','today')) I want to get: frozenset(['Today']) or at least: frozenset(['today']) The second option is doable if I lowercase everything I presume, but I'm looking for a more elegant way. Is it ...