Understanding How to Open Files in Python

Asked 2 years ago, Updated 2 years ago, 113 views

I have a question about how to open the file in python.

I checked the actual file, but I found it on jupyter-notebook.

import matplotlib.pyplot as plt
import numpy as np
import pandas aspd
path='ch02/usagov_bitly_data2012-03-16-1331923249.txt'
open(path).readline()

even if you type in
FileNotFoundError    

That's what happens.By the way, this is the actual file.
http://ch02/usagov_bitly_data 2012-03-16-1331923249.txt

Please tell me how to open the file successfully

python python3 jupyter-notebook

2022-09-30 15:01

1 Answers

By the way, this is the actual file.
http://ch02/usagov_bitly_data2012-03-16-1331923249.txt

From the URL, you can see that the data is on the network and that the protocol that accesses it is HTTP.
 If so, I think it would be better to use tools for web scraping such as Beautiful Soup.

The extension is .txt, so you don't need to use HTML parsers because it's a text file.

"ch02" alone cannot identify the server.
Use a proper hostname, such as "ja.stackoverflow.com" or "whitehouse.gov".


2022-09-30 15:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.