473,396 Members | 2,061 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,396 software developers and data experts.

How to control permission of file?

When one open()s a file (that doesn't exist) for writing , how
does one control that file's permissions (it's "mode" in Unix
terms).

--
Grant Edwards grante Yow! We just joined the
at civil hair patrol!
visi.com
Jun 30 '06 #1
5 4370
Grant Edwards wrote:
When one open()s a file (that doesn't exist) for writing , how
does one control that file's permissions (it's "mode" in Unix
terms).


Check out 'os.open'
It returns a file descriptor, and if you need a file object you can use
'os.fdopen' on the file descriptor

Regards
Sreeram

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEpYMFrgn0plK5qqURAsmWAJ9XmpwyuHCQBTd7Kti0ZL YEgM/PWwCfXLFP
UPtBmB5uTmW6ZgbAi6uOPMo=
=NEmK
-----END PGP SIGNATURE-----

Jun 30 '06 #2
On 2006-06-30, K.S.Sreeram <sr*****@tachyontech.net> wrote:
Grant Edwards wrote:
When one open()s a file (that doesn't exist) for writing , how
does one control that file's permissions (it's "mode" in Unix
terms).


Check out 'os.open'
It returns a file descriptor, and if you need a file object you can use
'os.fdopen' on the file descriptor


Thanks. I thought maybe there was a less arcane way to do it.

--
Grant Edwards grante Yow! FROZEN ENTREES may
at be flung by members of
visi.com opposing SWANSON SECTS...
Jun 30 '06 #3
Grant Edwards schrieb:
When one open()s a file (that doesn't exist) for writing , how
does one control that file's permissions (it's "mode" in Unix
terms).


what do you mean by "contor file's mode"?

usually you try to open and if you are not allowed
you will get the exception
try: .... f = file("/etc/shadow")
.... print f.read()
.... except IOError, e:
.... print e
....
[Errno 13] Permission denied: '/etc/shadow'
if you want to know more about file attributes
use os.stat and constants from stat module
import os
os.stat("/etc/shadow") (33184, 245390L, 771L, 1, 0, 15, 604L, 1151702662, 1149675585, 1149675585)
import stat
stat.ST_SIZE 6 os.stat("/etc/shadow")[stat.ST_SIZE] 604L


http://docs.python.org/lib/module-stat.html

hth, Daniel

Jun 30 '06 #4
On 2006-06-30, Schüle Daniel <uv**@rz.uni-karlsruhe.de> wrote:
When one open()s a file (that doesn't exist) for writing , how
does one control that file's permissions (it's "mode" in Unix
terms).
what do you mean by "contor file's mode"?


Are you asking what a file's mode is?

Under Unix, it's a bitmapped value that determines what the
access permissions are for the file. There are individual bits
that enable permissions for user-read, user-write,
user-execute, group-read, group-write, group-execute,
other-read, other-write, other-execute, etc.

If you look at os.open() there's a "mode" parameter (the same
as the mode parameter in Unix's libc open()). I wanted to know
how to control a file's mode when it was created by the builtin
open().

I'm afraid I don't know how else to say it.
usually you try to open and if you are not allowed you will
get the exception
try: ... f = file("/etc/shadow")
... print f.read()
... except IOError, e:
... print e
...
[Errno 13] Permission denied: '/etc/shadow'

True, but I don't see what it has to do with my question.
if you want to know more about file attributes


Um, thanks. I know all about file attributes.

--
Grant Edwards grante Yow! Inside, I'm already
at SOBBING!
visi.com
Jun 30 '06 #5
True, but I don't see what it has to do with my question.


my mistake, I misunderstood your question

as Sreeram said, os.open can be used
help(os.open)

Help on built-in function open:

open(...)
open(filename, flag [, mode=0777]) -> fd

Open a file (for low level IO).

import os
fd=os.open("secret", os.O_WRONLY|os.O_CREAT, 0400)
os.write(fd,"not for everybody") 17 os.close(fd)

ls -l secret
-r-------- 1 root root 17 2006-07-01 00:05 secret
Regards, Daniel
Jun 30 '06 #6

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

Similar topics

12
by: Russ | last post by:
Hello. My new dev machine is running XP Pro. In the past all equipment has only used Windows 2000. I have had a lot of problems getting my projects up and running on the new machine. The current...
16
by: Marina | last post by:
Hi, I am trying to find the minimum security settings to allow a windows control embedded in IE have full trust. If I give the entire Intranet zone full trust, this works. However, this is...
1
by: Moe | last post by:
I have a winForm control that contains an openFileDialog. I am using this control in a webForm by enbedding it using an <object> tag. I need to access some information about the file on the client....
5
by: dbuchanan | last post by:
Is it possible to detect the SQLS2K column level permission for the logged in user. I want to be able to hide a control or Button based on user permission to edit that column. Can anyone...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
0
by: Matt | last post by:
I have an intranet asp.net application that I am hosting a windows control in. The control is referenced using the <object> tag in the html. The control interfaces with a usb i/o device on the...
0
by: gxl034000 | last post by:
Hi, I have been trying to use a .net Forms control in my webpage to open up an application(notepad) on the client. The control works fine when embedded in a windows form, but I keep getting a...
2
by: Budhi Saputra Prasetya | last post by:
Hi, I managed to create a Windows Form Control and put it on my ASP .NET page. I have done the suggestion that is provided by modifying the security settings. From the stack trace, I would...
0
by: Budhi Saputra Prasetya | last post by:
Hi, I still have the same problem with embedding Windows Control. I'll just requote what I posted last time: I managed to create a Windows Form Control and put it on my ASP .NET page. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.