New Release with NakedObject and XDict Updates Coming This Weekend

Complete XDict (Python dictionary extension type – operator overloads, object metadata, new dictionary methods for keys and values) documentation will be released with the update.


How to Handle Standard Output and Standard Error from a Ruby Script on the Python Side with the Naked Framework

The function allows you to execute a Ruby script from your Python code and control the standard output and standard error streams on the Python side. These data are returned as attributes of a generic object without a write to the terminal and can be accessed (along with the exit status code) using standard Python dot syntax.

The returned object’s attributes include:

  • stdout = standard output stream data (or empty string on non-zero exit status)
  • stderr = standard error stream data (or empty string on zero exit status)
  • exitcode = the exit status code

Here’s an example of how a script named testscript.rb could be executed and handled on the Python side of your code:

from import muterun_rb

response = muterun_rb('testscript.rb')
if response.exitcode == 0:
    # the command was successful, handle the standard output
    standard_out = response.stdout
    # the command failed or the executable was not present, handle the standard error
    standard_err = response.stderr
    exit_code = response.exitcode
    print('Exit Status ' + exit_code + ': ' + standard_err)

The utility of this approach is that you can manipulate the output or suppress it altogether from the calling code. If you simply intend to print it to the terminal, then use the execute_rb() function in the same module. This allows the Ruby script to maintain control of the data that are displayed in the terminal.

Documentation of these functions is available here.

Naked Framework Update v0.1.25

The framework was updated to v0.1.25 today.  This release includes updates to the Naked.toolshed.file and Naked.toolshed.c.file library modules.  There are a number of available methods for file I/O in the FileReader and FileWriter classes and the read() and write() methods now support Unicode by default.

Complete file library documentation was released today and is available here.  Examples of the file module methods in action are available here.