本文整理汇总了Python中zhpy.convertor函数的典型用法代码示例。如果您正苦于以下问题:Python convertor函数的具体用法?Python convertor怎么用?Python convertor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convertor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_try
def test_try():
"""
test try except
"""
assert convertor("尝试: 导入 a; 异常 ImportError, e: 打印 e") == \
"try: import a; except ImportError, e: print e"
assert convertor("引发 例外") == "raise Exception"
示例2: test_string
def test_string():
"""
same as print test
"""
s = "hello.py"
assert convertor("s.開始字串('he')") == "s.startswith('he')"
assert convertor("s.結束字串('he')") == "s.endswith('he')"
示例3: test_import
def test_import():
"""
test import statement with from/import/as
"""
assert convertor("载入 sys") == "import sys"
assert convertor("载入 sys 取名 unix") == "import sys as unix"
assert convertor("从 os 载入 path 取名 url") == "from os import path as url"
示例4: test_print
def test_print():
"""
test output statement and string types
"""
assert convertor("印出 'hello'") == "print 'hello'"
assert convertor('印出 "hello"') == 'print "hello"'
assert convertor("""印出 'hello'""") == "print 'hello'"
示例5: test_is
def test_is():
"""
test is, is not statement
"""
assert convertor("4 為 4") == ("4 is 4")
assert convertor("4 是 4") == ("4 is 4")
assert convertor("4 不是 2") == ("4 is not 2")
示例6: test_if
def test_if():
"""
test if, elif, else
"""
assert convertor("如果 a: 略過") == "if a: pass"
assert convertor("如果 a: 略過; 否則: 略過") == "if a: pass; else: pass"
assert convertor("如果 a: 略過; 假使 b: 略過; 否則: 略過") == \
"if a: pass; elif b: pass; else: pass"
示例7: test_boolean
def test_boolean():
"""
test boolean type
"""
assert convertor("n = 真") == "n = True"
assert convertor("p = 假") == "p = False"
assert convertor("q = 实") == "q = True"
assert convertor("r = 虛") == "r = False"
示例8: test_string
def test_string():
"""
same as print test
"""
assert convertor("s.开头为('he')") == "s.startswith('he')"
assert convertor("s.结尾为('he')") == "s.endswith('he')"
assert convertor("items = 'zero one two three'.分离()") == "items = 'zero one two three'.split()"
assert convertor("''.连接(s)") == "''.join(s)"
示例9: test_list
def test_list():
"""
test list type
"""
assert convertor("列表((1,2,3,4)) == [1,2,3,4]") == "list((1,2,3,4)) == [1,2,3,4]"
assert convertor("a = []; a.加入(2); 宣告 a == [2]") == "a = []; a.append(2); assert a == [2]"
p = "h,e,l,l,o"
assert convertor('p.分离(",")') == 'p.split(",")'
示例10: test_bool
def test_bool():
"""
test boolean type
"""
assert convertor("布尔(1)") == "bool(1)"
assert convertor("n 是 真") == "n is True"
assert convertor("p 为 假") == "p is False"
assert convertor("q 不是 实") == "q is not True"
assert convertor("r 不为 虛") == "r is not False"
示例11: test_operators
def test_operators():
"""
test operators
>>> 1 == 1
True
"""
assert convertor("a 等於 b") == "a == b"
assert convertor("a 不等於 b") == "a != b"
示例12: test_convertor
def test_convertor():
"""
test convertor
"""
rev_annotator()
assert convertor("印出 'hello'") == "print 'hello'"
assert python_convertor("print 'hello'") == ("印出 'hello'")
assert python_convertor(convertor("印出 'hello'")) == ("印出 'hello'")
# check if variable convert correctly, not a python valid syntax
assert python_convertor(convertor("打出 '''哈囉'''")) == ("打出 '''哈囉'''")
示例13: test_print
def test_print():
"""
test output statement and string types
>>> print "hello"
hello
"""
assert convertor("打印 'hello'") == "print 'hello'"
assert convertor('打印 "hello"') == 'print "hello"'
assert convertor("""打印 'hello'""") == "print 'hello'"
示例14: test_list
def test_list():
"""
test list type
>>> list((1,2,3,4)) == [1,2,3,4]
True
"""
assert convertor("列表((1,2,3,4)) == [1,2,3,4]") == \
"list((1,2,3,4)) == [1,2,3,4]"
assert convertor("a = []; a.加入(2); 申明 a == [2]") == \
"a = []; a.append(2); assert a == [2]"
p = "h,e,l,l,o"
assert convertor('p.分離(",")') == 'p.split(",")'
示例15: push
def push(self, line):
self.buffer.append(line)
source = "\n".join(self.buffer)
more = self.runsource(convertor(source), self.filename)
if not more:
self.resetbuffer()
return more