-1

i am not getting the proper result

running the code using various variable values

import urllib.request
x=input("enter the source link") # from where the file is to be downloaded
y=input("enter the destination address") # where the file is to be saved
z=input("enter file name") # the name by which you wish to save
s=input("enter extension type") # the extension of the file
url = x  # from where the file is to be downloaded
urllib.request.urlretrieve(url, 'y/z.s') # using variables to write the destination 

print('Beginning file download') # ensure success of above code

i am getting an error in output due to line 7 in destination folder

following error


FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-f187f3520048> in <module>
      5 s=input("enter extension type") # the extension of the file
      6 url = x  # from where the file is to be downloaded
----> 7 urllib.request.urlretrieve(url, 'y/z.s') # using variables to write the destination
      8 
      9 print('Beginning file download') # ensure success of above code

C:\ProgramData\Anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
    255         # Handle temporary file setup.
    256         if filename:
--> 257             tfp = open(filename, 'wb')
    258         else:
    259             tfp = tempfile.NamedTemporaryFile(delete=False)

FileNotFoundError: [Errno 2] No such file or directory: 'y/z.s'

please guide

I8PI
  • 1
  • 1

2 Answers2

0

You use them in the same way as you would in any other string; by concatenation or interpolation.

'{}/{}.{}'.format(y, z, s)

or

f'{y}/{z}.{s}

or

y + '/' + z + '.' + s
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0
f'{x}:{y}'

use format for concat str. or use + operator dreactly.

goudan
  • 58
  • 4