日期:2014-05-16  浏览次数:20450 次

辅助生成mysql数据库的表字段
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''辅助生成mysql数据库的表字段'''

user_fields='Id,Name'
order_fields = 'id,status'

def generate_table_fields(name,strFields):    
    with open(r'd:\%s.sql' % (name),'w') as f:
        f.write(','.join(["`%s` varchar(45) DEFAULT NULL" % (f.lower()) for f in strFields.split(',')]))

if __name__=="__main__":
    generate_table_fields('users',user_fields)
    generate_table_fields('orders',order_fields)