作者mindscold (喵)
看板Python
标题[问题] 关於import的档名?
时间Fri Jul 29 09:00:05 2016
请问一下,我从网路教学资源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://webptt.com/cn.aspx?n=bbs/Python/M.1469754008.A.5C0.html
1F:推 daydream772: 是因为档案没放在同个资料夹吗? 07/29 09:51
2F:→ mindscold: 改名前後都在同一资料夹 没有变动 07/29 10:09
3F:→ micangela: 说不定是import 到内建的package了, 改档名看看? 07/29 11:11
4F:→ mindscold: !还真的有内建的叫test 换个名字就行了 谢谢! 07/29 11:18