diff --git a/include/cantera/base/ctml.h b/include/cantera/base/ctml.h index f0293d217..c45a98011 100644 --- a/include/cantera/base/ctml.h +++ b/include/cantera/base/ctml.h @@ -818,6 +818,15 @@ Cantera::XML_Node getCtmlTree(const std::string& file); */ void ct2ctml(const char* file, const int debug = 0); +//! Get a string with the ctml representation of a cti file. +/*! + * @param file Path to the input file in CTI format + * @return String containing the xml representation of the input file + * + * @ingroup inputfiles + */ +std::string ct2ctml_string(const std::string& file); + //! Convert a Chemkin-format mechanism into a CTI file. /*! * @param in_file input file containing species and reactions diff --git a/interfaces/cython/cantera/ctml_writer.py b/interfaces/cython/cantera/ctml_writer.py index afa6e6b94..245f759e9 100644 --- a/interfaces/cython/cantera/ctml_writer.py +++ b/interfaces/cython/cantera/ctml_writer.py @@ -18,6 +18,8 @@ from __future__ import print_function +import sys + class CTI_Error(Exception): """Exception raised if an error is encountered while parsing the input file. @@ -130,8 +132,11 @@ class XMLnode(object): s = ['\n'] self._write(s, 0) s.append('\n') - with open(filename, 'w') as f: - f.write(''.join(s)) + if isinstance(filename, str): + with open(filename, 'w') as f: + f.write(''.join(s)) + else: + filename.write(''.join(s)) def write_comment(self, s, level): s.append('\n'+indent[level]+'