Comments (2)
Unfortunately there's no reliable way to distinguish a list from a "string" in Erlang. So Erlang lists mapped to List class in ErlPort which is a subclass of list
but also can be converted to Unicode string with to_string() method.
I think there are at least two ways to pass str
to Python 3 (both of them require some Python code unfortunately):
-
A wrapper for a function can be created in Python which always convert string arguments to
str
. Something like the following code (not tested):def get_bucket(connection, bucket_name): return connection.get_bucket(bucket_name.to_string())
-
Custom data type decoder can be used to for example convert
{string, String}
Erlang tuple tostr
in Python. The code can look like this (not tested):def str_decoder(value): if isinstance(value, tuple) and len(value) == 2 and value[0] == "string": value = value[1].to_string() return value
from erlport.
I've managed to fix this for my uses (that is fire and forget calls from Elixir to Python) with the following:
in: decode
elif tag == 109:
# BINARY_EXT ... In Elixir this is a BitString
ln = len(string)
if ln < 5:
raise IncompleteData(string)
length = int4_unpack(string[1:5])[0] + 5
if ln < length:
raise IncompleteData(string)
stringy = string[5:length]
return stringy.decode(), string[length:]
and in OpaqueObject
:
@classmethod
def decode(cls, data, language):
if isinstance(data, str):
data = data.encode()
if language == b"python":
return loads(data)
return cls(data, language)
here: https://github.com/jdoig/erlport
My requirements are very simple so I've no idea the overall impact of doing this or how this would work with erlang. Just leaving this here in case any one arrives via a search.
from erlport.
Related Issues (20)
- Cannot Pickle built-in Python objects HOT 1
- Using erlport/ruby with Elixir v1.1.0 seems to have an issue, looking to understand the cause. HOT 1
- Should not convert negative integer in ruby array as erlang string HOT 1
- Cast/Call from Python to erlang? HOT 5
- Send message example not working HOT 3
- Port closed on erlport.cli, again HOT 2
- Erlport 1.0 release? HOT 3
- Documentation - Sending a message from Python to Erlang seems wrong HOT 2
- Enhancement request for monitoring erlport callers HOT 3
- How to install erlport.erlterms in Python 2.7 in Windows 10?
- system calls in Ruby script not working HOT 1
- importing erlport in Python3 yields syntax error HOT 4
- For those who might find it helpful. Applicable to python3 only HOT 1
- Could not compile erlport HOT 7
- Erlport dependency not compiling on Erlang's OTP 21 HOT 3
- :python.start() - {:error, {:not_found, 'erlport/priv'}} HOT 3
- python:start(Name,Options) throws exception.
- rebar3 compile doesn't run the makefile
- getargspec has been removed in Python 3.11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from erlport.