[英]How should I preferably "run" Python scripts in RStudio? Through run (using reticulate::repl_python()?) or source?
I just started to use RStudio with Python (up to now everything works) and I wonder if there is a preferred way to run scripts such as my small Test.py
containing我刚开始使用 RStudio 和 Python(到目前为止一切正常),我想知道是否有更好的方式来运行脚本,例如我的小
Test.py
包含
import inspect
import os
a = 5
print(a)
print(inspect.currentframe())
os.chdir("C:/.../") # a path, whatever you like
cwd = os.getcwd()
# print the current directory
print("Current working directory is:", cwd)
There is an answer for R here but this does not consider Python. I tried the flollowing:此处有 R 的答案,但这不考虑 Python。我尝试了以下操作:
reticulate::repl_python()
in R-console => Change from R- to Python-consolereticulate::repl_python()
启动 Python 控制台 => 从 R- 更改为 Python-console It seems, reticulate::repl_python()
forces the quit
first.似乎
reticulate::repl_python()
首先强制quit
。
This reference for reticulate and its description did not help : The reticulate package provides a comprehensive set of tools for interoperability between Python and R... Reticulate embeds a Python session within your R session, enabling seamless, high-performance interoperability. This reference for reticulate and its description did not help : The reticulate package provides a comprehensive set of tools for interoperability between Python and R... Reticulate embeds a Python session within your R session, enabling seamless, high-performance interoperability.
(Too long for a comment. Maybe it helps others and hopefully, everything is correct) (评论太长了。也许它可以帮助别人,希望一切都是正确的)
What I understand now, RStudio provides an editor for R (not surprising).据我所知,RStudio 为 R 提供了一个编辑器(不足为奇)。 When you run Python code within RStudio, there is an R-wrapper for Python translating the code to R.
当您在 RStudio 中运行 Python 代码时,有一个 Python 的 R-wrapper 将代码转换为 R。
Thus, RStudio does not switch the editor to a native Python-IDE (which was my expectation) like VScode or others.因此,RStudio 不会将编辑器切换到原生 Python-IDE(这是我的期望),如 VScode 或其他。
What I understand now: If you have projects with Python only, use a Python editor.我现在的理解是:如果您只有 Python 的项目,请使用 Python 编辑器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.