You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sublime无法执行if/else语句内代码的问题求助

Sublime无法执行if/else语句内代码的问题求助

我最近在Sublime里写Python代码时碰到了一个头疼的问题——if/else语句块里的代码完全不执行,哪怕是非常简单的测试代码都不行,但同样的代码在PyCharm里却能正常运行。我已经尝试重新安装Sublime了,可问题还是没解决,真的不想放弃用Sublime,来求助大家!

先给大家看一下我原本的爬虫代码(核心是想调用jc()函数,但不管输入yes还是no,函数里的逻辑都跑不起来):

import requests
from bs4 import BeautifulSoup
import lxml

def jc ():
    url = ("https://jc.ne10.uol.com.br")
    keywords = ["assaltos","petrobras", "Gasolina", "etanol", "diesel", "gnv", "postos", "postos de combustíveis", "ANP", "Petrobras", "construção civil", "mercado imobiliário", "Habitação estradas", "infraestrutura", "obras públicas", "argentinos","Brasil"]

    response = requests.get(url)
    soup = BeautifulSoup(response.content, "lxml")

    filtered_links = []
    for link in soup.find_all("a", href=True):
        for keyword in keywords:
            if keyword.lower() in link.text.lower() or keyword.lower() in link["href"].lower():
                filtered_links.append(link["href"])
                break

    Titles = []
    for title in soup.select("h1",class_="title"):
        for keyword in keywords:
            if keyword.lower() in title.text.lower():
                Titles.append(title.text)

    unique_links = list(set(filtered_links))

    for title in Titles:
        print("Titulo:")
        print(title)
    for link in unique_links:
        print("Link:")
        if (url == ("https://jc.ne10.uol.com.br//economia")):
            print("https://jc.ne10.uol.com.br/" + (link))
        else:
            print(link)

user_input = input("Do you want to execute the function? (yes/no): ").lower()

# Check user input and execute the function accordingly
if user_input == "yes":
    print(jc())
else:
    print("Function not executed.")

更离谱的是,哪怕是完全没有函数的极简测试代码,在Sublime里也同样不执行if/else里的内容:

response = input("Do you want to execute the function?")
if response == 'yes':
    print('hello')
else:
    print("goodbye")

有没有大佬遇到过类似的问题?或者能帮我排查一下是Sublime的设置问题,还是哪里的配置出了问题?

备注:内容来源于stack exchange,提问作者george Vasconcelos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 07:54:34