Is there a Moderator on line?


#1



https://www.codecademy.com/fr/courses/python-intermediate-fr-FR-i3pwf/1/1?curriculum_id=5370f030fed2a866a2000001


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"
else:
    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.close()

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

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 ==
text.txt
script.py
== 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.

None


#2

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