像我們有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