Reputation: 133
I want to write a function decode(chmod) that takes a three digit permissions number as a string and returns the permissions that it grants. It seems to be working unless I ask for the zeroth element. I couldn't figure out why so.
def decode(chmod):
liste = [int(i)for i in str(chmod)]
chmod = ["None", "Execute only", "Write only",
"Write and Execute", "Read only",
"Read and Execute", "Read and Write",
"Read Write and Execute"]
for i in liste:
print chmod[i]
return liste
print decode(043)
Upvotes: 0
Views: 129
Reputation: 44444
(Assuming you want to pass an integer)
043 is base 8 is same as 35 in base 10. You are therefore passing the integer 35 to the decode function.
Try changing the str
-> oct
liste = [int(i) for i in oct(chmod)[2:]] #Use [2:] in Py3, and [1:] in Py2
Upvotes: 1