- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我刚刚从一本书中用 Python34 键入了一个正在运行的命令提示符的示例。
但现在我想将这个 python 程序保存为文件以备将来使用。由于我以前从未使用过命令提示符,我也在网上搜索过,但大多数都无法回答。
谁能在这里展示解决方案?谢谢。
最佳答案
您可以使用 %save 在 ipython 中保存行:
用法:
%save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... Options:
-r: use ‘raw’ input. By default, the ‘processed’ history is used, so that magics are loaded in their transformed version to valid Python. If this option is given, the raw input as typed as the command line is used instead.
-f: force overwrite. If file exists, %save will prompt for overwrite unless -f is given.
-a: append to the file instead of overwriting it.
This function uses the same syntax as %history for input ranges, then saves the lines to the filename you specify.
It adds a ‘.py’ extension to the file if you don’t do so yourself, and it asks for confirmation before overwriting existing files.
If -r option is used, the default extension is .ipy.
In [1]: def foo():
...: print("hello world")
...:
In [2]: %save my_code 1
The following commands were written to file `my_code.py`:
def foo():
print("hello world")
In [3]: cat my_code.py
# coding: utf-8
def foo():
print("hello world")
关于python - 如何将命令提示符中的 Python 编码保存为文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30506069/
有什么方法可以自定义javascript提示框吗? 我想让我的提示只接受数字输入...(我想绑定(bind) keyup 事件 - 具体来说) 这可能吗? 最佳答案 默认的 javascript 提示
对我来说,现在是 bash-prompt-fiddling-time(总有一天……)。 我正在尝试获取两行提示: 第一行包含位置信息,背景颜色到行尾 第 2 行包含时间和上一个命令的退出代码 我快到了
大家好,我只是在学习 javascript,不过我有一些 html 和 css 背景。 我不知道如何只允许在提示中输入数字值,或者检查它是否是数字,如果不是则重新提示。文本框也是如此。 最佳答案 这是
编辑:原标题说“bash prompt”,但我使用“zsh”。我接受了@Artur R. Czechowski 的回答,因为它在 bash 上下文中是正确的,并且我能够在他的帮助下完成我的工作。 PR
是否可以配置stack ghci类似于ghci的方式通过 ~/.ghci 配置文件? 目前stack ghci不接受 ~/.ghci 中的设置文件。 我正在研究将提示设置为 lambda 而不是加载的
我喜欢在我的 PowerShell 提示符中包含 Mercurial/Git 存储库状态。有时这会减慢 prompt()功能相当大,导致长时间等待,直到您可以开始在 shell 中输入。我想知道,是否
我正在编写一个用于与远程服务交互的 PowerShell 模块。连接到远程服务时(通过模块中的函数),我想在提示符前添加用户名。断开连接后,我想删除用户名。 我以为我可以通过复制全局 prompt 来
我用java开发了我的远程屏幕共享软件。它工作正常,但是当使用 UAC 时,屏幕上会出现允许/禁止提示,但远程屏幕看不到它。所以每次用户都必须手动允许它。我想知道如何摆脱这个问题。 最佳答案 这正是
我有一个初始化脚本,它设置了几个变量供以后使用。最后一行定义了一个“提示”函数,我希望它能改变我的提示,作为初始化已经完成的指示。变量已设置,因此它不作为子进程运行,但我的提示顽固地停留在“PS”。出
我有一个与此类似的模板提示: prompt = f""" Write a poem about the topic delimited by triple backticks if it starts
我有一个与此类似的模板提示: prompt = f""" Write a poem about the topic delimited by triple backticks if it starts
我需要一些帮助才能恢复提示,现在我正在执行此 block ,不要让我恢复提示,我在运行末尾使用 &将此命令作为后台任务。执行脚本后如何返回提示符。 #!/bin/sh sudo su - user <
如果我的 html 中有一个简单的按钮: Start Game 我想要在我的 JS 中提示: var userAdjective = prompt("Please provide an Adjecti
我想提示用户在网页上进行一些输入。 我无法使用内置的 Javascript prompt 函数,因为它会在 IE 中创建安全警告。 是否有人们用来重新创建此内容的最佳实践/方法/示例? Javascr
我想将我的 bash 提示设置为固定宽度,并弥补 $ 之前的空格差异,因此无论长短,我的提示都保持相同的宽度: [name@host] ~/Directory/Dir...Another/LastDi
我有一个脚本可以读取用户的输入。这是我的代码: if [ -z $volreadexists ]; then echo -e "\tThis will overwrite the en
我的 ZSH 主题使用 .zsh-theme 文件中的 RPROMPT='$(vbox_status)' 输出我的 Vagrant/VBox VM 的状态(其中 vbox_status调用 a scr
我经常使用 vim,并且经常发现使用 !bash 进入命令行很有用。但是,我需要键入 exit 才能返回到 vim,有时我不确定我是否在子 shell 中或者这是否会关闭我的 session 。 我真
问题很简单。我想在我的 bash 脚本中评估 PS1 的当前值。 Google 上的所有资料都指向有关如何改进它的教程,但我想评估一下我当前的终端或至少 一些 终端将如何呈现它。 是否有任何软件/功能
如何在打印后台函数的输出后自动返回到我的 bash 提示符? 例如,当我在 bash shell 中运行以下脚本时: fn(){ sleep 10 echo "Done"
我是一名优秀的程序员,十分优秀!