'any' is not defined in Python scripts

Hi! Not sure if this is a bug or if it should be a feature request, so I’ll start here.

I’ve created a really small python script, named vacuum_room.py like this:

# Vacuum a specific room

rooms = []
roomString = data.get("room").lower()

if any(r in roomString for r in ["nursery", "kids room"]):
    rooms.append(20)

However, when I try to run it I get:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 205, in execute
    exec(compiled.code, restricted_globals)
  File "vacuum_room.py", line 6, in <module>
NameError: name 'any' is not defined

I would have guessed any is a builtin Python function that should be available to me when creating python scripts, no? Is there any way to make it available or should I just write my own any-function?

Running Home Assistant 0.115.6 in Docker on a Synology DS718+

Python scripts are running in a sandboxed environment which isvlimited and it may be that the any function is not available there, can’t test right now.

If you want access to python with full functionality and also imports of other librariers, there’s AppDaemon. With PyScript it may be possible as well.

1 Like

Thanks!

For this specific use case I managed to re-write the code to use for-loops and if-statements instead of any, as seen here.

I’ll see if I can raise this as a feature request as I think it would be nice to have access to more of the builtin python functions in this sandbox.