Python Forum
working with file problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
working with file problem
#1
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$
Reply
#2
Why are you using the bash type command? Did you mean to use cat?
Reply
#3
because I'm a dog.
Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020