同步操作将从 连享会/python-in-stata 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
This package includes a Stata C plugin and helper files for embedding the Python programming language within Stata. In short, the plugin gives Stata users the ability to use Python to interact with Stata data values, matrices, macros, and numeric scalars. The plugin can be used interactively inside the Stata GUI, or can be used to execute Python files. Python files can be used separately or in combination with Stata .ado or .do files.
The main source of documentation is python_plugin.tex.
The code in this package is experimental. Save your data before using the plugin. There is currently one known limitation/bug which can crash Stata. There may be other, unknown bugs that can crash Stata, too.
Dropping a Stata program that uses the Python plugin and then re-running it can crash Stata, depending on what Python modules are used in the program, and whether it's the only Stata program that uses the plugin. For many Python modules this is not a problem. Nor does it seem to be a problem to drop and re-run python.ado, even if it's the only program using the plugin.
Remedy: It's not clear what is causing this problem, but there seems to be a simple solution. If wanting to drop a program that uses the plugin, make sure that another program also uses it--for example, use python.ado at least once--or declare the plugin in Stata directly, with program python_plugin, plugin
.
The interactive Python interpreter within Stata is limited to single-line inputs. Unfortunately there is no remedy for this at the moment. With some creativity, though, quite a bit of Python code can be packed into a single line, or combinations of single-line inputs. If more than one line of input is needed in a single statement, you can write the code in a Python .py file, and run the file using the file option of python.ado or import it in an interactive session.
The Stata GUI's Break button does not interrupt the plugin. There is not recourse for infinite loops in the plugin besides closing Stata.
The plugin does not have continuous access to user input. Python code requiring continuous control over stdin, such as the input() function, will not work.
Calling sys.exit()
in a Python file will close Stata. In the interactive interpreter, sys.exit()
may be safely used to exit the plugin, but in a Python file sys.exit()
will close Stata.
The file INSTALL includes installation instructions for Windows and Mac OS X.
If the plugin is installed correctly, typing python
should open an interactive session of Python.
The functionality of the plugin comes mainly in the form of st_
functions that are meant to be analogs of Mata's st_
functions. For example,
. sysuse auto
(1978 Automobile Data)
. list make-head in 1
+----------------------------------------------+
| make price mpg rep78 headroom |
|----------------------------------------------|
1. | AMC Concord 4,099 22 3 2.5 |
+----------------------------------------------+
. scalar s = 1234.5
. python
--------------------------- python (type exit() to exit) ---
. st_numscalar("s")
1234.5
. st_isstrvar(0)
True
. _st_sdata(0, 0)
'AMC Concord'
. st_isnumvar(1)
True
. _st_data(0, 1)
4099.0
. exit()
------------------------------------------------------------
For more examples and a complete description of the package's functionality, see python_plugin.tex.
Copyright (c) 2013, James Fiedler (MIT License)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。