python

Eclipse pydev auto-suggestions don't work in some cases

Hello everyone! My question is probably stupid and I hope somebody has succeeded in solving this issue. Sometimes I cannot see right suggestions in auto-completion box (Eclipse 3.5.2, PyDev 1.5.7). For example: import email fp = open('my.eml', 'rb') msg = email.message_from_file(fp) msg now is a Message object. And functions like ge...

How can I make list or set translatable using gettext?

I have some structure in Python: > gender=( ('0','woman'), ('1','man') ) I want to translate it before I will display it in Django template. Unfortunately, below solution doesn't work: > from django.utils.translation import > ugettext_lazy as _ > > gender=( ('0',_('woman')), > ('1',_('man')) ) What shall I do to translate this? I ...

emacs/Python: running python-shell in line buffered vs. block buffered mode

Hi all - In a related question and answer here, someone hypothesized that python-shell within emacs(23.2) was block-buffered instead of line-buffered. The recommended fix was to add sys.stdout.flush() to the spot in my script where I want stdio to flush its contents to the python-shell. Is there someway to trick python-shell (running i...

Converting python collaborative filtering code to use Map Reduce

Using Python, I'm computing cosine similarity across items. given event data that represents a purchase (user,item), I have a list of all items 'bought' by my users. Given this input data (user,item) X,1 X,2 Y,1 Y,2 Z,2 Z,3 I build a python dictionary {1: ['X','Y'], 2 : ['X','Y','Z'], 3 : ['Z']} From that dictionary, I generate a...

Interpreted vs. Compiled vs. Late-Binding

Python is compiled into an intermediate bytecode(pyc) and then executed. So, there is a compilation followed by interpretation. However, long-time Python users say that Python is a "late-binding" language and that it should`nt be referred to as an interpreted language. How would Python be different from another interpreted language? Co...

bundles in java?

in symfony 2.0 and django there are bundles that contain everything for a feature (html, css, js, img, php/python). so if you want to delete one feature, you basically just delete that bundle and unregister it from "main". are there java frameworks for this too? or is it different in java cause java is a compiling language. thanks ...

Faster Insertion of Records into a Table with SQLAlchemy

I am parsing a log and inserting it into either MySQL or SQLite using SQLAlchemy and Python. Right now I open a connection to the DB, and as I loop over each line, I insert it after it is parsed (This is just one big table right now, not very experienced with SQL). I then close the connection when the loop is done. The summarized code ...

getting expat to use .dtd for entity replacement in python

I'm trying to read in an xml file which looks like this <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE dblp SYSTEM "dblp.dtd"> <dblp> <incollection> <author>Jos&eacute; A. Blakeley</author> </incollection> </dblp> The point that creates the problem looks is the Jos&eacute; A. Blakeley part: The parser calls its character han...

Creating a sliding frame containing widgets in tkinter in python

I am trying really hard to make a sliding frame containing widgets in tkinter in python. There is this frame inside a big window with different widgets. And as soon as i click on the next button on that frame the frame should slowly slide towards the left and vanish ultimately. As soon as it vanishes, i want new frame with widgets to com...

How to write a custom solution using a python package, modules etc

I am writing a packacge foobar which consists of the modules alice, bob, charles and david. From my understanding of Python packages and modules, this means I will create a folder foobar, with the following subdirectories and files (please correct if I am wrong) foobar/ __init__.py alice/alice.py bob/bob.py charles/charles.py ...

Spawning a thread in python

I have a series of 'tasks' that I would like to run in separate threads. The tasks are to be performed by separate modules. Each containing the business logic for processing their tasks. Given a tuple of tasks, I would like to be able to spawn a new thread for each module as follows. from foobar import alice, bob charles data = getWor...

Python - react to custom keyboard interrupt

Hello. I am writing python chatbot that displays output through console. Every half second it asks server for updates, and responds to message. In the console I can see chat log. This is sufficient in most cases, however, sometimes I want to interrupt normal workflow and write custom chat answer myself. I would love to be able to press ...

Identifying if a data is RSS or HTML on python

Is there a function or method I could call in Python That would tell me if the data is RSS or HTML? ...

Python MPS-format reader

I need to read MPS files into Python. [MPS is an old and standard format for representing linear programs.] Pure Python would be best, but I would be happy to use f2py if it meant that I could easily leverage existing Fortran MPS readers. Any pointers welcome! ...

How to parse large xml files on google app engine?

Hey, I have fairly large xml file 1mb in size that i host on s3. I need to parse that xml file into my app engine datastore entirely. I have written a simple DOM parser that works fine locally but online it reaches the 30sec error and stops. I tried lowering the xml parsing by downloading the xml file into a BLOB at first before the pa...

pdb is not working in django doctests

So I created the following file (testlib.py) to automatically load all doctests (throughout my nested project directories) into the __tests__ dictionary of tests.py: # ./testlib.py import os, imp, re, inspect from django.contrib.admin import site def get_module_list(start): all_files = os.walk(start) file_list = [(i[0], (i[1], ...

Running the same code for get(self) as post(self)

Its been mentioned in other answers about getting the same code running for both the def get(self) and the def post(self) for any given request. I was wondering what techniques people use, I was thinking of: class ListSubs(webapp.RequestHandler): def get(self): self._run() def post(self): self._run() def _r...

Capturing Mac OS X System Audio output with Python

Hello, I've been trying to "hijack" the Mac OS X system audio using PyAudio and save to a wav in python. That is, I do not want to record from an input device such as a microphone. I want to grab the sound output from any or all applications. I have followed the tutorials on the PyAudio site but these do not appear to cover my use case...

Calling MATLAB functions from python

Hi, Is it possible to run MATLAB functions from within Python? I search the internet, I could only find PyMat. The bad thing is the compiled version only supports Python2.2 and I am using 2.6. So I tied to download the source code, so I can compile it for myself. But I cannot compile it, VC++ express seems not to have the necessary funct...

Freezing a dual-mode (GUI and console) application using cx_Freeze

Hi, I've developed a Python application that runs both in the GUI mode and the console mode. If any arguments are specified, it runs in a console mode else it runs in the GUI mode. I've managed to freeze this using cx_Freeze. I had some problems hiding the black console window that would pop up with wxPython and so I modified my setup....