挽手叙旧

文章 评论 浏览 26

挽手叙旧 2025-02-11 12:11:08

浮点符号以完全相同的方式打破了您在小学时学到的十进制(基本10)符号,并且每天使用使用,仅适用于Base-2。

要理解,考虑将2/3表示为十进制价值。完全不可能做到!世界将在您完成小数点之后写6的内容之前结束,因此,我们将其写入一些位置,将其写入最后的7个位置,并认为它足够准确。

以同样的方式,1/10(十进制为0.1)不能完全以“十进制”值表示基础2(二进制);小数点后的重复模式永远存在。该值不准确,因此您无法使用普通的浮点方法对其进行精确数学。就像基本10一样,还有其他值也表现出此问题。

Floating point notation is broken in the exact same way the decimal (base-10) notation you learned in grade school and use every day is broken, just for base-2.

To understand, think about representing 2/3 as a decimal value. It's impossible to do exactly! The world will end before you finish writing the 6's after the decimal point, and so instead we write to some number of places, round to a final 7, and consider it sufficiently accurate.

In the same way, 1/10 (decimal 0.1) cannot be represented exactly in base 2 (binary) as a "decimal" value; a repeating pattern after the decimal point goes on forever. The value is not exact, and therefore you can't do exact math with it using normal floating point methods. Just like with base 10, there are other values that exhibit this problem as well.

浮点数学破裂了吗?

挽手叙旧 2025-02-10 09:58:57

我用enviroment.getExternalStorageDireTory()函数解决了此问题

I solved this with Enviroment.getExternalStorageDiretory() function

如何在Android Q API 30中导出CSV文件WIH OPENCSV库? -Kotlin

挽手叙旧 2025-02-10 05:16:14

iiuc,您可以尝试使用 str.Contains series.apply 尝试REGEX

val = 1

df['flag'] = df['col'].str.contains(f'(^{val},)|(,{val},)|(,{val}$)')
# or
df['flag'] = df['col'].apply(lambda s: str(val) in s.split(','))
print(df)

           col   flag
0        1,4,7   True
1    11,12,4,7  False
2  11,24,2,7,1   True

IIUC, you can try regex with str.contains or Series.apply

val = 1

df['flag'] = df['col'].str.contains(f'(^{val},)|(,{val},)|(,{val}$)')
# or
df['flag'] = df['col'].apply(lambda s: str(val) in s.split(','))
print(df)

           col   flag
0        1,4,7   True
1    11,12,4,7  False
2  11,24,2,7,1   True

如何搜索逗号分隔的列以1或10到19的值

挽手叙旧 2025-02-10 05:06:57

尝试/块将起作用,但完成此任务的更快,更清洁的方法是使用 str.isdigit()

while True:
    age = input("Please enter your age: ")
    if age.isdigit():
        age = int(age)
        break
    else:
        print("Invalid number '{age}'. Try again.".format(age=age))

if age >= 18: 
    print("You are able to vote in the United States!")
else:
    print("You are not able to vote in the United States.")

While a try/except block will work, a much faster and cleaner way to accomplish this task would be to use str.isdigit().

while True:
    age = input("Please enter your age: ")
    if age.isdigit():
        age = int(age)
        break
    else:
        print("Invalid number '{age}'. Try again.".format(age=age))

if age >= 18: 
    print("You are able to vote in the United States!")
else:
    print("You are not able to vote in the United States.")

询问用户输入,直到他们给出有效的响应

挽手叙旧 2025-02-10 04:34:01

我认为您应该在项目中使用DTOS!例如,模型B只有创建项目(即StringProperty和ModelAid)以及控制器内部所需的数据,您将与现有的Modela关联。

您可以在下面的链接上查看实体框架。

I think you should star to use DTOs on your project! For example, model B would have only the data necessary to create the item, i.e StringProperty and ModelAId, and inside of your controller, you would associate with the existing ModelA.

You can have a look on the entity framework on the link below.

https://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx

从邮政参数中删除导航属性

挽手叙旧 2025-02-10 02:52:00

您可以使用JSON路径表达式来过滤所需的行:

where the_column @? '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'

为了实际获取 fulnumber ,您需要重复JSON路径以提取所讨论的数组元素:

select id, 
       the_column ->> 'lastname', 
       jsonb_path_query_first(the_column, 
                              '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'
                             ) ->> 'fullNumber' as fullnumber
from the_table
where the_column @? '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'

条件可以潜在地使用 the_column 上的杜松子酒索引以提高性能。

如果没有这样的索引或性能并不重要,则可以通过使用派生表来避免重复JSON路径:

select *
from (
  select id, 
         the_column ->> 'lastname', 
         jsonb_path_query_first(the_column, '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)') ->> 'fullNumber' as fullnumber
  from the_table
) t 
where fullnumber is not null

You can use a JSON path expression to filter out the needed rows:

where the_column @? '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'

To actually get the fullNumber you need to repeat the JSON path in order to extract the array element in question:

select id, 
       the_column ->> 'lastname', 
       jsonb_path_query_first(the_column, 
                              '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'
                             ) ->> 'fullNumber' as fullnumber
from the_table
where the_column @? '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)'

The WHERE condition can potentially make use of a GIN index on the_column to improve performance.

If there is no such index or performance isn't that important, you can avoid repeating the JSON path by using a derived table:

select *
from (
  select id, 
         the_column ->> 'lastname', 
         jsonb_path_query_first(the_column, '$.contacts.phoneList[*] ? (@.fullNumber like_regex "^067" && @.verifyStateId == 1)') ->> 'fullNumber' as fullnumber
  from the_table
) t 
where fullnumber is not null

Postgres JSON数组 - 如何做选择字段

挽手叙旧 2025-02-09 17:57:41
import csv

excel = open(r"C:\Users\JP Dayao\Desktop\Python\Constraints Study\sample.csv")
raw = csv.reader(excel)
raw_int = []

for i in raw:
    for j in i:
        raw_int.append(int(j))

print(raw_int)
excel.close()
import csv

excel = open(r"C:\Users\JP Dayao\Desktop\Python\Constraints Study\sample.csv")
raw = csv.reader(excel)
raw_int = []

for i in raw:
    for j in i:
        raw_int.append(int(j))

print(raw_int)
excel.close()

将带有Str元素的列表转换为用整数元素列表

挽手叙旧 2025-02-09 10:54:53

原因 in 按钮未得到单击是因为xpath //*[@ID =“ __ next”]/div/div/div/div [3]/div [2]/div [2 ]/button [2] 是不正确的 ID Next 是主要容器 div ,我们通过它导致到<<代码>符号按钮通过提供剩余的HTML nodre结构

,您可以根据其类值直接选择“ clast ='button sign-in'] 基于其类值的符号

您的登录解决方案看起来像

driver = webdriver.Chrome(executable_path='C:\webdrivers\chromedriver.exe')
driver.maximize_window()
driver.get('https://www.metal.com/Nickel/201102250239')
# Click on Sign In
driver.find_element(By.XPATH, "//button[@class='button sign-in']").click()
# Enter username
driver.find_element(By.ID, "user_name").send_keys("your username")
# Enter password
driver.find_element(By.ID, "password").send_keys("your password") 
# Click Sign In
driver.find_element(By.XPATH, "//button[@type='submit']").click()

刮擦数据

for element in driver.find_elements_by_class_name("historyBodyRow___1Bk9u"):
 elements =element.find_elements_by_tag_name("div")
 print("Date="+ elements[0].text)
 print("Price Range="+ elements[1].text)
 print("Avg="+ elements[2].text)
 print("Change="+ elements[3].text)
 print("Unit="+ elements[4].text)

添加到csv

import csv
f = open('Path where you want to store the file', 'w')
writer = csv.writer(f)
for element in driver.find_elements_by_class_name("historyBodyRow___1Bk9u"):
  elements =element.find_elements_by_tag_name("div")
  entry = [elements[0].text ,elements[1].text ,elements[2].text , elements[3].text, elements[4].text]
  writer.writerow(entry)

f.close

The reason sign in button is not getting clicked is because the xpath //*[@id="__next"]/div/div[3]/div[2]/div[2]/button[2] is incorrect the id of next is the main container div through which we are naviagting to the sign button by providing remaining html nodre structure

Instead you can directly select the sign in button as //button[@class='button sign-in'] based on its class value Refer Image attached

Your solution for sign in would look like

driver = webdriver.Chrome(executable_path='C:\webdrivers\chromedriver.exe')
driver.maximize_window()
driver.get('https://www.metal.com/Nickel/201102250239')
# Click on Sign In
driver.find_element(By.XPATH, "//button[@class='button sign-in']").click()
# Enter username
driver.find_element(By.ID, "user_name").send_keys("your username")
# Enter password
driver.find_element(By.ID, "password").send_keys("your password") 
# Click Sign In
driver.find_element(By.XPATH, "//button[@type='submit']").click()

To scrape data

for element in driver.find_elements_by_class_name("historyBodyRow___1Bk9u"):
 elements =element.find_elements_by_tag_name("div")
 print("Date="+ elements[0].text)
 print("Price Range="+ elements[1].text)
 print("Avg="+ elements[2].text)
 print("Change="+ elements[3].text)
 print("Unit="+ elements[4].text)

Add To CSV

import csv
f = open('Path where you want to store the file', 'w')
writer = csv.writer(f)
for element in driver.find_elements_by_class_name("historyBodyRow___1Bk9u"):
  elements =element.find_elements_by_tag_name("div")
  entry = [elements[0].text ,elements[1].text ,elements[2].text , elements[3].text, elements[4].text]
  writer.writerow(entry)

f.close

Python Web刮擦/数据提取

挽手叙旧 2025-02-09 02:37:22

我遇到了相同的问题,并用 die() echo json_encode(...)在服务器端上解决

I had the same problem and solved it with a die() after echo json_encode(...) on server side

如何求解警告“ JSON分析错误:未识别的令牌”

挽手叙旧 2025-02-08 18:09:56

&lt; tab&gt; 替换或替换为 \ t 的字符,, cartince 。

并将输出保存到文件中:/tuber/dag_run_ctx/tbl_qc.csv

Replace or substitute each occurrence of <TAB> character represented as \t with , character.

And save the output into file: /tuber/dag_run_ctx/tbl_qc.csv

SED命令下方有什么?

挽手叙旧 2025-02-08 03:14:34

我在寻找相同问题的答案时找到了此页面,但我想我已经弄清楚了。我将使用计数器进行HTTP响应,然后添加包含状态代码值的标签,例如status_code。然后,您可以过滤它,例如 http_response {status_code =“ 200”} 。我希望那起作用。

I found this page while looking for the answer to the same question but I think I figured it out. I would use a counter for the http responses and then add a label, such as status_code, that contains the value of the status code. You can then filter it such as http_response{status_code="200"}. I hope that works.

Prometheus公制类型用于表示HTTP状态代码

挽手叙旧 2025-02-07 19:21:14

我遇到了一堆,但从未尝试过解决它。查看我找到的文档 Extended_schema_serializer ,可能会做您需要的事情。这是

  • component_name - 覆盖默认的类名称提取
@extended_schema_serializer(component_name="SomeNiceReallyLongId")
class Input(Serializer):
    # pass

其较长而丑陋,但可以由装饰器上的装饰器修复:d

eding

我最终实现了这一点。这是我写的小包装纸。这只是使序列化和字段之间的较短和一致的事情。

您可以在序列化器上多次使用 extended_schema_serializer ,因此不会破坏任何内容。

@oapi.name("UserEditRequest")
@extend_schema_serializer(examples=[]) # other settings
class EditSerializer(ModelSerializer):
    pass
# oapi.py
from drf_spectacular.utils import set_override as _set_override

def name(val: str):
    def decorator(klass):
        if issubclass(klass, BaseSerializer):
            _set_override(klass, "component_name", val)
        elif isinstance(klass, Field):
            _set_override(klass, "field_component_name", val)
        else:
            raise Exception(f"Unhandled class: {klass}")

        return klass

    return decorator

I've run into this a bunch, but never tried to solve it. Looking at the docs I found extended_schema_serializer, which might do what you need. Here is the full api, and the relevant point:

  • component_name – override default class name extraction
@extended_schema_serializer(component_name="SomeNiceReallyLongId")
class Input(Serializer):
    # pass

Its kinda long and ugly, but that can be fixed by a decorator on the decorator :D

Edit:

I ended up implementing this. Here is the small wrapper I wrote. It just makes things shorter and consistent between serializers and fields.

You can use extended_schema_serializer more than once on a serializer, so this won't break anything.

@oapi.name("UserEditRequest")
@extend_schema_serializer(examples=[]) # other settings
class EditSerializer(ModelSerializer):
    pass
# oapi.py
from drf_spectacular.utils import set_override as _set_override

def name(val: str):
    def decorator(klass):
        if issubclass(klass, BaseSerializer):
            _set_override(klass, "component_name", val)
        elif isinstance(klass, Field):
            _set_override(klass, "field_component_name", val)
        else:
            raise Exception(f"Unhandled class: {klass}")

        return klass

    return decorator

有没有一种方法可以更改DRF-Spectacular中序列化器的自动化shema名称

挽手叙旧 2025-02-07 15:25:59

简单的方式:将粒子作为空对象的孩子然后旋转父。

Easy Way: Place the particle as child of an empty object then rotate parent.

统一粒子2D不会旋转

挽手叙旧 2025-02-06 19:38:48

我有一个Minikube的问题,因为我只需要它来测试目的,所以我添加了 - set persistence.enabled =“ false”

完整命令是:

helm install minio bitnami/minio --namespace minio --create-namespace --set image.debug="true" --set service.type="ClusterIP" --set persistence.enabled="false"

I had this problem with a minikube, since I just needed it for testing purposes I added --set persistence.enabled="false"

The Full Command being:

helm install minio bitnami/minio --namespace minio --create-namespace --set image.debug="true" --set service.type="ClusterIP" --set persistence.enabled="false"

Minio允许拒绝

挽手叙旧 2025-02-06 10:52:59

尝试此代码: -

from zdrive import Downloader

output_directory = "/home/abhinav/Documents"
d = Downloader()

# folder which want to download from Drive
folder_id = 'XXXX-YYYY-ZZZZ'
d.downloadFolder(folder_id, destinationFolder=output_directory)

Try this code:-

from zdrive import Downloader

output_directory = "/home/abhinav/Documents"
d = Downloader()

# folder which want to download from Drive
folder_id = 'XXXX-YYYY-ZZZZ'
d.downloadFolder(folder_id, destinationFolder=output_directory)

使用Python从Google Drive下载文件

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文