[問題] 關於import的檔名?

看板Python作者 (喵)時間9年前 (2016/07/29 09:00), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
請問一下,我從網路教學資源copy了以下的code #encrypt.py import random class Encrypt: def setCode(self): self.code = [chr(i) for i in range(97, 123)] random.shuffle(self.code) def getCode(self): return "".join(self.code) def toEncode(self): return "toEncode" def toDecode(self): return "toDecode" e = Encrypt() e.setCode() print() print(e.getCode()) print(e.toEncode()) print(e.toDecode()) print() ================= 然後我在Shell裡 import encrypt 它也的確會print出字串 但當我把encrypt.py改名為test.py,然後輸入 import test 它反而不動了 為什麼呢?謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.17.41 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1469754008.A.5C0.html

07/29 09:51, , 1F
是因為檔案沒放在同個資料夾嗎?
07/29 09:51, 1F

07/29 10:09, , 2F
改名前後都在同一資料夾 沒有變動
07/29 10:09, 2F

07/29 11:11, , 3F
說不定是import 到內建的package了, 改檔名看看?
07/29 11:11, 3F

07/29 11:18, , 4F
!還真的有內建的叫test 換個名字就行了 謝謝!
07/29 11:18, 4F
文章代碼(AID): #1NcggON0 (Python)
文章代碼(AID): #1NcggON0 (Python)