zoukankan      html  css  js  c++  java
  • 导入模块

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


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

    hello
    H:python17wang
    C:UsersAdministratorAppDataLocalProgramsPythonPython35python35.zip
    C:UsersAdministratorAppDataLocalProgramsPythonPython35DLLs
    C:UsersAdministratorAppDataLocalProgramsPythonPython35lib
    C:UsersAdministratorAppDataLocalProgramsPythonPython35
    C:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-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:UsersAdministratorAppDataLocalProgramsPythonPython35libsite-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)
  • 相关阅读:
    Oracle数据库event事件与dump文件介绍
    (原)dbms_rowid.rowid_create来创建一个rowid
    Oracle读取事件的命名理由(哈哈)
    关于删除temporary tablespace的一点小建议
    oracle的rowid到底是什么
    电脑高手最常用的五个组合键
    win2008里如何取消IE游览器弹出增强的安全配置?
    经典SQL语句大全
    Win7中安装Rational Rose,启动提示计算机丢失suite objects.dll
    Asp.net页面跳转
  • 原文地址:https://www.cnblogs.com/wang43125471/p/7661005.html
Copyright © 2011-2022 走看看