構成ファイルを読み取って、値を変数に割り当てようとします。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
with open('bot.conf', 'r') as bot_conf:
config_bot = bot_conf.readlines()
bot_conf.close()
with open('tweets.conf', 'r') as tweets_conf:
config_tweets = tweets_conf.readlines()
tweets_conf.close()
def configurebot():
for line in config_bot:
line = line.rstrip().split(':')
if (line[0]=="HOST"):
print "Working If Condition"
print line
server = line[1]
configurebot()
print server
サーバー変数に値を割り当てないことを除いて、すべてうまくいくようです
ck@hoygrail ~/GIT/pptweets2irc $ ./testbot.py
Working If Condition
['HOST', 'irc.piratpartiet.se']
Traceback (most recent call last):
File "./testbot.py", line 23, in <module>
print server
NameError: name 'server' is not defined