• 导入模块


    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)
  • 相关阅读:
    案例8高级打砖块游戏
    案例17——Flash地图应用
    案例11——用遮障制作聚光灯效果及冷却动画
    案例1:用Flash CS工具制作进度条
    Flex 中可以应用于 ActionScript 类的元标签
    案例7用Flash Builder做虚拟计算器
    案例16——没特效还玩毛个Flash
    案例9不要在加载时面对苍白的屏幕
    案例15——游戏物品栏的制作(AS3高级应用)
    案例2心跳模拟
  • 原文地址:https://www.cnblogs.com/wang43125471/p/7661005.html
Copyright © 2020-2023  润新知