ChatCrawlersearch across public Telegram Open the app
P

Python 中文交流群

snapshot for June 2025
June 2025 ×
16 June 2025
我用cProfile+Snakeviz分析调用图时,发现deepcopy()调用了多次_deepcopy_dict(),但需要深度拷贝的对象并不含任何的字典。请问这是什么原因?调试器似乎没办法单步调试deepcopy()函数。
F
from itertools import product from copy import deepcopy class Team: def __init__(self, name: str, seed: int): self.name: str = name self.init_seed: int = seed self.middle_seed: int = seed self.wins: int = 0 self.losses: int = 0 self.opponents: list[Team] = [] self.buchholz: int = 0 t_teams = list[Team] def swiss_sim_ex(teams: t_teams): n = len(teams) // 2 c = 0 # 第一轮 round1_all_results = product([0, 1], repeat=n) for round1_results in round1_all_results: round1_teams = deepcopy(teams) round1_pairs = round1_pairing(round1_teams) simulate_matches_ex(round1_pairs, round1_results) # 第二轮 round2_all_results = product([0, 1], repeat=n) for round2_results in round2_all_results: round2_teams = deepcopy(round1_teams) round2_pairs = round2_pairing(round2_teams) simulate_matches_ex(round2_pairs, round2_results) # 第三轮 round3_pairs = round3_pairing(round2_teams) if not round3_pairs: c += 1 print(round1_results, round2_results) print(f"共{c}种回溯情况") NUM_TEAM = 16 teams = [Team(f"Team{i + 1}", i + 1) for i in range(NUM_TEAM)] swiss_sim_ex(teams)
将异常作为函数返回或者返回的一部分到底有什么好处呢(。・ω・。)?
一个写 rust 的朋友问我这 py 函数的返回定义是 None,那业务失败了怎么办
I
软件工程有讲吧
有个 Option 就不错了,给他看看 if err != nil 就折中了
Z
我觉得这样性能开销更小也更清晰
可以看一下这个视频
A
所以现在C++也有了std::expected
各有好坏 熟悉 rust 的朋友都知道两者怎么互操作(
🍳
不過很好奇到底有誰會 return Exception
S
🅼🆁🆂🆆🅸🆃🅲🅷我一般是谁调用谁负责,你找人家要东西,没要来,你不得自己想办法吗?
从用返回值返回错误的角度看,他这里的问题是,失败时返回None给的信息太少,导致调用方无法“正确”的进行处理,举个例子,我有个http接口,失败的情况有两种,一种是因为网络问题没返回结果,另一种是返回的结果不正确,那么第一种调用者可能能重试,但第二种没有重试的意义,如果都返回None那么就无法区分从而进行有意义的错误处理了
🅼
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog