python program for accessing values from csv files and storing it into a database using wamp
Question: I am new to Python and [WampServer](http://www.wampserver.com/en/). I want to
retrieve values from csv files (more than 10 GB) and, after some processing,
store them in a MySQL database using Wamp efficiently.

I have installed Python and Django on Wamp server, and have checked the
previous posts, but since I am a complete novice in this field, I am not
getting much from them.

Can somebody please suggest appropriate resources for a beginner like me? I
have already looked into [Python Power! The Comprehensive
Guide](http://rads.stackoverflow.com/amzn/click/1598631586), but I did not get
much from it. Any help would be appreciated.


Answer: You can read data from CSV files using the built-in [`csv`
module](http://docs.python.org/library/csv.html). For example:

    
    
    >>> import csv
    >>> open('test.csv','w').write('1,one\n2,two\n3,three\n')
    >>> list(csv.reader(open('test.csv')))
    [['1', 'one'], ['2', 'two'], ['3', 'three']]
    

You can write data to MySQL using the [`MySQL-python`
package](http://pypi.python.org/pypi/MySQL-python), which conforms to the
[Python database API](http://www.python.org/dev/peps/pep-0249/) and is
[documented here](http://mysql-python.sourceforge.net/MySQLdb.html). For
example, after you've installed this package, you can do this kind of thing:

    
    
    >>> import MySQLdb
    >>> conn = MySQLdb.connect(host, user, passwd, db)
    >>> cursor = conn.cursor()
    >>> cursor.executemany('INSERT INTO numbers (value, name) VALUES (%, %)',
    ...                    [['1', 'one'], ['2', 'two'], ['3', 'three']])
    ... 
    >>> cursor.commit()
    

However, if you're using Django to manage the database, then you may be better
off using Django's own database interface, for example
[`Model.save`](https://docs.djangoproject.com/en/dev/ref/models/instances/#saving-
objects) to save an instance of a model to the database.

