[Tutor] File Writing Permission?

David Millar davmillar at gmail.com
Sun Oct 7 20:53:04 CEST 2007


Hi everyone,

I'm working on making a Debian package for a game I'm working on, and it
works fine, but I've run into a problem with my script now. The script is
placed in /usr/bin so all users on the system have access, but even though
it will run fine, I can't save files to that directory, so the saving
feature doesn't work and the rest of my game is crippled now. Any ideas on
how I could progress? I tried appending "~/" to the filename for that copy
of the script, but it just makes the terminal window close without warning.
Any help would be appreciated.

def savegame(fname):
    # This part isn't necessary, I just wanted to see if it would save to
the user's home folder
    if os.name == "posix":
        fname = "~/" + fname
    infile = open(fname,"w")
    # Save the maps
    mapchanges.append([6,1,rrmap])
    mapchanges.append([6,2,treemap])
    picklelist = [choins, inventory, book, mapchanges, event, cdata]
    pickle.dump(picklelist,infile)
    # Delete the saved maps because they will just get in the way later
    del mapchanges[len(mapchanges)-1]
    del mapchanges[len(mapchanges)-1]
    infile.close()

David Millar
http://www.thegriddle.net/python/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071007/f31fea00/attachment.htm 


More information about the Tutor mailing list