0

I am having a small confusion on assigning variable to another variable . I have a code which takes value in a filter variable as

filter = '(uid=tommy)'

I am trying to pass tommy via command line using

user_id = sys.argv[1:]
print user_id
filter = '(uid=user_id)'

But of-course this doesn't replace the variable user_id , how can i achieve this ??

2
  • 1
    filter = '(uid={})'.format(user_id) Commented Apr 2, 2018 at 5:55
  • @xnx thanks man ! works Commented Apr 2, 2018 at 5:57

1 Answer 1

1

You need string format function:

user_id = "tommy"
filter = '(uid={})'.format(user_id)
print(filter)
# (uid=tommy)
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.