Repository navigation
Closed
Description
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)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
Metadata
Metadata
Assignees
Labels
No labels


Activity
hjdhnx commentedon Mar 1, 2024
@wesgarland Can you help me solve this problem?
[-]method cant't be convert[/-][+]method cant't be converted[/+]wesgarland commentedon Mar 9, 2024
@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.
hjdhnx commentedon Mar 9, 2024
thank you,I am waiting