5/9 Bug


#1



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


I have done all the exercises but i have to do again this one.
Why ? It was correct yersteday and now i am still on 99%.
Don't understand and always the same message :

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


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


#2

Sorry I am not fluent in french but, should there be a + here?:

If you want to read-only, just r will suffice.

mon_fichier = open("texte.text","r")

What do you want to do?


#3

Hi.
Thank you for you post but i try different way to resolved it with + or not but it doesn't work.


#4

Please post full-code, and well formatted for this exercise.


#5

mon_fichier = open("texte.text","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é.

Traceback (most recent call last):
File "python", line 1, in
IOError: [Errno 2] No such file or directory: 'texte.text'


#6

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

Python Reading Between the Lines Unable to Complete Exercise
#7

Always refresh page.
I tried before with this code but i can't pass.
But in the console every thing is correct :

==show us the existing files ==
script.py
== 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


#8

Hmmm... Now that is strange. I just posted same result here: 5/9 and it worked.

Please refresh and use all code I suggested.


#9

I have done it refreshing several times but it's driving me crazy.
But thanks a lot.
I would need an administrator or a moderator.


#10

Okay, @zystvan could help. He's a moderator. :slight_smile:


#11

Thank you.
The problem is i have done this exercise yesterday and it worked.


#12

Okay!

That's fine! :slight_smile:


#13

@snakefinger33gmail.c Here are two possible workarounds I found, thanks to @albionsrefuge:

Workaround 1: go to the text.txt tab and make any insignificant change

Workaround 2: add these two lines to the top of the exercise's code

my_file = open("text.txt","w") 
my_file.close()

Please let me know whether one/both of those works for you or not, and I can take a closer look at what might be going wrong if necessary :slight_smile:


#14

Hi zystvan.
Thank you for your Help.
I have resolved the problem.

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

In this code i have changed my_file to mon_fichier
and
text.text to texte.text
and it worked.

Thanks a lot.
Now i start Javascript.


#15

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