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)
  • 相关阅读:
    emacs 编程入门 函数
    boost库介绍
    jquery css attr
    html 相对定位 绝对 定位 css + div
    我常用的grep
    我常用的tar
    C#皮肤的用法(皮肤资源+使用实例下载)
    C#资源文件操作示例 创建资源和读取资源
    黄聪:c#中高效的excel导入sqlserver的方法
    黄聪:Delphi 中的 XMLDocument 类详解(2) 记要
  • 原文地址:https://www.cnblogs.com/wang43125471/p/7661005.html
Copyright © 2011-2022 走看看