jacolas
jacolas

Reputation: 1

Python3 / SWIG and output streams

I am using the SWIG generated Python wrappers for GDCM (comes with gdcm.py).

I am running the following Python3 script.

import gdcm
import sys

filename="path_to_data/gdcm_test.dcm"

r = gdcm.Reader()
r.SetFileName(filename)
r.Read()

f=r.GetFile()
ds = f.GetDataSet()

csa_t1 = gdcm.CSAHeader()

t1 = csa_t1.GetCSAImageHeaderInfoTag()

csa_t1.LoadFromDataElement(ds.GetDataElement( t1))
csa_t1.Print(sys.stdout)

The relevant snippet from the gdcmswig.py file (with the function that wraps Print) is below.

def Print(self, os: 'std::ostream &') -> "void":
    """
    void
    gdcm::CSAHeader::Print(std::ostream &os) const

    Print the CSAHeader (use only if Format == SV10 or NOMAGIC) 
    """
    return _gdcmswig.CSAHeader_Print(self, os)

The problem appears on the last line of my script. The call to Print(sys.stdout).

TypeError: in method 'CSAHeader_Print', argument 2 of type 'std::ostream &'

The problem, I think, is that Python’s sys.stdout is not the actual output file handle, but wraps the handle. What is the best way to solve this? Thanks in advance.

Upvotes: 0

Views: 341

Answers (0)

Related Questions