将客户帐户存储在文本文件中

时间:2019-03-22 18:21:29

标签: python-3.x tkinter

我正在为企业创建一个应用程序,并且需要能够将每个客户的帐户信息保存在一个文本文件中。写入并保存文件后,还需要按文件名进行搜索。我还需要具有使用以下格式命名新帐户文件的功能:[firstname_initial,lastname]这将是帐户的用户名。

我可以扫描目录并根据名称和扩展名查找特定文件。 我可以在条目中获取信息并将其写入文件。

# app.py

        # Tkinter Button class
        submit_button = Button(new_win, text="Submit", fg = "white", bg="green", command=self.save_profile).grid(row=10)

        user_name = name.strip + name.charAt(0) + # last name here

    def save_profile(self):
            pass

我在网上找到的搜索算法:

# scan.py

import os, fnmatch

# find with given extension (i would like the default to be .txt)
def find_by_ext(ext, path):
    for root, dirs, files in os.walk(path):
        for file in files:
            if file.endswith(ext):
                return os.path.join(file)

# finds file with given filename and root directory
def find(name, path):
    for root, dirs, files in os.walk(path):
        if name in files:
            return os.path.join(root, name)

# finds all files with given filenames and root directorys
def find_all(name, path):
    result = []
    for root, dirs, files, in os.walk(path):
        if name in files:
            result.append(os.path.join(root, name))
    return result

# finds a file pattern?
def find(pattern, path):
    result = []
    for root, dirs, files in os.walk(path):
        for name in files:
            if fnmatch.fnmatch(name, pattern):
                result.append(os.path.join(root, name))
    return result

def find_file(in_path, name):
    for root, directories, filenames in os.walk(in_path):
        if not filenames:
            continue

        for filename in filenames:
            if filename == name:
                return os.path.join(root, filename)

    return None


I want a data directory with every account written in a .txt file
and be able to: search, edit and read information from a customer file.

0 个答案:

没有答案