python 代码生成器_为VS代码创建Python类生成器

python 代码生成器

My motto...when you have a problem, do something about. I hated stubbing out Python classes so I created an extension in Visual Studio Code to do it for me. In this article, let's walk through how I created that extension. We will use several techniques to do so.

我的座右铭...当您遇到问题时,请采取一些措施。 我讨厌存根Python类,所以我在Visual Studio Code中创建了一个扩展来为我做。 在本文中,让我们逐步介绍如何创建该扩展。 我们将使用几种技术来做到这一点。

  • Prompting User Input

    提示用户输入
  • Array Map and Join Functions

    数组映射和联接函数
  • ES6 Template Literals

    ES6模板文字
  • Writing to the File System

    写入文件系统

TLDR (TLDR)

Create a new extension, prompt the user for input, convert the input to a string that represents the new class file, and write out tha

创建一个新的扩展名,提示用户输入,将输入转换为代表新类文件的字符串,然后写出

Check out the end result HERE.

此处检查最终结果。

Check out Learn Visual Studio Code to learn everything you need to know about about the hottest editor in Web Development for just \$10!

查看“ 学习Visual Studio Code” ,只需10美元即可了解有关Web开发中最热门的编辑器的所有信息。

创建项目 ( Creating the Project )

To get started with developing Code extensions, you'll need two different NPM packages installed, "yo" and "generator-code". If you're looking for a little more background on creating VS Code extensions, check out Creating Your First Visual Studio Code Extension!

要开始开发Code扩展,您需要安装两个不同的NPM软件包“ yo”和“ generator-code”。 如果您正在寻找创建VS Code扩展的更多背景知识,请查看创建您的第一个Visual Studio Code扩展

To generate your project, run the following command.

要生成您的项目,请运行以下命令。

yo code

This will follow up by asking you several questions about your project. Choose either JavaScript or TypeScript for your extension.

接下来,您会询问有关项目的几个问题。 为扩展名选择JavaScript或TypeScript。

After answering all of the questions, open the newly created project in Code.

回答所有问题后,在Code中打开新创建的项目。

You'll have a several different files created for you, the two most important are the package.json and extension.js files.

您将为您创建几个不同的文件,其中最重要的两个是package.json和extension.js文件。

Start by opening the extension.js file. Then, rename the extension command name to "createPyClass".

首先打开extension.js文件。 然后,将扩展命令名称重命名为“ createPyClass”。

Then, in the package.json file, rename the activation event and command to match the name of the command.

然后,在package.json文件中,重命名激活事件和命令以匹配命令的名称。

Update the title as well, which is what the user will type to activate the command.

同时更新标题,这是用户键入以激活命令的内容。

To run the extension, open the debug panel (looks like a bug) and press play. This will open up a new instance of VS Code. Open the command prompt (
Command+ Shift
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值