Python Forum

Full Version: working with file problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to work with a file but getting but I am unable to get it working correctly.

I created the following programme:

outFile = open('grades.txt','w')
grade = 0
print("Enter a grade (q to quit):")
grade = raw_input()
while (grade != 'q'):
       outFile.write(grade + '\n')
       print("Enter a grade (q to quit):")
       grade = raw_input()

outFile.close()
The command prompt:

Sandys-MBP:~ sandycaskie$ python writefile.py
Enter a grade (q to quit):
100
Enter a grade (q to quit):
90
Enter a grade (q to quit):
80
Enter a grade (q to quit):
q
Sandys-MBP:~ sandycaskie$ type grades.txt
-bash: type: grades.txt: not found
Sandys-MBP:~ sandycaskie$
Why are you using the bash type command? Did you mean to use cat?
because I'm a dog.
Make sure that your python script is run from the same directory as
you're searching from. As you are using linux, try typing

~
Then run your python2 script again and if the script exits ok you should
be able to see your created file with

ls grades.txt

Use cat or less or any text editor to view the file.