0

I'm trying to pass argument inside function but no successes. the purpose of this function is to return xml tag this code doesn't work:

from bs4 import BeautifulSoup
def xmlTag(message):
 conf = open('timeLimit.conf').read().lower()
 for config in conf.splitlines():
    if config in conf.splitlines():
        data = BeautifulSoup(conf, "lxml")
        tag = data.message
        print(tag['msg'])

    break

xmlTag("fun2")

if i put fun2 instead of "message" variable, like this "tag = data.fun2" the code works please help what i"m doing wrong

1
  • Method names can't be parameters in Python. Consider passing a lambda as the parameter that accepts data as its input and returns a tag. Commented Jul 3, 2017 at 15:43

1 Answer 1

2

Try doing:

... tag = getattr(data, message) ...

getattr is the way of retrieving an attribute from an object when you have its name in a variable.

(Though your code have some other issues as well - that break statement where it is ensures your loop will terminate on the first iteration, for example)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.