首页 \ 问答 \ Shift + Return在python中插入换行符(Shift + Return to insert linebreak in python)

Shift + Return在python中插入换行符(Shift + Return to insert linebreak in python)

我试图获得使用Return发送文本并按Shift + Return插入换行符的典型IM客户端的行为。 有没有一种方法可以在Python中以最少的努力实现这一点,例如使用readlineraw_input


I'm trying to get the behaviour of typical IM clients that use Return to send a text and Shift + Return to insert a linebreak. Is there a way to achieve that with minimal effort in Python, using e.g. readline and raw_input?


原文:https://stackoverflow.com/questions/11343317
更新时间:2023-01-06 06:01

最满意答案

事实证明,据我所知,不可能在python中使用不同版本的AST解析器。 (仍然可以通过每次使用不同的版本AST执行多次迭代来单独解析它们)


Turns out it is not possible to use different versions of AST parsers in python to the best of my knowledge. (It is still possible to parse them separately by carrying out multiple iterations each time using a different version AST)

相关问答

更多
  • 事实证明,据我所知,不可能在python中使用不同版本的AST解析器。 (仍然可以通过每次使用不同的版本AST执行多次迭代来单独解析它们) Turns out it is not possible to use different versions of AST parsers in python to the best of my knowledge. (It is still possible to parse them separately by carrying out multiple itera ...
  • 您需要将您匹配的每个符号与构建树的一小部分的回调关联起来。 例如,让我们来看一个相当常见的结构:嵌套函数调用。 a(b()) 您的终端令牌如下所示: L_PAREN ='(' R_PAREN =')' IDENTIFIER = [az] + 你的非终端符号是这样的: FUNCTION_CALL = IDENTIFIER,L_PAREN,R_PAREN 要么; FUNCTION_CALL = IDENTIFIER,L_PAREN,FUNCTION_CALL,R_PAREN 很明显,规则FUNCTION_CA ...
  • 当然,所有中间AST节点也可以移动/复制。 例如,如果您了解当x_rule解析为X然后解析x_rule % ','时会发生什么,这一点非常清楚。 向量(或其他容器)将移动/复制X in,并且所有其他元素可能由于重新分配而移动。 如果目标是在树外附加一些数据,而不过多地增加AST节点,则可以考虑单独存储信息并引用它(通过id,指针或某种类型的引用)。 在这种情况下,您可能只需要“垃圾收集”您单独存储的数据(并防止在重回溯的情况下失控累积)。 使用shared_ptr可以以更多开销为代价方便地使用它。 Of c ...
  • ASTParser.setResolveBindings()的javadoc说: 绑定信息从Java模型获得。 这意味着编译单元必须相对于Java模型。 当源代码来自setSource(ICompilationUnit)或setSource(IClassFile)时,会自动发生这种情况。 当source由setSource(char [])提供时,必须通过调用setProject(IJavaProject)和setUnitName(String)显式地创建该位置。 请注意,影响doc注释检查的编译器选项也可 ...
  • 这条线是非常错误的 : for line in temp_file.read(): temp_file.read()返回完整的文件内容 。 现在line是一个字符,这解释了为什么literal_eval在第一个[单独打印语法错误。 你想在线上迭代,简单地说: for line in temp_file: line = literal_eval(line) 我知道,我必须小心ast.literal_eval。 是否有比ast.literal_eval更适合的工具? 你将它与eval()混合,这是不 ...
  • 看起来它已在2.7中修复 请参阅https://github.com/gwtproject/gwt/issues/8714 Looks like it's fixed in 2.7 See https://github.com/gwtproject/gwt/issues/8714
  • 使用PS3.0 + 语言命名空间 AST解析器: $text = Get-Content 'pester-script.ps1' -Raw # text is a multiline string, not an array! $tokens = $null $errors = $null [Management.Automation.Language.Parser]::ParseInput($text, [ref]$tokens, [ref]$errors). FindAll([Func[Man ...
  • 好的,这是: pStmt = pFoo <|> pBar pWhiteStmt = do many whitespace p <- pStmt many whitespace return p pTest = do many semi pS <- sepEndBy pWhiteStm (some semi) eof return pS 并测试它: > parse pTest "" ";;foo;bar;\nfoo;; foo;bar;ba ...
  • 我不是特别了解Rhino所以我不知道它是否为此提供了具体的帮助。 但总的来说,你可以通过跟踪你所做的改变来直接做到这一点,作为“反改变”。 此方案适用于任何AST系统,而不仅仅是Rhino。 树由节点以及节点与其子节点之间的关系组成。 要构造树,您可以执行命令来创建节点,创建其子节点并将它们链接在一起。 当然,Rhino API为此提供了原始支持。 为了在以后重新构建树,我们仅根据节点构造和子连接/断开来制定要完成的动作列表。 想象一下下面的树: 1:* / \ ...
  • 所以事实证明你无法使用com.sun.source.tree。*的任意实现编译用户创建的树。 但是可以做的是将AST打印到字符串并使用Java 6 Compiler API在内存中编译字符串。 So it turns out you cannot compile a tree created by the user using the arbitrary implementations of com.sun.source.tree.*. What can be done though is to print ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)