Use of factory pattern in Python?

  • Thread starter Nathan Harmston
  • Start date
N

Nathan Harmston

Hi,

Im trying to find the best way to do a certain task and my so far I
have found that using something similar to factory pattern might be
the best bet.

I m parsing a file to be stored as a graph (using NetworkX). Each row
in the file corresponds to a node in the graph. However rows have
different types and different numbers of attributes. ( and their
corresponding nodes in the future will have methods )
eg

chr1 SGD gene 5 8 id=1 name=3 dbref=6
chr1 SGD intron 5 6 id=5 notes="spam"
chr1 SGD exon 7 8 id=5

so I was thinking of having a factory class to return the individual
objects for each row......ie

class Factory():
# if passed a gene return a gene object
# if passed an intron return an intron object
# if passed an exom return an exon object

Is this a good way of doing this, or is there a better way to do this
in Python, this is probably the way I d do it in Java.

Many Thanks

Nathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top