473,387 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Mar 7 '06 #1
3 4085
Hari wrote:
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
Mar 7 '06 #2
Hari wrote:
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".
Mar 7 '06 #3
> 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



Mar 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
4
by: Nick | last post by:
I'm developing an intranet app, and want to get the current user name for logging purposes. I've turned off anonymous access, and turned on windows authentication in the IIS config. The apps...
2
by: RAB | last post by:
I tested my code on my local computer and it worked fine. When I uploaded it to my webserver at Godaddy.com, I get the following error... Exception Details: System.Data.OleDb.OleDbException:...
10
by: John Salerno | last post by:
I always read about how you need to set certain file permissions (for cgi files, for example), but it's never been clear to me *how* you do this. I know you can run the line chmod 755...
1
by: mattcushing | last post by:
I'm trying to use a button click to download a file from a table I built using Iron Speed designer. When I am on my machine, it's fine, but when I move it to the server, it fails when it's...
1
by: kratc | last post by:
Hello. I've been wondering for quite a while now if this even is without trying to open the file or something like that? I'm trying to list all the files in a directory (with subdirectories) to...
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.