python:File

python OCR   Hand-written chinese    

https://github.com/topics/chinese-character-recognition
https://github.com/chineseocr
https://github.com/breezedeus/cnocr

handwritten-text-recognition

 

 

 

def getPreFile(prefixletter:str,ok:bool):
    """
    文件名添加后缀
    :param prefixletter:
    :param ok:  True 增加前缀,否则为删除
    :return:
    """
    try:
        nowfoloder = os.getcwd()
        curpath=os.path.join(nowfoloder,r"static")
        fiellist=os.listdir(curpath)
        n=1
        os.chdir(curpath)
        for i in fiellist:
            print("list", i)
            if os.path.isfile(i):
                if ok==True:
                    newname = prefixletter + i
                    os.rename(i, newname)
                else:
                    newlen = len(prefixletter)
                    newname = i[newlen:]
                    os.rename(i, newname)
            n+=1
    except Exception as ex:
        print(ex)

    finally:
        pass
    

  

 

 

def getFile(prefixletter:str,ok:bool):
    """
    文件名添加后缀
    :param prefixletter:
    :param ok:  True 增加后缀,否则为删除
    :return:
    """
    try:
        nowfoloder = os.getcwd()
        curpath=os.path.join(nowfoloder,r"static")
        fiellist=os.listdir(curpath)
        n=1
        os.chdir(curpath)
        for i in fiellist:
            print("list", i)
            if ok==False:
                newname=i.split("_")
            else:
                newname = i.split(".")
            print(newname[0]+'_'+prefixletter+"."+newname[1])
            #

            if os.path.isfile(i):
                if ok==True:
                    os.rename(i, newname[0] + '_' + prefixletter + "." + newname[1])
                else:
                    os.rename(i, newname[0] + ".text")
            n+=1
    except Exception as ex:
        print(ex)

    finally:
        pass




getFile("d", False)
"""
try:
    nowfoloder=os.getcwd()
    fillist=os.listdir(nowfoloder)
    print(fillist)
    curpath=os.path.join(nowfoloder,r"static")
    print(curpath)
    os.chdir(curpath)
    for f in os.listdir():
        print(f)
    if(not os.path.isdir("images")):
        os.mkdir("images")
    if (not os.path.isdir("test")):
        os.mkdir("test")

    for f in os.listdir():
        print(f)
    if os.path.isdir("test"):
        curpath = os.path.join(nowfoloder, r"static")
        os.chdir(curpath)
        print(os.getcwd())
        if os.path.isdir("test"):
            os.rmdir(os.path.join(curpath,"test"))
except Exception as ex:
    print(ex)

finally:
    pass

"""

  

 

"""
PassWordLenException.py
单例 模式
python (类名) super
java 继承可以使用 extends 和 implements 这两个关键字来实现继承
C++ :public 类名
C# :类名
可以重写父类方法
edit:geovindu,Geovin Du
date:20230709 python 311
IDE:PyCharm 2023.1.2

"""

import sys
import os

class PassWordLenException(Exception):
    """
    密码字符串长度自定义异常

    """


    def __init__(self,strLen:int,maxLen:int,minLen:int):
        """

        :param strLen: 字符串长的长度
        :param maxLen: 要求字符串的最长的长度
        :param minLen: 要求字符串的最短的长度
        """
        super().__init__(self)
        self.__strLen=strLen
        self.__maxLen=maxLen
        self.__minLen=minLen


    @property
    def strLen(self):
        return self.__strLen

    @strLen.setter
    def strLen(self,strlen):
        self.__strLen=strlen

    @property
    def maxLen(self):
        return self.__maxLen

    @maxLen.setter
    def maxLen(self,maxlen):
        self.__maxLen=maxlen

    @property
    def minLen(self):
        return  self.__minLen

    @minLen.setter
    def minLen(self,minlen):
        self.__minLen=minlen



    def __str__(self):
        print(f"你输入的密码长度为{self.__strLen},最短的密码长度为{self.__minLen}最长的密度为:{self.__maxLen}")



"""
PassWord.py
单例 模式
python (类名) super
java 继承可以使用 extends 和 implements 这两个关键字来实现继承
C++ :public 类名
C# :类名
可以重写父类方法
edit:geovindu,Geovin Du
date:20230709 python 311
IDE:PyCharm 2023.1.2

"""
import PassWordLenException


class PassWord(object):
    """

    """

    def __init__(self):
        """

        """
        self.__password="";


    @property
    def passWord(self):
        return self.__password;

    @passWord.setter
    def passWord(self,password):
        if (len(password)>=6) and (len(password)<=12):
            self.__password=password
        else:
            raise PassWordLenException.PassWordLenException(len(password),12,6)

  

调用:

try:
    p=PassWord.PassWord()
    p.passWord="2333333"
except PassWordLenException.PassWordLenException as e:
    print(e)

  

#备份文件

try:

    file=""
    with open(file,'r') as rfp, open(file,'w') as wfp: #不用写关闭 ,读写一起操作
        rstr=rfp.read()
        wfp.write(rstr)


    nowfoloder=os.getcwd()
    fillist=os.listdir(nowfoloder)
    print(fillist)
    curpath=os.path.join(nowfoloder,r"static")
    os.chdir(curpath)
    for f in os.listdir():
        if os.path.isfile(f):
            t=os.path.splitext(f) #文件名和扩展名分开的元组
            filename=t[0]
            fileexif=t[1]
            print(filename,fileexif)
            fstr=f.split(".")
            newname=fstr[0]+"备份"+".text"
            print(newname)
            shutil.copy(f'{curpath}//{f}',f"{curpath}//{newname}")
except Exception as e:
    print(e)

  

posted @ 2023-07-09 13:44  ®Geovin Du Dream Park™  阅读(22)  评论(0)    收藏  举报