外部cfg
(設定)ファイルからパスを読み取ることは可能ですか?cfgファイルから変数を読み取ることはできますか?
ファイルを開くアプリケーションを作成しています。現在私はパスを何度もコピーして貼り付けなければなりません。 cfg
ファイルにパスを書き、Pythonプログラムから呼び出したいと思います。
この私のPythonのファイル:
import ConfigParser
import os
class Messaging(object):
def __init__(self):
self.config = ConfigParser.RawConfigParser()
self.rutaExterna = os.path.join(os.getcwd(), "app/properties.cfg")
self.config.read(['properties.cfg', self.rutaExterna])
def net(self):
# with open('/etc/network/interfaces', 'r+') as f:
direccion = self.config.read('direccion', 'enlace')
with open('direccion') as f:
for line in f:
found_network = line.find('network')
if found_network != -1:
network = line[found_network+len('network:'):]
print ('network: '), network
return network
CFGファイル:
[direccion]
enlace = '/etc/network/interfaces', 'r+'
私は私のcfg
ファイルで変数にファイルパスを保存したいです。
次に、その変数をPythonファイルで使用してそのファイルを開くことができます。
が機能しました。ありがとう! –