创建类的对象时控制台上出现意外的空白行

时间:2016-09-07 22:04:28

标签: python python-2.7 printing console

我知道,这听起来很奇怪,但我在创建对象时在python中看到一个带有空行的奇怪输出。

例如:

test.py

from bar import Bar
from foo import Foo
if __name__ == '__main__':
    print "test1"
    f = Foo(params)
    b = Bar(params)
    print "test2"
    print f.method_one()
    print b.method_one()

foo.py

class Foo:
    def __init__(self, params):
        self.params = params
        self.arg1 = params.get('arg1')
        self.arg2 = params.get('arg2')
        self.arg3 = params.get('arg3')
        self.arg4 = params.get('arg4')
        self.argn = params.get('argn')

   def method_one(self):
       print "foo one"

bar.py

class Bar:
    def __init__(self, params):
        self.params = params
        self.arg1 = params.get('arg1')
        self.arg2 = params.get('arg2')
        self.arg3 = params.get('arg3')
        self.arg4 = params.get('arg4')
        self.argn = params.get('argn')

   def method_one(self):
       print "bar one"

以下是test.py的输出

test1



test2
foo one
bar one

预期输出为:

test1
test2
foo one
bar one

创建对象时如何避免这些空行?

0 个答案:

没有答案