当前位置: 首页 > news >正文

VSCode-Python传参数进行Debug

新建demo.py

import argparse
def parse_args():description = "debug example"                   parser = argparse.ArgumentParser(description=description)        help = "The path of address"parser.add_argument('--host',help = help)  parser.add_argument('--port',help = help)  parser.add_argument('--user',help = help)  args = parser.parse_args()                                                return argsif __name__ == '__main__':args = parse_args()host = args.hostport = args.portuser = args.userprint([host, port, user])   '''python demo.py --host 127.0.0.1 --port 22 --user root'''

命令行运行 python demo.py --host 127.0.0.1 --port 22 --user root 可以看到输出结果

在vscode点击debug的图标-->create a launch.json file--->python File

初始的json文件如下:

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Python: Current File","type": "python","request": "launch","program": "${file}","console": "integratedTerminal","justMyCode": true}]
}

Ctrl+shif+p切换python环境并更改./vscode/launch.json如下

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Python: Current File","type": "python","request": "launch","program": "${file}","console": "integratedTerminal","justMyCode": true,"env": {"CUDA_VISIBLE_DEVICES":"4"  // 设置cuda},// 添加参数"args":["--host", "127.0.0.1","--port", "22","--user","root"]}]
}

之后打断点按F5或者Run-->Start Debugging 就可以了

http://www.lryc.cn/news/122973.html

相关文章:

  • 实践-传统深度学习
  • 爬虫:使用Selenium模拟人工操作及获取网页内容
  • AOP开发
  • Streamlit项目: 轻松搭建部署个人博客网站
  • 手把手教你如何实现内网搭建电影网站并进行公网访问(保姆级教学)
  • Redis_事务操作
  • python质检工具(pylint)安装使用总结
  • “深入探究JVM:解密Java虚拟机的工作原理“
  • 同济子豪兄模板 半天搞定图像分类
  • 接口自动化测试,Fiddler使用抓包辅助实战,一篇彻底打通...
  • 概念解析 | 隐式神经表示:揭开神经网络黑盒的奥秘
  • 深入浅出PHP封装根据商品ID获取淘宝商品详情数据方法
  • 自动切换HTTP爬虫ip助力Python数据采集
  • 20230811导出Redmi Note12Pro 5G手机的录音机APP的录音
  • Python-OpenCV中的图像处理-傅里叶变换
  • 8.10 用redis实现缓存功能和Spring Cache
  • SPI协议个人记录
  • 【深度学习 video detect】Towards High Performance Video Object Detection for Mobiles
  • 时序预测 | MATLAB实现EEMD-LSTM、LSTM集合经验模态分解结合长短期记忆神经网络时间序列预测对比
  • 【软件工程】面向对象方法-RUP
  • Golang 的面向对象
  • STABLE DIFFUSION模型及插件的存放路径
  • Three.js 设置模型材质纹理贴图和修改材质颜色,材质透明度,材质网格
  • docker 安装mongodb 虚拟机安装mongodb
  • 在SockJS+Spring Websocket中convertAndSendToUser中的“用户”来自哪里?
  • 【软件测试】我的2023面试经验谈
  • SpringBoot 整合JDBC
  • TypeScript使用npm安装报错问题
  • 2023国赛数学建模思路 - 复盘:人力资源安排的最优化模型
  • 学习pytorch 3 tensorboard的使用