Module Sys
[hide private]
[frames] | no frames]

Module Sys

source code

The Blender.sys submodule.

sys

New: expandpath.

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.

Functions [hide private]
string
basename(path)
Get the base name (filename stripped from dir info) of 'path'.
source code
string
dirname(path)
Get the dir name (dir path stripped from filename) of 'path'.
source code
string
join(dir, file)
Join the given dir and file paths, using the proper separator for each platform.
source code
tuple of two strings
splitext(path)
Split 'path' into (root, ext), where 'ext' is a file extension including the full stop.
source code
string
makename(path='Blender.Get(\'filename\')', ext='', strip=0)
Remove extension from 'path', append extension 'ext' (if given) to the result and return it.
source code
int
exists(path)
Tell if the given pathname (file or dir) exists.
source code
float
time()
Get the current time in seconds since a fixed value.
source code
 
sleep(millisecs=10)
Sleep for the specified amount of time.
source code
string
expandpath(path)
Expand the given Blender 'path' into an absolute and valid path.
source code
string
cleanpath(path)
Clean the given 'path' by removing unneeded components such as "/./" and "/test/../"
source code
Variables [hide private]
  __package__ = None
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 [hide private]

basename(path)

source code 

Get the base name (filename stripped from dir info) of 'path'.

Parameters:
  • path (string) - a path name
Returns: string
the base name

dirname(path)

source code 

Get the dir name (dir path stripped from filename) of 'path'.

Parameters:
  • path (string) - a path name
Returns: string
the dir name

join(dir, file)

source code 

Join the given dir and file paths, using the proper separator for each platform.

Parameters:
  • dir (string) - the dir name, like returned from dirname.
  • file (string) - the bare filename, like returned from basename.
Returns: string
the resulting filename.

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

splitext(path)

source code 

Split 'path' into (root, ext), where 'ext' is a file extension including the full stop.

Example:

 import Blender
 file, ext= Blender.sys.splitext('/tmp/foobar.blend')
 print file, ext
 # ('/tmp/foobar', '.blend')
Parameters:
  • path (string) - a path name
Returns: tuple of two strings
(root, ext)

Note: This function will raise an error if the path is longer then 80 characters.

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

source code 

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 (string) - a path name or Blender.Get('filename'), if not given.
  • ext (string) - an extension to append. For flexibility, a dot ('.') is not automatically included.
Returns: string
the resulting string

exists(path)

source code 

Tell if the given pathname (file or dir) exists.

Returns: int
  • 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.

time()

source code 

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: float
the elapsed time in seconds.

sleep(millisecs=10)

source code 

Sleep for the specified amount of time.

Parameters:
  • millisecs (int) - the amount of time in milliseconds to sleep. The default is 10 which is 0.1 seconds.

expandpath(path)

source code 

Expand the given Blender 'path' into an absolute and valid path. Internally, Blender recognizes two special character sequences in paths:

  • '//' (used at the beginning): means base path -- the current .blend file's dir;
  • '#' characters in the filename will be replaced by the frame number.

The expanded string can be passed to generic python functions that don't understand Blender's internal relative paths.

Parameters:
  • path (string) - a path name.
Returns: string
the expanded (if necessary) path.
Notes:
  • this function is also useful for obtaining the name of the image that will be saved when rendered.
  • if the passed string doesn't contain the special characters it is returned unchanged.

cleanpath(path)

source code 

Clean the given 'path' by removing unneeded components such as "/./" and "/test/../"

Parameters:
  • path (string) - a path name.
Returns: string
the cleaned (if necessary) path.