]> Creatis software - gdcm.git/blob - gdcmPython/demo/PrintHeader.py
Trial to get gdcmPython working. demo/PrintHeader should now work.
[gdcm.git] / gdcmPython / demo / PrintHeader.py
1 from gdcmPython import *
2 import sys
3 import os
4
5 ### Get filename from command line or default it
6 try:
7    FileName = sys.argv[1]
8 except IndexError:
9    FileName = os.path.join(GDCM_DATA_PATH, "test.acr")
10
11 try:
12    printLevel = int(sys.argv[2])
13 except IndexError:
14    printLevel = 1
15
16 #if not os.path.isfile(FileName):
17 #   print "Cannot open file ", FileName
18 #   sys.exit()
19
20 # On debugging purposes uncomment the next line
21 #s = raw_input("Hit any key in this window to exit")
22
23 ### Build the header element list
24 print FileName, type(FileName)
25 toRead = gdcm.Header(FileName)
26 if not toRead.IsReadable():
27    print "The ", FileName, " file is not readable with gdcm. Sorry."
28    sys.exit()
29
30 print "##############################################################"
31 print "### Display all the elements and their respective values"
32 print "## found in the ", FileName, " file."
33 print "##############################################################"
34 ###toRead.SetPrintLevel(printLevel)
35 ###toRead.Print()
36
37 ValDict = toRead.GetEntry()
38 for key in ValDict.keys():
39         print "[%s] = [%s]" %(key, ValDict[key])
40