Module Sys
[frames | no frames]

Module Sys

The Blender.sys submodule.

sys

New: exists, makename, join, sleep.

This module provides a minimal set of helper functions and data. Its purpose is to avoid the need for the standard Python module 'os', in special 'os.path', though it is only meant for the simplest cases.

Example:
 import Blender

 filename = ""
 def f(name): # file selector callback
   global filename
   filename = name

 Blender.Window.FileSelector(f)

 if filename:
   print 'basename:', Blender.sys.basename(filename)
   print 'dirname:',  Blender.sys.dirname(filename)
   print 'splitext:', Blender.sys.splitext(filename)

 # what would basename(splitext(filename)[0]) print?

Attention: The module is called sys, not Sys.

Function Summary
string basename(path)
Get the base name (filename stripped from dir info) of 'path'.
string dirname(path)
Get the dir name (dir path stripped from filename) of 'path'.
int exists(path)
Tell if the given pathname (file or dir) exists.
string join(dir, file)
Join the given dir and file paths, using the proper separator for each platform.
string makename(path, ext, strip)
Remove extension from 'path', append extension 'ext' (if given) to the result and return it.
  sleep(millisecs)
Sleep for the specified amount of time.
list with two strings splitext(path)
Split 'path' into (root, ext), where 'ext' is a file extension.
float time()
Get the current time in seconds since a fixed value.

Variable Summary
char dirsep: same as sep.
string progname: the Blender executable (argv[0]).
char sep: the platform-specific dir separator for this Blender: '/' everywhere, except on Win systems, that use '\'.

Function Details

basename(path)

Get the base name (filename stripped from dir info) of 'path'.
Parameters:
path - a path name
           (type=string)
Returns:
the base name
           (type=string)

dirname(path)

Get the dir name (dir path stripped from filename) of 'path'.
Parameters:
path - a path name
           (type=string)
Returns:
the dir name
           (type=string)

exists(path)

Tell if the given pathname (file or dir) exists.
Returns:
  • 0: path does not exist;
  • 1: path is an existing filename;
  • 2: path is an existing dirname;
  • -1: path exists but is neither a regular file nor a dir.

           (type=int)

join(dir, file)

Join the given dir and file paths, using the proper separator for each platform.
Parameters:
dir - the dir name, like returned from dirname.
           (type=string)
file - the bare filename, like returned from basename.
           (type=string)
Returns:
the resulting filename.
           (type=string)

Warning: this simple function isn't intended to be a complete replacement for the standard os.path.join() one, which handles more general cases.

makename(path="Blender.Get('filename')", ext='', strip=0)

Remove extension from 'path', append extension 'ext' (if given) to the result and return it. If 'strip' is non-zero, also remove dirname from path.

Example:
 import Blender
 from Blender.sys import *
 print makename('/path/to/myfile.txt','.abc', 1) # returns 'myfile.abc'

 print makename('/path/to/myfile.obj', '-01.obj') # '/path/to/myfile-01.obj'

 print makename('/path/to/myfile.txt', strip = 1) # 'myfile'

 # note that:
 print makename(ext = '.txt')
 # is equivalent to:
 print sys.splitext(Blender.Get('filename'))[0]) + '.txt'
Parameters:
path - a path name or Blender.Get('filename'), if not given.
           (type=string)
ext - an extension to append. For flexibility, a dot ('.') is not automatically included.
           (type=string)
Returns:
the resulting string
           (type=string)

sleep(millisecs=10)

Sleep for the specified amount of time.
Parameters:
millisecs - the amount of time in milliseconds to sleep. The default is 10 which is 0.1 seconds.
           (type=int)

splitext(path)

Split 'path' into (root, ext), where 'ext' is a file extension.
Parameters:
path - a path name
           (type=string)
Returns:
(root, ext)
           (type=list with two strings)

time()

Get the current time in seconds since a fixed value. Successive calls to this function are guaranteed to return values greater than the previous call.
Returns:
the elapsed time in seconds.
           (type=float)

Variable Details

dirsep

same as sep.
Type:
char

progname

the Blender executable (argv[0]).
Type:
string

sep

the platform-specific dir separator for this Blender: '/' everywhere, except on Win systems, that use '\'.
Type:
char

Generated by Epydoc 2.1 on Thu Aug 12 21:47:30 2004 http://epydoc.sf.net