python - 没有使用 Python 的此类文件或目录
问题描述
我正在尝试用python编写一个程序,它从文件中读取用户名列表并向instagram发送请求以查看用户名是否可用。然后它应该提示一条消息说“此用户名可用”或“此用户名已被使用”。我在尝试读取我的文件时遇到错误,该文件指出“FileNotFoundError: [Errno 2] No such file or directory:'list.txt”,即使该文件位于程序所在的文件夹中。
我对 python 也很陌生。
这是我目前的代码:
import requests
filepath = 'list.txt'
separator = "\n" #Every time you use a newline it detects it as a new user
list = open(filepath, "r").read().split(separator)
notTaken = []
for i in list :
response = requests.get("https://instagram.com/" + i + "/")
if response.status_code == 404 :
notTaken.append(i)
解决方案
它在我的情况下有效。我list.txt
与我的 python 文件在同一个目录中
import requests
with open('list.txt','r') as f:
data = f.read().split("\n")
for i in data:
pass
#...(write the rest of the code)
推荐阅读
- c# - 如何在 LINQ 查询中将日期时间值与毫秒精度进行比较
- node.js - 汇总:如何要求 json 但不将其包含在包中
- angular - 角度发布请求参数未正确传递
- c# - 如何存储mysql查询的结果
- excel - 循环遍历表并删除数据
- ruby-on-rails - Rails 首先或初始化选择多个枚举
- sql-server - 从高级编辑器与数据转换转换更改数据类型
- angular - 如何强制 Angular 7+ Material Autocomplete 输入仅由数据源提供的字母?
- javascript - 如何在 Electron 中使用背景滤镜?
- angularjs - 如何在模式中设置自定义单选按钮的默认值