Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google应用程序引擎外壳中的Python原始输入_Python_Google App Engine_Console Application - Fatal编程技术网

Google应用程序引擎外壳中的Python原始输入

Google应用程序引擎外壳中的Python原始输入,python,google-app-engine,console-application,Python,Google App Engine,Console Application,我有一个在命令行上运行的Python程序。它使用raw_input()从用户键盘读取字符串。我想让程序在谷歌应用程序引擎上可用,并希望使用,因为它有一个命令提示符 然而,shell似乎提供了一个“假”提示,当我在程序中使用raw_input()时,它只返回EOF 您有没有关于使用什么来代替raw_input()的提示,或者关于使交互式控制台python应用可用的其他方法的提示?(不必是花哨的诅咒之类的东西,只要读一个缓冲字符串就行了。) 编辑:该程序是一个类似Zork的在线冒险程序,看起来App

我有一个在命令行上运行的Python程序。它使用raw_input()从用户键盘读取字符串。我想让程序在谷歌应用程序引擎上可用,并希望使用,因为它有一个命令提示符

然而,shell似乎提供了一个“假”提示,当我在程序中使用raw_input()时,它只返回EOF

您有没有关于使用什么来代替raw_input()的提示,或者关于使交互式控制台python应用可用的其他方法的提示?(不必是花哨的诅咒之类的东西,只要读一个缓冲字符串就行了。)


编辑:该程序是一个类似Zork的在线冒险程序,看起来AppEngineShell没有将stdin绑定到与浏览器的AJAX连接,后者用于交换命令和结果。换句话说,你不能用它来实现你的目标


我将创建一个简单的基于表单的包装器,作为底层命令行程序的前端,而不是通过web公开命令行界面(这听起来不是一个好主意)。

该应用程序的Python源代码位于Google代码中,供您学习或重用。出于安全原因,raw_input()可能已被禁用,并始终返回EOF

这个shell使用AJAX接口,只需从输入区域获取代码并对其进行解析。请参见存储库中的:

/**
 * This is the prompt textarea's onkeypress handler. Depending on the key that
 * was pressed, it will run the statement, navigate the history, or update the
 * current statement in the history.
 *
 * @param {Event} event the keypress event
 * @return {Boolean} false to tell the browser not to submit the form.
 */
shell.onPromptKeyPress = function(event) {
  var statement = document.getElementById('statement');

  if (this.historyCursor == this.history.length - 1) {
    // we're on the current statement. update it in the history before doing
    // anything.
    this.history[this.historyCursor] = statement.value;
  }

  // should we pull something from the history?
  if (event.ctrlKey && event.keyCode == 38 /* up arrow */) {
    if (this.historyCursor > 0) {
      statement.value = this.history[--this.historyCursor];
    }
    return false;
  } else if (event.ctrlKey && event.keyCode == 40 /* down arrow */) {
    if (this.historyCursor < this.history.length - 1) {
      statement.value = this.history[++this.historyCursor];
    }
    return false;
  } else if (!event.altKey) {
    // probably changing the statement. update it in the history.
    this.historyCursor = this.history.length - 1;
    this.history[this.historyCursor] = statement.value;
  }

  // should we submit?
  if (event.keyCode == 13 /* enter */ && !event.altKey && !event.shiftKey) {
    return this.runStatement();
  }
};
/**
*这是提示textarea的onkeypress处理程序。取决于
*按下时,它将运行语句、浏览历史记录或更新
*历史上的当前声明。
*
*@param{Event}Event按键事件
*@return{Boolean}false告诉浏览器不要提交表单。
*/
shell.onPromptKeyPress=函数(事件){
var语句=document.getElementById('statement');
if(this.historyCursor==this.history.length-1){
//我们正在处理当前语句。请在执行之前在历史记录中更新它
//什么都行。
this.history[this.historyCursor]=statement.value;
}
//我们应该从历史中汲取一些东西吗?
if(event.ctrlKey&&event.keyCode==38/*向上箭头*/){
如果(this.historyCursor>0){
statement.value=this.history[--this.historyCursor];
}
返回false;
}else if(event.ctrlKey&&event.keyCode==40/*向下箭头*/){
if(this.historyCursor
我通过将程序转换为生成器解决了这个问题

示例代码可以在

你可以在这里试试

程序存储在中,需要稍加修改;用产量替换
原始输入()
,并用修改后的打印替换打印。应用引擎处理程序将HTML表单中的输入发送到generator.send(输入)中,该生成器由yield语句“返回”

while True:
    print "What's your name?"
    name = raw_input()
    print "Hello "+name+"!"
    print
必须修改为

from appconsole import myprint, printoutput

def prog_gen(namn=""):

    while True:
        myprint("What's your name?")
        name = yield printoutput()
        myprint("Hello "+name+"!")
        myprint()