class too big for one file! How can I split it?

John Machin sjmachin at lexicon.net
Fri Apr 11 00:10:58 CEST 2003


meinmailfilter at gmx.de (HHaegele) wrote in message news:<e956b5f1.0304100512.597654d3 at posting.google.com>...
> OTLib.py :
> ---------------
> 
> XX = None
> 
> class Ot(a, e):
> 
>     def __init__(self, a = None, e = None):
>         global XX
>         XX = e    
>        
>     def Att(self):
>         global XX
>         print XX
>         ...
>         
> ---------------
> 
> Now, OTLib.py has more then 32000 lines. And that doesn´t work. Python
> 1.5 can´t execute then. So, how can I add the method Btt()? How can I
> make another file, which knows the global XX and who can be handled
> from the ot_starter, like it is in one file? Good would also be, if
> the Btt() can access XX the same way like Att() can. Is that possible?
> Or how must I change the structure?
> 
 
It does seem to be the number of lines that's a problem, not the size
of the information content. For example, a file huge.py created from:

   "# a biggie\n" + 40000 * "\n" + "def foo():\n   print 'bar'\n"

caused this:

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import huge
Traceback (innermost last):
  File "<stdin>", line 1, in ?
SystemError: com_addbyte: byte out of range

but changing the 40000 to 20000 gave the expected result.

So, why not delete some blank lines? Just enough to squeeze in the new
methods, not so many as to impair the legibility of your 32K line
source file :-)




More information about the Python-list mailing list