Re: simple client data base

Discussion in 'Python' started by Thomas 'PointedEars' Lahn, Sep 4, 2012.

  1. Mark R Rivet wrote:

    > Hello all, I am learning to program in python. I have a need to make a
    > program that can store, retrieve, add, and delete client data such as
    > name, address, social, telephone number and similar information. This
    > would be a small client database for my wife who has a home accounting
    > business.
    >
    > I have been reading about lists, tuples, and dictionary data
    > structures in python and I am confused as to which would be more
    > appropriate for a simple database.
    >
    > I know that python has real database capabilities but I'm not there
    > yet and would like to proceed with as simple a structure as possible.
    >
    > Can anyone give me some idea's or tell me which structure would be
    > best to use?
    >
    > Maybe its a combination of structures? I need some help.


    The data types that would choose are defined by your requirements and how
    well a data type meets your requirements.

    I can imagine: In a database you would want quick access to data. You would
    want to access fields primarily by name. You would also want to filter data
    by various criteria.

    Therefore, it appears to me that it would be best if your records were
    dictionaries or dictionary-like objects, and your recordsets were lists of
    records, like so

    #!/usr/bin/env python3

    from datetime import date

    data = [
    {
    'lastname': 'Doe',
    'firstname': 'John',
    'sn': '123-451-671-890',
    'birthdata': date(2000, 1, 2)
    },
    {
    'lastname': 'Doe',
    'firstname': 'Jane',
    'sn': '409-212-582-452',
    'birthdata': date(2001, 2, 3)
    },
    ]

    - You could quickly access the second record with data[1].
    - You could access the 'lastname' field of the second record with
    data[1]['lastname']
    - You could get a list of records where the person is born before 2001 CE
    with filter(lambda record: record['birthdate'] < date(2001, 1, 1), data)

    The advantage of dictionaries over dictionary-like objects is that they are
    easily extensible and that the memory footprint is probably lower (CMIIW);
    the disadvantage is slightly more complicated syntax and that you have to
    keep track of the keys. Therefore, you might want to consider instantiating
    a Record class instead; in its simplest form:

    class Record(object):
    def __init__(self, lastname, firstname, sn=None, birthdate=None):
    self.lastname = lastname
    self.firstname = firstname
    self.sn = str(sn)
    self.birthdate = birthdate

    data = [
    Record(lastname='Doe', firstname='John', sn='123-451-671-890',
    birthdate=date(2000, 1, 2)),
    Record(lastname='Doe', firstname='Jane', sn='409-212-582-452',
    birthdate=date(2001, 2, 3))
    ]

    - You could access the 'lastname' property of the second record with
    data[1].lastname
    - You get a list of records where the person is born before 2001 CE with
    list(filter(lambda record: record.birthdate < date(2001, 1, 1), data))
    (in Python 2.x without list())

    However, if you want your program to manipulate the data *persistently*. as
    it will probably be needed for business, you will need to also store it
    somewhere else than in the volatile memory in which these data structures
    are usually stored. The most simple way would be to store and parse the
    string representation of the objects.

    Production-quality implementations of those and other concepts already
    exist, of course, but using something finished and polished does not provide
    as much learning experience.

    HTH

    --
    PointedEars

    Twitter: @PointedEars2
    Please do not Cc: me. / Bitte keine Kopien per E-Mail.
     
    Thomas 'PointedEars' Lahn, Sep 4, 2012
    #1
    1. Advertising

  2. Mark R Rivet wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >> Mark R Rivet wrote:
    >>> Hello all, I am learning to program in python. I have a need to make a
    >>> program that can store, retrieve, add, and delete client data such as
    >>> name, address, social, telephone number and similar information. This
    >>> would be a small client database for my wife who has a home accounting
    >>> business.
    >>>
    >>> I have been reading about lists, tuples, and dictionary data
    >>> structures in python and I am confused as to which would be more
    >>> appropriate for a simple database.

    >>
    >> […]
    >> However, if you want your program to manipulate the data *persistently*.
    >> as it will probably be needed for business, you will need to also store
    >> it somewhere else than in the volatile memory in which these data
    >> structures are usually stored. The most simple way would be to store and
    >> parse the string representation of the objects.
    >>
    >> Production-quality implementations of those and other concepts already
    >> exist, of course, but using something finished and polished does not
    >> provide as much learning experience.

    >
    > Now this is the kind of answer I was hoping for. This gives me food
    > for thought. Now I have some Ideas of how to appproach this thing. I
    > know that there are solutions to this problem already but I need to do
    > my own before I can really use anything better. Thanks for the help. I
    > fully intend to go with a real realational database, but not now. My
    > version 1 will be a console interface and dictionaries, lists and
    > pickling. Version 2 will be with a GUI written in tkinter, and better
    > and better. I just want to learn how to lay the bricks before I start
    > using prefab walls.


    You are welcome. However, I have to concur with the others that in terms of
    efficiency and reliability, which leads to household peace, you are better
    off starting with a prepackaged solution instead.

    You can keep developing your Python-powered database as a pet project for
    the time being. Your wife will be even more impressed if at one day you can
    tell her that you wrote completely customizable software that works the same
    or even better than the one she has been getting used to :) Even if not,
    you will have learned much about Python and related concepts along the way.
    Keep in mind, then, that you probably also need a graphical user interface.

    Please trim your quotes to the relevant minimum next time.

    --
    PointedEars

    Twitter: @PointedEars2
    Please do not Cc: me. / Bitte keine Kopien per E-Mail.
     
    Thomas 'PointedEars' Lahn, Sep 11, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin P. Hellwig

    Re: simple client data base

    Martin P. Hellwig, Sep 3, 2012, in forum: Python
    Replies:
    0
    Views:
    195
    Martin P. Hellwig
    Sep 3, 2012
  2. Chris Angelico

    Re: simple client data base

    Chris Angelico, Sep 3, 2012, in forum: Python
    Replies:
    0
    Views:
    197
    Chris Angelico
    Sep 3, 2012
  3. Mark Lawrence

    Re: simple client data base

    Mark Lawrence, Sep 3, 2012, in forum: Python
    Replies:
    0
    Views:
    183
    Mark Lawrence
    Sep 3, 2012
  4. Peter Otten

    Re: simple client data base

    Peter Otten, Sep 3, 2012, in forum: Python
    Replies:
    1
    Views:
    242
    Dennis Lee Bieber
    Sep 8, 2012
  5. Wolfgang Keller

    Re: simple client data base

    Wolfgang Keller, Sep 3, 2012, in forum: Python
    Replies:
    2
    Views:
    261
    Wolfgang Keller
    Sep 4, 2012
Loading...

Share This Page