news 2026/8/16 10:39:03

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/8/4 22:24:21

万能分类器+CLIP联合使用教程:云端GPU双模型同时跑

万能分类器CLIP联合使用教程&#xff1a;云端GPU双模型同时跑 引言&#xff1a;当分类器遇上CLIP 想象你是一位博物馆管理员&#xff0c;手头有两件神奇工具&#xff1a;一个能自动识别展品类别的智能标签机&#xff08;万能分类器&#xff09;&#xff0c;另一个是精通艺术史…

作者头像 李华
网站建设 2026/8/16 2:05:28

分类模型微调实战:云端GPU 3小时完成训练,花费9元

分类模型微调实战&#xff1a;云端GPU 3小时完成训练&#xff0c;花费9元 引言&#xff1a;为什么选择云端GPU微调分类模型&#xff1f; 当你手头有一批行业数据&#xff08;比如电商评论、医疗报告或金融新闻&#xff09;&#xff0c;想要训练一个能自动分类的AI模型时&…

作者头像 李华
网站建设 2026/8/4 15:24:57

StructBERT中文情感分析镜像发布|CPU支持+开箱即用Web界面

StructBERT中文情感分析镜像发布&#xff5c;CPU支持开箱即用Web界面 1. 背景与需求&#xff1a;中文情感分析的工程落地挑战 在自然语言处理&#xff08;NLP&#xff09;的实际应用中&#xff0c;中文情感分析是企业级服务中最常见的需求之一。无论是电商评论、客服对话还是…

作者头像 李华
网站建设 2026/8/7 1:45:43

AutoGLM-Phone-9B核心优势解析|轻量9B模型赋能手机端AI

AutoGLM-Phone-9B核心优势解析&#xff5c;轻量9B模型赋能手机端AI 1. 技术背景与移动端大模型挑战 随着生成式AI技术的快速演进&#xff0c;将大语言模型部署到移动设备已成为行业关注的核心方向。传统大模型&#xff08;如百亿参数以上&#xff09;受限于算力、内存和功耗&…

作者头像 李华
网站建设 2026/8/8 11:52:21

分类模型A/B测试框架:云端流量切分,效果对比科学直观

分类模型A/B测试框架&#xff1a;云端流量切分&#xff0c;效果对比科学直观 引言&#xff1a;为什么需要A/B测试框架&#xff1f; 想象你开了一家奶茶店&#xff0c;最近研发了两种新配方。直接全部换成新配方风险太大&#xff0c;但让所有顾客都尝两种口味又不现实。最聪明…

作者头像 李华