我想迭代从 Digikey api 接收到的数据列表,任何谷歌搜索都没有太多运气,因为该功能enumerate(reversed(part.standard_pricing))
不起作用,并且part.standard_pricing
由于某种原因您无法逆转类似的事情是需要的:
for b_idx in range(part.standard_pricing, -1, -1):
print(f"Test at: {b_idx} , Q: {part.standard_pricing[b_idx].break_quantity}")
if PCountQ >= part.standard_pricing[b_idx].break_quantity:
parts_df['PRICE_PER_PCB_Q'][idx] = part.standard_pricing[b_idx].unit_price * PCountQ
break
Run Code Online (Sandbox Code Playgroud)
但范围也不适用于列表......
我想这样做:
for b_idx, price_break in enumerate(part.standard_pricing):
Run Code Online (Sandbox Code Playgroud)
只是从末尾开始part.standard_pricing
,让索引减少而不是增加
关于如何以Python方式做到这一点有什么想法吗?
我第一次学习 re 模块但遇到了错误。
代码-
import re
my_str='''pyhton
c++
java
c++
js node
ds algo
pyhton
js node
javac++
java
js node
ds algo'''
var = re.findall("c++",my_str)
Run Code Online (Sandbox Code Playgroud)
它给出了错误 -re.error: multiple repeat at position 2
我试图在 python 中实现装饰器,但在第 14 行出现错误,即 hello()
#The code-
def maint(item1):
def greet():
print("Good Morning")
item1()
print("Tanish")
return greet()
#decorator----
@maint
def hello():
print("Hello")
# hello=maint(hello)
hello()
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?