Re: [問題] python 3.0的import

看板Python作者 (台灣獨立建國不必錢嗎?)時間15年前 (2010/01/28 09:29), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串2/2 (看更多)
我在 Linux 上用 Python3 跑你的程式,並沒有問題 ※ 引述《zeldo (Zeldo)》之銘言: : 最近開始想說放假了,玩玩看這個語言。 : 於是照著網路上的範例跟著練習。 : 不過由於版本不同,所以有些地方老是會出錯。 : 這兩天練習到使用文字檔轉開為.py檔的部分。 : 可在做載入模組的部分卻一直出問題,所以來問問看各位要如何解決。 : 以下是程式碼: : #-*- coding: UTF-8 -*- 以上這行是說,你寫的這個檔案是用 UTF-8 編碼的 : 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 從這錯誤訊息來看,你是在 Windows 上跑的 所以,有可能你的檔案是用 Big5 編碼 但你卻跟他說用 UTF-8 去解碼 試試看把檔案轉成 UTF-8 : 他那位置的部分,不太明白。 : 麻煩各位解答一下了。 : 另外python 3.0 print要輸出為橫的要怎麼做? Python3 中的 print 是一個函數,跟 Python2 是關鍵字不太一樣 所以可以用 print.__doc__ >>> print(print.__doc__) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. 如: for i in range(10): print(i, end=' ') : 之前的版本好像是加上逗號就可以了。 : 可3.0好像沒有辦法。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.30.32 ※ 編輯: oaz 來自: 140.112.30.32 (01/28 09:30)

01/28 10:47, , 1F
Thx
01/28 10:47, 1F

01/28 20:08, , 2F
Windows上建議將utf8改成cp950
01/28 20:08, 2F

01/29 00:10, , 3F
樓上的理由是?
01/29 00:10, 3F

01/29 14:51, , 4F
help(print)
01/29 14:51, 4F
文章代碼(AID): #1BOEXpTN (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1BOEXpTN (Python)