Re: [Tutor] Efficiency of Doxygen on Python vs C++?

2007-08-17 Thread Duncan Gibson
> Is this not just evidence of a very bad Python coding style? > Should we not always declare *all* class fields in the class definition > by assigning to them, even if the assignment is token or dummy > i.e. 'None', "", [], {} etc. this is one of the many things that pylint can warn you about. I

Re: [Tutor] converting a source package into a dll/shared library?

2007-08-16 Thread Duncan Gibson
Alan asked me: > As to access to the internal data would it be difficult to > parameterise it so that each companies data is in a > local config file? That way even if the dissasemble > the code it won't help? Unfortunately no. The input files are human readable geometrical models. Each tool ha

Re: [Tutor] converting a source package into a dll/shared library?

2007-08-15 Thread Duncan Gibson
I asked: > Is it possible to convert a Python package, with __init__.py and > related python modules, into a single DLL or shared library that can > be imported in the same way? > > We have used py2exe and cx_freeze to create a complete executable, > but we are curious whether there is a middle wa

[Tutor] converting a source package into a dll/shared library?

2007-08-14 Thread Duncan Gibson
Is it possible to convert a Python package, with __init__.py and related python modules, into a single DLL or shared library that can be imported in the same way? We have used py2exe and cx_freeze to create a complete executable, but we are curious whether there is a middle way between this singl

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Duncan Gibson
> I have a text file (mylist.py actually), it contains exactly below: > --- > # file mylist.py > jobs = [ > 'Lions', > 'SysTest', > 'trainDD', > 'Cats', > 'train', > 'sharks', > 'whale', > ] > > > I want

Re: [Tutor] Generating simple HTML from within Python

2007-05-14 Thread Duncan Gibson
> I've been searching for a module to allow simple HTML generation, but > most of them appear to be more concerned with *parsing* HTML and XML. > The only one that looks promising from reviews dating back to 1998 or > so is HTMLgen, but the link on starship.python.net appears long dead. > > So my

[Tutor] Generating simple HTML from within Python

2007-05-10 Thread Duncan Gibson
I'm updating an application at the moment that generates simple HTML files. However, it's all done using plain strings and brute force. It's hard to read, and isn't very robust in the face of special characters and matching start and end tags. I've been searching for a module to allow simple HTML

Re: [Tutor] import and unittest

2007-01-16 Thread Duncan Gibson
> I wondered if it was possible to do something like this: > > src/ >-a_module/ >-sub_module/ > test/ >-a_module/ >-sub_module/ Why not really keep the test code with the main code? # module code here # if __name__ == '__main__': import unittest class TestModul

Re: [Tutor] line number when reading files using csv module

2006-10-30 Thread Duncan Gibson
Duncan Gibson wrote: > > > > import csv > > > > class MyReader(object): > > > > def __init__(self, inputFile): > > self.reader = csv.reader(inputFile, delimiter=' ') > >

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Duncan Gibson
Kent Johnson wrote: > The line_num attribute is new in Python 2.5. This is a doc bug, > it should be noted in the description of line_num. Is there some way to create a wrapper around a 2.4 csv.reader to give me pseudo line number handling? I've been experimenting with: import csv clas

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Duncan Gibson
On Fri, 27 Oct 2006 11:35:40 +0200 Duncan Gibson <[EMAIL PROTECTED]> wrote: > > If I have the following data file, data.csv: > 1 2 3 > 2 3 4 5 > > then I can read it in Python 2.4 on linux using: > > import csv > f = file('data.csv', &

[Tutor] line number when reading files using csv module

2006-10-27 Thread Duncan Gibson
If I have the following data file, data.csv: 1 2 3 2 3 4 5 then I can read it in Python 2.4 on linux using: import csv f = file('data.csv', 'rb') reader = csv.reader(f) for data in reader: print data OK, that's all well and good, but I would like to record the li

[Tutor] Handling large arrays/lists

2006-10-09 Thread Duncan Gibson
One part of the application I'm dealing with handles a conceptual 'cube' of data, but is in fact implemented as a single python list. Items are stored and retrieved - no manipulation at the moment - by the classical approach of multiplying the appropriate x, y and z indices with the x, y and z ex

Re: [Tutor] Handling function parameters of mixed object and basic types

2006-09-04 Thread Duncan Gibson
I wrote: > >def newOutput(x): > >if x is None: > >pass > >return > >try: > >x.output() > >except AttributeError: > >if isinstance(x, int): > >pass > >elif isinstance(x, float): > >

[Tutor] Handling function parameters of mixed object and basic types

2006-09-04 Thread Duncan Gibson
I've taken over someone else's code (yes, honestly!) that has a complex class hierarchy on top of the main procedural code. This is unfortunate because it means that isinstance() is everywhere. Profiling recently highlighted one particular formatted output function that has a cascade of isinstan

Re: [Tutor] is there any Python code for spatial tessellation?

2005-10-10 Thread Duncan Gibson
This is off-topic for Python: I've seen this on the FLTK mailing list, but you might find some of the links under this page useful: http://myweb.tiscali.co.uk/oaktree/nshea/tesselsphere/tesselsphere_index.html "OpenGL spherical subdivision utility. Currently employs particle and geodesic mod

Re: [Tutor] deriving class from file to handle input line numbers?

2005-08-16 Thread Duncan Gibson
I wrote: > > class MyFile(file): > > etc > > > > I couldn't see how to have an instance of MyFile returned from the > > built-in 'open' function. I thought this was the crux of the problem. Kent Johnson replied: > open() is actually just an alias for file(): > >>> open is file > Tru

Re: [Tutor] deriving class from file to handle input line numbers?

2005-08-16 Thread Duncan Gibson
Kent Johnson wrote: > If you just want to keep track of line numbers as you read the file by lines, > you could use enumerate(): > > f = open('myfile.txt') > for line_number, line in enumerate(f): > ... This is neat, but not all of the parsers work on a 'line by line' basis, so sometimes there

[Tutor] deriving class from file to handle input line numbers?

2005-08-16 Thread Duncan Gibson
I was sure that this must be a frequently asked [homework?] question, but trying to search for 'file open line number' didn't throw up the sort of answers I was looking for, so here goes... I regularly write parsers for simple input files, and I need to give helpful error messages if the input is

[Tutor] pychecker: x is None or x == None

2005-08-12 Thread Duncan Gibson
We've been programming in Python for about a year. Initially we had a lot of tests of the form if x == None: do_something() but then someone thought that we should really change these to if x is None: do_something() However. if you run pychecker on these two snippets of