manuell_191
manuell_191
MModular
Created by manuell_191 on 9/8/2023 in #questions
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.
6 replies