0

I am trying to concat output of a sql output to a string as below:

dwh_cur.execute("""select name from sales where id = 123""")
name = dwh_cur.fetchone()[0]
a = print(name)
b = str(a) + " is the name of the agent"
print(b)

The above returns

None is the name of the agent

Expected output:

Steve is the name of the agent
1
  • 2
    Remove a = , i.e.: print(name); b = f"{name} is the name of the agent" Commented Dec 13, 2018 at 12:29

1 Answer 1

1
a = print(name)

returns None

Try:

b = "{} is the name of the agent".format(name)
Sign up to request clarification or add additional context in comments.

4 Comments

The str(name) part is useless - name is already a string. And this would better be done using string formatting, ie b = "{} is the name of the agent".format(name)
yes you're right. i just copied the line from him and changed 'a' to 'name' to make it work for him :)
But it's not too late to edit your post ;) (SO is not only about "making it work", it's also about "making it right").
true, i edieted my post !

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.