os.path.walk not pruning descent tree (and I'm not happy with that behavior?)
Good day, everybody! From what I can tell from the archives, this is everyone's favorite method from the standard lib, and everyone loves answering questions about it. Right? :) Anyway, my question regards the way that the visit callback modifies the names list. Basically, my simple example is: ## def listUndottedDirs( d ): dots = re.compile( '\.' ) def visit( arg, dirname, names ): for f in names: if dots.match( f ): i = names.index( f ) del names[i] else: print "%s: %s" % ( dirname, f ) os.path.walk( d, visit, None ) ### Basically, I don't want to visit any hidden subdirs (this is a unix system), nor am I interested in dot-files. If I call the function like, "listUndottedDirs( '/usr/home/ardent' )", however, EVEN THOUGH IT IS REMOVING DOTTED DIRS AND FILES FROM names, it will recurse into the dotted directories; eg, if I have ".kde3/" in that directory, it will begin listing the contents of /usr/home/ardent/.kde3/ . Here's what the documentation says about this method: "The visit function may modify names to influence the set of directories visited below dirname, e.g. to avoid visiting certain parts of the tree. (The object referred to by names must be modified in place, using del or slice assignment.)" So... What am I missing? Any help would be greatly appreciated. -- Joe Ardent -- http://mail.python.org/mailman/listinfo/python-list
An unexpected visit_decref assertion fail (code works under python 2.4, doesn't under 2.5)
Hello, I'm running into a very odd problem here with a Python module (written in C). The following code works fine when built against and loaded into Python 2.4, but fails when built against and loaded into Python 2.5.1: klass = PyClass_New(bases, classDict, className); if (klass && methods) { /* add methods to class */ for (def = methods; def->ml_name != NULL; def++) { printf( "IlmPyClass: %d, def = %s\n", __LINE__, def- >ml_name ); PyObject *func = IlmPyClass_NewFunction(def); if (!func) { Py_XDECREF(klass); return NULL; } printf( "We get here\n" ); func = PyMethod_New(func, NULL, klass); printf( "We don't get here\n" ); # ... } } The output of 'python2.5 -c "import mymod"' is: """ We get here python2: Modules/gcmodule.c:276: visit_decref: Assertion `gc- >gc.gc_refs != 0' failed. Abort """ The obvious things, such as Py_INCREFing klass or func, do not work. What's extra strange, in addition to this code working fine in an earlier python version, is that this code works fine for most of the classes (this module has a bunch of C++ classes that get turned into python classes). Does anyone have any tips for debugging this? I'd really like to know what exactly is being decref'd. This has been driving me crazy for a while. Thanks in advance for any insights or tips! -- Joe Ardent -- http://mail.python.org/mailman/listinfo/python-list