Getting File Permissions

H

Hari

Hi,
For getting permissions of a file, the following script has been
suggested in the same group

import os, stat
st = os.stat(myfile)
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)

But while executing I am getting error message as follows

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'octal' is not defined

Since I am new to python, can any one help me to solve this error?
A bunch of thanks in advance.

Hari
 
K

Kent Johnson

Hari said:
Hi,
For getting permissions of a file, the following script has been
suggested in the same group

import os, stat
st = os.stat(myfile)
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)

But while executing I am getting error message as follows

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'octal' is not defined

The correct name is oct(). The docs on built-in functions are helpful here:
http://docs.python.org/lib/built-in-funcs.html

Kent
 
J

Juho Schultz

Hari said:
Hi,
For getting permissions of a file, the following script has been
suggested in the same group

import os, stat
st = os.stat(myfile)
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)

But while executing I am getting error message as follows

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'octal' is not defined

Since I am new to python, can any one help me to solve this error?
A bunch of thanks in advance.

Hari

You can use "oct" instead of "octal".
 
T

Tim Chase

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'octal' is not defined

Since I am new to python, can any one help me to solve this error?

Looks like you just want the oct() function (not "octal()")
>>> [x for x in dir(__builtins__) if x.lower().find("oct")
!= -1]
['oct']

The __builtins__ will tell you what functions python
supports natively, and you can query against this list for
patterns, as done above.

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top