from lib.username import f
f()
import sys
for i in sys.path:
    print(i)


在当前目录开始查找, lib文件夹下面有一个username.py导入具体的函数

hello
H:\python17\wang
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python35.zip
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\DLLs
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib
C:\Users\Administrator\AppData\Local\Programs\Python\Python35
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages

from lib  import username
username.f()
import sys
for i in sys.path:
    print(i)
另外一种方式导入
import lib.username
lib.username.f()
系统自带的的,直接import导入,
自定义import
第三方
进行安装
C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages
from lib import username as bbb 
bbb.f()#别名
以后尽量用from ,而import功能单一的

通过hash算法加密登陆
 1 #!/usr/bin/env python3
 2 import hashlib
 3 def md5(s1):
 4     hash = hashlib.md5(bytes("dkfskf", encoding="utf-8"))
 5     hash.update(bytes(s1, encoding="utf-8"))
 6     return  hash.hexdigest()
 7 def regester(user,pwd):
 8     with open('db','a',encoding="utf-8") as f:
 9        temp = user + "|" + md5(pwd)
10        f.write(temp)
11 
12 def login(username,pwd):
13     with open('db','r',encoding="utf-8") as f:
14         for line in f:
15            u,p = line.strip().split("|")
16            if u == username and p == md5(pwd):
17                return True
18            return False
19 t = input("1、登陆 2、注册 :")
20 if t == '2' :
21     user = input("Username:")
22     pwd  = input("pasword:")
23     regester(user,pwd)
24 elif t == '1':
25     user = input("Username:")
26     pwd  = input("pasword:")
27     m = login(user,pwd)
28     if m:
29         print("登陆成功")
30     else:
31         print("登陆失败")

 

1 import os
2 t = os.path.exists('./lib/commons')#判断当前文件夹是否存在
3 print(t)

 

posted on 2017-10-13 14:27  43125471  阅读(133)  评论(0编辑  收藏  举报