No basic input function and Python class acting weird

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)
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)
~~~~~~~~~~^~~~~~~~~~~~
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.
5 Replies
Stole
Stole15mo ago
I can't think of a reason why Python.__str__ would need a struct instance. Probably should file an issue
namo
namo14mo ago
mmm I've faced the same problem..
gabrieldemarmiesse
@manuell_191 in the meantime you can use the function input() I have implemented in pure mojo if that helps: https://github.com/gabrieldemarmiesse/mojo-stdlib-extensions#complete-list-of-what-is-available-here
Big Jam
Big Jam14mo ago
since you have imported the builtins module you can call py.input() and that should work as an input function
namo
namo14mo ago
yeap, the library from @gabrieldemarmiesse works. 👍
Want results from more Discord servers?
Add your server