读取config文件时路径os.path.realpath('.')

# coding:utf-8
import ConfigParser
import os


def config_reader():

    # 这个路径可以在文件被调用时,仍然路径正常
    root_dir = os.path.realpath('.')
    # 或者这个路径
    # root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    config = ConfigParser.ConfigParser()
    file_path = root_dir + '/config/config.ini'
    config.read(file_path)

    browser = config.get('browserType','browserName')
    url = config.get('testServer','URL')

    return browser, url



print config_reader()

猜你喜欢

转载自blog.csdn.net/weixin_38892128/article/details/86680125