0
def Save_hotels():

    global numberOfHotels
    global My_Hotels

    file = open('data.csv', "w", newline="\n")
    dataEX = csv.writer(file, delimiter=",")

    mylist = [numberOfHotels]
    dataEX.writerow(mylist)

    for hotel in My_Hotels:

        mylist = [hotel.ID,hotel.Name,hotel.Stars,hotel.Rooms]

        for i in hotel.Reservations:
            res = [i.Customer_Name,i.Date,i.Time]
            mylist.extend(res)

        dataEX.writerow(mylist)

    file.close()

Here's the error:

File "D:/Python Projects/Domes Dedomenwn Project(2017)/Main.py", line 54, in 
Save_hotels
file = open('data.csv', "w", newline="\n")
PermissionError: [Errno 13] Permission denied: 'data.csv'
jez
  • 14,867
  • 5
  • 37
  • 64
Garry
  • 1
  • 1
  • What makes you think you have permission to write to that file? – Scott Hunter May 17 '17 at 18:09
  • did you run it once then open data.csv? is it still open? – Nick is tired May 17 '17 at 18:09
  • 1
    Welcome to StackOverflow! please read [How to ask a good question](https://stackoverflow.com/help/how-to-ask). Asking question properly will help you get better answers and help others be able to understand your question if they have a similar problem. – Mike - SMT May 17 '17 at 18:11
  • @jez How did you edit this post? I tried to do the exact same thing you just did and the editor told me I needed to add more info. – Mike - SMT May 17 '17 at 18:13
  • @SierraMountainTech The "Edit Questions And Answers" privilege is awarded at 2000 reputation. – jez May 17 '17 at 18:14
  • @jez: I can still propose edits. I have done so several times. I guess at 2000 you can edit content without restrictions from the editor. – Mike - SMT May 17 '17 at 18:15
  • 2
    `data.csv` might be already open. Or it might exist and have particular permissions set on it (or be owned by a different user) preventing you from overwriting it. Or (more likely) your current *working directory* (query it with `os.getcwd()`; change it with `os.chdir()` ) might not be one in which your username has permission to create files. – jez May 17 '17 at 18:22
  • This is exactly what the "open" function is supposed to do, according to the python documentation. https://docs.python.org/2/library/functions.html#open If the file cannot be opened, IOError is raised. (We know it's python2 because it would be OSError in python3) The error message further says it failed because you do not have permission. – Kenny Ostrom May 17 '17 at 19:17
  • http://stackoverflow.com/questions/29331872/ioerror-errno-13-permission-denied – whackamadoodle3000 May 18 '17 at 00:49
  • http://stackoverflow.com/questions/10575750/python-ioerror-errno-13-permission-denied – whackamadoodle3000 May 18 '17 at 00:49
  • http://stackoverflow.com/questions/40984791/python-errno-13-permission-denied – whackamadoodle3000 May 18 '17 at 00:50
  • http://stackoverflow.com/questions/18529323/permission-denied-error-while-writing-to-a-file-in-python – whackamadoodle3000 May 18 '17 at 00:51
  • http://stackoverflow.com/questions/36434764/permissionerror-errno-13-permission-denied – whackamadoodle3000 May 18 '17 at 00:51
  • http://stackoverflow.com/questions/13207450/permissionerror-errno-13-in-python – whackamadoodle3000 May 18 '17 at 00:51

0 Answers0