pyparsing - Error when pickling ParseResult in Python 3.5.1 -


i have test code works in python 2.7.11, fails in python 3.5.1:

import pyparsing pp import pickle  class greeting():     def __init__(self, toks):         self.salutation = toks[0]         self.greetee = toks[1]  word = pp.word(pp.alphas+"'.") salutation = pp.oneormore(word) comma = pp.literal(",") greetee = pp.oneormore(word) endpunc = pp.oneof("! ?") greeting = salutation + pp.suppress(comma) + greetee + pp.suppress(endpunc) greeting.setparseaction(greeting)  string = 'good morning, miss crabtree!'  g = greeting.parsestring(string)  pkl = 'test .pkl' pickle.dump(g, open(pkl, 'wb')) pickle.load(open(pkl, 'rb')) 

the error message follows:

traceback (most recent call last): file "c:/users/arne/parser/test.py", line 23, in <module>    pickle.load(open(pkl, 'rb')) typeerror: __new__() missing 1 required positional argument: 'toklist' 

__new__() refers pyparsing.parseresults.__new__(cls, toklist, name=none, aslist=true, modal=true ).

is still in general possible pickle objects returned pyparsing in python 3.5.1 or has changed?

could provide brief code sample of use of pickle , pyparsing 2.0.7?

my real grammar takes few minutes parse, appreciate being able store results before further processing.

this fails protocol=2 (optional 3rd arg pickle.dump), passes if use pickle protocol = 0 or 1. on python 2.7.10, 0 default protocol. on python 3.5, pickle has protocols 0-4, , again, pickling parseresults works protocols 0 , 1. in py3.5, default protocol has changed 3. can work around problem specifying protocol of 0 or 1.

more info on pickle protocols @ https://docs.python.org/3/library/pickle.html?highlight=pickle#data-stream-format


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -