[Tutor] Please Help

Alan Gauld alan.gauld at btinternet.com
Sat Sep 7 14:47:29 EDT 2019


On 07/09/2019 13:22, Sean Frazier wrote:
> Then when I was working with the reference file, running a function, my IDLE crashed and is no longer able to locate files using [var = open('file.txt')]
>
> I have tried opening as 'r' and 'w', with no luck.
>
> Also, sometimes I do not get an error, but when I go to read the list, it is empty ''.

Start with basic investigations.


Check the path. What does:


>>> import os

>>> os.getcwd()

>>> os.listdir('.')

Produce?

Is it the folder with your fdile in it - does it appear in the listdir()
result?

If so then open the file with an ordinary text editor (or IDLE) and see
what it holds.
Is it corrupted?

What are the file permissions? Do they allow you to read/write etc?


If everything looks OK at this stage then try opening the file the old
shool way:


f = open(fname)

try examining the file objects attributes.

Try reading a single line. What do you get back?

Does it match ghe results using the text editor?


That should suffice to start with,. IF nothing shows up that explains
things
then let us know what you found.

A cut 'n paste of the session will be helpful...


-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list