如何从命令行运行IPython脚本 - 魔术函数的语法错误,% [英] How to run IPython script from the command line - syntax error with magic functions, %

查看:160
本文介绍了如何从命令行运行IPython脚本 - 魔术函数的语法错误,%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从命令行运行IPython。但是,我在第一行遇到语法错误,使用魔术函数导入pylab %pylab 在%上给出语法错误。我使用的命令只是 ipython -i script.py

I want to run IPython from the command line. However, I get a syntax error on the first line, importing pylab with the magic function %pylab is giving a syntax error on the %. The command I am using is simply ipython -i script.py.

任何想法如何解决这个问题?

Any ideas how to solve this?

推荐答案

您需要将文件命名为script.ipy。当它以.ipy结尾时,它可以包含ipython语法。

You need to name your file script.ipy. When it ends in .ipy it can contain ipython syntax.

来自 ipython --help

Usage

    ipython [subcommand] [options] [files]

    If invoked with no options, it executes all the files listed in sequence
    and exits, use -i to enter interactive mode after running the files.  Files
    ending in .py will be treated as normal Python, but files ending in .ipy
    can contain special IPython syntax (magic commands, shell expansions, etc.)

这篇关于如何从命令行运行IPython脚本 - 魔术函数的语法错误,%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆