[問題] python 3.0的import

看板Python作者 (Zeldo)時間15年前 (2010/01/28 08:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
最近開始想說放假了,玩玩看這個語言。 於是照著網路上的範例跟著練習。 不過由於版本不同,所以有些地方老是會出錯。 這兩天練習到使用文字檔轉開為.py檔的部分。 可在做載入模組的部分卻一直出問題,所以來問問看各位要如何解決。 以下是程式碼: #-*- coding: UTF-8 -*- from point import Point a = Point(1,1) b = Point(2,2) print(a,"+",b,"=",a+b) print() input("請按<Enter>來結束視窗。") 接著這是被import的point.py檔: class Point(object): def __init__(self, x=0, y=0): self.x=x self.y=y def __str__(self): return "(" + str(self.x) + "," + str(self.y) + ")" def __add__(self,other): return Point(self.x + other.x , self.y + other.y) def __sub__(self,other): return Point(self.x - other.x , self.y - other.y) def __mul__(self,other): return self.x * other.x + self.y * other.y 簡單說就是利用class Point來做四則運算。 def __rmul__(self,other): return Point(other * self.x, other * self.y) 最後這是顯示錯誤的內容: Traceback (most recent call last): File "C:\Documents and Settings\user\獢颤\瘣暹ㄝ\test2.py", line 3, in <module> UnicodeDecodeError: 'utf8' codec can't decode byte 0xae in position 31: unexpected code byte 他那位置的部分,不太明白。 麻煩各位解答一下了。 另外python 3.0 print要輸出為橫的要怎麼做? 之前的版本好像是加上逗號就可以了。 可3.0好像沒有辦法。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.161.120.182
文章代碼(AID): #1BODIDQU (Python)
討論串 (同標題文章)
文章代碼(AID): #1BODIDQU (Python)