#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Writing and managing files


    Hello people, I have a minor problem regarding files in Python. It says something about a permission and denying it but I have not found any additional info about it and how it could help me. Here's what it says:

    My code as written:

    Name='MyFirstText.txt'
    The_File=file(Name,'w')
    Enter=raw_input('The Text ')
    The_File.write(Enter)
    The_File.close()

    and the error:

    Traceback (most recent call last):
    File "<modul1>", line 13, in <module>
    IOError: [Errno 13] Permission denied: 'MyFirstText.txt'



    Please, I've been stuck on this lesson for days and am having trouble moving on. Thanks for any response.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    4
    First of all, I think it's preferable to use "open(fname,mode)" rather than "file(fname,mode)". Still, I doubt that's your problem.
    What operating system are you on? You might actually not have permission to edit a file in the current directory. Which brings me to: what is the current directory? Try this:
    Code:
    import os
    print os.getcwd
    Better yet, explicitly qualify the file name:
    Code:
    Name="/abc/def/MyFirstText.txt"
    or on Windows
    Code:
    Name="c:/abc/def/MyFirstText.txt"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    164
    Rep Power
    20
    Originally Posted by howidied
    The_File=file(Name,'w')
    You mean open(Name, 'w') right?

    Originally Posted by howidied
    IOError: [Errno 13] Permission denied: 'MyFirstText.txt'
    Did you check if you have permission to write to the file? On your shell prompt (assuming you're working on unix), try this ls -l MyFirstText.txt
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    I am using Windows 7.

    I know about the permission but how do I get it, the permission I mean?
  8. #5
  9. Contributing User

    Join Date
    Aug 2011
    Posts
    5,284
    Rep Power
    504
    you may need to change the permission on the directory into which you want to write files. And change the permissions to what I do not for sure know.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo