[旋木]

文章 评论 浏览 30

[旋木] 2025-02-07 02:40:14

基本上,您需要以某种方式构造一个集合,以便在结果中只有唯一的组合(删除列表的所有排列除外)。这可以通过对列表的每个子列表进行排序,然后构建字典来完成。

import more_itertools as mit
import pprint as pp
from operator import itemgetter
from itertools import groupby
lst=[2, 2, 2, 3, 5, 7]
x = [part for k in range(1, len(lst) + 1) for part in mit.set_partitions(lst, k)]
x.sort()
x = list(map(itemgetter(0), groupby(x)))

# sort each sublist
for temp in x:
    temp = temp.sort()

# create a dictionary(hashtable), key of a dictionary should be immutable therefore stringified it
unique_combinations = {str(temp):temp for temp in x}
# since unique keys will have unique values, we have unique combinations here
unique_combinations = list(unique_combinations.values())
pp.pprint(unique_combinations)

输出

[[[2], [2], [2], [3], [5], [7]],
 [[2], [2], [2], [3], [5, 7]],
 [[2], [2], [2], [3, 5], [7]],
 [[2], [2], [2], [3, 5, 7]],
 [[2], [2], [2], [3, 7], [5]],
 [[2], [2], [2, 3], [5], [7]],
 [[2], [2], [2, 3], [5, 7]],
 [[2], [2], [2, 3, 5], [7]],
 [[2], [2], [2, 3, 5, 7]],
 [[2], [2], [2, 5], [3, 7]],
 [[2], [2], [2, 5], [3], [7]],
 [[2], [2], [2, 5, 7], [3]],
 [[2], [2], [2, 7], [3], [5]],
 [[2], [2], [2, 7], [3, 5]],
 [[2], [2], [2, 3, 7], [5]],
 [[2], [2, 2], [3], [5], [7]],
 [[2], [2, 2], [3], [5, 7]],
 [[2], [2, 2], [3, 5], [7]],
 [[2], [2, 2], [3, 5, 7]],
 [[2], [2, 2], [3, 7], [5]],
 [[2], [2, 2, 3], [5], [7]],
 [[2], [2, 2, 3], [5, 7]],
 [[2], [2, 2, 3, 5], [7]],
 [[2], [2, 2, 3, 5, 7]],
 [[2], [2, 2, 5], [3, 7]],
 [[2], [2, 3], [2, 5], [7]],
 [[2], [2, 3], [2, 5, 7]],
 [[2], [2, 3], [2, 7], [5]],
 [[2], [2, 3, 5], [2, 7]],
 [[2], [2, 3, 7], [2, 5]],
 [[2], [2, 2, 5], [3], [7]],
 [[2], [2, 2, 5, 7], [3]],
 [[2], [2, 5], [2, 7], [3]],
 [[2], [2, 2, 7], [3], [5]],
 [[2], [2, 2, 7], [3, 5]],
 [[2], [2, 2, 3, 7], [5]],
 [[2, 2], [2, 3], [5], [7]],
 [[2, 2], [2, 3], [5, 7]],
 [[2, 2], [2, 3, 5], [7]],
 [[2, 2], [2, 3, 5, 7]],
 [[2, 2], [2, 5], [3, 7]],
 [[2, 2], [2, 5], [3], [7]],
 [[2, 2], [2, 5, 7], [3]],
 [[2, 2], [2, 7], [3], [5]],
 [[2, 2], [2, 7], [3, 5]],
 [[2, 2], [2, 3, 7], [5]],
 [[2, 2, 2], [3], [5], [7]],
 [[2, 2, 2], [3], [5, 7]],
 [[2, 2, 2], [3, 5], [7]],
 [[2, 2, 2], [3, 5, 7]],
 [[2, 2, 2], [3, 7], [5]],
 [[2, 2, 2, 3], [5], [7]],
 [[2, 2, 2, 3], [5, 7]],
 [[2, 2, 2, 3, 5], [7]],
 [[2, 2, 2, 3, 5, 7]],
 [[2, 2, 2, 5], [3, 7]],
 [[2, 2, 3], [2, 5], [7]],
 [[2, 2, 3], [2, 5, 7]],
 [[2, 2, 3], [2, 7], [5]],
 [[2, 2, 3, 5], [2, 7]],
 [[2, 2, 5], [2, 3, 7]],
 [[2, 2, 5], [2, 3], [7]],
 [[2, 2, 5, 7], [2, 3]],
 [[2, 3], [2, 5], [2, 7]],
 [[2, 2, 7], [2, 3], [5]],
 [[2, 2, 7], [2, 3, 5]],
 [[2, 2, 3, 7], [2, 5]],
 [[2, 2, 2, 5], [3], [7]],
 [[2, 2, 2, 5, 7], [3]],
 [[2, 2, 5], [2, 7], [3]],
 [[2, 2, 7], [2, 5], [3]],
 [[2, 2, 2, 7], [3], [5]],
 [[2, 2, 2, 7], [3, 5]],
 [[2, 2, 2, 3, 7], [5]]]

You basically need to construct a set somehow so that you only have unique combinations in your result(removing all permutations of a list except 1). This can be done by sorting each sublist of the list and then constructing a dictionary.

import more_itertools as mit
import pprint as pp
from operator import itemgetter
from itertools import groupby
lst=[2, 2, 2, 3, 5, 7]
x = [part for k in range(1, len(lst) + 1) for part in mit.set_partitions(lst, k)]
x.sort()
x = list(map(itemgetter(0), groupby(x)))

# sort each sublist
for temp in x:
    temp = temp.sort()

# create a dictionary(hashtable), key of a dictionary should be immutable therefore stringified it
unique_combinations = {str(temp):temp for temp in x}
# since unique keys will have unique values, we have unique combinations here
unique_combinations = list(unique_combinations.values())
pp.pprint(unique_combinations)

Output

[[[2], [2], [2], [3], [5], [7]],
 [[2], [2], [2], [3], [5, 7]],
 [[2], [2], [2], [3, 5], [7]],
 [[2], [2], [2], [3, 5, 7]],
 [[2], [2], [2], [3, 7], [5]],
 [[2], [2], [2, 3], [5], [7]],
 [[2], [2], [2, 3], [5, 7]],
 [[2], [2], [2, 3, 5], [7]],
 [[2], [2], [2, 3, 5, 7]],
 [[2], [2], [2, 5], [3, 7]],
 [[2], [2], [2, 5], [3], [7]],
 [[2], [2], [2, 5, 7], [3]],
 [[2], [2], [2, 7], [3], [5]],
 [[2], [2], [2, 7], [3, 5]],
 [[2], [2], [2, 3, 7], [5]],
 [[2], [2, 2], [3], [5], [7]],
 [[2], [2, 2], [3], [5, 7]],
 [[2], [2, 2], [3, 5], [7]],
 [[2], [2, 2], [3, 5, 7]],
 [[2], [2, 2], [3, 7], [5]],
 [[2], [2, 2, 3], [5], [7]],
 [[2], [2, 2, 3], [5, 7]],
 [[2], [2, 2, 3, 5], [7]],
 [[2], [2, 2, 3, 5, 7]],
 [[2], [2, 2, 5], [3, 7]],
 [[2], [2, 3], [2, 5], [7]],
 [[2], [2, 3], [2, 5, 7]],
 [[2], [2, 3], [2, 7], [5]],
 [[2], [2, 3, 5], [2, 7]],
 [[2], [2, 3, 7], [2, 5]],
 [[2], [2, 2, 5], [3], [7]],
 [[2], [2, 2, 5, 7], [3]],
 [[2], [2, 5], [2, 7], [3]],
 [[2], [2, 2, 7], [3], [5]],
 [[2], [2, 2, 7], [3, 5]],
 [[2], [2, 2, 3, 7], [5]],
 [[2, 2], [2, 3], [5], [7]],
 [[2, 2], [2, 3], [5, 7]],
 [[2, 2], [2, 3, 5], [7]],
 [[2, 2], [2, 3, 5, 7]],
 [[2, 2], [2, 5], [3, 7]],
 [[2, 2], [2, 5], [3], [7]],
 [[2, 2], [2, 5, 7], [3]],
 [[2, 2], [2, 7], [3], [5]],
 [[2, 2], [2, 7], [3, 5]],
 [[2, 2], [2, 3, 7], [5]],
 [[2, 2, 2], [3], [5], [7]],
 [[2, 2, 2], [3], [5, 7]],
 [[2, 2, 2], [3, 5], [7]],
 [[2, 2, 2], [3, 5, 7]],
 [[2, 2, 2], [3, 7], [5]],
 [[2, 2, 2, 3], [5], [7]],
 [[2, 2, 2, 3], [5, 7]],
 [[2, 2, 2, 3, 5], [7]],
 [[2, 2, 2, 3, 5, 7]],
 [[2, 2, 2, 5], [3, 7]],
 [[2, 2, 3], [2, 5], [7]],
 [[2, 2, 3], [2, 5, 7]],
 [[2, 2, 3], [2, 7], [5]],
 [[2, 2, 3, 5], [2, 7]],
 [[2, 2, 5], [2, 3, 7]],
 [[2, 2, 5], [2, 3], [7]],
 [[2, 2, 5, 7], [2, 3]],
 [[2, 3], [2, 5], [2, 7]],
 [[2, 2, 7], [2, 3], [5]],
 [[2, 2, 7], [2, 3, 5]],
 [[2, 2, 3, 7], [2, 5]],
 [[2, 2, 2, 5], [3], [7]],
 [[2, 2, 2, 5, 7], [3]],
 [[2, 2, 5], [2, 7], [3]],
 [[2, 2, 7], [2, 5], [3]],
 [[2, 2, 2, 7], [3], [5]],
 [[2, 2, 2, 7], [3, 5]],
 [[2, 2, 2, 3, 7], [5]]]

将给定列表划分为两个或多个无序集

[旋木] 2025-02-06 13:20:24

有2个步骤:

1。盒子细分

我们可以假设由于存在传送带,因此不会发生背景更改。我们可以使用不同的颜色空间进行分割。在下面,我使用了HSV色彩空间:

img = cv2.imread('box.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Performing threshold on the hue channel `hsv[:,:,0]`
th = cv2.threshold(hsv[:,:,0],127,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)[1]

掩盖二进制图像中最大的轮廓:

def get_region(image):
    contours, hierarchy = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    c = max(contours, key = cv2.contourArea)
    black = np.zeros((image.shape[0], image.shape[1]), np.uint8)
    mask = cv2.drawContours(black,[c],0,255, -1)
    return mask
mask = get_region(th)

在原始图像上应用掩码:

masked_img = cv2.bitwise_and(img, img, mask = mask)

“在此处输入映像”

2。文本检测:

文本区域以白色封闭,可以通过应用合适的阈值再次隔离。 (您可能需要采用一些统计措施来计算阈值

# Applying threshold at 220 on green channel of 'masked_img'
result = cv2.threshold(masked_img[:,:,1],220,255,cv2.THRESH_BINARY)[1]

“在此处输入图像说明”

注意:

  1. 代码是为共享图像编写的。对于不同尺寸的盒子,您可以用大约4个顶点/侧面过滤轮廓。
# Function to extract rectangular contours above a certain area
def extract_rect(contours, area_threshold):                           
    rect_contours = []
    for c in contours:
        if  cv2.contourArea(c) > area_threshold:
            perimeter = cv2.arcLength(c, True)  
            approx = cv2.approxPolyDP(c, 0.02*perimeter, True)    
            if len(approx) == 4:
                cv2.drawContours(image, [approx], 0, (0,255,0),2)
                rect_contours.append(c)
    return rect_contours
  1. 使用统计值(平均值,中值等)的实验以找到最佳阈值来检测文本区域。

There are 2 steps to be followed:

1. Box segmentation

We can assume there will be no background change since the conveyor belt is present. We can segment the box using a different color space. In the following I have used HSV color space:

img = cv2.imread('box.jpg')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Performing threshold on the hue channel `hsv[:,:,0]`
th = cv2.threshold(hsv[:,:,0],127,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)[1]

Masking the largest contour in the binary image:

def get_region(image):
    contours, hierarchy = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    c = max(contours, key = cv2.contourArea)
    black = np.zeros((image.shape[0], image.shape[1]), np.uint8)
    mask = cv2.drawContours(black,[c],0,255, -1)
    return mask
mask = get_region(th)

Applying the mask on the original image:

masked_img = cv2.bitwise_and(img, img, mask = mask)

enter image description here

2. Text Detection:

The text region is enclosed in white, which can be isolated again by applying a suitable threshold. (You might want to apply some statistical measure to calculate the threshold)

# Applying threshold at 220 on green channel of 'masked_img'
result = cv2.threshold(masked_img[:,:,1],220,255,cv2.THRESH_BINARY)[1]

enter image description here

Note:

  1. The code is written for the shared image. For boxes of different sizes you can filter contours with approximately 4 vertices/sides.
# Function to extract rectangular contours above a certain area
def extract_rect(contours, area_threshold):                           
    rect_contours = []
    for c in contours:
        if  cv2.contourArea(c) > area_threshold:
            perimeter = cv2.arcLength(c, True)  
            approx = cv2.approxPolyDP(c, 0.02*perimeter, True)    
            if len(approx) == 4:
                cv2.drawContours(image, [approx], 0, (0,255,0),2)
                rect_contours.append(c)
    return rect_contours
  1. Experiment using a statistical value (mean, median, etc.) to find optimal threshold to detect text region.

使用OpenCV检测纸板箱和文字

[旋木] 2025-02-06 11:31:29

Axios是单身人士,这意味着您在任何导入的情况下都有一个实例。

这意味着,如果我们将其包括在测试中,则它将与您要测试的代码中的实例相同。

因此,如果您在测试代码中导入Axios

import axios from 'axios';

组件和测试中的一个Axios实例。您将能够对此做任何事情,包括嘲笑和固执。
您可以用开玩笑对其进行模拟:

jest.mock("axios");

我在模拟Axios上找到了一些更多信息, jest 在这里

Axios is a singleton, meaning that you have a single instance wherever you import it.

It means that if we include it in our tests, it will be the same instance as in the code you are trying to test.

So if you'd import axios in your test code:

import axios from 'axios';

You would have a single axios instance in your component and tests. And you would be able to do anything with it, mocking and stubbing included.
You could mock it with jest with:

jest.mock("axios");

I found a bit of more info on mocking axios with jest here.

开玩笑的莫克 - 阿克西奥斯模拟拦截器

[旋木] 2025-02-06 09:22:18

column_cell是对象的元组。因此,column_cell [0]是第一个元组,但是对象不会

if column_cell[0] == column_name:

使用值属性等于字符串值,否则它将不匹配您的标题,并且永远不会继续与代码的打印部分。

if column_cell[0].value == column_name:

column_cell is a tuple of objects. So column_cell[0] is the first tuple but the object is not going to equal a string value

if column_cell[0] == column_name:

try using the value attribute, otherwise it will not match your header and never continue to the print part of the code.

if column_cell[0].value == column_name:

打印功能不会从python中的xlsx返回python的数据

[旋木] 2025-02-06 02:20:43

我通过执行以下操作修复了它:

if ($_REQUEST['lines_available'] == 0) {
    $campaign->lines_available = null;
}

这是在将条目保存在控制器中之前完成的。

I fixed it by doing the following:

if ($_REQUEST['lines_available'] == 0) {
    $campaign->lines_available = null;
}

This is done before the entry is saved within the controller.

无效的表单数据是返回值的“ 0”。在数据库中

[旋木] 2025-02-05 16:17:31

扩展当用例将步骤添加到另一个头等舱用例时。

例如,想象“提取现金”是自动柜员机(ATM)的用例。 “评估费”将延长撤回现金,并描述ATM用户不在ATM拥有机构存储时实例化的条件“扩展点”。请注意,基本的“提取现金”用例就独立存在,而无需扩展。

包括用于提取在多种用例中重复的用例片段。随附的用例不能单独使用,如果没有包含的用例,原始用例就不完整。仅在重复且通过设计(而不是偶然)存在重复的情况下,才应很少使用。

例如,在每个ATM用例开始时发生的事件流(当用户放入其ATM卡时,输入PIN并显示为主菜单时)将是一个很好的候选人。

Extend is used when a use case adds steps to another first-class use case.

For example, imagine "Withdraw Cash" is a use case of an Automated Teller Machine (ATM). "Assess Fee" would extend Withdraw Cash and describe the conditional "extension point" that is instantiated when the ATM user doesn't bank at the ATM's owning institution. Notice that the basic "Withdraw Cash" use case stands on its own, without the extension.

Include is used to extract use case fragments that are duplicated in multiple use cases. The included use case cannot stand alone and the original use case is not complete without the included one. This should be used sparingly and only in cases where the duplication is significant and exists by design (rather than by coincidence).

For example, the flow of events that occurs at the beginning of every ATM use case (when the user puts in their ATM card, enters their PIN, and is shown the main menu) would be a good candidate for an include.

包括用例图和扩展的用例中的差异是什么?

[旋木] 2025-02-05 14:14:33

用于

subnet: {
  id: subnet.id
}

NIC属性中的子网参考...如Thomas所述,您需要对NetworkSecurityGroup进行相同的操作。

Use

subnet: {
  id: subnet.id
}

for the subnet reference in the NIC's properties... you'll need the same for the networkSecurityGroup as Thomas mentioned.

将新的NIC添加到现有子网

[旋木] 2025-02-05 12:11:00

您可以在settings.py文件中设置多个数据库。

DATABASES = {
    'default': {
        ...
    },
    'other': {
        ...
    }
}

而且,您需要创建另一个应用程序其他,并在新创建的项目文件夹中定义模型。假设您在其他应用程序中定义了sport模型。
然后在views.py文件中您可以参考此模型。

from other.models import Sport

# in one of your api view
def SomeView(...):
    ...
    Sport.objects.using('other').create(...)

主代码是使用('...')

注意:当您需要进行迁移时,您无需为其他应用程序进行迁移。

You can set multiple databases in settings.py file.

DATABASES = {
    'default': {
        ...
    },
    'other': {
        ...
    }
}

And you need to create another app other and define the models in models.py of the newly created project folder. Let's say, you defined a Sport model in other app.
Then in views.py file you can refer to this model.

from other.models import Sport

# in one of your api view
def SomeView(...):
    ...
    Sport.objects.using('other').create(...)

The main code is using('...').

Note: You don't need to make migrations for the other app when you need to make migrations.

DJANGO-REST-FRAMEWORK-从另一台服务器中获取数据

[旋木] 2025-02-05 06:00:36

如果我正确理解的话,您只需要使用 set-Query-参数政策:

<set-query-parameter name="$select" exists-action="override ">
    <value>firstname,nickname</value>
</set-query-parameter>

If I understand correctly, all you need is to use set-query-parameter policy:

<set-query-parameter name="$select" exists-action="override ">
    <value>firstname,nickname</value>
</set-query-parameter>

限制通过Azure APIM要求的字段

[旋木] 2025-02-05 03:34:35

如果禁用了此功能,重复一次?

根据我的经验,这并不是很多,但这并不重要,您的系统需要能够以一种或另一种方式处理它们,因为它会发生。

有没有启用此功能的方法避免重复的方法?

在Google方面?不,否则,选项的重点是什么。用户应仅处理每个ID,或确保执行的任何操作都是智力的。或者,您不会打扰,希望它不会经常发生并承受后果(无论是崩溃,在您可能会或可能无法修复的地方都有腐败,...)。

从文档中不清楚重复的频率以及在禁用此选项的情况下会发生什么情况。

Pub/sub是一个复杂的高度扩展分布式系统,重复的消息不是固定时间表上的预期功能,如果您想要高性能,它们是必要的邪恶。没有人可以预测它们何时会发生,只能发生它们。

How often do duplicates occur if this feature is disabled?

Not super often in my experience, but this doesn't matter, your system needs to be able to handle them one way or another, because it will happen.

Are there ways to avoid duplicates without enabling this feature?

On googles side? No, otherwise what would be the point of the option. The user should either de-duplicate it with the messageID, by only processing each id once, or make sure that whatever operation you perform is idempotent. Or you don't bother, hope it doesn't happen often and live with the consequences (be it by crashing, having corruption somewhere that you may or may not fix,...).

Its unclear from the docs how often duplicates will occur and under what circumstances they will occur if this option is disabled.

Pub/sub is a complex highly scaling distributed system, duplicated messages are not an intended feature on a fixed schedule, they are a necessary evil if you want high performance. Nobody can predict when they will happen, only that they can occur.

如果我不确切地设置一次交付”,重复的频率是重复的频率。使用pubsub?

[旋木] 2025-02-04 23:46:30

工厂模式工作如下:
存在一个接口

public interface Foo {
  String make(String someString);
}

,并且该接口有多个实现:

public class DishOrder implements Foo {
  //constructor
  String make(String someString) {-- custom implementation--}
}

public class DrinkOrder implements Foo {
  //constructor
  String make(String someString) {-- custom implementation--}
}

然后工厂存在:

public class OrderFactory {
 private DishOrder dishOrder;
 private DrinkOrder drinkOrder;
 
 //constructor
 public Foo getFoo(String type) {
  if(type.equals("Dish"))
   return DishOrder;
   //and every other implementation of the interface
   //can use switch here as well
}
}

Factory pattern works as follows:
An interface exists

public interface Foo {
  String make(String someString);
}

and there are multiple implementations of that interface:

public class DishOrder implements Foo {
  //constructor
  String make(String someString) {-- custom implementation--}
}

public class DrinkOrder implements Foo {
  //constructor
  String make(String someString) {-- custom implementation--}
}

And then the factory exists:

public class OrderFactory {
 private DishOrder dishOrder;
 private DrinkOrder drinkOrder;
 
 //constructor
 public Foo getFoo(String type) {
  if(type.equals("Dish"))
   return DishOrder;
   //and every other implementation of the interface
   //can use switch here as well
}
}

此类是否符合工厂方法模式?

[旋木] 2025-02-04 14:53:09

假设该行

 # &  G -,

是一条评论的线路,以后可能会被毫不费力,则在此行中处理&amp;也可能是有意义的。不知道数据的目的,这可能或可能没有用。

使用 gnu awk,该命令

awk 'BEGIN { RS=",";ORS="" } { printf "%s%s", ORS, gensub(/(\n[ \t#]*)&/, " \\&\\1 ",1); ORS=RS }' inputfile

将将输入转换

      A +,
   &  B -,
   &  C ),
   &  D +,
   &  E (,
   &  F *,
 # &  G -,
   &  H +,
   &  I (,
   &  J +,
      K ?,

为此

      A +, &
      B -, &
      C ), &
      D +, &
      E (, &
      F *, &
 #    G -, &
      H +, &
      I (, &
      J +,
      K ?,

脚本,只有在最后一行被Newline终止或其他任何其他字符遵循> 时,该脚本才能正确起作用。 ,

说明:

  • rs =“,”,“将逗号设置为记录分离器,而不是输入的新线。
  • ors =“”在第一个记录之前将输出记录分离器设置为空字符串。
  • fprintf“%s%s”,ors,gensub(...) pre pred 对记录分隔符而不是附加记录。
  • Gensub gnu特定的替换功能,允许反向提示匹配组。
  • /(\ n [\ t#]*)&amp;/搜索模式:括号定义一个由newline \ n组成的组(1),然后是任何序列空间,选项卡或注释字符[\ t#]*。该组之后是&amp;字符。
  • “ \\&amp; \\ 1”替换:空间后跟&amp;,然后是捕获的组(1)(\\ 1)以及替换删除的&amp;的附加空间。 (\\&amp;对于获得字面&amp;字符而不是插入整个匹配是必要的。)
  • ors = rs = rs设置输出在第一行之后,将分隔符记录到。 (实际上,在每一个ROS之后)在第二次和以下记录之前预先逗号。这样可以确保应成为新线的最后一个记录将无法获得尾随

GNU尴尬脚本的下面版本
如果输入文件的最后一行未用newline终止,则将按预期 工作。
它将使用创建一条额外的行,因为最后一个包含新线的记录将由输出记录分隔器终止。

awk 'BEGIN { RS=ORS="," } { print gensub(/(\n[ \t#]*)&/, " \\&\\1 ",1) }' inputfile

如果输入文件以newline结束,则输出将

...
      I (, &
      J +,
      K ?,
,

在最后一个之后没有Newline。

Assuming that the line

 # &  G -,

is a commented line which could get uncommented later, it might make sense to handle the & in this line as well. Not knowing the purpose of the data, this might or might not be useful.

With GNU Awk, the command

awk 'BEGIN { RS=",";ORS="" } { printf "%s%s", ORS, gensub(/(\n[ \t#]*)&/, " \\&\\1 ",1); ORS=RS }' inputfile

will turn the input

      A +,
   &  B -,
   &  C ),
   &  D +,
   &  E (,
   &  F *,
 # &  G -,
   &  H +,
   &  I (,
   &  J +,
      K ?,

into

      A +, &
      B -, &
      C ), &
      D +, &
      E (, &
      F *, &
 #    G -, &
      H +, &
      I (, &
      J +,
      K ?,

This script will only work correct if the last line is terminated by a newline or if any other character follows the ,.

Explanation:

  • RS="," sets the comma as record separator instead of a newline for input.
  • ORS="" sets the output record separator to an empty string before the first record.
  • fprintf "%s%s", ORS, gensub(...) prepends the record separator instead of appending it.
  • gensub GNU specific substitution function which allows backreferences to matched groups.
  • /(\n[ \t#]*)&/ search pattern: The parentheses define a group (1) that consists of a newline \n followed by any sequence of spaces, tabs or comment characters [ \t#]*. The group is followed by an & character.
  • " \\&\\1 " replacement: space followed by &, followed by captured group (1) (\\1) and an additional space to replace the removed &. (The \\& is necessary to get a literal & character instead of inserting the whole match.)
  • ORS=RS sets the output record separator to , after the first row. (after every ros, in fact) to prepend a comma before the 2nd and following records. This ensures that the last record which should be a newline will not get a trailing ,.

The version below of the GNU Awk script
will work as expected only if the last line of the input file is not terminated with a newline.
It will create an additional line with a , because the last record containing a newline will be terminated by the output record separator ,.

awk 'BEGIN { RS=ORS="," } { print gensub(/(\n[ \t#]*)&/, " \\&\\1 ",1) }' inputfile

If the input file ends with a newline, the output will be

...
      I (, &
      J +,
      K ?,
,

with no newline after the last ,.

更换线之间的模式

[旋木] 2025-02-04 10:31:21
<input type="radio" name="filter" class="btn active" onclick="filterSelection('all')" value="Show all" checked="checked"  />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('cars')" value="Cars" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('animals')" value="Animals" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('fruits')" vlaue="Fruits" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('colors')" value="Colors" />
</div>

您所缺少的就是使用类型无线电输入中检查的属性。

<input type="radio" checked="checked">
<input type="radio" name="filter" class="btn active" onclick="filterSelection('all')" value="Show all" checked="checked"  />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('cars')" value="Cars" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('animals')" value="Animals" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('fruits')" vlaue="Fruits" />
  <input type="radio" class="btn" name="filter" onclick="filterSelection('colors')" value="Colors" />
</div>

all you are missing is checked attribute in input with type radio.

<input type="radio" checked="checked">

我需要一个特定的代码部分来使用无线电类型而不是按钮

[旋木] 2025-02-03 05:43:37

你可以做这样的事情

 export default function StudentsList({ students }) {
  const [collapsed, setCollapsed] = useState(null);


  const handleCollapse = (id) => {
    setCollapsed(prev => prev === id? null : id);
  };


  return (
    <div className={studentsBox}>

      {students.map((student) => (
          <div className={card} key={student.id}>
             <div
                className={plus}
                onClick={() => handleCollapse(student.id)}
                onMouseMove={() => setId(`${student.id}`)}
              >
                {collapsed === student.id ? '+' : '-'}
              </div>
                
                <div className={collapsed === student.id ? collapse : ''}>
                  <p>Test 1:    {student.grades[0]}%</p>
                  <p>Test 2:    {student.grades[1]}%</p>
                  <p>Test 3:    {student.grades[2]}%</p>
                  <p>Test 4:    {student.grades[3]}%</p>
                  <p>Test 5:    {student.grades[4]}%</p>
                  <p>Test 6:    {student.grades[5]}%</p>
                  <p>Test 7:    {student.grades[6]}%</p>
                  <p>Test 8:    {student.grades[7]}%</p>
                </div>

              </div>
          </div>
        ))}
      );
   }

you can do something like this

 export default function StudentsList({ students }) {
  const [collapsed, setCollapsed] = useState(null);


  const handleCollapse = (id) => {
    setCollapsed(prev => prev === id? null : id);
  };


  return (
    <div className={studentsBox}>

      {students.map((student) => (
          <div className={card} key={student.id}>
             <div
                className={plus}
                onClick={() => handleCollapse(student.id)}
                onMouseMove={() => setId(`${student.id}`)}
              >
                {collapsed === student.id ? '+' : '-'}
              </div>
                
                <div className={collapsed === student.id ? collapse : ''}>
                  <p>Test 1:    {student.grades[0]}%</p>
                  <p>Test 2:    {student.grades[1]}%</p>
                  <p>Test 3:    {student.grades[2]}%</p>
                  <p>Test 4:    {student.grades[3]}%</p>
                  <p>Test 5:    {student.grades[4]}%</p>
                  <p>Test 6:    {student.grades[5]}%</p>
                  <p>Test 7:    {student.grades[6]}%</p>
                  <p>Test 8:    {student.grades[7]}%</p>
                </div>

              </div>
          </div>
        ))}
      );
   }

如何仅在地图中扩展一个Div?

[旋木] 2025-02-02 14:39:04

有一个选项numrows,例如:10000。

val outputStream = inputStream.writeStream.format("console")
                    .option("truncate", value = false)
                    .option("numRows",10000)
                    .option("checkpointLocation", "checkpoint")

There is an option numRows, for example: 10000.

val outputStream = inputStream.writeStream.format("console")
                    .option("truncate", value = false)
                    .option("numRows",10000)
                    .option("checkpointLocation", "checkpoint")

仅显示前20行

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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