gosatriani
gosatriani

Reputation: 307

how to pass variable value to urllib in python

How do I pass the value of variable a the below url after token:

   a = 123
   import urllib
   testfile = urllib.URLopener()
   testfile.retrieve("'https://test.test.com/comp/export?format=csv& 'token:' ,"data.csv")

Upvotes: 0

Views: 41

Answers (1)

Rakesh
Rakesh

Reputation: 82765

You can use str.format

Ex:

a=123
import urllib
testfile = urllib.URLopener()
testfile.retrieve("https://test.test.com/comp/export?format=csv&token:{0}".format(a),"data.csv")

Demo:

a = 123
print("https://test.test.com/comp/export?format=csv&token:{0}".format(a))
https://test.test.com/comp/export?format=csv&token:123

Upvotes: 1

Related Questions