简体   繁体   English

如何将结果转换为变量,然后从 .accdb 文件调用数据?

[英]How do I turn my results in a variable and then call data from a .accdb file?

在此处输入图片说明

So I have several Attachment.accdb files in my directory.所以我的目录中有几个 Attachment.accdb 文件。 I need help figuring out the correct python code to first call out to my directory and to list out all the .accdb files ONLY.我需要帮助找出正确的 python 代码,以便首先调用我的目录并仅列出所有 .accdb 文件。

So then my output data should look something like this: Attachment1.accdb Attachment2.accdb Attachment3.accdb Attachment4.accdb Attachment5.accdb那么我的输出数据应该是这样的: Attachment1.accdb Attachment2.accdb Attachment3.accdb Attachment4.accdb Attachment5.accdb

From there I need to figure out a way to turn my output into a variable that I can call upon later.从那里我需要找出一种方法将我的输出转换为我以后可以调用的变量。

I then need to figure out a way to make a connection to the .accdb files and build a list of every ReqID within the .accdb file.然后我需要找到一种方法来连接到 .accdb 文件并在 .accdb 文件中构建每个 ReqID 的列表。 This list will hold all the ReqIDs from all the .accdb files.此列表将保存所有 .accdb 文件中的所有 ReqID。

***The ID and ReqID are from the image link shown above. *** ID 和 ReqID 来自上面显示的图像链接。 If I were to open up an attachment.accdb file they consist of the following table information如果我打开一个attachment.accdb文件,它们包含下表信息

In the end I will have a detailed list showing: ID (Unique integer), ReqID, name of accdb file ID (Unique integer), ReqID, name of accdb file ID (Unique integer), ReqID, name of accdb file ID (Unique integer), ReqID, name of accdb file ID (Unique integer), ReqID, name of accdb file最后我会有一个详细的列表显示:ID(唯一整数)、ReqID、accdb文件名ID(唯一整数)、ReqID、accdb文件名ID(唯一整数)、ReqID、accdb文件名ID(唯一整数) integer), ReqID, accdb 文件名 ID (Unique integer), ReqID, accdb 文件名

I am very new to python.我对python很陌生。 But am in need of great guidance and assistance.但我需要很好的指导和帮助。

Follow up to my previous question Previous question in regards to this跟进我之前的问题上一个关于此的问题

Okay, so you basically need to extract and merge data from files with the same name.好的,所以您基本上需要从具有相同名称的文件中提取和合并数据。 Here is the first step这是第一步

import pathlib

my_directory = pathlib.Path("./path/to/my_dir")
paths = list(my_directory.glob("**/*.accdb"))
# If you only want the file names
# file_names = [path.name for path in my_directory.glob("**/*.accdb")]

This will give you a list containing the path to all of your files.这将为您提供一个包含所有文件路径的列表。 Now you need to process them, which will look like this:现在你需要处理它们,看起来像这样:

results = {}
for path in paths:
    with path.open() as file:
        for line in file:
            line = line.strip() # To remove the trailing line feed
            # Do stuff with your line to put it into your result

Since I have no idea what a .accdb file is like I can't really help further.因为我不知道.accdb文件是什么样的,所以我真的.accdb You should either clarify your question or look into it by yourself.您应该澄清您的问题或自行调查。 What you need to figure out now is: - which data structure do you want for you result?您现在需要弄清楚的是: - 您想要哪种数据结构? - what's in a .accdb and how to extract the data you need from it to put it in your data structure - .accdb以及如何从中提取所需的数据以将其放入数据结构中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM