Getting File Permissions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hari

    #1

    Getting File Permissions

    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

  • Kent Johnson

    #2
    Re: Getting File Permissions

    Hari wrote:[color=blue]
    > 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[/color]

    The correct name is oct(). The docs on built-in functions are helpful here:


    Kent

    Comment

    • Juho Schultz

      #3
      Re: Getting File Permissions

      Hari wrote:[color=blue]
      > 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
      >[/color]

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

      Comment

      • Tim Chase

        #4
        Re: Getting File Permissions

        > Traceback (most recent call last):[color=blue]
        > 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?[/color]

        Looks like you just want the oct() function (not "octal()")
        [color=blue][color=green][color=darkred]
        >>> [x for x in dir(__builtins_ _) if x.lower().find( "oct")[/color][/color][/color]
        != -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







        Comment

        Working...