我有一个配置文件,我正在使用ConfigParser阅读。 其中一个值是路径中包含空格的文件路径:
[Configuration]
mysqldumpexecutable_location = C:/Program Files (x86)/MySQL/MySQL Server 5.7/bin/
对于此参数,get()返回的值似乎只是“C:/ Program” - 直到空格。
以下是相关代码:
import os
import time
import datetime
import configparser
def BackupDB():
try:
config = configparser.RawConfigParser()
config.read(r"etc\configuration.txt")
DB_HOST = config.get('Configuration', 'db_host')
DB_USER = config.get('Configuration', 'db_username')
DB_USER_PASSWORD = config.get('Configuration', 'db_password')
#DB_NAME = '/backup/dbnames.txt'
DB_NAME = config.get('Configuration', 'db_schema')
BACKUP_PATH = config.get('Configuration', 'backup_path')
MYSQLDUMP_LOCATION = config.get('Configuration', 'mysqldumpexecutable_location')
DATETIME = time.strftime('%d%m%Y-%H%M%S')
TODAYBACKUPPATH = BACKUP_PATH + DATETIME
db = DB_NAME
dumpcmd = MYSQLDUMP_LOCATION + "mysqldump -u " + DB_USER + " -p" + DB_USER_PASSWORD + " " + db + " > " + TODAYBACKUPPATH + "/" + db + ".sql"
os.system(dumpcmd)
except Exception as e:
print("something here")
return None
我收到此错误: 'c:/ Program'未被识别为内部或外部命令, 可操作程序或批处理文件。
如何正确传递此Windows路径?
谢谢!