Is there a Moderator on line?


Refresh, refresh, refresh.

import os
print "==show us the existing files =="
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
    print str(f)

print "== if the file doesn't exist, create one =="
if os.path.exists('text.txt'):
    print "File exists"
    print "Creating the text.txt-file"
    mon_fichier = open("text.txt", 'w')
    mon_fichier.write("I'm the first line of the file!" +"\n")
    mon_fichier.write("I'm the second line."+"\n")
    mon_fichier.write("Third line here, boss."+"\n")

mon_fichier = open("text.txt","r")
print mon_fichier.readline()
print mon_fichier.readline()
print mon_fichier.readline()

Oups, merci de réessayer. Désolé, mais vous allez devoir actualiser la page ! Ne vous inquiétez pas, votre code est sauvegardé. 

==show us the existing files ==
== if the file doesn't exist, create one ==
File exists
I'm the first line of the file!

I'm the second line.

Third line here, boss.



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.