“mit offenem Python” Code-Antworten

Offene Anwendungen von Python

dir = 'C:\\myprogram.exe'

import os
os.startfile(dir)
os.system(dir)

import subprocess
subprocess.Popen([dir])
subprocess.call(dir)
Erorri Motrali

mit offenem Python

#pystyle
with open("test.txt", encoding = 'utf-8') as f:
  file = f.read()
#classic
file = open("file.txt")
file.close()
psw

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 lesen

fin = open("NAME.txt", 'r')
body = fin.read().split("\n")
line = fin.readline().strip()
Bewildered Baboon

mit offen als Datei Python

>>> with open('workfile') as f:
...     read_data = f.read()

>>> # We can check that the file has been automatically closed.
>>> f.closed
True
Powerful Platypus

mit offenem Python

with open(...) as f:
    for line in f:
        # Do something with 'line'
Harish Vasanth

Ähnliche Antworten wie “mit offenem Python”

Fragen ähnlich wie “mit offenem Python”

Weitere verwandte Antworten zu “mit offenem Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen