Lev Elblert wrote:
[color=blue]
> Does Python allow to open files in shared mode like fsopen or _open
> do? If not how to make it happen?[/color]
Probably the "os" module's version of open() will do what you
need: http://docs.python.org/lib/os-fd-ops.html, assuming the
standard builtin open() is not doing what you need.
The file() constructor probably takes any second argument that your OS's
fopen() does, though this may have changed with the creation of
universal newlines.
If there's something that os.open() can do that file() can't, you
should be able to achieve it by using os.fdopen(): (untested)
def magic_file(file name, flag=os.O_RDONL Y, mode='r', bufsize=None):
fd = os.open(filenam e, flag)
return os.fdopen(fd, mode, bufsize)
On Sat, 18 Jun 2004, Lev Elblert wrote:
[color=blue]
> Does Python allow to open files in shared mode like fsopen or _open
> do? If not how to make it happen?[/color]
Assuming you're on a Win32 platform, I think the msvcrt module has what
you're looking for. The standard file object supports only the standard C
library file stream API.
Andrew MacIntyre <andymac@bullse ye.apana.org.au > wrote in message news:<mailman.6 8.1087793423.45 4.python-list@python.org >...[color=blue]
> On Sat, 18 Jun 2004, Lev Elblert wrote:
>[color=green]
> > Does Python allow to open files in shared mode like fsopen or _open
> > do? If not how to make it happen?[/color]
>
> Assuming you're on a Win32 platform, I think the msvcrt module has what
> you're looking for. The standard file object supports only the standard C
> library file stream API.[/color]
This extension returnns a Python file object or rases an exception.
Also MS docs say, that fsopen is ANSI C function. I do not have access
to unix machine, so can't check it.
On Mon, 21 Jun 2004 10:28:24 -0400, Peter Hansen <peter@engcorp. com>
declaimed the following in comp.lang.pytho n:
[color=blue]
> Lev Elblert wrote:
>[color=green]
> > 2. msvcrt.lib does have a lot of functions, but not msvcrt module in
> > Python. (correct me if I'm wrong)[/color]
>
> http://docs.python.org/lib/module-msvcrt.html shows there are a variety
> of functions there (try typing "import msvcrt" as well), but I can't
> see that they have what you need.
>[/color]
Somehow, I suspect one would have to using the win32 modules for
the desired functionality:
Creates or opens the a file or other object and returns a handle that
can be used to access the object.
"""
Of course, this then means one also has to use the win32file.*
routines for all the I/O. Though maybe the msvcrt module
open_osfhandle( ) can then be used -- pass it the handle from
win32file.Creat eFile(), pass that result to os.fdopen(), etc... and use
the rest of the msvcrt routines.
Doesn't common Linux practice rely upon creating a lock-file
first, to prevent shared access to a file? That would Linux/UNIX doesn't
really have "exclusive access" control on files. So I wouldn't expect to
find any support for such in anything using a Posix compatible I/O
system.
I do not know what kind of msvcrt module you have, but here is the
output of relavant commands on my machine:
[color=blue][color=green][color=darkred]
>>> import msvcrt
>>> str(msvcrt)[/color][/color][/color]
"<module 'msvcrt' (built-in)>"[color=blue][color=green][color=darkred]
>>> print msvcrt.__doc__[/color][/color][/color]
None[color=blue][color=green][color=darkred]
>>> dir (msvcrt)[/color][/color][/color]
['LK_LOCK', 'LK_NBLCK', 'LK_NBRLCK', 'LK_RLCK', 'LK_UNLCK', '__doc__',
'__name__', 'get_osfhandle' , 'getch', 'getche', 'heapmin', 'kbhit',
'locking', 'open_osfhandle ', 'putch', 'setmode', 'ungetch'][color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
out of all functions, probably kbhit and getch are used, to control
multythereaded applications from console.
Peter Hansen <peter@engcorp. com> wrote in message news:<ZcOdnWZyx boXbUvdRVn-jw@powergate.ca >...[color=blue]
> Lev Elblert wrote:
>[color=green]
> > 2. msvcrt.lib does have a lot of functions, but not msvcrt module in
> > Python. (correct me if I'm wrong)[/color]
>
> http://docs.python.org/lib/module-msvcrt.html shows there are a variety
> of functions there (try typing "import msvcrt" as well), but I can't
> see that they have what you need.
>
> -Peter[/color]
Lev Elblert wrote:
[color=blue]
> Peter!
>
> I do not know what kind of msvcrt module you have, but here is the
> output of relavant commands on my machine:[/color]
[snip]
You misread the message below, I believe. You seem to think I was
the one saying that the msvcrt module did not have lots of functions...
Also, please don't top-post. Thank you.
-Peter
[color=blue]
> Peter Hansen <peter@engcorp. com> wrote in message news:<ZcOdnWZyx boXbUvdRVn-jw@powergate.ca >...[color=green]
>>Lev Elblert wrote:[color=darkred]
>>>2. msvcrt.lib does have a lot of functions, but not msvcrt module in
>>>Python. (correct me if I'm wrong)[/color]
>>
>>http://docs.python.org/lib/module-msvcrt.html shows there are a variety
>>of functions there (try typing "import msvcrt" as well), but I can't
>>see that they have what you need.[/color][/color]
Comment