0

def W():
  print("deleting")
  [f.unlink() for f in Path("../Image-Loader-V20/IMG").glob("*") if f.is_file()] 
  [f.unlink() for f in Path("../Image-Loader-V20/TXT").glob("*") if f.is_file()] 
  pass


Clock.schedule_interval(W, 10.0)

I am trying to delete the contents of a file every hour but here i put 10 seconds but when I run it nothing happens which is kinda weird does anyone know what is happenening? Like the files do delete with the function but the thing just dont work...

I tried it with () next to W but that neither

Ellirio
  • 1
  • 1
  • 1
    Just a heads up that your use of comprehensions here is frowned on. https://stackoverflow.com/questions/5753597/is-it-pythonic-to-use-list-comprehensions-for-just-side-effects – JonSG Mar 17 '23 at 20:26

1 Answers1

0

In kivi docs it's said, that you should use e.g. lambda to schedule a function which does not take any arguments (and that looks like your case):

def no_args_func():
    print("I accept no arguments, so don't schedule me in the clock")

Clock.schedule_once(lambda dt: no_args_func(), 0.5)

Source: https://kivy.org/doc/stable/api-kivy.clock.html

So assuming your function works on its own (which you said and I didn't check) your code would be:

def W():
  print("deleting")
  [f.unlink() for f in Path("../Image-Loader-V20/IMG").glob("*") if f.is_file()] 
  [f.unlink() for f in Path("../Image-Loader-V20/TXT").glob("*") if f.is_file()] 
  pass


Clock.schedule_interval(lambda dt:W(), 10.0)
Gameplay
  • 1,142
  • 1
  • 4
  • 16