ATLAS Offline Software
pickleTool.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 
6 """
7 A small utility to deal with pickled files.
8 """
9 __author__ = 'Juerg Beringer'
10 __version__ = '$Id: pickleTool.py 216126 2009-09-29 16:12:59Z atlidbs $'
11 __usage__ = 'pickleTool [options] arg1 [arg2]'
12 
13 
14 import sys, pickle, pprint
15 
16 # Option parsing
17 from optparse import OptionParser
18 parser = OptionParser(usage=__usage__, version=__version__)
19 parser.add_option('-c', '--create', dest='create', action='store_true', default=False, help='Pickle input file')
20 parser.add_option('-p', '--pretty', dest='pretty', action='store_true', default=False, help='Pretty-print/write data')
21 (options,args) = parser.parse_args()
22 
23 if options.create:
24  if len(args)<2:
25  parser.error('missing input or output file')
26  inFile = open(args[0], 'r')
27  data = inFile.read()
28  inFile.close()
29  object = eval(data)
30  outFile = open(args[1], 'wb')
31  pickle.dump(object,outFile)
32  outFile.close()
33 
34 else:
35  if len(args)<1:
36  parser.error('missing input file')
37  inFile = open(args[0], 'rb')
38  data = pickle.load(inFile)
39  inFile.close()
40  if options.pretty:
41  s = pprint.pformat(data)
42  else:
43  s = repr(data)
44  if len(args)>1:
45  outFile = open(args[1], 'w')
46  outFile.write(s)
47  outFile.write('\n')
48  outFile.close()
49  else:
50  print (s)
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
Trk::open
@ open
Definition: BinningType.h:40