When running abaqus nogui python script I would like to output the status of the script to the terminal. But when I do, e.g.:
print("Opening ODB...")
print("Plotting images...")
I also tried:
print "Opening ODB..."
print "Plotting images..."
and
sys.stdout.write("Opening ODB...")
sys.stderr.write("Plotting images...")
Nothing gets outputted to the terminal. Despite this my code runs fine and does everything it supposed to do.
Does anyone have any ideas how to solve this issue?
Abaqus automatically redefines standards output to its own custom object. To be precise, standard output gets set to an instance of abaqus.AbaqusStdout. This is what you would get if you were to, for example, write str(sys.stdout) to a file.
However, the original definition of Python's standard output is stored in sys.__stdout__. You could use it to redefine standard output again or directly use it for writing to it.
Since Abaqus installation is using Python older than 2.7, you could write
import sys
print >> sys.__stdout__, 'Opening ODB'
To make it cleaner, simply create a function, e.g. log, which will do the dirty work for you and then write only log('some message').
There are other ways you could do logging once you know the definition of the standard output, but this is then up to you to explore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With