[Tutor] inserting path to open a file from a variable

Alan Gauld alan.gauld at btinternet.com
Thu May 28 23:04:58 CEST 2015


CCing tutor list.
ASlways use ReplyAll (or ReplyList ) to include the list.

On 28/05/15 19:08, richard kappler wrote:
>
>     What I've tried (none worked):
>     file = open(rd1, 'r')
>
>
> This should have worked.
>
> What happened when you tried it? "Did not work" is a tad vague!
>
> Traceback (most recent call last):
> File "21FileMonitor.py", line 28, in <module>
> file = open(rd1, 'r')
> IOError: [Errno 2] No such file or directory: 
> 'Documents/MyScripts/fileMonitor/log.txt'
>

Notice that path is a relative path not an absolute one.
Its looking for a folder called Documents in the current directory.


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