RE: Fixed-length text file to database script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Edwin.Madari@VerizonWireless.com

    RE: Fixed-length text file to database script

    here is a working code snippet to read from MySQL db.
    python tutorial has examples of reading from files.
    put them together to do your task.
    =============== =============== =============== ======
    import MySQLdb

    con = MySQLdb.connect (host='127.0.0. 1',
    port=4321, user='joe', passwd='shmoe', db='tst')
    cursor = con.cursor()
    sql = 'select * from YOUR_TABLE'
    cursor.execute( sql)
    results = cursor.fetch()
    con.close()
    =============== =============== =============== ========

    hope that helps. good luck
    Edwin
    -----Original Message-----
    From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
    [mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
    On Behalf Of Diez B. Roggisch
    Sent: Thursday, August 14, 2008 7:11 AM
    To: python-list@python.org
    Subject: Re: Fixed-length text file to database script


    Stacey wrote:
    Hi Guys,

    I'm new to Python (mostly) and I'm wanting to use it for a new project
    I'm faced with.

    I have a machine (PLC) that is dumping its test results into a
    fixed-length text file. I need to pull this data into a database
    (MySQL most likely) so that I can access it with Crystal Reports to
    create daily reports for my engineers.

    I've been reading the Python manual for about a week now and I'm
    learning a lot. Unfortunately, I was given a deadline today that I
    cannot meet without a little help.

    I need to know how to write a script that will DAILY pull this text
    file into a MySQL database.

    Can anyone show me how to do this?
    Show us code & data, and we show you how to improve the code.

    Or would you be able to write the script with the above information?

    Diez
    --



    The information contained in this message and any attachment may be
    proprietary, confidential, and privileged or subject to the work
    product doctrine and thus protected from disclosure. If the reader
    of this message is not the intended recipient, or an employee or
    agent responsible for delivering this message to the intended
    recipient, you are hereby notified that any dissemination,
    distribution or copying of this communication is strictly prohibited.
    If you have received this communication in error, please notify me
    immediately by replying to this message and deleting it and all
    copies and backups thereof. Thank you.


Working...