news 2026/5/9 7:32:58

VScode python插件

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
VScode python插件

1.LiveCode

从扩展商店安装完以后初次使用可能异常
要配置一下解释器的路径
设置(ctrl+,)-> 搜索 Livecode:Python Path
然后填解释器的路径


如果我们有循环或需要展示一些中间变量状态,就可以使用该插件,LiveCode主要拥有下面四个功能

实时评估:不需要运行Python脚本就可以查看各个变量的值

变量显示:每当声明或更改一个变量时,它的新值都会同时改变并显示

2在 VS Code 调试器中自动显示变量形状和维度信息

原文在这里

win下

C:\Users\<你的用户名>\.vscode\extensions\ms-python.debugpy-<版本号>-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_xml.py

linux下

~/.vscode/extensions/ms-python.debugpy-*\bundled\libs\debugpy\_vendored\pydevd\pydevd_plugins\extensions\types/

修改 get_variable_details() 函数
打开 pydevd_xml.py 文件,找到get_variable_details()函数,完整修改之后如下

def get_variable_details(val, evaluate_full_value=True, to_string=None, context: Optional[str] = None): """ :param context: This is the context in which the variable is being requested. Valid values: "watch", "repl", "hover", "clipboard" """ try: # This should be faster than isinstance (but we have to protect against not having a '__class__' attribute). is_exception_on_eval = val.__class__ == ExceptionOnEvaluate except: is_exception_on_eval = False if is_exception_on_eval: v = val.result else: v = val _type, type_name, resolver = get_type(v) type_qualifier = getattr(_type, "__module__", "") if not evaluate_full_value: value = DEFAULT_VALUE else: try: # 添加形状信息 shape_info = "" try: # 处理 PyTorch Tensor if type_qualifier == "torch" and hasattr_checked(v, 'shape') and hasattr_checked(v, 'dtype'): shape = tuple(v.shape) dtype = str(v.dtype) shape_info = f"{{Tensor: {shape}}} " # 处理 NumPy ndarray elif type_qualifier == "numpy" and hasattr_checked(v, 'shape') and hasattr_checked(v, 'dtype'): shape = tuple(v.shape) dtype = str(v.dtype) shape_info = f"{{ndarray: {shape}}} " # 处理 Pandas DataFrame elif type_qualifier == "pandas.core.frame" and hasattr_checked(v, 'shape'): shape = tuple(v.shape) shape_info = f"{{DataFrame: {shape}}} " # 处理 Pandas Series elif type_qualifier == "pandas.core.series" and hasattr_checked(v, 'shape'): shape = tuple(v.shape) dtype = str(v.dtype) shape_info = f"{{Series: {shape}}} " # 处理其他有 shape 属性的对象 elif hasattr_checked(v, 'shape'): shape_info = f"{{{v.shape}}} " # 处理可计数对象 elif hasattr_checked(v, '__len__'): try: length = len(v) # 对于字符串类型,只显示 {str} 而不显示长度 if type_name == "str": shape_info = f"{{{type_name}}} " else: shape_info = f"{{{type_name}: {length}}} " except: pass except: pass str_from_provider = _str_from_providers(v, _type, type_name, context) if str_from_provider is not None: value = shape_info + str_from_provider elif to_string is not None: value = shape_info + to_string(v) elif hasattr_checked(v, "__class__"): if v.__class__ == frame_type: value = pydevd_resolver.frameResolver.get_frame_name(v) elif v.__class__ in (list, tuple): if len(v) > 300: value = "%s: %s" % (str(v.__class__), "<Too big to print. Len: %s>" % (len(v),)) else: value = "%s: %s" % (str(v.__class__), v) else: try: cName = str(v.__class__) if cName.find(".") != -1: cName = cName.split(".")[-1] elif cName.find("'") != -1: # does not have '.' (could be something like <type 'int'>) cName = cName[cName.index("'") + 1 :] if cName.endswith("'>"): cName = cName[:-2] except: cName = str(v.__class__) value = "%s: %s" % (cName, v) else: value = shape_info + str(v) except: try: value = repr(v) except: value = "Unable to get repr for %s" % v.__class__ # fix to work with unicode values try: if value.__class__ == bytes: value = value.decode("utf-8", "replace") except TypeError: pass return type_name, type_qualifier, is_exception_on_eval, resolver, value

再重启即可

3 Better Comments

写注释的好帮手
它能根据关键词用不同的颜色高亮代码片段。支持以下类型的高亮:

感叹号 “!” 代码警告。
问号“?”代表存留疑问。
TODO 代码未来将要进行的操作。
@param 参数

此外,它还支持在设置中自定义需要高亮句子的首部关键词。

4 autoDocstring

写注释的好帮手
能够自动生成函数的注释格式,通过tab键快速切换填充块编写相应的注释。

Python Indent

python 自动缩进

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/10 0:00:37

开箱即用的中文情感分析方案|StructBERT镜像集成WebUI与API

开箱即用的中文情感分析方案&#xff5c;StructBERT镜像集成WebUI与API 1. 背景与需求&#xff1a;为什么需要轻量级中文情感分析&#xff1f; 在自然语言处理&#xff08;NLP&#xff09;的实际应用中&#xff0c;情感分析是企业洞察用户反馈、监控舆情、优化服务体验的核心…

作者头像 李华
网站建设 2026/5/5 23:33:05

32 位浮点数(IEEE 754 单精度)数轴分布技术文档

目录 1. 文档概述 2. 核心定义与格式 2.1 IEEE 754 单精度浮点数结构 2.2 数值表示公式 3. 数轴分布核心特性 3.1 整体分布规律 3.2 关键区间分布说明 3.3 直观示例 4. 编程指导意见 4.1 精度控制建议 4.2 边界值处理 4.3 性能与精度权衡 5. 常见问题与解决方案 6…

作者头像 李华
网站建设 2026/5/9 4:03:16

如何高效运行AutoGLM-Phone-9B?一文掌握本地部署全流程

如何高效运行AutoGLM-Phone-9B&#xff1f;一文掌握本地部署全流程 随着多模态大模型在移动端的广泛应用&#xff0c;轻量化、高效率的推理能力成为关键需求。AutoGLM-Phone-9B 作为一款专为移动设备优化的90亿参数多模态大语言模型&#xff0c;融合了文本、语音与视觉处理能力…

作者头像 李华
网站建设 2026/5/3 10:44:47

分类模型压测工具:云端GPU模拟百万QPS,成本可控

分类模型压测工具&#xff1a;云端GPU模拟百万QPS&#xff0c;成本可控 引言 作为技术负责人&#xff0c;你是否遇到过这样的困境&#xff1a;系统上线前需要验证承载能力&#xff0c;但本地测试环境根本无法模拟真实的高并发场景&#xff1f;传统的压测工具要么性能不足&…

作者头像 李华
网站建设 2026/5/7 18:41:08

IP静态是什么意思?静态IP适用于哪些业务场景?

1 什么是IP静态&#xff1f;“IP静态”&#xff0c;指的是不会随时间或网络重连而发生变化的固定IP地址&#xff0c;也被称为“静态IP”或“固定IP”。 相对地&#xff0c;普通用户使用的多是“动态IP”&#xff0c;每次拨号或断网重连后IP都会变动。在网络业务中&#xff0c;I…

作者头像 李华
网站建设 2026/5/3 1:33:09

AI万能分类器实战:10分钟部署完成商品分类

AI万能分类器实战&#xff1a;10分钟部署完成商品分类 引言&#xff1a;电商运营的AI分类神器 作为一名电商运营人员&#xff0c;你是否经常遇到这样的困扰&#xff1a;每天上新几十款商品&#xff0c;手动分类耗时耗力&#xff1b;IT部门排期要等一个月&#xff0c;而市场机…

作者头像 李华