niazalikhan87 / qutip

Automatically exported from code.google.com/p/qutip
2 stars 1 forks source link

Qobj.__str__ returns empty string, prints to console directly, makes output in file difficult #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
import qutip as qt

someqobj=qt.sigmax()
with open('somefile', 'a') as fh:
    fh.write(str(someqobj))

What is the expected output? What do you see instead?
Output to file is nothing since Qobj.__str__ always returns an empty string.
It outputs everything to the console instead.

What version of the product are you using? On what operating system?
Debian Linux (testing) 2.6.39, python 2.6.7/2.7.2+, QuTiP 1.1.2 (1.1.3 seems to 
still use the same code here)

Please provide any additional information below.
Inside Qobj.__str__, just have it return the stuff you currently print directly 
to the console.

Original issue reported on code.google.com by konstan...@schukraft.org on 1 Dec 2011 at 4:36

GoogleCodeExporter commented 8 years ago
Hi

Thanks for the bug report. You're right, the __str__ function should return a 
string and instead of printing to stdout. I've fixed it now (revision r1465), 
and it should be included in the next release.

By the way, if you really are interested in storing a Qobj to file, check out 
the qobj_save and qobj_load functions, or alternatively file_data_store and 
file_data_load functions in file_io. This would probably be preferable if you 
will need to read back the Qobj into python code again at some later time.

Original comment by jrjohans...@gmail.com on 2 Dec 2011 at 1:25

GoogleCodeExporter commented 8 years ago
I'll handle this one.

Original comment by jrjohans...@gmail.com on 2 Dec 2011 at 1:28

GoogleCodeExporter commented 8 years ago

Original comment by nonhermitian on 22 Mar 2012 at 8:04