Re: system and open

Steven D. Majewski (sdm7g@aemsun.med.Virginia.EDU)
Fri, 27 Mar 92 15:09:54 EST

>From asbarnes@mtu.edu>
>
> Ok, a couple of questions. Where is write and related functions located?
> They aren't in built-in with open. I cannot find close either.

write & close are methods of file objects, so they are built-in, even
though you don't see them in the scope of 'builtin' .

>>>import builtin
>>>dir(builtin)
['AttributeError', 'EOFError',
'IOError', 'ImportError', 'IndexError', 'KeyError',
'KeyboardInterrupt', 'MemoryError', 'NameError', 'None',
'OverflowError', 'RuntimeError', 'SyntaxError', 'SystemError',
'TypeError', 'ValueError', 'ZeroDivisionError', 'abs', 'apply', 'chr',
'dir', 'divmod', 'eval', 'exec', 'float', 'hex', 'input', 'int',
'len', 'long', 'max', 'min', 'oct', 'open', 'ord', 'pow', 'range',
'raw_input', 'reload', 'type']

>>>f = open( '/dev/tty', 'r' )
>>>f
<open file '/dev/tty', mode 'r'>

>>>f.__methods__
['close', 'flush', 'isatty', 'read', 'readline', 'readlines',
'seek', 'tell', 'write']

>>>f.write
<built-in method 'write' of some file object>
>>>f.close
<built-in method 'close' of some file object>

> Also, is there any way to get the output
> of a system command assigned to a variable?
> e.g. list = system('ls').

>>>import posix
>>>ls = posix.popen( 'ls -l', 'r' ).readlines()
>>>ls
['total 75\012',
'-rw-r--r-- 1 sdm7g 2401 Mar 27 14:55 #Re11196#\012',
'-rw------- 1 zhu 34 Mar 19 19:15 MTda01454\012',
'-rw-r--r-- 1 zhu 34 Mar 27 11:45 MTda10945\012',
'-rw------- 1 zhu 5530 Mar 19 19:15 MTvia01454\012',
'-rw------- 1 sdm7g 2270 Mar 27 14:44 Re11196\012',
'-rw------- 1 zhu 0 Mar 19 19:15 Text1454.0\012',
.
.
.
'-rw------- 1 zhu 0 Mar 27 11:41 tty.txt.a10942\012']

>
> .sig deleted
>

My condolences.
That's about the WORST case of .sig virus I've seen around! :-)

- Steve Majewski sdm7g@Virginia.EDU