Re: [Tutor] Help

2010-05-14 Thread Steven D'Aprano
On Fri, 14 May 2010 06:08:30 pm she haohao wrote:

> Say I have a .fa file and I want to print a subsequence from the file
> without the \n how can i do it.
>
> Example: Inside the test.fa file I have
>
> >chromosome 1
>
> ACTGTGTTC
> ACGTCGACC
> AVGTT
> ACGTTaGTC
>
> so if I say i wan the subsequence starting from the 7th character to
> the 11th(i.e when i let p=(7+11)/2=9 and v=2) character.(excluding
> the first line), mean I want TTCAC.
>
> So how should I write the code so that \n does not appear if i want
> p=10 and v=3.


text = open('test.fa', 'r').read()  # includes newlines
text = text.replace('\n', '')  # remove newlines

To get the characters 7 to 11 inclusive "TTCAC", you have to remember 
that Python starts counting at 0, not 1, and the second position is 
excluded. So you have to write:

text[6:11]

to get TTCAC.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [SOLVED] First steps for C++/Qt developers

2010-05-14 Thread M. Bashir Al-Noimi

Thanks Alan,

On 15/05/2010 01:51 ص, Alan Gauld wrote:

"M. Bashir Al-Noimi"  wrote


> Although, I personally am a bit biased towards:
> http://www.cherrypy.org/
In simple words could you give me what's distinguished differences 
between cherrypy and django (I didn't stat with django cuz I'm still 
python principles)?


They work a little differently and Django gives you lots of extra 
features that CherryPy doesn't - you need extra libraries to get the 
exta features. (Things like a templating engine and onject persistent 
database access. I'm also not sure how much of an admin GUI CherryPy 
delivers out of the box) In fact you can use TurboGears which is a 
direct competitor to Django and uses CherryPy as part of its 
framework. (Or it did - I know the latest version of TG has changed a 
lot!)


One of the good and bad things about Python is that it supports many, 
many, different web tookits from the simplest CGI through to Zope and 
Plone which are enterprise class web frameworks(albeit with very 
different emphases). For most folks the middle ground includes things 
like Pylons, CherryPy and TG and Django. You can do most of what most 
people need with these and they are simpler in practice than either 
raw CGI or the heavyweight tools. So pick one and stick to it. Like 
languages or GUI toolkits, once you learn one moving to another is 
relatively painfree. Provided it does what you need and has a good 
support network don't stress over it!
After reading many posts and articles I picked up Django because it fits 
my needs till now.


Thanks once again for all.

--
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Luke Paireepinart
Thanks for that info, Alan! It's pretty awesome to have support for a
gui that looks native and is also included with Python by default.
I'll check it out soon.

On 5/14/10, Alan Gauld  wrote:
>
> "Luke Paireepinart"  wrote
>
>> well, but tkinter looks kinda crappy and non-native on almost every
>> platform.
>
> Check out the new themed widgets in Tkinter for Python 2.7 and 3.1
> They use native platform widgets so don't just look like the native
> interface they are the native interface...
>
> Hello world example here:
>
> http://www.testingreflections.com/node/view/8382
>
> Module doc here
>
> http://docs.python.org/dev/library/ttk.html
>
> And the Tk tutorial with screenshots here:
>
> http://www.tkdocs.com/tutorial/onepage.html
>
> And a new TKGui builder that includes support for Python - I haven't tried
> this
> yet...
>
> http://puretkgui.sourceforge.net/
>
> I'm hoping to add a page to my tutorial on the use of both Tix and ttk in
> the new Python v3 version, if I ever get time to finish it!
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First steps for C++/Qt developers

2010-05-14 Thread Alan Gauld

"M. Bashir Al-Noimi"  wrote


> Although, I personally am a bit biased towards:
> http://www.cherrypy.org/
In simple words could you give me what's distinguished differences 
between cherrypy and django (I didn't stat with django cuz I'm still 
python principles)?


They work a little differently and Django gives you lots of extra features 
that CherryPy doesn't - you need extra libraries to get the exta features. 
(Things like a templating engine and onject persistent database access. 
I'm also not sure how much of an admin GUI CherryPy delivers out of 
the box) In fact you can use TurboGears which is a direct competitor 
to Django and uses CherryPy as part of its framework. (Or it did - I 
know the latest version of TG has changed a lot!)


One of the good and bad things about Python is that it supports 
many, many, different web tookits from the simplest CGI through to Zope 
and Plone which are enterprise class web frameworks(albeit with very 
different emphases). For most folks the middle ground includes things 
like Pylons, CherryPy and TG and Django. You can do most of what 
most people need with these and they are simpler in practice than either 
raw CGI or the heavyweight tools. So pick one and stick to it. Like languages 
or GUI toolkits, once you learn one moving to another is relatively painfree. 
Provided it does what you need and has a good support network don't 
stress over it!


HTH,

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Alan Gauld


"Luke Paireepinart"  wrote


well, but tkinter looks kinda crappy and non-native on almost every
platform.


Check out the new themed widgets in Tkinter for Python 2.7 and 3.1
They use native platform widgets so don't just look like the native
interface they are the native interface...

Hello world example here:

http://www.testingreflections.com/node/view/8382

Module doc here

http://docs.python.org/dev/library/ttk.html

And the Tk tutorial with screenshots here:

http://www.tkdocs.com/tutorial/onepage.html

And a new TKGui builder that includes support for Python - I haven't tried this 
yet...


http://puretkgui.sourceforge.net/

I'm hoping to add a page to my tutorial on the use of both Tix and ttk in
the new Python v3 version, if I ever get time to finish it!

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating distribution lists in outlook

2010-05-14 Thread Alan Gauld


"Pirritano, Matthew"  wrote
 It does seem like the python solution is going to be too labor intensive. 
As with many such issues I thought it would be a fun challenge to see 
if I could get it to work. : )


You probably could, but there is another way. Python does not have 
Outlook's limitations so, if you only need the distro lists for 
announcements - or even as a mail relay - you could use Python's 
native email libraries. Build a simple config/admin UI of your own 
and then use Python to send out messages - which could be text files.
Or use Python (or indeed mailman or any other email list handler) 
as a relay so you send a mail to the relay and have it send the mail 
out to as many people as you want. That way you avoid Outlook's 
limits and all you need is an SMTP relay host. (You could even 
install sendmail or such to do that if you wanted)


And all for free...apart from the cost of administering it of course...

Alan G.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Hugo Arts
On Fri, May 14, 2010 at 7:55 PM, Gary Koskenmaki  wrote:
> Hi,
>
>
> My plan so far was to use tabs for the different functions of the
> application such as entering data into the database, viewing data, and
> running reports.  I'm running into problems combining tabs with multiple
> data fields and buttons.  I can create multiple fields(text boxes) with
> wxFrame and wxPanel, but when using wxNotebook to create tabs only the
> last text box in each tab shows up.  Say I have 3 text boxes, only the
> third one shows up.  If I comment it out the second one shows up.  I
> have a very similar problem with buttons.
>

I don't know how exactly you're doing it, but in general you'd create
a wxPanel for each tab, place all your controls on it, and then use
the notebook.addPage call to add the panel.

> I have read and experimented with the examples on wxpywiki with no joy.
> Using the following example from wxpywiki the text boxes created in the
> TabPanel class are shown on every tab.  When moving the text box
> creation to the NotebookDemo class, so that I can have different
> types/numbers of text boxes on each tab, I run into the problem of
> having more than one text field displayed in each tab.
>

Right, that example pretty uses the approach I describe. The example
does have three different tabs, they just all look the same because
they are created from the same class. Please show us what exactly the
code you're using that leads to the problem you describe. I suspect
this is where things go wrong.

Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] application with tabs

2010-05-14 Thread Luke Paireepinart
On Fri, May 14, 2010 at 12:55 PM, Gary Koskenmaki  wrote:
> Hi,
>
> I'm new to any kind of application development, but have done some
> python scripting.
>
> What I'm doing is creating an application for a non-profit social
> services organization that will allow them to track the services they
> give their clients.
>
> My plan so far was to use tabs for the different functions of the
> application such as entering data into the database, viewing data, and
> running reports.  I'm running into problems combining tabs with multiple
> data fields and buttons.  I can create multiple fields(text boxes) with
> wxFrame and wxPanel, but when using wxNotebook to create tabs only the
> last text box in each tab shows up.  Say I have 3 text boxes, only the
> third one shows up.  If I comment it out the second one shows up.  I
> have a very similar problem with buttons.
>

I have never used this tabbing before, but I'm guessing that you have
to catch the tab switching event and manually set the active panel
that the tab widget is displaying.
Something like (pseudocode)

panel1 = MyPanel()
panel2 = MyPanel2()
tabber = WxNotebook()

def myfunc(event):
if event.name == 'tab1':
tabber.set_active(panel1)
else:
tabber.set_active(panel2)

tabber.register_callback('tabswitch', myfunc)

That's purely a guess though.

>
> Am I going about creating this application interface in the most
> difficult way?  Is there a better/easier way to create multiple
> application views in the same window?  Can anyone recommend good books,
> tutorials, etc...?
>

Personally I like Qt more than WxWindows.  In fact I like TK more as
well, but tkinter looks kinda crappy and non-native on almost every
platform.
There are lots of resources for Qt, and for pyQt specifically.

This is probably not the right place to ask this question though,
we're more for general Python questions.  May be better to ask on a
wxpython list.

HTH,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help

2010-05-14 Thread Hugo Arts
On Fri, May 14, 2010 at 9:25 PM, Abhishek Mishra  wrote:
>
 linear1 = ''.join(foo.split('\n'))
 linear2 = foo.replace('\n','')
> ^^ these are the two ways in which you can linearize the input text by
> removing all  '\n'

+1 for the replace. More obvious, cleaner, more efficient.

Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help

2010-05-14 Thread Abhishek Mishra
Not sure if I understood the problem exactly, but you could linearize the
text by using something like this  --

>>> foo = '''ACTGTGTTC
... ACGTCGACC
... AVGTT
... ACGTTaGTC'''
>>> foo
'ACTGTGTTC\nACGTCGACC\nAVGTT\nACGTTaGTC'
>>> linear1 = ''.join(foo.split('\n'))
>>> linear1
'ACTGTGTTCACGTCGACCAVGTTACGTTaGTC'
>>>
>>> linear2 = foo.replace('\n','')
>>> linear2
'ACTGTGTTCACGTCGACCAVGTTACGTTaGTC'
>>>

>>> linear1 = ''.join(foo.split('\n'))
>>> linear2 = foo.replace('\n','')

^^ these are the two ways in which you can linearize the input text by
removing all  '\n'

after that you can grab 7th to 11th character like this -

>>> linear2[6:11]
'TTCAC'

^^ notice that the index is zero based, so 7th character actually 6 as its
index.

2010/5/14 she haohao 

>
>
> Hi,
>
>
> I am a beginner in python and I have a problem here and I hope someone can
> help me.
>
> Your help is greatly appreciated.
>
> Question.
>
> Say I have a .fa file and I want to print a subsequence from the file
> without the \n how can i do it.
>
> Example: Inside the test.fa file I have
>
> >chromosome 1
> ACTGTGTTC
> ACGTCGACC
> AVGTT
> ACGTTaGTC
>
> so if I say i wan the subsequence starting from the 7th character to the
> 11th(i.e when i let p=(7+11)/2=9 and v=2) character.(excluding the first
> line), mean I want TTCAC.
>
> So how should I write the code so that \n does not appear if i want p=10
> and v=3.
>
> Thanks for the help.
>
> Have a wonderful day ahead!
> Angeline
>
>
> --
> Hotmail: Powerful Free email with security by Microsoft. Get it 
> now.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help

2010-05-14 Thread she haohao

 

 

Hi,
 
 
I am a beginner in python and I have a problem here and I hope someone can help 
me.
 
Your help is greatly appreciated.
 
Question.
 
Say I have a .fa file and I want to print a subsequence from the file without 
the \n how can i do it.
 
Example: Inside the test.fa file I have
 
>chromosome 1
ACTGTGTTC
ACGTCGACC
AVGTT
ACGTTaGTC
 
so if I say i wan the subsequence starting from the 7th character to the 
11th(i.e when i let p=(7+11)/2=9 and v=2) character.(excluding the first line), 
mean I want TTCAC.
 
So how should I write the code so that \n does not appear if i want p=10 and 
v=3.
 
Thanks for the help.
 
Have a wonderful day ahead!
Angeline

  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] application with tabs

2010-05-14 Thread Gary Koskenmaki
Hi,

I'm new to any kind of application development, but have done some
python scripting.

What I'm doing is creating an application for a non-profit social
services organization that will allow them to track the services they
give their clients.  

My plan so far was to use tabs for the different functions of the
application such as entering data into the database, viewing data, and
running reports.  I'm running into problems combining tabs with multiple
data fields and buttons.  I can create multiple fields(text boxes) with
wxFrame and wxPanel, but when using wxNotebook to create tabs only the
last text box in each tab shows up.  Say I have 3 text boxes, only the
third one shows up.  If I comment it out the second one shows up.  I
have a very similar problem with buttons.

I have read and experimented with the examples on wxpywiki with no joy.
Using the following example from wxpywiki the text boxes created in the
TabPanel class are shown on every tab.  When moving the text box
creation to the NotebookDemo class, so that I can have different
types/numbers of text boxes on each tab, I run into the problem of
having more than one text field displayed in each tab.  

The first code example is the one I'm using.

http://wiki.wxpython.org/Notebooks

Am I going about creating this application interface in the most
difficult way?  Is there a better/easier way to create multiple
application views in the same window?  Can anyone recommend good books,
tutorials, etc...?  

I'm doing this on an i386 install of Debian and have python-wxgtk2.8
installed as well as libwxgtk2.8.  The version of python itself is
2.5.5.  All related packages are Debian packages.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First steps for C++/Qt developers

2010-05-14 Thread M. Bashir Al-Noimi

Thanks Steve,

On 14/05/2010 11:22 ص, steve wrote:

Hello Bashir,

On 05/13/2010 08:48 AM, M. Bashir Al-Noimi wrote:

Thanks Alan,
[...snip...]
Oh my god, I finished the basics of python within one day (continues 10
hours)!!!
What's amazing language :-*



Yes, everyone here feels the same way :). Anyways, now that you have a 
hang of python and you already know Qt, I would recommend playing 
around with PyQT just to get a feel of the language using API that you 
already know.


http://www.riverbankcomputing.co.uk/
http://www.commandprompt.com/community/pyqt/
Actually I wrote first PyQt application yesterday by using eric IDE, 
although it has stupid autocompleting and bad GUI but I could create 
Hello World app within 5 minutes, that's it.


My adventure in python going smoothly and community of python has truly 
open minds.




If you want to directly head on to learning Web Programming though, I 
suggest you start with:

http://www.djangobook.com/en/2.0/

Although, I personally am a bit biased towards:
http://www.cherrypy.org/

...which is a lean, no-frills web application framework.
In simple words could you give me what's distinguished differences 
between cherrypy and django (I didn't stat with django cuz I'm still 
python principles)?




Like other have mentioned, you don't need to know CGI programming to 
write web applications these days, but knowing how CGI works helps 
immensely. For a high level overview of web programming using python, 
see:


http://docs.python.org/howto/webservers.html

hth,
cheers,
- steve



--
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First steps for C++/Qt developers

2010-05-14 Thread steve

Hello Bashir,

On 05/13/2010 08:48 AM, M. Bashir Al-Noimi wrote:

Thanks Alan,
[...snip...]
Oh my god, I finished the basics of python within one day (continues 10
hours)!!!
What's amazing language :-*



Yes, everyone here feels the same way :). Anyways, now that you have a hang of 
python and you already know Qt, I would recommend playing around with PyQT just 
to get a feel of the language using API that you already know.


http://www.riverbankcomputing.co.uk/
http://www.commandprompt.com/community/pyqt/

If you want to directly head on to learning Web Programming though, I suggest 
you start with:

http://www.djangobook.com/en/2.0/

Although, I personally am a bit biased towards:
http://www.cherrypy.org/

...which is a lean, no-frills web application framework.

Like other have mentioned, you don't need to know CGI programming to write web 
applications these days, but knowing how CGI works helps immensely. For a high 
level overview of web programming using python, see:


http://docs.python.org/howto/webservers.html

hth,
cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Design Question: File Object used everywhere

2010-05-14 Thread spir ☣
On Fri, 14 May 2010 06:49:59 +0200
Jan Jansen  wrote:

> Hi there,
> 
> I'm working on a code to read and write large amounts of binary data 
> according to a given specification. In the specification there are a lot 
> of "segments" defined. The segments in turn have defintions of datatypes 
> and what they represent, how many of some of the data values are present 
> in the file and sometimes the offset from the beginning of the file.
> 
> Now I wonder, what would be a good way to model the code.
> 
> Currently I have one class, that is the "FileReader". This class holds 
> the file object, information about the endianess and also a method to 
> read data (using the struct module). Then, I have more classes 
> representing the segements. In those classes I define data-formats, call 
> the read-method of the FileReader object and hold the data. Currently 
> I'm passing the FileReader object as arguement.
> 
> Here some examples, first the "FileReader" class:
> 
> class JTFile():
> 
>  def __init__(self, file_obj):
>  self.file_stream = file_obj
>  self.version_string = ""
>  self.endian_format_prefix = ""
> 
>  def read_data(self, fmt, pos = None):
>  format_size = struct.calcsize(fmt)
>  if pos is not None:
>  self.file_stream.seek(pos)
>  return struct.unpack_from(self.endian_format_prefix + fmt, 
> self.file_stream.read(format_size))

Since JTFile (as name says) is mainly a file, you could subtype it from file, 
thus avoiding its file_stream attribute and replacing 
self.file_stream.read/seek with direct self.read/seek. Also, this better 
mirrors the model, I guess.

> and here an example for a segment class that uses a FileReader instance 
> (file_stream):
> 
> class LSGSegement():
> 
>  def __init__(self, file_stream):
>  self.file_stream = file_stream
>  self.lsg_root_element = None
>  self._read_lsg_root()
> 
>  def _read_lsg_root(self):
>  fmt = "80Bi"
>  raw_data = self.file_stream.read_data(fmt)
>  self.lsg_root_element = LSGRootElement(raw_data[:79], raw_data[79])
> 
> So, now I wonder, what would be a good pythonic way to model the 
> FileReader class. Maybe use a global functions to avoid passing the 
> FileReader object around? Or something like "Singleton" I've heard about 
> but never used it? Or keept it like that?

A singleton object is just a unique instance of a type. The singleton pattern 
simply ensures this unicity by refusing to create more instances. The python 
way, I guess, is rather a gentleman agreement, which in this case means 
creating a single instance and no more, since you are the only user of your 
file-reading service. If this were to be distributed as module, then document 
this "uncity" point, or implement the singleton pattern.
(But I don't understand why there should be only one file-reader. Rather, there 
should be only one per (disk) file ;-) If you make the type a subtype of file, 
then this is certainly automatically ensured since no 2 python file objects can 
point to the same disk file -- I guess -- to be checked.)

> Cheers,
> 
> Jan

Denis


vit esse estrany ☣

spir.wikidot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Design Question: File Object used everywhere

2010-05-14 Thread Dave Angel

Jan Jansen wrote:

Hi there,

I'm working on a code to read and write large amounts of binary data 
according to a given specification. In the specification there are a 
lot of "segments" defined. The segments in turn have defintions of 
datatypes and what they represent, how many of some of the data values 
are present in the file and sometimes the offset from the beginning of 
the file.


Now I wonder, what would be a good way to model the code.

Currently I have one class, that is the "FileReader". This class holds 
the file object, information about the endianess and also a method to 
read data (using the struct module). Then, I have more classes 
representing the segements. In those classes I define data-formats, 
call the read-method of the FileReader object and hold the data. 
Currently I'm passing the FileReader object as arguement.


Here some examples, first the "FileReader" class:

class JTFile():

def __init__(self, file_obj):
self.file_stream = file_obj
self.version_string = ""
self.endian_format_prefix = ""

def read_data(self, fmt, pos = None):
format_size = struct.calcsize(fmt)
if pos is not None:
self.file_stream.seek(pos)
return struct.unpack_from(self.endian_format_prefix + fmt, 
self.file_stream.read(format_size))


and here an example for a segment class that uses a FileReader 
instance (file_stream):


class LSGSegement():

def __init__(self, file_stream):
self.file_stream = file_stream
self.lsg_root_element = None
self._read_lsg_root()

def _read_lsg_root(self):
fmt = "80Bi"
raw_data = self.file_stream.read_data(fmt)
self.lsg_root_element = LSGRootElement(raw_data[:79], 
raw_data[79])


So, now I wonder, what would be a good pythonic way to model the 
FileReader class. Maybe use a global functions to avoid passing the 
FileReader object around? Or something like "Singleton" I've heard 
about but never used it? Or keept it like that?


Cheers,

Jan



I agree with Luke's advice, but would add some comments.

As soon as you have a global (or a singleton) representing a file, 
you're making the explicit assumption that you'll never have two such 
files open.  So what happens if you need to merge two such files?  Start 
over?  You need to continue to pass something representing the file 
(JTFile object) into each constructor.


The real question is one of state, which isn't clear from your example.  
The file_stream attribute of an object of class JTFile has a file 
position, which you are implitly using.  But you said some segments are 
at fixed positions in the file, and presumably some are serially related 
to other segments. Or perhaps some segments are really a section of the 
file containing smaller segments of different type(s).


Similarly, each object, after being created, probably has relationship 
to other objects.  Without knowing that, you can't design those object 
classes.


Finally, you need to decide early on what to do about data validation.  
If the file happens to be busted, how are you going to notify the user.  
If you read it in an ad-hoc, random order, you'll have a very hard time 
informing the user anything useful about what's wrong with it, never 
mind recovering from it.


It's really a problem in serialization, where you read a file by 
deserializing.  Consider whether the file is going to be always small 
enough to support simply interpreting the entire stream into a tree of 
objects, and then dealing with them.  Conceivably you can do that 
lazily, only deserializing objects as they are referenced.  But the 
possibility of doing that depends highly on whether there is what 
amounts to a "directory" in the file, or whether each object's position 
is determined by the length of the previous one.


In addition to deserializing in one pass, or lazily deserializing, 
consider deserializing with callbacks. In this approach you do not 
necessarily keep the intermediate objects, you just call a specified 
user routine, who should keep the objects if she cares about them, or 
process them or ignore them as needed.


I've had to choose each of these approaches for different projects, and 
the choice depended in large part on the definition of the data file, 
and whether it could be randomly accessed.


DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor