python

will Python ever have LINQ like thing

Possible Duplicate: LINQ in Python Hi Will python ever have Microsoft LINQ ported to it . I find LINQ to be very cool ...

Should I use Celery or Carrot for a Django project?

I'm a little confused as to which one I should use. I think either will work, but is one better or more appropriate than the other? http://github.com/ask/carrot/tree/master http://github.com/ask/celery/tree/master ...

python - Problem storing Unicode character to MySQL with Django

I have the string u"Played Mirror's Edge\u2122" Which should be shown as Played Mirror's Edge™ But that is another issue. My problem at hand is that I'm putting it in a model and then trying to save it to a database. AKA: a = models.Achievement(name=u"Played Mirror's Edge\u2122") a.save() And I'm getting : 'ascii' codec can...

python how to create different instances of the same class into an iteration

My problem is: I would like to add to a Composite class Leaf objects created at runtime inside a Composite routine like this: def update(self, tp, msg, stt): """It updates composite objects """ d = Leaf() d.setDict(tp, msg, stt) self.append_child(d) return self.status() Inside main: import lib.composite c =...

Moving files under python

I'm confused with file moving under python. Under windows commandline, if i have directory c:\a and a directory c:\b, i can do move c:\a c:\b which moves a to b result is directory structure c:\b\a If I try this with os.rename or shutil.move: os.rename("c:/a", "c:/b") I get WindowsError: [Error 17] Cannot create a file when that...

Python data/file Crc

I am wanting to generate and store a CRC (or similar) value for a given list of files which can be used as a comparison at a later point. Writing a function to do this is simple enough, but is there a more standard way to do it within the Python libs? The value generated does not need to be of any particular standard. ...

Can I detect if my code is running on cPython or Jython?

I'm working on a small django project that will be deployed in a servlet container later. But development is much faster if I work with cPython instead of Jython. So what I want to do is test if my code is running on cPython or Jython in my settiings.py so I can tell it to use the appropriate db driver (postgresql_psycopg2 or doj.backend...

How to match search strings to content in python

Usually when we search, we have a list of stories, we provide a search string, and expect back a list of results where the given search strings matches the story. What i am looking to do, is the opposite. Give a list of search strings, and one story and find out which search strings match to that story. Now this could be done with re b...

Upload a potentially huge textfile to a plain WSGI-server in Python

I need to upload a potentially huge plain-text file to a very simple wsgi-app without eating up all available memory on the server. How do I accomplish that? I want to use standard python modules and avoid third-party modules if possible. ...

Run (remote) php script from (local) python script

How do I make python (local) run php script on a remote server? I don't want to process its output with python script or anything, just execute it and meanwhile quit python (while php script will be already working and doing its job). edit: What I'm trying to achieve: python script connects to ftp server and uploads php script (I al...

Combining module files in Python

Is there a way to put together Python files, akin to JAR in Java? I need a way of packaging set of Python classes and functions, but unlike a standard module, I'd like it to be in one file. ...

Scrolling QGraphicsView programmatically

I've want to implement a scroll/pan-feature on a QGraphicsView in my (Py)Qt application. It's supposed to work like this: The user presses the middle mouse button, and the view scrolls as the user moves the mouse (this is quite a common feature). I tried using the scroll() method inherited from QWidget. However, this somehow moves the vi...

Twisted sometimes throws (seemingly incomplete) 'maximum recursion depth exceeded' RuntimeError

Because the Twisted getPage function doesn't give me access to headers, I had to write my own getPageWithHeaders function. def getPageWithHeaders(contextFactory=None, *args, **kwargs): try: return _makeGetterFactory(url, HTTPClientFactory, contextFactory=contextFactory, ...

Lengthy single line strings in Python without going over maximum line length

How can I break a long one liner string in my code and keep the string indented with the rest of the code? PEP 8 doesn't have any example for this case. Correct ouptut but strangely indented: if True: print "long test long test long test long test long \ test long test long test long test long test long test" >>> long test long te...

Python tell when an ftp transfer sits on completion

I have to download some files from an FTP server. Seems prosaic enough. However, the way this server behaves is if the file is very large, the connection will just hang when the download ostensibly completes. How can I handle this gracefully using ftplib in python? Sample python code: from ftplib import FTP ... ftp = FTP(host) ftp.l...

Pythonic way to get some rows of a matrix

I was thinking about a code that I wrote a few years ago in Python, at some point it had to get just some elements, by index, of a list of lists. I remember I did something like this: def getRows(m, row_indices): tmp = [] for i in row_indices: tmp.append(m[i]) return tmp Now that I've learnt a little bit more sinc...

How to exclude U+2028 from line separators in Python when reading file?

I have a file in UTF-8, where some lines contain the U+2028 Line Separator character (http://www.fileformat.info/info/unicode/char/2028/index.htm). I don't want it to be treated as a line break when I read lines from the file. Is there a way to exclude it from separators when I iterate over the file or use readlines()? (Besides reading t...

storing uploaded photos and documents - filesystem vs database blob

My specific situation Property management web site where users can upload photos and lease documents. For every apartment unit, there might be 4 photos, so there won't be an overwhelming number of photo in the system. For photos, there will be thumbnails of each. My question My #1 priority is performance. For the end user, I want...

Starting an INDIVIDUAL instance of a subclass from asynchat

So the situation I have is that I have loaded more than one class that I've made that subclasses from asynchat, but I only want one of them to run. Of course, this doesn't work out when I call asyncore.loop() as they all begin. Is there any way to make only one of them begin running? edit: I think it has something to do with the map par...

python - parse annotations from a pdf

I want a python function that takes a pdf and returns a list of the text of the note annotations in the document. I have looked at python-poppler (https://code.launchpad.net/~poppler-python/poppler-python/trunk) but I can not figure out how to get it to give me anything useful. I found the get_annot_mapping method and modified the demo ...