windows python Python v3.2.2文本文件读取没有错误也没有输出

时间:2012-08-19 17:55:56

标签: python python-3.x

尝试通过win python 3读取文本文件,奇怪的是我没有得到任何错误或任何输出。 TAI。

f = open ('C:\\Users\\test\\Desktop\\test.txt','r')
data = f.read()
print data
f.close()

2 个答案:

答案 0 :(得分:1)

print是py3中的一个函数

f = open ('C:\\Users\\test\\Desktop\\test.txt','r')
data = f.read()
print(data)
f.close()

但是,它应该会给你无效的语法错误。

答案 1 :(得分:-2)

class Item:
        def __init__(self, Name = "NA",ID = -1,Price = -1):
            self.Name = Name
            self.ID = ID
            self.Price = Price

            def __str__(self):
                return "Name is %s,Id is %d,and price is %f" %(self.Name,self.Id,self.price)

                ob=Item ()
                ob1=Item("deepak",121,120.00)
                print(ob)
                print(ob1)

我在运行时没有得到输出。任何人都可以帮助我。