为什么从python文件运行dir(asyncio)不能提供与从交互式shell运行相同的输出?

我的项目解释器是python3.8 我的代码:

import asyncio
print(dir(asyncio))

将上面的代码写入文件并运行该文件会产生以下输出:

['Chainmap','Counter','OrderedDict','UserDict','UserList','UserString','_Link','_OrderedDictItemsView','_OrderedDictKeysView','_OrderedDictvaluesView','__all__','__builtins__','__cached__','__doc__','__file__','__getattr__','__loader__','__name__','__package__','__path__','__spec__','_chain','_collections_abc','_count_elements','_eq','_heapq','_iskeyword','_itemgetter','_proxy','_recursive_repr','_repeat','_starmap','_sys','_tuplegetter','defaultdict','deque','namedtuple']
['Chainmap','namedtuple']

请注意,我两次获得相同的列表

现在,当我在交互式shell中尝试上述代码时,我得到:

['ALL_COMPLETED','AbstractChildWatcher','AbstractEventLoop','AbstractEventLoopPolicy','AbstractServer','BaseEventLoop','BaseProtocol','BaseTransport','BoundedSemaphore','BufferedProtocol','CancelledError','Condition','DatagramProtocol','DatagramTransport','DefaultEventLoopPolicy','Event','FIRST_COMPLETED','FIRST_EXCEPTION','FastChildWatcher','Future','Handle','IncompleteReadError','InvalidStateError','LifoQueue','LimitOverrunError','Lock','MultiLoopChildWatcher','PriorityQueue','Protocol','Queue','QueueEmpty','QueueFull','ReadTransport','SafeChildWatcher','SelectorEventLoop','Semaphore','SendfileNotAvailableError','StreamReader','StreamReaderProtocol','StreamWriter','Subprocessprotocol','SubprocessTransport','Task','ThreadedChildWatcher','TimeoutError','TimerHandle','Transport','WriteTransport','_all_tasks_compat','_enter_task','_get_running_loop','_leave_task','_register_task','_set_running_loop','_unregister_task','all_tasks','as_completed','base_events','base_futures','base_subprocess','base_tasks','constants','coroutine','coroutines','create_subprocess_exec','create_subprocess_shell','create_task','current_task','ensure_future','events','exceptions','format_helpers','futures','gather','get_child_watcher','get_event_loop','get_event_loop_policy','get_running_loop','iscoroutine','iscoroutinefunction','isfuture','locks','log','new_event_loop','open_connection','open_unix_connection','protocols','queues','run','run_coroutine_threadsafe','runners','selector_events','set_child_watcher','set_event_loop','set_event_loop_policy','shield','sleep','sslproto','staggered','start_server','start_unix_server','streams','subprocess','sys','tasks','transports','trsock','unix_events','wait','wait_for','wrap_future']

为什么两种情况下的输出不同?

gyglove2008 回答:为什么从python文件运行dir(asyncio)不能提供与从交互式shell运行相同的输出?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3165440.html

大家都在问