像我们有source()
函数在R studio中执行另一个R
程序中的R
程序,如何在另一个python程序中执行python程序?等效于Python中R的源()
5
A
回答
4
鉴于2 Python脚本:first.py
和second.py
,从第二执行第一通常的方式是在东西的线:
first.py:
def func1():
print 'inside func1 in first.py'
if __name__ == '__main__':
# first.py executed as a script
func1()
second.py:
import first
def second_func():
print 'inside second_func in second.py'
if __name__ == '__main__':
# second.py executed as a script
second_func()
first.func1() # executing a function from first.py
编辑:
- 如果您愿意,也可以使用简单的
execfile("second.py")
(尽管它只在调用名称空间内)。 - 最后的选项是使用
os.system
像这样:
os.system("second.py")
。
0
如果您习惯从GitHub直接采购,您可以使用请求包下载带有http get的原始* .py文件,然后执行该文件。
import requests
exec(requests.get('http://github.myorg.net/raw/repo/directory/file.py').text)
免责声明:我的R用户学习Python的,所以这可能是违反了一些Python最佳实践
相关问题
- 1. Python IDLE等效于R中的CTRL-R
- 2. 等效于从R到Python
- 3. R rbind.fill等效于Python Pandas
- 4. R中的method_missing等效于
- 5. 等效于R中的matlab'ans'
- 6. 外()等效于R中
- 7. Matlab。等效于R
- 8. 等效于Python中的createDataPartition
- 9. R的removeSparseTerms在Python中的等效
- 10. Python的条形图等效中的R
- 11. R在Python中的read.table等效项
- 12. str_replace_all()R等效在python
- 13. Excel SUMIFS等效于R
- 14. roxygen2等效于python
- 15. cout.precision()等效于python
- 16. JRE等效于Python
- 17. R ggplot2 bar等效于R基图
- 18. Golang等效于Python的NotImplementedException
- 19. 等效于Python的Object.create()
- 20. Python等效于Ruby的#each_cons?
- 21. PHP等效于Python的repr()
- 22. Python的os.execvp等效于PHP
- 23. PHP等效于Python的`urljoin`
- 24. python的%(从R)的等效函数
- 25. - [R等效的Python“通”语句的
- 26. R等同于`python -i`
- 27. - [R等效Python的np.dot为3D阵列
- 28. 等效于Python中cor.test的R's
- 29. 等效于Python中的C#matchObject.Value?
- 30. 等效于Python中的BASH_XTRACEFD重定向
我找到了'execfile'是最相似的r'source' – vpipkt