【问题标题】:Script waits for input when importing the webbrowser module脚本在导入 webbrowser 模块时等待输入
【发布时间】:2017-01-01 08:21:45
【问题描述】:

我在使用 Python 时遇到了一个小而令人讨厌的问题。当我在从 IDLE 运行的 Python 脚本中导入 webbrowser 模块时,它工作得非常好。但是,如果脚本在 IDLE 之外运行,则导入 webbrowser 模块会使程序停止并等待用户输入。

我做了以下基本示例,逐步显示问题:

print('the program has started')
print('importing some random modules')
import sys
print('sys imported')
import pyperclip
print('pyperclip imported')
import logging
print('logger imported')
print('this is the line before importing the webbrowser module')
import webbrowser
print('webbrowser module imported')
print('end of demo program')

Here 是我启动程序时发生的屏幕截图。最后,here 是我输入一些文本并按回车后的程序截图。

在 IDLE 之外导入 webbrowser 模块时它会停止什么?我只希望程序导入模块并正常继续。

【问题讨论】:

  • 这里是第三个链接:imgur.com/a/HNCs9
  • 当前目录下是否有自己的模块webbrowser.py?
  • @JohnGordon 我唯一的webbrowser.py是lib目录下的那个,python自带的那个。调试器说这是我运行程序时导入的那个:/
  • @eryksun 是的,对不起,我对编程世界很陌生。我知道 cmd 实际上并没有自己运行 python,这也是为什么我不明白在空闲时运行它时发生了什么不同的原因。它在空闲时完美运行。
  • 哦,如果我只是在 cmd 中运行 python.exe,当我尝试导入 webbrowser 时,它也会等待输入

标签: python windows python-3.x windows-console


【解决方案1】:

发现问题了!在我存储脚本的文件夹中有一个“copy.py”脚本。 webbrowser 模块必须导入一个名为 copy 的模块。从目录中删除了“copy.py”,一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多