Embed pickle (or arbitrary) data in python script

前端 未结 4 1046
孤城傲影
孤城傲影 2021-01-13 10:08

In Perl, the interpreter kind of stops when it encounters a line with

__END__

in it. This is often used to embed arbitrary data at the end

4条回答
  •  萌比男神i
    2021-01-13 10:37

    With pickle you can also work directly on strings.

    s = pickle.dumps(obj)
    pickle.loads(s)
    

    If you combine that with """ (triple-quoted strings) you can easily store any pickled data in your file.

提交回复
热议问题