python

Django Reporting Options

I want to create a new "Business" application using the Django framework. Any suggestions as to what I can use as a reporting framework? The application will need to generate reports on various business entities including summaries, totals, grouping, etc. Basically, is there a Crystal reports-like equivalent for Django/Python? ...

How to print output using python?

I have been working on this particular assignment and ran into one issue. I'm fairly new to python and needed a quick fix. When this .exe file runs it prints a screen full of information and I want to print a particular line out to the screen here line "6". cmd = ' -a ' + str(a) + ' -b ' + str(b) + str(Output) process = Popen(...

Decorator to mark a method to be executed no more than once even if called several times

I will go straight to the example: class Foo: @execonce def initialize(self): print 'Called' >>> f1 = Foo() >>> f1.initialize() Called >>> f1.initialize() >>> f2 = Foo() >>> f2.initialize() Called >>> f2.initialize() >>> I tried to define execonce but could not write one that works with methods. PS: I cannot define the code ...

Pythonic way to log specific things to a file?

I understand that Python loggers cannot be instantiated directly, as the documentation suggests: Note that Loggers are never instantiated directly, but always through the module-level function logging.getLogger(name) .. which is reasonable, as you are expected not to create logger objects for every class/module for there is a...

How to make custom PhotoEffects in Django Photologue?

I'm creating an image gallery in Django using the Photologue application. There are a number of PhotoEffects that come with it. I'd like to extend these and make my own so that I can do more complicated effects such as adding drop shadows, glossy overlays, etc. Is is possible to create custom effects that Photologue can then use to pr...

Financial Charts / Graphs in Ruby or Python

What are my best options for creating a financial open-high-low-close (OHLC) chart in a high level language like Ruby or Python? While there seem to be a lot of options for graphing, I haven't seen any gems or eggs with this kind of chart. http://en.wikipedia.org/wiki/Open-high-low-close_chart (but I don't need the moving average or Bol...

Python remove all lines which have common value in fields

I have lines of data comprising of 4 fields aaaa bbb1 cccc dddd aaaa bbb2 cccc dddd aaaa bbb3 cccc eeee aaaa bbb4 cccc ffff aaaa bbb5 cccc gggg aaaa bbb6 cccc dddd Please bear with me. The first and third field is always the same - but I don't need them, the 4th field can be the same or different. The thing is, I only wan...

Sending an email from Pylons

I am using Pylons to develop an application and I want my controller actions to send emails to certain addresses. Is there a built in Pylons feature for sending email? ...

Python: Inflate and Deflate implementations

I am interfacing with a server that requires that data sent to it is compressed with Deflate algorithm (Huffman encoding + LZ77) and also sends data that I need to Inflate. I know that Python includes Zlib, and that the C libraries in Zlib support calls to Inflate and Deflate, but these apparently are not provided by the Python Zlib m...

Even and odd number

To check for odd and even integer, is the lowest bit checking more efficient than using the modulo? >>> def isodd(num): return num & 1 and True or False >>> isodd(10) False >>> isodd(9) True ...

Any drawbacks to storing an integer as a string in a database?

I have id values for products that I need store. Right now they are all integers, but I'm not sure if the data provider in the future will introduce letters or symbols into that mix, so I'm debating whether to store it now as integer or string. Are there performance or other disadvantages to saving the values as strings? ...

How does Python store lists internally?

How are lists in python stored internally? Is it an array? A linked list? Something else? Or does the interpreter guess at the right structure for each instance based on length, etc. If the question is implementation dependent, what about the classic CPython? ...

How can I parse marked up text for further processing?

See updated input and output data at Edit-1. What I am trying to accomplish is turning + 1 + 1.1 + 1.1.1 - 1.1.1.1 - 1.1.1.2 + 1.2 - 1.2.1 - 1.2.2 - 1.3 + 2 - 3 into a python data structure such as [{'1': [{'1.1': {'1.1.1': ['1.1.1.1', '1.1.1.2']}, '1.2': ['1.2.1', '1.2.2']}, '1.3'], '2': {}}, ['3',]] I've looked ...

Using Python to call Mencoder with some arguments

Hello, I'll start by saying that I am very, very new to Python. I used to have a Windows/Dos batch file in order to launch Mencoder with the right set of parameters, without having to type them each time. Things got messy when I tried to improve my script, and I decided that it would be a good opportunity to try coding something in pyt...

Special (magic) methods in Python

What are all the special (magic) methods in Python? The __xxx__ methods, that is. I'm often looking for a way to override something which I know is possible to do through one of these methods, but I'm having a hard time to find how since as far as I can tell there is no definitive list of these methods, PLUS their names are not really G...

Search a folder for files like "/*tmp*.log" in Python

As the title says, I'm using Linux, and the folder could contain more than one file, I want to get the one its name contain *tmp*.log (* means anything of course!). Just like what I do using Linux command line. ...

Handling Multiple Network Interfaces in Python

How can I do the following things in python: List all the IP interfaces on the current machine. Receive updates about changes in network interfaces (goes up, goes down, changes IP address). Any python package available in Ubuntu Hardy will do. ...

How to communicate between Python and C# using XML-RPC?

Assume I have simple XML-RPC service that is implemented with Python: from SimpleXMLRPCServer import SimpleXMLRPCServer def getTest(): return 'test message' if __name__ == '__main__' : server = SimpleThreadedXMLRPCServer(('localhost', 8888)) server.register_fuction(getText) server.serve_forever(...

Python operators

I am learning Python for the past few days and I have written this piece of code to evaluate a postfix expression. postfix_expression = "34*34*+" stack = [] for char in postfix_expression : try : char = int(char); stack.append(char); except ValueError: if char == '+' : stack.append(stack.pop() + stack.pop(...

How to test if a class attribute is an instance method.

In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object. hasattr returns true regardless of whether the attribute is an instance method or not. Any suggestions? For example: class Test...