Skip to content

method cant't be converted #253

Closed

Description

@hjdhnx

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

windows11

Python version (python --version)

3.8

PythonMonkey version (pip show pythonmonkey)

0.3.1.dev42+6b5fb9d

Bug Description

py_module.js

const py_module = require('./py_module.py')
console.log('console.log py_module:', py_module)
module.exports = {
    print: py_module.print,
    set: py_module.set,
    get: py_module.get,
}

py_module.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : py_module.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2024/3/1
import json
import os.path


class Local:
    def __init__(self, path):
        self.path = path
        if not os.path.exists(self.path):
            with open(self.path, mode='w+', encoding='utf-8') as f:
                f.write('{}')

    def get(self, key, value=''):
        with open(self.path, encoding='utf-8') as f:
            _dict = json.loads(f.read())
        return _dict.get(key) or value

    def set(self, key, value):
        with open(self.path, encoding='utf-8') as f:
            _dict = json.loads(f.read())
        _dict[key] = value
        with open(self.path, mode='w+', encoding='utf-8') as f:
            f.write(json.dumps(_dict, ensure_ascii=False))


local = Local('./store.json')
if not local.get('url'):
    local.set('url', 'https://github.com/Distributive-Network/PythonMonkey/issues/253')

exports = {
    'print': print,
    'set': local.set,
    'get': local.get,
}

py_module_test.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File  : py_module_test.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date  : 2024/3/1

import pythonmonkey as pm
from pythonmonkey import eval as js_eval, require as js_require
print(pm.__version__)
local = js_require('./py_module')
print(local)

image
image

I get two diffrent result
it's error

<class 'method'> python code can't use in js

Standalone code to reproduce the issue

No response

Relevant log output or backtrace

No response

Additional info if applicable

No response

What branch of PythonMonkey were you developing on? (If applicable)

No response

Activity

  1. hjdhnx commented on Mar 1, 2024

    @hjdhnx
    Author

    @wesgarland Can you help me solve this problem?

  2. changed the title [-]method cant't be convert[/-] [+]method cant't be converted[/+] on Mar 5, 2024
  3. wesgarland commented on Mar 9, 2024

    @wesgarland
    Collaborator

    @hjdhnx PR 227 is expected to fix this. Please follow up once you have that code. I believe it is on the main branch now and will be in the next release.

  4. hjdhnx commented on Mar 9, 2024

    @hjdhnx
    Author

    @hjdhnx PR 227 is expected to fix this. Please follow up once you have that code. I believe it is on the main branch now and will be in the next release.

    thank you,I am waiting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions