
var.py: s = This is a multi-line string. This is the second line. print s run "python var.py" 书上说结果应该是: This is a multi-line string. This is the second line. 但输出为: File "var.py", line 1 s = This is a multi-line string. ^ SyntaxError: invalid syntax 甚至print Hello World都说: File "helloworld.py", line 1 print Hello World ...
by 共舞秋雨 - Python - 2009-09-23 12:44:12 阅读(11745) 回复(7)
我用三个单引号 ''' 或者3个 """来注释几行时,解释器提示说: """ ^ IndentationError: expected an indented block,比较郁闷,书上是这么说注释的。。。。
初看之下,python 里缺少块注释(block comment)。 解决方法 把 code block 放在if 0: ... 的缩进块里 用”“”或者'''的 triple quotes 把要注释的代码包起来。不过这种办法必须要注意 triple quotes 的缩进,必须服从上下文。另外,被注释的代码不能含有 triple quote(s)。 像样的编辑器都应该有块注释的功能。Emacs: C-c # 就是块注释,C-u C-c # 就是取消块注释 每一行都用“#”自有它的好处,而块注释标记则有其让人...
[code]typedef union { ... } AA; typedef union { ... } BB; typedef union { ... } CC; [/code]我想中上面的的文本中提取出 union CC的定义。 我试了下以下正则式:[code]re.compile(r'typedef union \{(.*?)\} CC', re.S|re.M)[/code]得到的结果是:[code]>>> pat.search(msg).groups()[0] ' \n...\n} AA;\n\ntypedef union { \n...\n} BB;\n\ntypedef union { \n...\n'[/code]好像没有去...
读取下面的文件,重新组合字符,合并成输出格式为由Line开头的3行。 需要读取的数据文件如下 Line1 Q E Line2 P E Line3 P V 想要达到的输出方式如下 Line1 QE Line2 PE Line3 PV 我写了一个程序只能按照原来的格式进行输出,请帮我看看如何进行那三行的重新排列。多谢!! #!/usr/bin/python import sys filename=sys.argv[1] data=open(filename) a=0 lines = data.readlines() for linestr in lines: lines...
str = dom.getElementsByTagName('Message')[0].getElementsByTagName('Body')[0].getElementsByTagName('response')[0].getElementsByTagName('parameter')[0].getElementsByTagName('file')[0].firstChild.data 这行代码能否像别的语言一样换行?
如题,我只要替换掉下面的版权信息,为“xxx”该如何编写python脚本呢?请指教,不甚感激,我可以另外开贴追加200分 /* * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * ...