AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-3765883

user3765883's questions

Martin Hope
user3765883
Asked: 2024-12-12 23:49:09 +0800 CST

奇怪的布尔表达式

  • 7

我正在尝试调试(重写?)其他人的 Python/cherrypy Web 应用程序,并且遇到了以下“if”语句:

if not filename.endswith(".dat") and (
    filename.endswith(".dat") or not filename.endswith(".cup")
):
    raise RuntimeError(
        "Waypoint file {} has an unsupported format.".format(
            waypoint_file.filename
        )
    )

我认为这与以下内容相同:

if not A and (A or not B):

如果是这样,那么:

  • 如果A = False,那么它减少到if True and (False or not B):

    • if True and not B=not B
  • 如果A = True,那么它会减少到if False:即该if块永远不会执行

我很确定该块的目的if是警告用户所讨论文件的扩展名不是 也不是.DAT,.CUP但在我看来它并没有真正执行该意图。

我认为该if区块应该是:

if(not .DAT and not .CUP) = if not(.DAT or .CUP)

那正确吗?

python
  • 2 个回答
  • 69 Views
Martin Hope
user3765883
Asked: 2024-12-10 08:49:10 +0800 CST

Python:lines =file.readlines() 在每行前面添加额外的“b”字符?

  • 3

我正在尝试调试其他人构建的 Web 应用程序。该应用程序应该解析一个文本文件,其中包含以逗号分隔格式表示地理航点的行。当在 Windows 应用程序(如 notepad++)或基于 Web 的文本查看器https://filehelper.com中查看时,这些行看起来应该如此,即:

name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc

"Abfaltersb Chp",Abfalter,,4645.518N,01232.392E,952.0m,1,,,,

"Admont Chp",Admont C,,4734.994N,01427.156E,628.0m,1,,,,

"Admont Stift Kir",Admont S,,4734.517N,01427.700E,646.0m,1,,,,

"Admonterhaus",Admonter,,4737.917N,01429.483E,1720.0m,1,,,,

"Aflenz Kirche",Aflenz K,,4732.717N,01514.467E,772.0m,1,,,,

但是当我在循环中使用'cherrypy.log('line%s: %s' % (wpnum, line))在 Linux 终端窗口中显示行时,我得到:

[09/Dec/2024:23:37:08]  line1: b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n'
[09/Dec/2024:23:37:08]  line2: b'"Abfaltersb Chp",Abfalter,,4645.518N,01232.392E,952.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line3: b'"Admont Chp",Admont C,,4734.994N,01427.156E,628.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line4: b'"Admont Stift Kir",Admont S,,4734.517N,01427.700E,646.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line5: b'"Admonterhaus",Admonter,,4737.917N,01429.483E,1720.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line6: b'"Aflenz Kirche",Aflenz K,,4732.717N,01514.467E,772.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line7: b'"Afritz Church",Afritz C,,4643.650N,01347.983E,710.0m,1,,,,\r\n'
[09/Dec/2024:23:37:08]  line8: b'"Aich Assac Chp",Aich Ass,,4725.480N,01351.460E,736.0m,1,,,,\r\n'

在每行的开头添加“b'”。

所以我的问题是 - Python 的 lines = file.readlines() 函数是否真的在每一行中添加了“b'”,或者这是 cherrypy.log() 机制的某种产物?或者,正如 1981 年 Memorex 磁带广告所说的那样,“它是真实的,还是 Memorex?”

短暂性脑缺血发作,

坦率

python
  • 1 个回答
  • 35 Views
Martin Hope
user3765883
Asked: 2024-12-04 04:49:22 +0800 CST

在虚拟环境中成功安装了 cherrypy,但 cherrypy --version 说未找到命令

  • 5

Debian 书虫:

我正在尝试调试 cherrypy web 应用程序,因此我的计划是添加一些基于 cherrypy 的日志记录语句并在本地运行该应用程序。但是,当我尝试通过 pip 安装 cherrypy 时,我收到了“此环境由外部管理”错误 - 创建一个虚拟环境。因此,我创建了一个虚拟环境并(我认为成功)在那里安装了 cherrypy,但是当我询问版本号时,我得到了“未找到命令”的信息。详情如下:

使用 python3 -m venv my-virtual-env 创建虚拟环境,使用 . ./my-virtual-env/bin/activate 激活(提示现在显示'(my-virtual-env)') 使用 pip install cherypy 安装 cherrypy(得到'成功安装 cherrypy-18.10.0') 使用 cherrypy --version 检查 cherrypy 版本(得到'未找到命令') 使用 sudo cherrypy --version 检查 cherrypy 版本(得到'未找到命令')

进入 my-virtual-env 并执行 cherrypy --version (出现“未找到命令”)

有人能看到我在这里做错什么吗?

短暂性脑缺血发作,

坦率

pip
  • 1 个回答
  • 12 Views
Martin Hope
user3765883
Asked: 2024-05-27 22:15:18 +0800 CST

Python/Selenium 网络抓取脚本中的“str”对象不可调用错误

  • 4

我有一个非常简单的 Python/Selenium 网络抓取脚本,如下所示:

from re import L
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

cService = webdriver.ChromeService(executable_path="C:\\Users\\Frank\\Documents\\Visual Studio 2022\\Projects\\IV3_WebsiteAutomation\\chromedriver.exe")
driver = webdriver.Chrome(service = cService)
driver.get("https://app.iv3.us/login")
print(driver.title)

search_bar = driver.find_element("name", "userName")
search_bar.send_keys("[email protected]")
search_bar = driver.find_element("name", "password")
search_bar.send_keys("xxxxxxxxxxxxxxx")
search_bar.send_keys(Keys.RETURN)

# res = driver.find_element(By.XPATH(".//a[contains(@href,'View Active')]"))
# res = driver.find_element(By.XPATH("//a[contains(@href,'View Active')]"))
XXX = driver.find_element(By.XPATH("//div[./h4[text()='Moved from Registered Address']]//a[text()='View Active']"))

driver.close() 

运行时,“XXX = driver.find_element...”行会产生可怕的“str”对象不可调用错误。

谷歌搜索这个错误让我看到了很多帖子,描述了这个错误是如何因尝试使用Python保留字作为变量而引起的,但我看不出在我的脚本中会发生这种情况;我什至将“res”变量名称更改为“XXX”,但这并没有改变任何东西。

难道是这一行:

from selenium.webdriver.common.by import By

以及它在脚本最后一行的后续使用导致了问题?我从Selenium“定位元素”教程中得到了这个用法,所以如果这是问题所在,我会感到惊讶,但是......

TIA,

坦率

[编辑]:根据@OneCricketeer的请求,我已经包含了错误回溯:

IV3 'str' object is not callable Stack trace: > File "C:\Users\Frank\Documents\Visual Studio 2022\Projects\IV3_WebsiteAutomation\IV3_WebsiteAutomation.py", line 20, in <module> (Current frame) > XXX = driver.find_element(By.XPATH("//div[./h4[text()='Moved from Registered Address']]//a[text()='View Active']")) >TypeError: 'str' object is not callable Loaded 'main' Loaded 'runpy'
python
  • 1 个回答
  • 25 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve