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

  • SEARCH
  • Home
  • 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 8950339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:25:56+00:00 2026-06-15T13:25:56+00:00

I have a requirement to create repeating config files using the IP and hostnames

  • 0

I have a requirement to create repeating config files using the IP and hostnames of some servers. This data is contained in a large list similar to the mock data included;

192.168.0.1 -   data    info    hosta
192.168.0.2 -   data    info    hostb
192.168.0.3 -   data    info    hostc
192.168.0.4 -   data    info    hostb

This data contains arbitrary information that I don’t want, such as the following items, ‘

-   data    info    '

I had the idea that I could read the split data into a list.
Then I would be able to loop over the list specifying only each numbered element within the list to be displayed, leaving only;

192.168.0.1
192.168.0.2
...

This would then be placed into a new list containing only the IP addresses.

I created a function that would read the the file into a list

def importlines():
    mf = open('C:\\scripts\\nagios\\filename.txt','r')
    lines = mf.read().split()
    print(lines)
mf.close()

#the data is read in correctly
#I then attempted to create a blank list
hosts = []

#then append the output from the function call to the list
hosts.append(importlines())

However this results in ‘None’, if I execute hosts.append(importlines()) once again I’m met with None,None. So it’s it seems to be appending an elememt containing nothing into the list. I’ve tried executing hosts.append(print(importlines())) however I have the same issue.

As you can tell I’m what you might describe as an accidental sysadmin and have no experience in this. I’m also aware of the issue that this will create one large list, in my head I believe I require a list containing a list of each line. Am I off the mark here?

Thanks,

  • 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-15T13:25:58+00:00Added an answer on June 15, 2026 at 1:25 pm

    You are splitting the whole file, not each line. Moreover, your function only prints, it doesn’t actually use return to return the result to the caller.

    def importlines():
        with open('C:/scripts/nagios/filename.txt') as mf:
            return [l.split()[0] for l in mf]
    

    would return only a list of ip addresses. You can assign the result directly to hosts:

    hosts = importlines()
    

    Your own code did not return anything in importlines(), and the default return values for a python function is None.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI, I have a requirement to create instance for list object at runtime using
If I have a requirement to create a data structure that has the following
I have a requirement to create some objects that implement a given interface, where
I have a requirement to create a simple database in Access to collect some
I have a requirement to create some NSDecimalNumber objects objects as part of my
Hi I have requirement to create ,compile and load java classes run time. Using
I have a requirement to create some xml structs (to borrow a C-phrase) in
I have a requirement to create internationalization with regular text files (perhaps simple xml).
I have a requirement to create a linq query that selects data from a
I have a requirement to create an application to upload data into database from

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.