[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
>>> for (i, (ac, bc)) in enumerate(zip(a, b)): ... if ac != bc: ... print(i, repr(ac), repr(bc)) ... print(repr(a[i-20: ...
changes. There are a variety of solutions to such goals—from shell commands, to find operations, to custom tree walkers, to gene ...
instance, the following Unix command line would pinpoint lines and files at and below the current directory that mention the str ...
if name == 'main': import sys namepattern, startdir = sys.argv[1], sys.argv[2] for name in find(namepattern, startdir): print(na ...
the letter q or t. Note how find returns full directory paths that begin with the start directory specification: C:\...\PP4E\Too ...
By comparison, find.find with just “” for its name pattern is also roughly equivalent to platform-specific directory tree listin ...
For example, one of the other common tasks I perform on a regular basis is removing all the bytecode files in a tree. Because th ...
This script works, but it’s a bit more manual and code-y than it needs to be. In fact, now that we also know about find operatio ...
so is portable; run this to delete .pyc's from an old Python release; """ import os, sys, find # here, gets Tools.find count = 0 ...
################################################################################ """ import os, sys listonly = False textexts = ...
Skipping .\__init__.pyc 7 => .\Preview\attachgui.py 8 => .\Preview\bob.pkl Skipping .\Preview\bob.pkl ...more lines omitte ...
Visitor: Walking Directories “++” Laziness is the mother of many a framework. Armed with the portable search_all script from Exa ...
concrete realization of these goals. It exports a general FileVisitor class that mostly just wraps os.walk for easier use and ex ...
self.dcount += 1 # override or extend me if self.trace > 0: print(dirpath, '...') def visitfile(self, filepath): # called for ...
if testmask & dolist: visitor = FileVisitor(trace=2) visitor.run(sys.argv[2]) print('Visited %d files and %d dirs' % (visito ...
Technically, passing this script a first argument of 3 runs both a FileVisitor and a SearchVisitor (two separate traversals are ...
Example 6-19. PP4E\Tools\visitor_edit.py """ Use: "python ...\Tools\visitor_edit.py string rootdir?". Add auto-editor startup to ...
Skipping C:\temp\PP3E\Examples\PP3E\TempParts\lawnlake1-jan-03.jpg 1428 => C:\temp\PP3E\Examples\PP3E\TempParts\part-001.txt ...
if name == 'main': listonly = input('List only?') == 'y' visitor = ReplaceVisitor(sys.argv[2], sys.argv[3], listonly) if listonl ...
This is both wildly powerful and dangerous. If the string to be replaced can show up in places you didn’t anticipate, you might ...
«
14
15
16
17
18
19
20
21
22
23
»
Free download pdf