go-python / gpython

gpython is a python interpreter written in go "batteries not included"
BSD 3-Clause "New" or "Revised" License
870 stars 95 forks source link

function not found with error AttributeError: "'module' has no attribute 'pre_save'" #224

Open dequeb opened 1 year ago

dequeb commented 1 year ago

I have the small script below that I try to test:

import sys

def pre_save(value, numb):
    if value == "value":
        return("accepted by Python script " + sys.version)
    else:
        return("refused by Python script" + sys.version)

When I do a py.RunSrc(ctx, pythonCode, "", nil), I get "AttributeError: "'module' has no attribute 'pre_save'""

sbinet commented 1 year ago

it's (I think) the convolution of a bug and a missing feature.

the missing feature:

$> gpython
Python 3.4.0 (none, unknown)
[Gpython dev]
- os/arch: linux/amd64
- go version: devel go1.21-688d75b14f Wed Jun 7 06:52:47 2023 +0000
>>> import sys
>>> sys.version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: "'module' has no attribute 'version'"

the bug: the error being reported is misleading and doesn't point at the actual culprit.

dequeb commented 1 year ago

Merci Sébastien.