-
Notifications
You must be signed in to change notification settings - Fork 525
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
error: name 'bytearray' is not defined #177
Comments
Hi @setop, note that Codon's strings are (currently) ASCII, so you can often just use a |
Thanks How can I transform a |
Use pickle module as the example shown below: import gzip
import pickle
def read_test():
path = 'testjar.bin'
jar = gzopen(path, 'rb')
a = pickle.load(jar, List[byte])
print(a)
jar.close()
def write_test():
path = 'testjar.bin'
jar = gzip.open(path, 'wb')
a = [byte(1), byte(2), byte(3)]
pickle.dump(a, jar)
jar.close()
write_test()
read_test() |
I'm trying to implement a codec whom format has already been specified. So I cannot change it to pickle+gzip. I have to be able to handle raw bytes. Hence the initial question : "What is the good way to write programs that manipulate bytes ?". |
Solutions:
|
I found an hidden method in File implementation, codon/stdlib/internal/file.codon Line 43 in fc70c83
But I'm not sure if it should be used ... |
I already have an implementation in Python, using bytearray.
Executing python code in Codon will make it pointless (see #178). |
If your goal is to optimize performance while making minimal modifications, there are alternative solutions available that you can consider:
Indeed, there may be other solutions available, but these are the ones that I am aware of at this time. |
You could use |
Mypy is a type checker, the compiler is mypyc. There is also Nuitka. But they mostly do like Cython : melt a python interpreter into c code and call a C compiler to build an executable. This does not produce faster programs. Pypy is a JIT Compiler. It does not produce standalone executable. It is a drop-in replacement of the official interpreter. It is sometimes surprisingly faster and sometimes surprisingly slower than the official interpreter. In best case don't expect more than 10x. Numba, Pythran and Taichi are specialized in scientific computing, using dedicated annotations. And there is Codon that can sometime achieve 100x faster. And that's good news, I'm here to evaluate it. I've been successful in the past at writing code that run on both python interpreter and Codon. Sometimes it is only a matter at changing a type or a structure. So, if you don't mind, I'll try to pursue ;-) |
Yeah, nice to meet you here! I just provided you with some suggestions to see if they align with your needs. Definitely, Codon is amazing, and it's a good idea to keep exploring its features. |
This is something that we will need to implement in our standard library. No ETA for now 😞, however we'll be happy to accept PRs for this feature. |
Merging into #608 . |
I seems Codon does not understand bytes/bytearray/ByteString.
I tried to type with ByteString (from typing module) but is just makes thing worst.
What is the good way to write programs that manipulate bytes ?
The text was updated successfully, but these errors were encountered: