[Tutor] File access by os.system

Luke Paireepinart rabidpoobear at gmail.com
Wed May 16 07:28:04 CEST 2007

Rikard Bosnjakovic wrote:
> On 5/15/07, Mike Hansen <Mike.Hansen at atmel.com> wrote:
>> Should the os.system command be something like
>> command = "dsspcmbi -v %s %s" %(Pdb, temp1)
>> os.system(command)
>> ?
> Yes.
Not Quite, I think.
 >>> import tempfile
 >>> help(tempfile.TemporaryFile)
Help on function NamedTemporaryFile in module tempfile:

NamedTemporaryFile(mode='w+b', bufsize=-1, suffix='', prefix='tmp', 
    Create and return a temporary file.
    'prefix', 'suffix', 'dir' -- as for mkstemp.
    'mode' -- the mode argument to os.fdopen (default "w+b").
    'bufsize' -- the buffer size argument to os.fdopen (default -1).
    The file is created as mkstemp() would do it.
    Returns an object with a file-like interface; the name of the file
    is accessible as file.name.  The file will be automatically deleted
    when it is closed.

So I'd expect to use

command = "dsspcmbi -v %s %s" %(Pdb, temp1.name)

That is, unless __str__ and/or __repr__ return the file name also.

More information about the Tutor mailing list