Reputation: 380
I am having an issue finding an answer to this, currently below is my get request, currently I have one variable "tii", I need to add another variable to put as the URL IP, how can I add another variable? If I add it with tii I do not understand how to specify which var you want placed where.
group_1_a_source = requests.get("http://100.104.35.16/slot/6//htdocs/v.api/apis/EV/GET/parameters/960.0.%s" % tii)
Upvotes: 3
Views: 2311
Reputation: 21
Use either f string
or concatenation. I havent tried concatenation for urls yet but explore it. If you want a quick solution just use an f string I always use it in case of urls.
Upvotes: 2
Reputation: 1721
You can use Python's f-string
functionality to achieve that. For example, you could write—
variable_1 = "foo"
variable_2 = "bar"
group_1_a_source = requests.get(f"http://100.104.35.16/slot/6//htdocs/v.api/apis/EV/GET/parameters/960.0.{variable_1}.{variable_2}")
Upvotes: 2
Reputation: 1153
This is more of a strings question to me. You can use fstrings:
a = 1
b = 'hello'
c = f'{b} there sir. The number is {a}'
print(c)
>>> hello there sir. The number is 1
In your case it would be:
r = f"http://100.104.35.16/slot/6//htdocs/v.api/apis/EV/GET/parameters/960.0.{tii}.{other_variable}" # or however else you need to format it
group_1_a_source = requests.get(r)
Or something similar
Upvotes: 4