From: Reuben R. <si...@em...> - 2017-12-16 14:06:00
|
>>> Instead I would like to use some features that are only available python3, >>> e.g. coroutines or something as trivial as "yield from". >> Off-topic: Python3 has some neat features. I wanted to have drop in >> module support for my accounting system and Python3 had support for that >> in a very fluent way. Let's say you have file(s) /file?name?.py class Module: def __init__ (self, my_parameter): variable_one = 1 /in a directory, you have no idea what the file is called, but you want to make it accessible, you would then: /import importlib.util as i_utils// //cwd = os.getcwd()// //module_folder = cwd + "/pycam/modules/"// //files = os.listdir(module_folder)// //menu = self.builder.get_object('menu11')// //for file_ in files:// // if file_.endswith(".py") and file_ != "__init__.py":// // file_name = file_.strip(".py")// // f_path = module_folder+file_// // spec = i_utils.spec_from_file_location(file_name , f_path)// // module = i_utils.module_from_spec(spec)// // spec.loader.exec_module(module)// // file_label = file_name.capitalize()// // file_label = file_label.replace("_", " ") // // menuitem = Gtk.MenuItem.new_with_label(file_label)// // menuitem.connect("activate", module.Module, 'pycam')// // menuitem.show()// // menu.append(menuitem) /I can't find the original place I got this feature, but Google 'dynamic import python3' and you will find tens of links. Or feel free to ask for explanation on anything I missed. This code was a copied and pasted from /https://sourceforge.net/p/pygtk-posting/code/ci/master/tree/src/pygtk_posting.py /line 97 with minor changes for Pycam. / /// > I am interested in this topic: could you give me a reference? > > Cheers, > Lars > |