“Plik istnieje Python” Kod odpowiedzi

Python Sprawdź, czy plik istnieje

import os

os.path.exists("file.txt") # Or folder, will return true or false
Duco Defiant Dogfish

Jak sprawdzić, czy plik istnieje w Python

import os.path

if os.path.isfile('filename.txt'):
    print ("File exist")
else:
    print ("File not exist")
Lovely Lyrebird

Python OS, jeśli istnieje plik

import os.path

if os.path.isfile('filename.txt'):
    print ("File exist")
else:
    print ("File not exist")
Stupid Stoat

Plik istnieje Python

import os.path

if os.path.exists('filename.txt'):
    print ("File exist")
else:
    print ("File not exist")
Puzzled Penguin

Python Sprawdź, czy plik istnieje

#using pathlib
from pathlib import Path

file_name = Path("file.txt")
if file_name.exists():
    print("exists") 
else:
    print("does not exist") 
Fun Bee

Jak sprawdzić, czy plik istnieje Pyuthon

import os
file_exists = os.path.exists("example.txt") # Returns boolean representing whether or not the file exists
Vivacious Vole

Odpowiedzi podobne do “Plik istnieje Python”

Pytania podobne do “Plik istnieje Python”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu