小编Par*_*007的帖子

jQuery - 如何找到具有特定ID的元素?

我有一张桌子,每个td都有一个唯一的id,对应一些时间间隔(0800到0830 ...... 0830到0900等等).我有一个输入文本,用户将键入他们想要阻止的时间间隔.如果他们输入我的表中不存在的区间,换句话说,如果他们键入的区间与我的任何td的id不对应,我想显示一条警告说"此区间不是可用于阻止".

但是,我很难找到这个id.我这样做:

    var horaInicial = $("#horaInicial").val().split(':')[0] + $("#horaInicial").val().split(':')[1]; // this is remover the ":" from a formatted hour

    var verificaHorario = $("#tbIntervalos").find("td").attr("id", horaInicial);
Run Code Online (Sandbox Code Playgroud)

但是这个"verificaHorario"实际上是将我所有的td设置为这个horaInicial id.

那么,如何在我的表中找到一个id,如果它不存在则显示一些警告.

谢谢!!

jquery

39
推荐指数
4
解决办法
24万
查看次数

错误 429,在 google 上使用请求 python 进行简单查询

我试图在 Google 上的一个简单查询中获得第一个非广告结果。

res = requests.get('https://www.google.com?q=' + query)
Run Code Online (Sandbox Code Playgroud)

为查询分配任何值,您将收到错误消息。我试图添加一些标题,但没有任何变化。

我试图添加谷歌通常与查询相关联的所有其他参数,但没有任何变化。

如果您使用硒进行搜索,则没有问题。

错误代码是 429,但这似乎只是此查询的标准响应。它与我的 IP 无关,我也没有向 Google 发送垃圾邮件,而且这不会在一段时间后消失。

您知道为什么会发生这种情况吗,是否有我可以添加的标题或任何其他解决方案来查看结果,就像您在 google 上搜索该关键字一样?

python python-3.x python-requests selenium-webdriver

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

为什么输出不是1和1?

a = 0
b = 0
def test():
    a = 1
    b = 1

    class Test:
        print(a, b)
        a = 2
test()
Run Code Online (Sandbox Code Playgroud)

它给

0 1
Run Code Online (Sandbox Code Playgroud)

它应该是

1 1
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

python python-3.x

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

使用 Pytest 捕获 SystemExit 消息

我正在使用 pytest 编写测试。我遇到的情况是,SystemExit如果输入错误,某些函数会在终端上抛出一些错误消息。

我想为抛出的情况编写测试SystemExit,并验证输出错误消息中是否有特定的字符串。

这是代码:


def test_validate_input():
  ...
  with pytest.raises(SystemExit) as error:
    _validate_function(test_wrong_input)
  assert error.value.code == 1
Run Code Online (Sandbox Code Playgroud)

error如果我运行验证某些输入的实际函数,我无法获得输出错误消息,因为我在命令行上得到的消息。请让我知道我在这里缺少什么。

编辑:

我正在调用 asubprocess.call_output来运行引发错误的命令。我必须在调用stderr=subprocess.STDOUT中添加call_output作为参数才能获取错误消息。然后我在测试中使用了@p3j4p5的答案。

python systemexit pytest python-3.x

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

tesseract中以下代码的字典输出的键值是什么意思?

我在 python 中使用以下代码:

我在字典中得到以下键值:

'block_num' 'conf'  'level' 'line_num'  'page_num'  'par_num', 'text', 'top', 'width', 'word_num', 'height, 'left'.
Run Code Online (Sandbox Code Playgroud)

这些关键值意味着什么

我试图在tesseract的官方文档中找到这些。如果您有一些解释相同的链接,请提供或解释它。

'block_num' 'conf'  'level' 'line_num'  'page_num'  'par_num', 'text', 'top', 'width', 'word_num', 'height, 'left'.
Run Code Online (Sandbox Code Playgroud)

tesseract text-extraction python-3.x python-tesseract

4
推荐指数
1
解决办法
1966
查看次数

如何在 vscode 中调试单个 Django 测试?

我添加了一个启动配置,允许我在 Django 中运行所有测试,另一个允许我运行服务器,这两个都可以正常工作。

我正在寻找一种调试单个文件的方法,但是${file}在参数中使用给出了 django 不喜欢的正常路径。

我想要一种更改${file}为 python 路径的方法,以便我可以在单个文件上调试我的测试。

python manage.py test --noinput --keepdb python.path.to.my.file

在命令行中工作。

下面的配置好像差不多:

      {   "name": "Test File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "test",
                "--noinput",
                "--keepdb",
                "${file}"
            ],
            "django": true
        }
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此配置时出现错误,我认为这是因为 ${file}变成

path/to/my/file而不是path.to.my.file.

python django visual-studio-code vscode-debugger

3
推荐指数
4
解决办法
2888
查看次数

Selenium 围绕“TimeoutException”的工作未定义?

我想解决Python Selenium 中的TimeOutException

有时候是这样的:

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements
Run Code Online (Sandbox Code Playgroud)

3.)在我们遇到异常2.2)并且 try/catch 不起作用之后,我永远无法到达步骤。

步骤之后3.)还有许多其他步骤。我怎样才能让程序在这个超时时间内运行。当元素不存在时,就会超时。

代码

1.) Open Browser, Call URL
2.) Trying to find Element
2.1) Works sometimes
2.2) Works not sometimes and throws TimeoutException
3.) Should look for other elements
Run Code Online (Sandbox Code Playgroud)

结果

    def getByClass(InputElement, driver):
        getByClass = WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, InputElement)))
        return getByClass …
Run Code Online (Sandbox Code Playgroud)

python selenium

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

AND感知器的权重和偏差是多少?

我正在实现AND Perceptron,在确定权重和组合的偏向以使其与AND Truth表匹配时遇到困难。

这是我编写的代码:

import pandas as pd

# Set weight1, weight2, and bias
weight1 = 2.0
weight2 = -1.0
bias = -1.0

# Inputs and outputs
test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
correct_outputs = [False, False, False, True]
outputs = []

# Generate and check output
for test_input, correct_output in zip(test_inputs, correct_outputs):
    linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias
    output = int(linear_combination >= 0)
    is_correct_string = 'Yes' if output == correct_output …
Run Code Online (Sandbox Code Playgroud)

python neural-network pandas

1
推荐指数
2
解决办法
1094
查看次数

使用 python3 创建 virtualenv

我一般python2.7用于项目。

对于一个项目,我需要使用python 3.5+.

我在 Mac 上安装了 python3。

virtualenv使用 pip3安装。

现在当我运行命令时

virtualenv -p python3 test
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Running virtualenv with interpreter /usr/bin/python3
Already using interpreter /Library/Developer/CommandLineTools/usr/bin/python3
Using base prefix '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7'
New python executable in /Users/sourabh/virtualenvs/test/bin/python3
Also creating executable in /Users/sourabh/virtualenvs/test/bin/python
Traceback (most recent call last):
  File "/Library/Python/3.7/site-packages/virtualenv.py", line 2632, in <module>
    main()
  File "/Library/Python/3.7/site-packages/virtualenv.py", line 870, in main
    symlink=options.symlink,
  File "/Library/Python/3.7/site-packages/virtualenv.py", line 1156, in create_environment
    install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
  File "/Library/Python/3.7/site-packages/virtualenv.py", line 1621, …
Run Code Online (Sandbox Code Playgroud)

python virtualenv python-3.x

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

Finding Subarrays of Vowels from a given String

You are given a string S, and you have to find all the amazing substrings of S.

Amazing Substring is one that starts with a vowel (a, e, i, o, u, A, E, I, O, U).

Input

The only argument given is string S.

Output

Return a single integer X mod 10003, here X is number of Amazing Substrings in given string.

Constraints

  • 1 <= length(S) <= 1e6
  • S can have special characters

Example

Input
    ABEC

Output
    6

Explanation
    Amazing …
Run Code Online (Sandbox Code Playgroud)

python arrays string algorithm

-1
推荐指数
1
解决办法
204
查看次数

TypeError:“bool”类型的对象没有 len()

我有以下代码:

store_id = 1
acc_id = str(store_id)
print("type of acc_id is ", type(acc_id))

x = len(acc_id)
print(x)

if len(acc_id == 1):
    acc_id += '000' + acc_id
Run Code Online (Sandbox Code Playgroud)

输出:

 type of acc_id is  <class 'str'>
 1
 TypeError: object of type 'bool' has no len()
Run Code Online (Sandbox Code Playgroud)

acc_id当显然是一个字符串时,为什么我会收到此错误?

python python-3.x

-1
推荐指数
1
解决办法
9476
查看次数