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 from __future__ import print_function
6 
7 """
8 A small utility to deal with pickled files.
9 """
10 __author__ = 'Juerg Beringer'
11 __version__ = '$Id: pickleTool.py 216126 2009-09-29 16:12:59Z atlidbs $'
12 __usage__ = 'pickleTool [options] arg1 [arg2]'
13 
14 
15 import sys, pickle, pprint
16 
17 # Option parsing
18 from optparse import OptionParser
19 parser = OptionParser(usage=__usage__, version=__version__)
20 parser.add_option('-c', '--create', dest='create', action='store_true', default=False, help='Pickle input file')
21 parser.add_option('-p', '--pretty', dest='pretty', action='store_true', default=False, help='Pretty-print/write data')
22 (options,args) = parser.parse_args()
23 
24 if options.create:
25  if len(args)<2:
26  parser.error('missing input or output file')
27  inFile = open(args[0], 'r')
28  data = inFile.read()
29  inFile.close()
30  object = eval(data)
31  outFile = open(args[1], 'wb')
32  pickle.dump(object,outFile)
33  outFile.close()
34 
35 else:
36  if len(args)<1:
37  parser.error('missing input file')
38  inFile = open(args[0], 'rb')
39  data = pickle.load(inFile)
40  inFile.close()
41  if options.pretty:
42  s = pprint.pformat(data)
43  else:
44  s = repr(data)
45  if len(args)>1:
46  outFile = open(args[1], 'w')
47  outFile.write(s)
48  outFile.write('\n')
49  outFile.close()
50  else:
51  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