1

I have written the following code in python jupyterlite notebook using Pyolite kernel:

min_length = 2
name = input("Please enter your name:")

print(name)

while not(len(name) >= min_length and name.isprintable() and name.isalpha()):
    name = input("Please enter your name:")

print("Hello {0}".format(name)) 

Upon executing the above code, I am getting below error:

<Future pending>
TypeError: object of type 'Future' has no len()

I have not redefined input to be something else anywhere earlier in the jupyter notebook.

More detailed error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [1], in <module>
      6 name = input("Please enter your name:")
      8 print(name)
---> 10 while not(len(name) >= min_length and name.isprintable() and name.isalpha()):
     11     name = input("Please enter your name:")
     13 print("Hello {0}".format(name))

TypeError: object of type 'Future' has no len()
meallhour
  • 13,921
  • 21
  • 60
  • 117
  • 1
    That looks like a bug in Pyolite, particularly in the implementation of the `input` function. Your code is perfectly valid Python syntax. – larsks Feb 14 '22 at 03:47
  • 2
    I agree with @larsks. My guess is they implemented input with asyncio and are returning the future rather than the result. – William Allcock Feb 14 '22 at 17:29
  • This issue, along with several other current pain points with jupyterlite/pyolite, is mentioned [here](https://discourse.jupyter.org/t/codes-on-https-jupyter-org-try-jupyter-lab-not-working-properly-anymore/13374/2?u=fomightez). The solution proposed [here](https://github.com/jupyterlite/jupyterlite/issues/275) of adding `await` in front of `input` eliminates the note about 'Future' showing up in the provided code, but even changing them all doesn't make it quite run as well as in a real python kernel. This realm of issues is currently much under development and so things could change fast. – Wayne Mar 12 '22 at 19:12
  • Actually, it appears adding `await` isn't fixing it for JupyterLab using pyolite (or pyodide) now either. (When I try that, I see `JsException: TypeError: Cannot read properties of null (reading 'sendInputRequest')` Sorry this cutting-edge stuff still has several issues developers are working out. For now, I suggest using a full python kernel using the links [here](https://discourse.jupyter.org/t/codes-on-https-jupyter-org-try-jupyter-lab-not-working-properly-anymore/13374/4?u=fomightez) to get to your favorite interface. – Wayne Jun 29 '22 at 17:33

0 Answers0