Re: Why NOT only one class per file?

2007-04-04 Thread Dillon Collins
On Wednesday 04 April 2007, Chris Lasher wrote:
> He doesn't find my arguments convincing, so I thought I'd ask here to
> see why the Python idiom is the way it is: why should we NOT be
> placing classes in their own separate files?

Because it really just provides as an artificial limitation that could only be 
annoying at best?  After all, programmers can put one class per file if the 
want anyway.

I know I would like Python less if I had to make a directory of files each 
with somehing like:

class MyError(Exception):
   pass

Of course, there are other cases as well where logically grouping classes is 
much nicer.  However, at the end of the day the question is almost 
meaningless because of the way Python treats classes.  
Examples:

class A(object):
class B:
pass
C=A.B

class A(object):
pass
A=1

class A(object):
pass
B=type('B', (object,), {})


The first creates a class with a contained class, but then "exports" the 
contained class as C.  The second creates class A, but then destroys it by 
writing over it with the value 1.  The third also creates a class A, but this 
time creates a top-level class B.  You'll note that the method of 
construction allows for B to be created dynamically.

So the idea of one class per file is almost meaningless.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: encoding ascii data for xml

2008-10-04 Thread Dillon Collins
On Friday 03 October 2008, harrelson wrote:
> import xml.dom.minidom
> print chr(3).encode('utf-8')
> dom = xml.dom.minidom.parseString( "%s" %
> chr(3).encode('utf-8') )
>
> chr(3) is the ascii character for "end of line".  [...] My
> question is why doesn't encode() blow up?

You just answered your question.  0x03 may not be a printing character, but it 
is a valid character in the ascii character set and therefore is not a 
problem.  For xml, however, it is an illegal character so that's why the 
parser is throwing an error.
--
http://mail.python.org/mailman/listinfo/python-list