#No basic input function and Python class acting weird

5 messages · Page 1 of 1 (latest)

tiny terrace
#

Is there any built in funciton to take input from the user? I've been importing it from python for now, and it's just been a bit annoying to deal with.

Second question (so I don't litter this channel with my questions), I wanted to convert a python object given from the Python input function into a mojo string, but this happened:

from python import Python as py

let input = py.import_module("builtins").input
        var user_input: PythonObject = input()
        var user_input_str: StringRef = py.__str__(user_input)

And I get this error:

invalid call to '__str__': callee expects 2 arguments, but 1 was specified
        var user_input_str: StringRef = py.__str__(user_input)
                                        ~~~~~~~~~~^~~~~~~~~~~~

I have been creating an instance of the Python class to convert it into a string reference, which works, but I wasn't sure if this was a feature or an issue, so I wanted to check in here before adding an issue on the github.

gusty root
#

I can't think of a reason why Python.__str__ would need a struct instance. Probably should file an issue

tawny gust
#

mmm I've faced the same problem..

mint panther
wanton blaze
#

since you have imported the builtins module you can call py.input() and that should work as an input function