python - 对功能感到困惑
问题描述
我正在开始制作一个函数,这是我现在的代码:
def shortest_path(source, target):
frontier_d = {}
frontier_d[source]=1
raise NotImplementedError
基本上,我正在尝试制作一个字典并将源(函数的输入)作为与值 1 关联的键。但是,Pycharm 告诉我源是一个未解决的参考。如果 source 是函数的输入,为什么会发生这种情况?
解决方案
看看这个 ——什么时候使用“raise NotImplementedError”?
source="abc"
target=156
def shortest_path(source, target):
try:
frontier_d = {}
frontier_d[source]=target
print(frontier_d)
except:
raise NotImplementedError
shortest_path(source, target)
输出:{'abc':156}
推荐阅读
- python-3.x - 修复第三方库中的内存泄漏
- python - 如何在单视图中在 Django 中拥有多个 ModelForm?
- bash - 是否有一个方便的等价物“find -mtime
" 一天中的部分时间 - linux - Wiki.js 无法通过企业代理
- primefaces - Primefaces 升级 8 getScriptsToExecute 等效
- quicksort - CS50 pset 3:Tideman sort_pairs 函数
- flutter - 播放 TTS 时降低背景音量
- java - 如何从 java.lang.reflect.Type 创建通用列表
- rabbitmq - ZMTP 和 AMQP 协议的区别
- ruby-on-rails - 如何将语言环境变量传递给局部变量