- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
是否有任何现有的网络应用程序可以让多个用户同时使用交互式 IDLE 类型 session ?
类似于:
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
如果没有,我想创建一个。有没有我可以使用的模块来模拟交互式 session ?我想要这样的界面:
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
(尽管最后一个功能更像是一个额外的功能。)
以另一种方式表述我的问题:我想为 IDLE 创建一个新的前端。我该怎么做?
更新: 或者我可以通过 eval()
模拟 IDLE?
更新 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()
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()
这行得通吗,或者我偏离了方向/这种方法不可行/我在重复工作,而我应该使用已经构建的东西?
更新 3:另外,假设我的其他一切正常,我想要语法高亮显示。理想情况下,我有一些可以使用的 API 或服务来解析代码并适本地设计它的样式。
for c in "characters":
会变成:
<span class="keyword">for</span> <span class="var">c</span> <span class="keyword">in</span> <span class="string>"characters"</span><span class="punctuation">:</span>
是否有一个很好的现有 Python 工具来执行此操作?
最佳答案
我可以在 Nevow 中快速实现类似的东西.显然,访问需要受到严格限制,因为这样做涉及允许某人通过 HTTP 访问 Python 控制台。
我要做的是为控制台创建一个 Athena 小部件,它使用了 code.InteractiveInterpreter 的自定义子类的实例。这对所有登录用户都是通用的。
更新:好的,您在 GAE 中有了类似聊天的东西。如果您只是将代码行提交给看起来像这样的 code.InteractiveInterpreter 子类,它应该适合您。请注意,该界面与您描述的 InteractiveSession 类非常相似:
class SharedConsole(code.InteractiveInterpreter):
def __init__(self):
self.users = []
def write(self, data):
# broadcast output to connected clients here
for user in self.users:
user.addOutput(data)
class ConnectedUser(object):
def __init__(self, sharedConsole):
self.sharedConsole = sharedConsole
sharedConsole.users.append(self) # reference look, should use weak refs
def addOutput(self, data):
pass # do GAE magic to send data to connected client
# this is a hook for submitted code lines; call it from GAE when a user submits code
def gotCommand(self, command):
needsMore = self.sharedConsole.runsource(command)
if needsMore:
pass # tell the client to change the command line to a textarea
# or otherwise add more lines of code to complete the statement
关于Python:在使用相同后端的同时联网的 IDLE/Redo IDLE 前端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2893401/
我正在寻找一种快速开始使用可以访问相机、快速拍摄快照并将其上传到互联网站点的应用程序的方法。 由于我正在寻找 RIA 开发,我想我需要一个框架(理想情况下尽可能轻量级)。 对我和大多数读者来说,最好的
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我一直在尝试理解 rxSwift。我面临请求问题并希望以良好的方式实现这一点。目前,我正在使用此代码: enum RequestState { case loading case lo
我正在使用 Linux epoll 工具开发一个用 C 语言编写的网络应用程序。 我确实在实现我自己的事件循环,是的,我知道有一些库可以为我做这件事。然而,这只是一个练习,我_想_自己实现事件循环。
我正在为 WatchOS 构建一个应用程序扩展,我想在 Watch 应用程序中执行一些 URL 请求。我在网络部分使用 Alamofire。 每当我做一个简单的请求时,我在模拟器和真实设备上都会收到这
我使用这个官方指南在 Windows 7 机器上设置 Docker: https://docs.docker.com/windows/started/ 我成功地从 docker hub 拉取了一个镜像
我使用的示例代码来自这个 Stack Overflow 问题 (http://stackoverflow.com/questions/3240617/cfnetwork-and-bonjour-int
在 Windows 平台上使用套接字的最佳方式是什么? 我猜是基本套接字,TCP/IP。也许是为了聊天客户端,或者只是为了学习。 谁能给我一个 WININET 用法的例子? 也许是 ftpgetfil
这是我的问题: 我写了一个可以运行的 python 脚本,但只能在我的机器上运行(当我在我的解释器中运行它时)。 我还编写了 .bat 和 .ini 文件(就像我已经为其他有效的脚本所做的那样),当我
我是一名优秀的程序员,十分优秀!