溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

configparser.ConfigParser.writer()

發(fā)布時間:2020-07-21 11:50:05 來源:網(wǎng)絡(luò) 閱讀:557 作者:cooperfang 欄目:編程語言
    ①
    write(fileobject, space_around_delimiters=True)

Write a representation of the configuration to the specified file object,which must be opened in text mode(accepting strings),This representation can ba parsed by a future read() call.if space_around_delimiters is true,delimiters between keys an values are surrounded by spaces.

config = configparser.Configparser()
must be opened in text mode (accept strings):只能使用text模式打開的文件才能被寫入,with open('users.pkl', 'w') as f:
config.writer(f)

②
read(filenames, encoding=None)
            If filenames is a string or path-like object, it is treated as a single filename. If a file named in filenames cannot be opened, that file will be ignored. This is designed so that you can specify a list of potential configuration file locations (for example, the current directory, the user’s home directory, and some system-wide directory), and all existing configuration files in the list will be read.

If none of the named files exist, the ConfigParser instance will contain an empty dataset. An application which requires initial values to be loaded from a file should load the required file or files using read_file() before calling read() for any optional files:

    import configparser, os

config = configparser.ConfigParser()
config.read_file(open('defaults.cfg'))

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI