- 重要な情報
- はじめに
- 用語集
- ガイド
- エージェント
- インテグレーション
- OpenTelemetry
- 開発者
- API
- CoScreen
- アプリ内
- Service Management
- インフラストラクチャー
- アプリケーションパフォーマンス
- 継続的インテグレーション
- ログ管理
- セキュリティ
- UX モニタリング
- 管理
ID: python-best-practices/open-add-flag
言語: Python
重大度: エラー
カテゴリー: ベストプラクティス
フラグが読み取り専用に開かれている場合は、ファイルを開くフラグを付ける必要はありません。
def print_foo():
with open("myfile.txt", "r") as myfile: # "r" フラグの指定は不要です
content = myfile.read()
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
def print_foo():
with open("myfile.txt") as myfile:
content = myfile.read()