Python:网络IDLE /重做IDLE前端,同时使用相同的后端?

Nic*_*ner 6 python user-interface python-idle

是否有任何现有的Web应用程序可以让多个用户同时使用交互式IDLE类型会话?

就像是:

IDLE 2.6.4
Morgan: >>> letters = list("abcdefg")
Morgan: >>> # now, how would you iterate over letters?
Jack: >>> for char in letters:
    print "char %s" % char


char a
char b
char c
char d
char e
char f
char g
Morgan: >>> # nice nice
Run Code Online (Sandbox Code Playgroud)

如果没有,我想创建一个.我可以使用哪些模块来模拟交互式会话吗?我想要一个这样的界面:

def class InteractiveSession():
    ''' An interactive Python session '''

    def putLine(line):
        ''' Evaluates line '''
        pass

    def outputLines():
        ''' A list of all lines that have been output by the session '''
        pass

    def currentVars():
        ''' A dictionary of currently defined variables and their values '''
        pass
Run Code Online (Sandbox Code Playgroud)

(虽然最后一个函数更像是一个额外的功能.)

用另一种方式表达我的问题:我想为IDLE创建一个新的前端.我怎样才能做到这一点?

更新:或者我可以通过模拟IDLE eval()

更新2:如果我做了这样的事情怎么办:

  • 我已经设置了一个简单的GAE Python聊天应用程序,允许用户登录,建立聊天室以及互相聊天.

  • 我可以做类似这样的事情,而不仅仅是将传入的消息保存到数据存储区:


def putLine(line, user, chat_room):
''' Evaluates line for the session used by chat_room '''

# get the interactive session for this chat room
curr_vars = InteractiveSession.objects.where("chatRoom = %s" % chat_room).get()

result = eval(prepared_line, curr_vars.state, {})

curr_vars.state = curr_globals

curr_vars.lines.append((user, line))
if result:
    curr_vars.lines.append(('SELF', result.__str__()))

curr_vars.put()
Run Code Online (Sandbox Code Playgroud)

InteractiveSession模型:

def class InteractiveSession(db.Model):


 # a dictionary mapping variables to values
    # it looks like GAE doesn't actually have a dictionary field, so what would be best to use here?
    state = db.DictionaryProperty()

    # a transcript of the session
    #
    # a list of tuples of the form (user, line_entered)
    #
    # looks something like:
    #
    # [('Morgan', '# hello'),
    #  ('Jack', 'x = []'),
    #  ('Morgan', 'x.append(1)'),
    #  ('Jack', 'x'),
    #  ('SELF', '[1]')]
    lines = db.ListProperty()
Run Code Online (Sandbox Code Playgroud)

这可行,或者我离开/这种方法是不可行的/我在复制工作时应该使用已经构建的东西?

更新3:另外,假设我得到其他所有工作,我想要语法高亮.理想情况下,我可以使用一些API或服务来解析代码并适当地设置样式.

for c in "characters":
Run Code Online (Sandbox Code Playgroud)

会成为:

<span class="keyword">for</span> <span class="var">c</span> <span class="keyword">in</span> <span class="string>"characters"</span><span class="punctuation">:</span>
Run Code Online (Sandbox Code Playgroud)

有一个很好的现有Python工具来做到这一点?

Aut*_*tic -1

随着即将使用 0MQ 后端的 IPython 的实现,这很可能成为可能。