如何在Python中运行一段代码,类似于Matlab

2024-05-14 10:41:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个代码,它包括1)加载数据,2)处理数据。在

# Load data
import geoio.vtio as vtio
(traces, params)=vtio.vt_read("../Seismic/R2771_10PRDMkf_Full_T_Rzn_RMO.vt")

# Do things with the data
N=params['num_samples']
dt=params['digi']

通常,当我运行一个Python脚本时,我只需在IDLE中点击“F5”,重新运行之前的任何计算不会花费太长时间。但是,在这种情况下,数据的加载需要几秒钟的时间,我只想运行附加命令,类似于在Matlab中运行m文件中的一段代码。这可能吗?在


Tags: 数据代码importreaddataasloadparams
1条回答
网友
1楼 · 发布于 2024-05-14 10:41:25

如果你真的谈论iPython

学习iPython goodies

使用?开始

>>> ?
IPython   An enhanced Interactive Python
=========================================

IPython offers a combination of convenient shell features, special commands
and a history mechanism for both input (command history) and output (results
caching, similar to Mathematica). It is intended to be a fully compatible
replacement for the standard Python interpreter, while offering vastly
improved functionality and flexibility.

At your system command line, type 'ipython -h' to see the command line
options available. This document only describes interactive features.

MAIN FEATURES
      -

* Access to the standard Python help. As of Python 2.1, a help system is
  available with access to object docstrings and the Python manuals. Simply
  type 'help' (no quotes) to access it.

* Magic commands: type %magic for information on the magic subsystem.

* System command aliases, via the %alias command or the configuration file(s).

* Dynamic object information:

  Typing ?word or word? prints detailed information about an object.  If
  certain strings in the object are too long (docstrings, code, etc.) they get
  snipped in the center for brevity.

  Typing ??word or word?? gives access to the full information without
  snipping long strings. Long strings are sent to the screen through the less
  pager if longer than the screen, printed otherwise.
  ....etc....

学习%magic

^{pr2}$

我最喜欢的

  • %编辑-在外部编辑器中编辑内容(前几行、函数、我的文件)
  • %加载-从文件中加载数据,然后添加一些文本,然后运行它
  • %调试-调试崩溃的脚本
  • %历史-展示你迄今为止所做的
  • %粘贴-从剪贴板粘贴并运行代码
  • %宏-这可能是你问题的答案
  • %timeit-测量执行时间
  • %回忆-也接近你的问题
  • %重新运行-也试试

总的来说,如果我浏览iPython的帮助,我总能在iPython中找到一些提高生产力的工具。也试试吧。在

注意:我在控制台上使用iPyhton,但是其他UI版本应该提供非常相似的功能,如果不是完全相同的话。在

相关问题 更多 >

    热门问题