'How to return False when file exists with FIleSensor
I'm trying to reverse FileSensor(): that is, with
sensor=FileSensor(filepath='test.txt', task_id='dummy_file_test')
It will return True if the file exists. But, how can it return False when the file exists and True when it does not?
Solution 1:[1]
You could create a PythonSensor that checks for the existence of a file with the logic that you want.
def my_sensor_func(some_path):
return not os.exists(some_path)
Solution 2:[2]
You can achieve it by creating your own function:
SF = lambda **kwargs: not FileSensor(**kwargs)
sensor=SF(filepath='test.txt', task_id='dummy_file_test')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Collin McNulty |
| Solution 2 | MSH |
