[Python]将Excel文件中数据导入MySQL

来源:互联网 发布:永恒之塔人物数据男 编辑:程序博客网 时间:2024/06/05 09:57

PREPARE:

  1. xlrd包
    下载 https://pypi.python.org/pypi/xlrd (VERSION2.6, 2.7, 3.2+)
    安装 http://huaxia524151.iteye.com/blog/1173828
  2. mysql-connector-python
    下载 http://dev.mysql.com/downloads/connector/python/1.0.html
    安装 双击下载文件即可

LEARN:

  1. 字符串和数字的转换
    字符串->数字 int(string) string可以是字符串变量或者是一个字符串
    数字->字符串 str(num) num可以是数字变量或者是一个数字字符串
  2. 字符串操作
    http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html

  3. MySQL Python 教程 http://kodango.com/mysql-python-tutorial-part-one

  4. dict 中的 zip
    https://docs.python.org/2/library/stdtypes.html?highlight=dict#dict.items
    http://www.cnblogs.com/BeginMan/archive/2013/03/14/2959447.html
    >>> a = dict(one=1, two=2, three=3)
    >>> b = {'one': 1, 'two': 2, 'three': 3}
    >>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
    >>> d = dict([('two', 2), ('one', 1), ('three', 3)])
    >>> e = dict({'three': 3, 'one': 1, 'two': 2})
    >>> a == b == c == d == e
    True
  5. python使用mysql数据库
    http://www.cnblogs.com/fnng/p/3565912.html

    6.python之xlwt模块列宽width、行高Heights详解
    http://www.knowsky.com/886361.html

ERROR:

  1. unexpected indent: http://dikar.iteye.com/blog/308934
  2. SyntaxError{invalid syntax:
    1.检查缩进
    2.检查错误附近有没有少写 ‘(‘, ‘)’, ‘:’这些符号
  3. 建表 (#1064 - You have an error in your SQL syntax; check the manual that correspond )
    检查sql语句,表名,列名不能是关键字,标点符号不要写错,表名不能是纯数字-_-

  4. notepad++炸了
    注意及时备份,及时备份

  5. TypeError: list indices must be integers, not str
    indices – index 的复数,所以以上意为数组索引一定是整数值,不能是字符串

  6. UnboundLocalError: local variable ‘sql’ referenced before assignment
    存在未声明就使用的变量‘sql’,定义一下就完了

0 0