小编Sni*_*gie的帖子

在 try / except 中捕获特定的错误消息

我是 python 的新手,我即将制作这个新程序,它会问你生日。我做了一些 try/except 子句来避免人们以字符串或高数字输入信息。我希望我的程序找出输入的信息最终是否等于日期。如果是,我希望将其打印出来,如果没有,我希望它找出用户输入的哪一部分是错误的。因此,我在最后一个 except 子句中创建了一些 if 子句,其想法是错误将等于一条消息。

我想知道是否有可能让程序将消息与错误进行匹配,以找出具体的错误并找出输入的哪一部分是错误的。

我的代码如下所示:

try: 
    print(datetime.date(int(birthYear), int(birthMonth), int(birthDay)))
except TypeError:
    if ValueError == "ValueError: month must be in 1..12": 
        print("Month " + str(birthMonth) + " is out of range. The month must be a number in 1...12")
    if ValueError == "ValueError: year " + str(birthYear) + " is out of range": 
        print("Year " + str(birthMonth) + " is out of range. The year must be a number in " + str(datetime.MINYEAR) + "..." …
Run Code Online (Sandbox Code Playgroud)

python datetime if-statement python-3.x try-except

7
推荐指数
1
解决办法
4239
查看次数

.vscode中的调试问题

我最近在VSCODE中进行调试遇到了一个大问题。我试图通过搜索站点并重新安装一些扩展程序来修复自身。

而不是在调试控制台中显示我的结果,而是将以下输出写入我的终端

cd /Users/AVFL/Documents/Programming ; env "PYTHONIOENCODING=UTF-8"
PYTHONUNBUFFERED=1" /usr/local/bin/python3
/Users/AVFL/.vscode/extensions/ms-python.python-2018.3.1/pythonFiles/PythonTools/visualstudio_py_launcher.py
/Users/AVFL/Documents/Programming 54323 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput
/Users/AVFL/Documents/Programming/Python/Projects/Entrepeneuring/employeeDatabase.py
Run Code Online (Sandbox Code Playgroud)

我的脚本的结果显示在下面。结果也显示在调试控制台中,但我希望它们只显示在调试控制台中。

我正在使用Python调试:当前文件。我尝试将控制台none更改为外部和集成终端功能,但是我需要将其设置为默认值。

使用Python:Current File时,该如何做才能使其在调试控制台中进行调试?


我看过一篇关于这个问题的文章,但他们将控制台更改为无,并在Python中进行调试:集成终端而不是当前文件

当我在文件夹中创建virtualenv时发生了问题。

python python-3.x visual-studio-code python-3.6 vscode-debugger

5
推荐指数
1
解决办法
930
查看次数

查找除已使用的锚以外的另一个锚的位置

我创建了一个代码来显示我的问题。看起来像这样:

userNameID = tkinter.Label(root, text="Name/ID")
userNameID.place(x=640, y=320, anchor="e")

userNameID = tkinter.Label(root, text="Password")
userNameID.place(x=640, y=360, anchor="e")

entButton = tkinter.Button(root, text="Enter", command=enterPrint)
entButton.place(x=640, y=400, anchor="w")
Run Code Online (Sandbox Code Playgroud)

问题是我在中心的一个尺寸上对齐了一些文本,在另一侧对齐了一个按钮。我想知道文本的西北锚的位置,以确保所有内容与中心的距离均相同,并且仍然对齐。

python tkinter python-3.x

3
推荐指数
1
解决办法
124
查看次数