用python遍历目录下文件(不包括子目录)

#!/usr/bin/env python
#coding=gbk
__author__ = 'lc'

import MySQLdb
import glob
import os
import sys

DB_HOST = "localhost"
DB_USER = "root"
DB_PWD = "root"
DB_DATABASE = "database"
CHARVAR_PATH = "dir"
NOT_EXIST_FILE = "./not_exist_character.txt"
EXPORT_SQL_FILE = "./character_var.sql"

def check_arg():
    if len(sys.argv) != 2:
        print("参数不正确! 用法: convert_charvar.py 变量目录")
        exit(1)
        
    global CHARVAR_PATH
    CHARVAR_PATH = sys.argv[1]
    
def convert_and_dump():
    check_arg()
    print("正在执行转换, 请稍候......")
    
    try:
        fp = None        
        cursor = None
        sql_fp = open(EXPORT_SQL_FILE, "w")
        not_exist_fp = open(NOT_EXIST_FILE, "w")
        dbConn = MySQLdb.connect(DB_HOST, DB_USER, DB_PWD, DB_DATABASE)
        cursor = dbConn.cursor()

你可能感兴趣的:(python,python,sql,character,insert,file,database)