(LOGO.JPG) Python for OpenVMS

(go to: table of contents, index, list of pyvms, prev: CRTL_TO_VMS)


FILE_OPEN - call C RTL fopen() routine


Calls the C RTL fopen() routine, but returns a Python file object. This is similar to the 'open()' builtin, but it allows to specify a fourth argument.

Note: the creat() and open() routine in the C RTL accept an optional argument list. The Python interface requires that you specify all the arguments as a single tuple that is passed as argument 4 - see the examples section below.

Format:

    fo = pyvms.file_open (filename, [,mode] [,buffer] [,RMS-arguments])
Returns:
fo
Python file object
Arguments:
filename
name of the file to open
mode
'r', 'w', 'a' - see the online documentation for details:
print pyvms.file_open.__doc__
buffering
0 = unbuffered, 1 = line-buffered, others = actual buffer size
RMS-arguments
This is a tuple of strings to control the file attributes. See the examples section below.

Do not use the "acc" or "err" keywords! The interface does neither support these callback routines nor prevent use of them!

Examples:

>>> import pyvms

>>> fo = pyvms.file_open \
...      ('FILE_OPEN.TMP'                 # filename
...      ,'w'                             # mode
...      ,-1                              # buffering
...      ,("alq=200","rat=ftn","rfm=var") # RMS-arguments
...      )
>>> print type(fo)
<type 'file'>
>>> fo.write (' Hello!\n')
>>> fo.close ()
>>>

$ directory/full FILE_OPEN.TMP

Directory DKA100:[PYTHON.PYTHON-1_5_2.VMS]

FILE_OPEN.TMP;1               File ID:  (8949,43,0)
Size:            1/200        Owner:    [G1,SYSTEM]
Created:   26-DEC-1999 17:55:09.20
Revised:   26-DEC-1999 17:55:15.38 (1)
Expires:   
Backup:    
Effective: 
Recording: 
File organization:  Sequential
Shelved state:      Online
File attributes:    Allocation: 200, Extend: 0, Global buffer count: 0
                    No version limit
Record format:      Variable length, maximum 2 bytes
Record attributes:  Fortran carriage control
RMS attributes:     None
Journaling enabled: None
File protection:    System:RWED, Owner:RWED, Group:RE, World:
Access Cntrl List:  None

Total of 1 file, 1/200 blocks.
$

----------

>>> fo = pyvms.file_open \
...      ('%FILE_OPEN.TMP'                 # filename
...      ,'w'                             # mode
...      ,-1                              # buffering
...      ,("alq=200","rat=ftn","rfm=var") # RMS-arguments
...      )
Traceback (innermost last):
  File "<stdin>", line 5, in ?
IOError: [Errno 65535] invalid wildcard operation: '%FILE_OPEN.TMP'
>>>

@@ output from pyvms.crtl_open() is:

@@Traceback (innermost last):
@@  File "<stdin>", line 1, in ?
@@pyvms.error: (100164, '%RMS-F-WLD, invalid wildcard operation')

----------
$!+
$! Create a simple test queue to demonstrate spool-on-close.
$! Need to point SYS$PRINT to this queue.
$!-
$ initialize /queue /device /noSTART PY_SPL_TEST
$ define SYS$PRINT PY_SPL_TEST

$ python
[...]
>>> import pyvms

>>> fo = pyvms.file_open \
...      ('SPOOL.TMP'                     # filename
...      ,'w'                             # mode
...      ,-1                              # buffering
...      ,("fop=spl",)                    # RMS-arguments
...      )        # ^- need a tuple, here !  
>>> fo.write (' Hello!')
>>> fo.close ()
>>>

$ show queue /full /all PY_SPL_TEST
Printer queue PY_SPL_TEST, stopped, mounted form DEFAULT
 /BASE_PRIORITY=4 /DEFAULT=(FEED,FORM=DEFAULT) /OWNER=[G1,SYSTEM]
 /PROTECTION=(S:M,O:D,G:R,W:S)

 Entry  Jobname         Username     Blocks  Status
 -----  -------         --------     ------  ------
    30  SPOOL           ZESSIN            1  Pending (queue stopped)
        Submitted 26-DEC-1999 17:59 /FORM=DEFAULT /PRIORITY=100
        File: _$99$DKA100:[PYTHON.PYTHON-1_5_2.VMS]SPOOL.TMP;1
$
$! -- cleanup
$ deassign SYS$PRINT
$ delete /queue PY_SPL_TEST
$ delete SPOOL.TMP;1
$

(go to: table of contents, index, list of pyvms, prev: CRTL_TO_VMS)

26-DEC-1999 ZE.