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 8617529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:52:56+00:00 2026-06-12T05:52:56+00:00

I’m new to the python programming language and I encountered a problem while doing

  • 0

I’m new to the python programming language and I encountered a problem while doing something (apparently not) fairly simple. This is the code :

# Get the list of available network interfaces
listNIC = os.system("ifconfig -s | awk '{print $1}'")
listNIC.split('\r?\n')

# Get the name of the wireless network card with iwconfig
wlanNIC = ''
i = 0
while i < len(listNIC) :
    if listNIC[i].match('eth[0-9]{1}') :
        wlanNIC = listNIC[i]
        break
    i += 1

First error comes at line 3, because for some odd reason listNIC is of type int. The error is :

Traceback (most recent call last):
  File "Kol.py", line 9, in <module>
    listNIC.split('\r?\n')
AttributeError: 'int' object has no attribute 'split'

I solved it by changing :

listNIC = os.system("ifconfig -s | awk '{print $1}'")

into

listNIC = str(os.system("ifconfig -s | awk '{print $1}'"))

But now I get an even stranger problem. I get an error that says that a string doesn’t have an attribute match. Here’s the error :

Traceback (most recent call last):
  File "Kol.py", line 15, in <module>
    if listNIC[i].match('eth[0-9]{1}') :
AttributeError: 'str' object has no attribute 'match'

So my question is the following :

  • How to solve the AttributeErrors and where do they come from ?

Thanks in advance !

  • 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-12T05:52:57+00:00Added an answer on June 12, 2026 at 5:52 am

    os.system returns the exit code of the command, not its output. You turn this number into a string, but this will not do what you want it to do. It is also deprecated. You might want to look at the subprocess module.

    output = subprocess.check_output('command', shell=True)
    

    Furthermore, you need to match using the module re. Check its documentation for the precise syntax, but it should look something like re.match(your_pattern, yourstring).

    Finally, although your version is not wrong, it is more common to loop through a list like in the sample below. It is slightly shorter and more readable as you save a variable and a call to len. It is also considered more pythonic.

    for nic in listNIC:
        if re.match(pattern, nic):
            wlanNIC = nic
            break
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.