簡體   English   中英

Pyspark-Python3使用configparser從文件獲取變量

[英]Pyspark - Python3 get variable from file using configparser

我正在嘗試使用Configparser從文件獲取變量,但它總是返回字符串而不是變量。 請協助

config.ini

[db]
connection_sting =sqlContext.read.format(driver).load(table_nm)

config_conn = ConfigParser() 
conn_string = config_conn.get('db', 'connection_sting')

當前結果:

conn_string = 'sqlContext.read.format(driver).load(table_nm)'

預期:

conn_string = sqlContext.read.format(driver).load(table_nm)

只是不要嘗試。 配置文件用於提供配置選項,而不是可執行代碼。

代替

config.ini

[db]
driver = some_format
table_nm = some_table

config = configparser.ConfigParser()
config.read("config.ini")

connection_sting = (sqlContext.read
    .format(config.get("db", "driver")
    .load(config.get("db", "table_nm")))

並且,如果您需要可執行代碼,請使用適當的模塊,而不是配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM