|
发表于 2016-4-16 21:57:01
|
显示全部楼层
或者这样!
- >>> import os
- >>> s = os.walk(os.curdir)
- >>> print(s)
- <generator object walk at 0x00D2E558>
- >>> s
- <generator object walk at 0x00D2E558>
- >>> help(s)
- Help on generator object:
- walk = class generator(object)
- | Methods defined here:
- |
- | __del__(...)
- |
- | __getattribute__(self, name, /)
- | Return getattr(self, name).
- |
- | __iter__(self, /)
- | Implement iter(self).
- |
- | __next__(self, /)
- | Implement next(self).
- |
- | __repr__(self, /)
- | Return repr(self).
- |
- | close(...)
- | close() -> raise GeneratorExit inside generator.
- |
- | send(...)
- | send(arg) -> send 'arg' into generator,
- | return next yielded value or raise StopIteration.
- |
- | throw(...)
- | throw(typ[,val[,tb]]) -> raise exception in generator,
- | return next yielded value or raise StopIteration.
- |
- | ----------------------------------------------------------------------
- | Data descriptors defined here:
- |
- | gi_code
- |
- | gi_frame
- |
- | gi_running
- >>> s.__next__()
- ('.', ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'Scripts', 'tcl', 'Tools'], ['first.py', 'jchess.py', 'LICENSE.txt', 'NEWS.txt', 'opt_parse.py', 'python.exe', 'pythonw.exe', 'qt.conf', 'README.txt', 'test.txt', 'tmp.py'])
- >>> s.__next__()
- ('.\\DLLs', [], ['py.ico', 'pyc.ico', 'pyexpat.pyd', 'python3.dll', 'select.pyd', 'sqlite3.dll', 'tcl86t.dll', 'tk86t.dll', 'unicodedata.pyd', 'winsound.pyd', '_bz2.pyd', '_ctypes.pyd', '_ctypes_test.pyd', '_decimal.pyd', '_elementtree.pyd', '_hashlib.pyd', '_lzma.pyd', '_msi.pyd', '_multiprocessing.pyd', '_overlapped.pyd', '_socket.pyd', '_sqlite3.pyd', '_ssl.pyd', '_testbuffer.pyd', '_testcapi.pyd', '_testimportmultiple.pyd', '_tkinter.pyd'])
- >>> s.__next__()
- ('.\\Doc', [], ['python340.chm'])
- >>> s.__next__()
- ('.\\include', [], ['abstract.h', 'accu.h', 'asdl.h', 'ast.h', 'bitset.h', 'bltinmodule.h', 'boolobject.h', 'bytearrayobject.h', 'bytesobject.h', 'bytes_methods.h', 'cellobject.h', 'ceval.h', 'classobject.h', 'code.h', 'codecs.h', 'compile.h', 'complexobject.h', 'datetime.h', 'descrobject.h', 'dictobject.h', 'dtoa.h', 'dynamic_annotations.h', 'enumobject.h', 'errcode.h', 'eval.h', 'fileobject.h', 'fileutils.h', 'floatobject.h', 'frameobject.h', 'funcobject.h', 'genobject.h', 'graminit.h', 'grammar.h', 'import.h', 'intrcheck.h', 'iterobject.h', 'listobject.h', 'longintrepr.h', 'longobject.h', 'marshal.h', 'memoryobject.h', 'metagrammar.h', 'methodobject.h', 'modsupport.h', 'moduleobject.h', 'namespaceobject.h', 'node.h', 'object.h', 'objimpl.h', 'opcode.h', 'osdefs.h', 'parsetok.h', 'patchlevel.h', 'pgen.h', 'pgenheaders.h', 'pyarena.h', 'pyatomic.h', 'pycapsule.h', 'pyconfig.h', 'pyctype.h', 'pydebug.h', 'pyerrors.h', 'pyexpat.h', 'pyfpe.h', 'pygetopt.h', 'pyhash.h', 'pymacconfig.h', 'pymacro.h', 'pymath.h', 'pymem.h', 'pyport.h', 'pystate.h', 'pystrcmp.h', 'pystrtod.h', 'Python-ast.h', 'Python.h', 'pythonrun.h', 'pythread.h', 'pytime.h', 'py_curses.h', 'rangeobject.h', 'setobject.h', 'sliceobject.h', 'structmember.h', 'structseq.h', 'symtable.h', 'sysmodule.h', 'token.h', 'traceback.h', 'tupleobject.h', 'typeslots.h', 'ucnhash.h', 'unicodeobject.h', 'warnings.h', 'weakrefobject.h'])
- >>>
复制代码 |
|