0

I have a url link for a zip file. I want to download the zip file. Then I want to list the name of all files that are in the zip file. One of them is a .csv file. I also want to read from the csv file.

Can anybody tell me how I can do it in python3?

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Mina
  • 11
  • 7
  • Other than `ZipFile`? – Ignacio Vazquez-Abrams Feb 15 '18 at 23:36
  • I'm even stuck in the first step. I use 'zf = zipfile.ZipFile('http://files.grouplens.org/datasets/movielens/ml-latest-small.zip', 'r')' and I get an error of OSError: [Errno 22] Invalid argument: 'http://files.grouplens.org/datasets/movielens/ml-latest-small.zip' – Mina Feb 15 '18 at 23:42
  • Welcome to SO. Unfortunately this isn't a discussion forum or tutorial. Please take the time to read [ask] and the other links on that page. Invest some time with [the Tutorial](https://docs.python.org/3/tutorial/index.html) practicing the examples. It will give you an idea of the tools Python offers to help you solve your problem. [“Can someone help me?” not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). – wwii Feb 15 '18 at 23:45
  • @mina the path you are supplying is a malformed web url. It shoudl probably be `http://files.grouplens.org/datasets/movielens/ml-latest-small.zip`. I doubt if `ZipFile` will actually download the file (not sure if it does the docs will tell you). You will need to use another function to download the file to your local disk and then use `ZipFile` on the saved file. – Paul Rooney Feb 16 '18 at 00:10

1 Answers1

2
  • Thanks for your response. I'm a newbie in Python and this is the first code I am writing. Your links are quite intense. I am a little confused how to use them. – Mina Feb 15 '18 at 23:47
  • 1
    @Mina if you are finding the docs a bit hard going, may I suggest you search for simple examples of each step online [example](https://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python), you'll find these will often bring you back to SO. This answer is a 'tough love' answer and the idea is you take the steps laid out before you and discover how to do each one in turn. You gain much more from this, than if you get the complete answer laid out before you, so you can just cut and paste it and learn nothing from it. – Paul Rooney Feb 16 '18 at 00:12
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/18837448) – Graham Feb 16 '18 at 03:25
  • thanks for info @Graham – Altan Özlü Oct 27 '18 at 19:54