“Python -Datei” Code-Antworten

Python -Dateizeile nach Zeile

with open("file.txt") as file_in:
    lines = []
    for line in file_in:
        lines.append(line)
Caleb McNevin

Python -Lesedatei

with open("file.txt", "r") as txt_file:
  return txt_file.readlines()
Supermavster

Python -Dateien

f = open('filename.txt', 'r') #open for reading (default)
f = open('filename.txt', 'w') #open for writing, truncating the file first
f = open('filename.txt', 'x') #open for exclusive creation, failing if the file already exists
f = open('filename.txt', 'a') #open for writing, appending to the end of the file if it exists
Jsandtrooper

Python -Datei offen

#there are many modes you can open files in. r means read.
file = open('C:\Users\yourname\files\file.txt','r')
text = file.read()

#you can write a string to it, too!
file = open('C:\Users\yourname\files\file.txt','w')
file.write('This is a typical string')

#don't forget to close it afterwards!
file.close()
Dr. Hippo

Python -Datei

>>> f = open('workfile', 'w')
Shy-ny Star-ling

Python -Datei

***Run error***
Traceback (most recent call last):
  File "__tester__.python3", line 5, in <module>
    fhandle.write(fcontentes)
NameError: name 'fcontentes' is not defined
Imansa Damindie

Ähnliche Antworten wie “Python -Datei”

Fragen ähnlich wie “Python -Datei”

Weitere verwandte Antworten zu “Python -Datei” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen