【问题标题】:Concatenate a String and a variable in a .conf file在 .conf 文件中连接字符串和变量
【发布时间】:2021-12-06 02:47:54
【问题描述】:

我想问如何在 .conf 文件中连接字符串和变量。 示例:

settings.conf 文件中:

# The credential is in another, separate passphrase.conf file, declared as 'password'
    credential = passphrase/${password} 
      url = "XYZ.${credential}XYZ.com"

如果我按照我的示例中所示进行操作,我会收到一个错误,提示我的密码错误,所以它以某种方式连接不正确。

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python configuration config


【解决方案1】:

检查一下

import configparser
config = configparser.ConfigParser()
config.read('passphrase.conf')
pass=config['__REPLACE WITH CONFIG SECTION__']['password']
url = "XYZ"+pass+"XYZ.com"

【讨论】:

  • 这在 .conf 文件中不起作用:/
【解决方案2】:

这是连接字符串和变量的简单方法。

password_var = 123456
new_string = f"This is my password: {password_var}"

输出:
这是我的密码:1234

【讨论】:

  • 它也在一个 .conf 文件中。不是 .py :) 所以这不起作用...
猜你喜欢
  • 1970-01-01
  • 2013-10-23
  • 1970-01-01
  • 2018-12-17
  • 1970-01-01
  • 2016-11-15
  • 2018-06-23
相关资源
最近更新 更多