python

Reportlab 'LayoutError' handling and debugging.

I have been working with some complex PDF outputs with reportlab. These are generally fine but there are some cases still where I get LayoutErrors - these are usually because Flowables are too big at some point. It's proving o be pretty hard to debug these as I don't often have more information than something like this; Flowable <Table...

Some kind of event functionality in Django?

I have a view my Django application which when invoked calls my backend. My backend logic sometimes reaches a point when it needs user input to continue. When this happens, I pickle dump my backend data into the session so that i can resume it later on. Currently i have defined the scenario when user input is required as a custom except...

Can I use python ast module for this?

I'd like to write a program that modify python programs in this way: change "some literal string %" % SOMETHING to functioncall("some literal string %") % SOMETHING Thanks, ...

Ironpython call numpy problem

Ironpython 2.6, python 2.6.5, numpy, SciPy import sys sys.path.append(r'D:\Python26\dll') sys.path.append(r'D:\Python26\Lib') sys.path.append(r'D:\Python26\Lib\site-packages') » import numpy Traceback (most recent call last): File "", line 1, in File "D:\Python26\Lib\site-packages\numpy\__init__.py", line 132, in File "D:\Pyth...

Red hat enterprise 5 Linux with Python 2.5

Hi, I have to deploy a Django project on Red hat enterprise linux 5, the project has been developed on Python 2.5 but the server environment has Python 2.4 which is causing some issues. I googled a lot over internet to get the Python 2.5 built rpm for the server but there are only src rpm available for the mentioned Linux version. I h...

How to use float ** from C in Python?

Hi, after having no success with my question on How to use float ** in Python with Swig?, I started thinking that swig might not be the weapon of choice. I need bindings for some c functions. One of these functions takes a float**. What would you recomend? Ctypes? Interface file: extern int read_data(const char *file,int *n_,int *m_,f...

How to store an integer leaded by zeros in django

Hello, I'm trying to store a number in django that looks like this: 000001 My problem is that if I type this inside an IntegerField it gets converted to "1" without the leading zeros. I've tried also with a DecimalField with the same result. How can I store the leading zeros whithout using a CharField? (I need to manipulate that numb...

Generate table schema inspecting Excel(CSV) and import data

How would I go around creating a MYSQL table schema inspecting an Excel(or CSV) file. Are there any ready Python libraries for the task? Column headers would be sanitized to column names. Datatype would be estimated based on the contents of the spreadsheet column. When done, data would be loaded to the table. I have an Excel file of ~2...

Yield only as many are required from a generator

I wish to yield from a generator only as many items are required. In the following code a, b, c = itertools.count() I receive this exception: ValueError: too many values to unpack I've seen several related questions, however I have zero interest in the remaining items from the generator, I only wish to receive as many as I ask for...

Need a way to determine if a file is done being written to.

The situation I'm in is this - there's a process that's writing to a file, sometimes the file is rather large say 400 - 500MB. I need to know when it's done writing. How can I determine this? If I look in the directory I'll see it there but it might not be done being written. Plus this needs to be done remotely - as in on the same int...

reduce python list of objects to dict object.id -> object

Hello! You have list of objects each of them have id property. Here's my way to covert it to dict where keys are ids and values are objects: reduce( lambda x,y: dict(x.items() + { y.id : y}.items()), list, {} ) Suggest better way to do it. ...

An algo for generating code callgraphs

I am working on a project which requires generating some metrices of a code (it can be C/C++/Java/Python). One of the metrices can be that I create a callgraph after parsing the code entered (the programs are expected to be small - probably under 1000L). As of now, I am looking for a way to create a program (it can be C/Python) which ca...

Python Logging across multiple classes and files; how to configure so as to be easily disabled?

Currently, I have osmething like this in all of my classes: # Import logging to log information import logging # Set up the logger LOG_FILENAME = 'log.txt' logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG) This works well, and I get the output I want, but I would really like to have all this sort of information in one pl...

What python equivalent of Sinatra would you recommend?

I like the sinatra framework, but might have to work in python. A quick web search has uncovered a few python equivalents including itty, flask and juno. I'd like to know people's experience of these, or other sinatra equivalents. Which would you recommend? ...

Access static class variable of parent class in Python

I have someting like this class A: __a = 0 def __init__(self): A.__a = A.__a + 1 def a(self): return A.__a class B(A): def __init__(self): # how can I access / modify A.__a here? A.__a = A.__a + 1 # does not work def a(self): return A.__a Can I access the __a class variable in B? It's possible writing a ...

Does REGEX differ from PHP to Python

hi there, I found this post: http://stackoverflow.com/questions/118143/python-regex-vs-php-regex but I actually did not get if Python's REGEX syntax matches PHP's REGEX syntax. I started to convert some of my old PHP code to python (due to g's appengine etc.), and now I would like to know whether the regex is 100% convertable, by simpl...

Help getting retweets with Python Twitter Tools

I'm using this library: http://mike.verdone.ca/twitter/ to access Twitter. The author states, "Its methods are directly bound to the Twitter API's URLs. For instance twitter.statuses.friends_timeline() will always hit the URL http://twitter.com/statuses/friends_timeline.json. Always." If this is the case, would it even be possible to hit...

Joining the previous and next sentence using python

I'm trying to join a set of sentences contained in a list. I have a function which determines whether a sentence in worth saving. However, in order to keep the context of the sentence I need to also keep the sentence before and after it. In the edge cases, where its either the first or last sentence then, I'll just keep the sentence a...

SQLAlchemy: Inserting the results of a query into another table

So I have some results which I've got from the install table, like so: install = metadata.tables['install'] results = session.query(install) #<sqlalchemy.orm.query.Query object> I'd like to insert these same results into the install_archive table. I'm not entirely sure how to do this, because I don't want to duplicate the schema b...

Problem accessing config files within a Python egg

I have a Python project that has the following structure: package1 class.py class2.py ... package2 otherClass.py otherClass2.py ... config dev_settings.ini prod_settings.ini I wrote a setup.py file that converts this into an egg with the same file structure. (When I examine it using a zip program the structure seems id...