痴情

文章 评论 浏览 30

痴情 2025-01-31 09:39:27

您正在打印for循环中使用的元素。为了解决此问题,只需打印您要添加的值即可。例如:

print(img.get_attribute('src'))

You are printing the element used in the for loop. To solve this just print the value you are adding. E.g:

print(img.get_attribute('src'))

使用Python Selenium从网页获取图像缩略图URL

痴情 2025-01-31 05:03:43

如果我理解正确的话,您想集中新行(这是最后一行):

gridView.FocusedRowHandle = gridView.RowCount - 1;

如果没有,则必须使用i 0-> gridview.rowcount -1,然后当您找到ID时以I值聚焦行。

for (int i = 0; i <= gridView.RowCount - 1; i++) 
    {
      if (gridView.GetRowCellValue(i, gridView.columns(column_number)))
          {
        gridView.FocusedRowHandle = i;
          }
    }

If i understand correct you want to focus the new row (which is the last row):

gridView.FocusedRowHandle = gridView.RowCount - 1;

If not, you have to search the id inside the gridvw with for i 0-> gridView.RowCount - 1 and then when you will find the Id to focus the row with the i value.

for (int i = 0; i <= gridView.RowCount - 1; i++) 
    {
      if (gridView.GetRowCellValue(i, gridView.columns(column_number)))
          {
        gridView.FocusedRowHandle = i;
          }
    }

focusedRowhandle在DeVexpress GridView C#中未正确设置

痴情 2025-01-30 14:57:10

嗨,您可以使用此逻辑
,,,,,,

 public virtual IEnumerable<TEntity> Get(Expression<Func<TEntity,bool>>  Where=null)
        {
            IQueryable<TEntity> query = _dbSet;
            if(Where != null)
            {
                query = query.Where(Where);
            }
            return query.ToList();
        }


我希望这对你有帮助

hi you can use this logic
,,,

 public virtual IEnumerable<TEntity> Get(Expression<Func<TEntity,bool>>  Where=null)
        {
            IQueryable<TEntity> query = _dbSet;
            if(Where != null)
            {
                query = query.Where(Where);
            }
            return query.ToList();
        }

,,,
i hope this help you

如何使LINQ表达式接收参数到通用存储库中的LINQ查询

痴情 2025-01-29 18:07:00

如果lst是您问题的列表,则可以执行:

import csv

with open("data.csv", "w") as f_out:
    csv_writer = csv.writer(f_out)
    i = iter(lst)
    csv_writer.writerow(["deg", "min", "sec", "direction"])
    for t in zip(*[i] * 4):
        csv_writer.writerow(t)

此写入data.csv

deg,min,sec,direction
9,22,26.9868,N
118,23,48.876,E
9,22,18.6132,N
118,23,5.2188,E
9,19,41.4804,N
118,19,23.1852,E

screenshot来自libreoffice:

If lst is the list from your question, you can do:

import csv

with open("data.csv", "w") as f_out:
    csv_writer = csv.writer(f_out)
    i = iter(lst)
    csv_writer.writerow(["deg", "min", "sec", "direction"])
    for t in zip(*[i] * 4):
        csv_writer.writerow(t)

this writes data.csv:

deg,min,sec,direction
9,22,26.9868,N
118,23,48.876,E
9,22,18.6132,N
118,23,5.2188,E
9,19,41.4804,N
118,19,23.1852,E

screenshot from LibreOffice:

enter image description here

使用Python将存储在列表中的DMS值转换为CSV文件

痴情 2025-01-29 15:12:18

初始化一个大小为m x n的2D矩阵,0

m,n = map(int,input().split())
l = [[0 for i in range(m)] for j in range(n)]
print(l)

Initializing a 2D matrix of size m X n with 0

m,n = map(int,input().split())
l = [[0 for i in range(m)] for j in range(n)]
print(l)

如何初始化Python中的二维数组(如果不使用Numpy的列表)?

痴情 2025-01-29 12:42:27

兄弟,您必须停止使用颤音流动,否则每次都必须使用flutter f找到替代方案

bro you gotta stop using flutter flow or you have to find alternatives every time when you want to use flutter f

颤音:单击Textformfield将我重定向回到家:

痴情 2025-01-29 11:52:32

方法 valueof(string)返回概述当参数无效时:

  • illegalargumentException如果指定的枚举类型没有指定名称的常数,或者指定的类对象没有代表对象。枚举类型
  • nullpoInterException如果enumtype或name为null,则

可以写:

public static GenderEnum from(String text) {
    GenderEnum gender;

    try {
        gender = valueOf(text);
    } catch (IllegalArgumentException | NullPointerException e) {
        gender = INVALID;
    }
    
    return gender;
}

或简化:

public static GenderEnum from(String text) {
    GenderEnum gender = INVALID;

    try {
        gender = valueOf(text);
    } catch (Exception ignore) { }
    
    return gender;
}

The method valueOf(String) return Expection when argument is invalid :

  • IllegalArgumentException if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type
  • NullPointerException if enumType or name is null

You can write:

public static GenderEnum from(String text) {
    GenderEnum gender;

    try {
        gender = valueOf(text);
    } catch (IllegalArgumentException | NullPointerException e) {
        gender = INVALID;
    }
    
    return gender;
}

Or simplify:

public static GenderEnum from(String text) {
    GenderEnum gender = INVALID;

    try {
        gender = valueOf(text);
    } catch (Exception ignore) { }
    
    return gender;
}

将枚举字段设置为默认值,以防万一未传递值

痴情 2025-01-29 07:44:45

getserverserversideprops 仅在服务器端触发,并且在客户端无法使用

getServersideProps仅在服务器端运行,并且永远不会在浏览器上运行。

如果您想拥有该存储逻辑,我建议您改用cookie。不像LocalStorage,服务器端和客户端都可以使用Cookie。

来修改逻辑

export async function getServerSideProps(context) {
  const filterId = context.req.cookies.filterId || ''; //get filterId from cookies

  // ...some code, and filterId variable still empty array
  const scoresRes = await fetchData('scores',{filterId});

  return {
    props: {scoresRes}
  };
}

您可以使用cookie的另一种可能的方法 ,是使用 getInitialProps 双方都可以使用

MainComponent.getInitialProps() {
  let filterId = []

  if (typeof window !== 'undefined') {
    filterId = global.window?.localStorage.getItem('filterId') || '';
  }

  // ...some code, and filterId variable still empty array
  const scoresRes = await fetchData('scores',{filterId});

  return scoresRes;
}

getServerSideProps only trigger on the server-side and it won't be available on the client-side

getServerSideProps only runs on server-side and never runs on the browser.

If you want to have that storage logic, I'd suggest you use cookies instead. Not like localStorage, cookies are available on both server-side and client-side.

You can modify your logic like below with cookies

export async function getServerSideProps(context) {
  const filterId = context.req.cookies.filterId || ''; //get filterId from cookies

  // ...some code, and filterId variable still empty array
  const scoresRes = await fetchData('scores',{filterId});

  return {
    props: {scoresRes}
  };
}

Another possible approach is using getInitialProps which is available on both sides

MainComponent.getInitialProps() {
  let filterId = []

  if (typeof window !== 'undefined') {
    filterId = global.window?.localStorage.getItem('filterId') || '';
  }

  // ...some code, and filterId variable still empty array
  const scoresRes = await fetchData('scores',{filterId});

  return scoresRes;
}

如何获取global.window.localstorage Inside getServersideProps

痴情 2025-01-29 02:36:03

我面临类似的问题,但找不到任何答案。也许您已经解决了这个问题,但是让我在这里分享我的工作方式。

阅读 blob.open 方法,我发现此image> image_flush参数:

(可选)对于非文本模式写入,使flush()无需做任何事情而不是提出错误。远程服务不支持flush()没有关闭的情况,因此通常将其称为io.unsupporteDoperation。但是,这种行为与python中的一些消费者和文件包装器不兼容,例如zipfile.zipfile或io.textiowrapper。设置ignore_flush将导致flush()成功地做任何事情,以兼容这些上下文。实际刷新到远程服务器的正确方法是关闭(使用上下文管理器,例如在示例中,将自动发生这种情况)。

AVRO需要在二进制模式下打开文件,因此打开BLOB时,我们需要将此参数设置为true以避免错误。

另外,如果您不调用.close() avro方法,则文件无法正确生成,因此我们需要将io对象馈送给作者,而无需将其包裹在上下文管理器上它将由Avro本身处理。

最终解决方案看起来像这样:

import google.cloud.storage as gcs
from avro.datafile import DataFileWriter
from avro.io import DatumWriter

gcs_client = gcs.Client()
bucket = gcs_client.bucket(bucketname)
blob = bucket.blob(filename)

writer = DataFileWriter(blob.open('wb', ignore_flush=True), DatumWriter(), schema_parsed)
for record in records:
    writer.append(record)
writer.close()

I was facing a similar problem but couldn't find any answer for this. Maybe you already solved this, but let me share here how I had this working.

Reading Google Cloud docs for blob.open method, I found this ignore_flush parameter:

(Optional) For non text-mode writes, makes flush() do nothing instead of raising an error. flush() without closing is not supported by the remote service and therefore calling it normally results in io.UnsupportedOperation. However, that behavior is incompatible with some consumers and wrappers of file objects in Python, such as zipfile.ZipFile or io.TextIOWrapper. Setting ignore_flush will cause flush() to successfully do nothing, for compatibility with those contexts. The correct way to actually flush data to the remote server is to close() (using a context manager, such as in the example, will cause this to happen automatically).

Avro needs to open the files on binary mode, so when opening the blob we need to set this parameter to True to avoid errors.

Also, if you don't call the .close() avro method the file won't be generated properly, so we need to feed our IO object to the writer without wrapping it on a context manager as it will be handled by avro itself.

The final solution looks like this:

import google.cloud.storage as gcs
from avro.datafile import DataFileWriter
from avro.io import DatumWriter

gcs_client = gcs.Client()
bucket = gcs_client.bucket(bucketname)
blob = bucket.blob(filename)

writer = DataFileWriter(blob.open('wb', ignore_flush=True), DatumWriter(), schema_parsed)
for record in records:
    writer.append(record)
writer.close()

创建和加载avro文件,创建文件,但很空

痴情 2025-01-28 20:48:28
awk 'BEGIN { print index("$string", "$substring") }'

您无法在gnu awk命令中使用这样的shell变量,请考虑简单的示例

string="HELLOWORLD" && awk 'BEGIN{print "$string"}' emptyfile.txt

输出

$string

观察出现文字$ string出现,请使用-V,如果您想要将浮动在壳中浮动的变量浮动到gnu awk命令例如

string="HELLOWORLD" && awk -v s=$string 'BEGIN{print s}' emptyfile.txt

输出

HELLOWORLD

(在GNU AWK 5.0.1中测试)

awk 'BEGIN { print index("$string", "$substring") }'

You can not use your shell variables like this in GNU AWK command consider simple example

string="HELLOWORLD" && awk 'BEGIN{print "$string"}' emptyfile.txt

output

$string

Observe that literal $string appeared, use -v if you want to ram variable floating in your shell into GNU AWK command for example

string="HELLOWORLD" && awk -v s=$string 'BEGIN{print s}' emptyfile.txt

output

HELLOWORLD

(tested in GNU Awk 5.0.1)

如何使用AWK方法在BASH脚本上实现Startswith函数

痴情 2025-01-28 19:33:24

尝试这样:

def reverse(lst,start,end):
      if start>=end:
         return lst
      else:
        temp=lst[start]
        lst[start]=lst[end]
        lst[end]=temp
        return reverse(lst,start+1,end-1)

l = [1,2,3]
print(reverse(l,0,len(l)-1))

输出:

[3, 2, 1]

Try like this :

def reverse(lst,start,end):
      if start>=end:
         return lst
      else:
        temp=lst[start]
        lst[start]=lst[end]
        lst[end]=temp
        return reverse(lst,start+1,end-1)

l = [1,2,3]
print(reverse(l,0,len(l)-1))

Output:

[3, 2, 1]

python递归功能逆转列表

痴情 2025-01-28 19:24:27

您可以使用l1Hs使用dplyr进行简单的left_join将级别添加到。

library(dplyr)

L1HS %>%
  left_join(., recurrent %>% select(unique, level), by = c("Sequence" = "unique"))

或使用合并

merge(x=L1HS,y=recurrent[, c("unique", "level")], by.x = "Sequence", by.y = "unique",all.x=TRUE)

输出

                Sequence level
1 chr1_35031657_35037706     4
2 chr1_67544575_67550598     2
3 chr1_81404889_81410942    NA
4 chr1_84518073_84524089     3
5 chr1_87144764_87150794    NA

*注意:这仍然将保留l1Hs中的所有列。我只是没有在下面的示例数据中创建任何其他列。

数据

recurrent <- structure(list(chr = c("chr4", "chr1", "chr2", "chr5", "chr7", 
"chr1"), start = c(56707846L, 20252181L, 224560903L, 131849595L, 
46361610L, 20251169L), end = c(56708347L, 20252682L, 224561404L, 
131850096L, 46362111L, 20251670L), X = c(0L, 0L, 0L, 0L, 0L, 
0L), Y = c(38L, 37L, 37L, 36L, 36L, 36L), level = c(3L, 2L, 3L, 
3L, 3L, 4L), unique = c("chr4_56707846_56708347", "chr1_67544575_67550598", 
"chr2_224560903_224561404", "chr5_131849595_131850096", "chr1_84518073_84524089", 
"chr1_35031657_35037706")), class = "data.frame", row.names = c(NA, 
-6L))

L1HS <- structure(list(Sequence = c("chr1_35031657_35037706", "chr1_67544575_67550598", 
"chr1_81404889_81410942", "chr1_84518073_84524089", "chr1_87144764_87150794"
)), class = "data.frame", row.names = c(NA, -5L))

You can do a simple left_join to add level to L1HS with dplyr.

library(dplyr)

L1HS %>%
  left_join(., recurrent %>% select(unique, level), by = c("Sequence" = "unique"))

Or with merge:

merge(x=L1HS,y=recurrent[, c("unique", "level")], by.x = "Sequence", by.y = "unique",all.x=TRUE)

Output

                Sequence level
1 chr1_35031657_35037706     4
2 chr1_67544575_67550598     2
3 chr1_81404889_81410942    NA
4 chr1_84518073_84524089     3
5 chr1_87144764_87150794    NA

*Note: This will still retain all the columns in L1HS. I just didn't create any additional columns in the example data below.

Data

recurrent <- structure(list(chr = c("chr4", "chr1", "chr2", "chr5", "chr7", 
"chr1"), start = c(56707846L, 20252181L, 224560903L, 131849595L, 
46361610L, 20251169L), end = c(56708347L, 20252682L, 224561404L, 
131850096L, 46362111L, 20251670L), X = c(0L, 0L, 0L, 0L, 0L, 
0L), Y = c(38L, 37L, 37L, 36L, 36L, 36L), level = c(3L, 2L, 3L, 
3L, 3L, 4L), unique = c("chr4_56707846_56708347", "chr1_67544575_67550598", 
"chr2_224560903_224561404", "chr5_131849595_131850096", "chr1_84518073_84524089", 
"chr1_35031657_35037706")), class = "data.frame", row.names = c(NA, 
-6L))

L1HS <- structure(list(Sequence = c("chr1_35031657_35037706", "chr1_67544575_67550598", 
"chr1_81404889_81410942", "chr1_84518073_84524089", "chr1_87144764_87150794"
)), class = "data.frame", row.names = c(NA, -5L))

从循环粘贴到数据框架r的粘贴值r

痴情 2025-01-28 16:25:24
SELECT 
first_name
,last_name
,email_address
,count(1) as number
FROM datalake.core.profile_snapshot
GROUP BY 
first_name
,last_name
,email_address

如果要将结果设置减少到特定的电子邮件地址,请添加一个条款即可。

我已经使用了email_address而不是email.personal

SELECT 
first_name
,last_name
,email_address
,count(1) as number
FROM datalake.core.profile_snapshot
GROUP BY 
first_name
,last_name
,email_address

If you want to reduce the result set to a particular email address then just add a where clause to do so.

I've used email_address instead of email.personal.

使用不同计数时,如何显示多个字段?

痴情 2025-01-28 09:25:41

它认为如果您倒转操作顺序会更容易

const listcode =["IN","FI"];
const listarr1 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "SP", value: "B3456"},
  {id:4, name: "ben", cid: "FI", value: "C5678"},
]

const listarr2 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "SG", value: "C5678"},
  {id:4, name: "ben", cid: "SP", value: "C5678"},
]

const listarr3 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "IN", value: "C5678"},
  {id:4, name: "ben", cid: "IN", value: "C5678"},
]



const checkIdMembers = data => {

const ALL = 'ALL'
 const dataObj  = data.reduce((res, d) => {

   const existingValue = res[d.value] || {}
   const existing = existingValue[d.cid] || []
   const existingAll = existingValue[ALL] || []
   
   existingValue[d.cid] = [...existing, d]
   
   if(!listcode.includes(d.cid)){
     existingValue[ALL] = [...existingAll, d]
   }
   res[d.value] = existingValue 
   return res
 }, {})
 return Object.values(dataObj).flatMap(v => {
    return Object.values(v).filter(group => group.length > 1)
 })
 
}

console.log(checkIdMembers(listarr1))
console.log(checkIdMembers(listarr2))
console.log(checkIdMembers(listarr3))

我意识到我的答案不正确,所以我进行了编辑。

我缺少您的先决条件之一,我不得不更改方法,

一旦有了此对象,我就将您的初始数组转换在这样的对象中,

{
  "<value>" : {
     "<cid>" : [...elements with same cid and value]
      ....
     "ALL"   : [...elements with same value different cid but not in listcode]
  }
}

您只需取值,而不是在其上使用flatmap来合并所有数组的所有组有长度&gt; 1

我希望这有帮助

It think it's easier if you invert the order of the operations

const listcode =["IN","FI"];
const listarr1 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "SP", value: "B3456"},
  {id:4, name: "ben", cid: "FI", value: "C5678"},
]

const listarr2 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "SG", value: "C5678"},
  {id:4, name: "ben", cid: "SP", value: "C5678"},
]

const listarr3 =[
  {id:1, name: "dino", cid: "IN", value: "A1234"},
  {id:2, name: "hem", cid: "IN", value: "B3456"},
  {id:3, name: "zen", cid: "IN", value: "C5678"},
  {id:4, name: "ben", cid: "IN", value: "C5678"},
]



const checkIdMembers = data => {

const ALL = 'ALL'
 const dataObj  = data.reduce((res, d) => {

   const existingValue = res[d.value] || {}
   const existing = existingValue[d.cid] || []
   const existingAll = existingValue[ALL] || []
   
   existingValue[d.cid] = [...existing, d]
   
   if(!listcode.includes(d.cid)){
     existingValue[ALL] = [...existingAll, d]
   }
   res[d.value] = existingValue 
   return res
 }, {})
 return Object.values(dataObj).flatMap(v => {
    return Object.values(v).filter(group => group.length > 1)
 })
 
}

console.log(checkIdMembers(listarr1))
console.log(checkIdMembers(listarr2))
console.log(checkIdMembers(listarr3))

I realize that my answer wasn't correct so i edited it.

I was missing one of your prerequisite and I had to change the approach a bit

I transformed your initial array in an object like this

{
  "<value>" : {
     "<cid>" : [...elements with same cid and value]
      ....
     "ALL"   : [...elements with same value different cid but not in listcode]
  }
}

Once you have this object you can just take the values and than use flatMap on it to merge all groups of array that have length > 1

I hope this helps

如何使用JavaScript根据条件获取具有数组对象和数组列表的对象数组

痴情 2025-01-28 07:14:45

您可以将MAP与分组步骤组合在一起,然后只有sort数组

const orders=[{orderId:1,orderDate:"2021-04-28T08:20:58Z",status:"Confirmed",sellerName:"Chris Gilmour",revenue:2316.49},{orderId:2,orderDate:"2020-12-19T12:30:18Z",status:"Confirmed",sellerName:"Alanna Sumner",revenue:2928.88},{orderId:4,orderDate:"2020-12-24T08:00:09Z",status:"Confirmed",sellerName:"Beth North",revenue:1550.19},{orderId:5,orderDate:"2021-06-06T04:40:48Z",status:"Confirmed",sellerName:"Laura Ponce",revenue:35.5},{orderId:8,orderDate:"2021-08-27T05:13:40Z",status:"Canceled",sellerName:"Blade Newman",revenue:2957.29},{orderId:9,orderDate:"2020-12-26T08:07:57Z",status:"Confirmed",sellerName:"Alanna Sumner",revenue:2164.75},{orderId:10,orderDate:"2021-04-23T18:44:19Z",status:"Confirmed",sellerName:"Blade Newman",revenue:2287.55}];

const result = Object.values(orders.reduce((acc, { sellerName, revenue }) => {
    acc[sellerName] ??= { sellerName, totalRevenue: 0 };
    acc[sellerName].totalRevenue += revenue;
    return acc;
}, {}))
.sort(({ totalRevenue: a }, { totalRevenue: b }) => b - a);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

You can combine map with grouping step together, and then just sort array

const orders=[{orderId:1,orderDate:"2021-04-28T08:20:58Z",status:"Confirmed",sellerName:"Chris Gilmour",revenue:2316.49},{orderId:2,orderDate:"2020-12-19T12:30:18Z",status:"Confirmed",sellerName:"Alanna Sumner",revenue:2928.88},{orderId:4,orderDate:"2020-12-24T08:00:09Z",status:"Confirmed",sellerName:"Beth North",revenue:1550.19},{orderId:5,orderDate:"2021-06-06T04:40:48Z",status:"Confirmed",sellerName:"Laura Ponce",revenue:35.5},{orderId:8,orderDate:"2021-08-27T05:13:40Z",status:"Canceled",sellerName:"Blade Newman",revenue:2957.29},{orderId:9,orderDate:"2020-12-26T08:07:57Z",status:"Confirmed",sellerName:"Alanna Sumner",revenue:2164.75},{orderId:10,orderDate:"2021-04-23T18:44:19Z",status:"Confirmed",sellerName:"Blade Newman",revenue:2287.55}];

const result = Object.values(orders.reduce((acc, { sellerName, revenue }) => {
    acc[sellerName] ??= { sellerName, totalRevenue: 0 };
    acc[sellerName].totalRevenue += revenue;
    return acc;
}, {}))
.sort(({ totalRevenue: a }, { totalRevenue: b }) => b - a);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

卖方的一系列销售组,从每个卖方那里获取总数,按总销售额订购

更多

推荐作者

佚名

文章 0 评论 0

今天

文章 0 评论 0

゛时过境迁

文章 0 评论 0

达拉崩吧

文章 0 评论 0

呆萌少年

文章 0 评论 0

孤者何惧

文章 0 评论 0

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