python

Question on moduli

Hi, I want to find all the numbers divisble by all the numbers between 1 and 5. how do I write the program so that if the remainder of 'start' divided by all the numbers that x goes through is equal to 0 that it will print start. Is there any syntax that will calculate what I'm looking for. thanks. import math def main(): one = 1 ...

Adding elements to python generators

Is it possible to append elements to a python generator? I'm currently trying to get all images from a set of disorganized folders and write them to a new directory. To get the files, I'm using os.walk() which returns a list of image files in a single directory. While I can make a generator out of this single list, I don't know how to c...

Django and Sqlite Concurrency issue

I've done a bit of reading related to the concurrency issues with sqlite, but I don't see how they'd apply to Django since it's inherently single threaded. I'm not using any multiprocess modules either. I have absolutely no experience with concurrent programming either, so if someone can identify WHY the following code is causing an Oper...

Solr search with escaping solr reserved keywords

How do i query fields that contain solr reserved keywords as ":" in solr? For instance, q = 'uri:http://www.example.com' throws up an error for "http://www.example.com" containing reserved word ":" ...

CPython internal structures

GAE has various limitations, one of which is size of biggest allocatable block of memory amounting to 1Mb (now 10 times more, but that doesn't change the question). The limitation means that one cannot put more then some number of items in list() as CPython would try to allocate contiguous memory block for element pointers. Having huge l...

Drawing a chart with proportional X axis in Python

Hi everyone! Is there an easy way to draw a date/value chart in Python, if the "dates" axis had non-equidistant values? For example, given these: 2009-02-01: 10 2009-02-02: 13 2009-02-07: 25 2009-03-01: 80 I'd like the chart to show that between the 2nd and 3nd value there's a longer gap than between the 1st and the 2nd. I tried a fe...

Python C-API Object Allocation‏

I want to use the new and delete operators for creating and destroying my objects. The problem is python seems to break it into several stages. tp_new, tp_init and tp_alloc for creation and tp_del, tp_free and tp_dealloc for destruction. However c++ just has new which allocates and fully constructs the object and delete which destructs ...

Any way to create a NumPy matrix with C API?

I read the documentation on NumPy C API I could find, but still wasn't able to find out whether there is a possibility to construct a matrix object with C API — not a two-dimensional array. The function is intended for work with math matrices, and I don't want strange results if the user calls matrix multiplication forgetting to convert ...

Python serialize lexical closures?

Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example: def foo(bar, baz) : def closure(waldo) : return baz * waldo ...

Django - Set Up A Scheduled Job?

I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this. Does anyone know how to set this up? To cl...

Sentiment analysis for twitter in python

I'm looking for an open source implementation, preferably in python, of Textual Sentiment Analysis (http://en.wikipedia.org/wiki/Sentiment_analysis). Is anyone familiar with such open source implementation I can use? I'm writing an application that searches twitter for some search term, say "youtube", and counts "happy" tweets vs. "sad"...

Using wget in python (Error Code Help me)

Heres my code. import os, sys if len(sys.argv) != 2: sys.exit(1) h = os.popen("wget -r %s") % sys.argv[1] fil = open("links.txt","w") dir = os.listdir("%s") % sys.argv[1] for file in dir: print file.replace("@","?") fil.write("%s/"+file.replace("@","?")) % sys.argv[1] fil.write("\n") h.close() running the it, li...

Docs for the internals of CPython Implementation

I am currently in the process of making an embedded system port of the CPython 3.0 Python interpreter and I'm particularly interested in any references or documentation that provides details about the design and structure of code for Release 3.0 or even about any of the 2.x releases. One useful document I have found so far is this infor...

How do YOU deploy your WSGI application? (and why it is the best way)

Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this. So how can it be done? Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it) Pure Python web server eg paste, cherrypy, Spawning, Twisted.web as 2 but with reverse pr...

One view ( frontpage ) for many controllers (sub views)

Notes: Cannot use Javascript or iframes. In fact I can't trust the client browser to do just about anything but the ultra basics. I'm rebuilding a legacy PHP4 app as a MVC application, with most of my research currently focused with the Pylon's framework. One of the first weird issues I've run into and one I've solved in the past by us...

How to determine number of files on a drive with Python?

Howdy! I have been trying to figure out how to retrieve (quickly) the number of files on a given HFS+ drive with python. I have been playing with os.statvfs and such, but can't quite get anything (that seems helpful to me). Any ideas? Edit: Let me be a bit more specific. =] I am writing a timemachine-like wrapper around rsync for va...

Python: How to ignore an exception and proceed?

I have a try...except block in my code and When an exception is throw. I really just want to continue with the code because in that case, everything is still able to run just fine. The problem is if you leave the except: block empty or with a #do nothing, it gives you a syntax error. I can't use continue because its not in a loop. Is the...

Include html part in a mail with python libgmail

I've a question about its usage: i need to send an html formatted mail. I prepare my message with ga = libgmail.GmailAccount(USERNAME,PASSWORD) msg = MIMEMultipart('alternative') msg.attach(part1) msg.attach(part2) ... ga.sendMessage(msg.as_string()) This way doesn't works, it seems can't send msg with sendMessage method. What is th...

How can you extract all 6 letter Latin words to a list?

I need to have all 6 letter Latin words in a list. I would also like to have words which follow the pattern Xyzzyx in a list. I have used little Python. ...

Why doesn't Python release file handles after calling file.close() ?

I am on windows with Python 2.5. I have an open file for writing. I write some data. Call file close. When I try to delete the file from the folder using Windows Explorer, it errors, saying that a process still holds a handle to the file. If I shutdown python, and try again, it succeeds. ...