Comments (4)
Your second example works fine on top-of-tree and will work in 24.2:
from python import Python
fn main() raises:
var json = Python.import_module("json")
var a = json.loads('{"a": 1, "b": 2}')
print(a.values())
for v in a.values():
print(v)
It prints:
dict_values([1, 2])
1
2
Your first example:
from python import Python
def main():
var json = Python.import_module("json")
a = json.loads('{"a": 1}')
print(a.values())
print(a.values()[0])
crashes on the subscript operator as you mentioned. We should fix that to give a better error message. The print(a.values())
prints:
dict_values([1])
as expected
from mojo.
This is fixed in the next update, thank you for reporting this!
from mojo.
Tried also iterating over that, which fails to iterator not being mutable or something like that.
(venv) mlepisto@stevetop:~/projects/learn-machine$ cat test.mojo
from python import Python
fn main() raises:
var json = Python.import_module("json")
var a = json.loads('{"a": 1, "b": 2}')
print(a.values())
for v in a.values():
print(v)
(venv) mlepisto@stevetop:~/projects/learn-machine$ mojo run test.mojo
/home/mlepisto/projects/learn-machine/test.mojo:8:22: error: invalid call to '__iter__': argument #0 must be mutable in order to pass as a by-ref argument
for v in a.values():
~~~~~~~~^~
/home/mlepisto/projects/learn-machine/test.mojo:1:1: note: function declared here
from python import Python
^
mojo: error: failed to parse the provided Mojo
from mojo.
@akirchhoff-modular helped track this down - this is caused by register-only types being handled by VariadicList instead of VariadicListMem, so their copy constructors don't get run correctly. There is a big migration to move the variadic list representation over to this new form, which can hopefully help, but I'm not exactly sure when it will converge
from mojo.
Related Issues (20)
- [BUG] Crash when declaring a nested struct with a variable of the same type HOT 2
- [Modular CLI] install modular command tool without require root permissions HOT 4
- [BUG] crash when first trying to debug a mojo app in VSCode using WSL VS Code Server: "free(): invalid pointer"
- [Feature Request] Merge `init_pointee_move` and `move_pointee_into`.
- [BUG] trouble reading a file HOT 2
- [BUG] rounding error with UInt32 HOT 2
- [Feature Request] A `Type[AnyStruct | AnyClass | etc]` operator that returns the type's interface (as a trait)
- [BUG] Sneaky ternary operator bugs
- [BUG] Varaint Types using function types Don't Allow Parameters When calling the function.
- [BUG] Values get set to 1 when passing one Scalar into another Scalar's constructor HOT 3
- [BUG] crash when passing offset DTypePointer into Tensor
- [BUG] Unsigned integer casting overflowing as if signed when using `int()` or `UInt32()` HOT 5
- [BUG] modular: error: failed to run script
- Implement arithmetic operators for `UInt`
- [BUG] math/numeric functions weird behavior with float16 types HOT 5
- [BUG] question about writing to file
- [BUG] Cannot materialize a capturing closure
- [Docs] the "random" module should not be imported by default HOT 2
- [BUG] Index out of bound with nested list literals
- [Feature Request] Allow __get_item__ calls to use a mix of colon slices and integers
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 mojo.