Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7890843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:27:45+00:00 2026-06-03T06:27:45+00:00

I try to read a config file and assign the values to variables: #!/usr/bin/env

  • 0

I try to read a config file and assign the values to variables:

#!/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

it seems to do all fine except it doesn’t assign any value to the server variable

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:27:46+00:00Added an answer on June 3, 2026 at 6:27 am

    server symbol is not define in the scope you use it.

    To be able to print it, you should return it from configurebot().

    #!/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
            return line[1]
    
    
    print configurebot()
    

    You can also make it global by declaring it before the call to configurebot() as followed:

    server = None
    configurebot()
    print server
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to load a config file and read all the values
I'm new to Python and would like to read a config file using the
I have an app.config file inside my TestProject, but when I try to read
I try to read file /proc/'pid'/status, using c program. The code is as follows,
I am not able to read the appSettings from the config file ( MyService.exe.config
Puppy meta data gets read in from config file using (General::Config) and creates this
I created an App.config file in my WPF application: <?xml version="1.0" encoding="utf-8" ?> <configuration>
I have an app.config file that looks like this: <?xml version=1.0 encoding=utf-8 ?> <configuration>
I am reading bytes from a file using: FileSystem fs = config.getHDFS(); try {
i am trying to read values from properties file and when i tried to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.