Grasshopper

algorithmic modeling for Rhino

Can somebody tell me why am i getting an error at line 5?

import os
path = y #change this path
files = os.listdir(path + '.')
files = [path+x for x in files]
files = sorted(files,key=os.path.getmtime(path))[::-1]

a = files

this is the error message:

Runtime error (ArgumentTypeException): int is not callable
Traceback:
line 5, in script

Thanks

Views: 575

Replies to This Discussion

Hi Dimitar:

Try switching line 5 to:

files = sorted(files, key = lambda(f): os.path.getmtime(f)[::-1])

or

files = sorted(files, key =  os.path.getmtime) [::-1])

Thanks Jason. I sorted it out several hours ago but I failed to report it on the forum. Anyway I checked your suggestion but it doesn't work. I'm posting the working code. (Or at least working for me)


import os
path = y
os.chdir(path)
files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)

newest = files[-1]
if newest == "Thumbs.db":
newest = files[-2]

newest = [path+"/"+newest]
a = newest

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service