ultra newbie question (don't laugh)

Gal Diskin gal.diskin at gmail.com
Tue Sep 26 10:09:49 EDT 2006


John Salerno wrote:
> Ok, I've decided to make a little project for myself which involves
> storing employee information in an XML file. I'm doing this partly to
> experiment with working with XML. The blocks in the file will look
> something like this:
>
> <researcher id="salerjo01">
>    <first_name>John</first_name>
>    <last_name>Salerno</last_name>
>    <birth_country>United States</birth_country>
>    <birth_state>Texas</birth_state>
>    <birth_city>Houston</birth_city>
>    #etc.......
> <researcher>
>
> I also plan to make a GUI frontend with wxPython for entering the
> records. This will be fairly easy, but not as fun as writing the logic.
> For now I've decided to focus just on writing the logic, and not worry
> about the GUI yet.
>
> So this is what I came up with so far, then I sat staring at the screen
> wondering how to proceed:
>
> class LabXMLWriter(object):
>
>      def write_name(self, first, last, given=''):
>
> Suddenly I realized I just have no idea how to start thinking about what
> I need to do. My first instinct was to use a class, as above, but then I
> wondered if that was even necessary, since all I need to do is get
> information from a user and write it to a file. Do I really need that
> information stored in an object?
>
> Then I wondered if I needed an __init__ method, and what could go in it?
> Or should I just make separate methods for each bit of information to
> write to the file (i.e., name, birth location, address, phone number,
> etc.). I thought maybe I could create the ID in the __init__ method
> (salerjo01), but to do that I need the name first. I could do this:
>
> def __init__(self, first_name, last_name, given_name=''):
>      # code to initialize name and create ID
>
> But then I wondered if this detracts from the work that the class
> methods would do later.
>
> So you see, what I'm asking for is very basic help, sort of along the
> lines of "what things do I need to consider before I even begin this?"
> Is OOP necessary here? Would utility functions work just as well for
> simply writing the information to a file?
>
> Perhaps I should just take some kind of programming intro class! I read
> all these Python books, but when it comes time to write something
> non-trivial, I get stuck almost immediately with all the possibilities.
>
> Thanks,
> John

I think this is marely a matter of programming style in your case. If
you like to use OOP use it. If not, don't. It doesn't seem to me that
OOP is necessary to anything you just mentioned. Don't let the
possibilities slow you - they're there so you can use whatever you
like, not to flood you with too many options.

Good luck,
Gal




More information about the Python-list mailing list