Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How are file Pointers passed #9

Open
CL98K opened this issue Jan 6, 2024 · 2 comments
Open

How are file Pointers passed #9

CL98K opened this issue Jan 6, 2024 · 2 comments

Comments

@CL98K
Copy link

CL98K commented Jan 6, 2024

`* (py4cl2-cffi:import-module "pickle" :as "pkl")
T

  • (with-open-file (stream "/mnt/d/Worker/Lisp/test/xx.plk" :element-type '(unsigned-byte 8))
    (py4cl2-cffi:pycall "pkl.load" (sb-sys:fd-stream-fd stream)))

debugger invoked on a PY4CL2-CFFI:PYERROR in thread
#<THREAD tid=53 "main thread" RUNNING {1001128093}>:
A python error occurred:
file must have 'read' and 'readline' attributes

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE-IGNORING-ERRORS]
1: [ABORT ] Exit debugger, returning to top level.

(PY4CL2-CFFI::PYTHON-MAY-BE-ERROR)
source: (ERROR 'PYERROR :FORMAT-CONTROL "A python error occurred:~% ~A"
:FORMAT-ARGUMENTS (LIST VALUE-STR))`

@digikar99
Copy link
Owner

Currently, there is no native translation for file stream objects. To implement this, one would have to implement a py4cl2-cffi:pythonize method returning a pointer to an appropriate CPython object.

However, you can also write a python function that takes a lisp object, like string, and read the file in python itself. So, something like -

(py4cl2-cffi:raw-pyexec "
def read_python_object(filename):
  with open(filename, 'b') as f:
    return pkl.load(f)
")

@CL98K
Copy link
Author

CL98K commented Jan 7, 2024

Okay, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants