5/9 Need an HELP


#1



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


How to fix the bug please ?


Replace this line with your code.


#2

Yup, I think there is a bug. This is how I resolved it.

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)
#my_file.close()
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"
    my_file = open("text.txt", 'w')
    my_file.write("I'm the first line of the file!" +"\n")
    my_file.write("I'm the second line."+"\n")
    my_file.write("Third line here, boss."+"\n")
    my_file.close()

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

#3

Hi.
I have this code but i can't fix the bug !

Always "refresh page"

But thanks a lot.


#4

Please post what you have.

Thank you.

Formatting it will help! :slight_smile:


#5

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()

In the console :

==show us the existing files ==
== if the file doesn't exist, create one ==
Creating the text.txt-file
I'm the first line of the file!

I'm the second line.

Third line here, boss.

None

Error message :

**

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

I am trying for 2 days but NOTHING let me pass.

**


#6

And my indentation is correct in the window editor.


#7

In your text.txt file, ensure it is as below and not with space.

I'm the first line of the file!
I'm the second line.
Third line here, boss.

I might have to refer you to a moderator, @albionsrefuge to help.


#8

There is spaces in the console but how can i resolve it ?


#9

Use the back space key. Or copy and paste the above posted.


#10

It doesn't work.
I give up.


#11

I resolved it.
I've changed text.text in texte.text.
That's all.

Thank you for your help.


#12

Okay.

Funny though.

Code on and don't "give up"! :slight_smile:


#13

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