简体   繁体   English

如何直接在终端中运行用 atom 编辑器编写的 python fie?

[英]How can I run a python fie written in atom editor directly in Terminal?

I am new to atom editor.我是原子编辑器的新手。 I was wondering if by a single command I can directly run the file in the command prompt?我想知道是否可以通过单个命令直接在命令提示符下运行文件?
For example in Sublime Text 3, I made a custom Build system where I wrote these lines例如在 Sublime Text 3 中,我制作了一个自定义构建系统,我在其中编写了这些行

{
    "cmd": ["python", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "target": "console_exec"
}

Now just by ctrl+b the cmd opens up and the codes executes.现在只需按ctrl+b即可打开 cmd 并执行代码。
How can I do this in atom?我怎么能在原子中做到这一点?

There many ways to run an atom written python file in the terminal.有很多方法可以在终端中运行原子写入的 python 文件。
The most common way to do this is to run it using python3 in the command prompt.最常见的方法是在命令提示符下使用 python3 运行它。

  1. Save your python file as .py将 python 文件另存为.py
  2. Use cd to enter the directory with the python file使用cd进入有python文件的目录
  3. If on python 2 run: python script_name.py如果在 python 2 上运行: python script_name.py
    If on python 3 run: python3 scrip_name.py如果在 python 3 上运行: python3 scrip_name.py

You can also use extensions to make this easier.您还可以使用扩展来简化此操作。 Atom is a text editor, not an IDE, however certain extensions can provide some IDE capabilities to Atom. Atom 是一个文本编辑器,而不是 IDE,但是某些扩展可以为 Atom 提供一些 IDE 功能。 One of them is the atom-python-run extension.其中之一是atom-python-run扩展。 Here is the installation instructions and documentation .这是安装说明和文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM