简体   繁体   English

我如何将 json 文件名(不带扩展名)加载到列表框和组合框(python)中?

[英]how do i load json file names (without extension) into a listbox and into a combobox (python)?

I need to import json files from a folder as items in a listbox and then a combobox.我需要从文件夹中导入 json 文件作为列表框中的项目,然后是组合框。 I try loading the files to the list box with this:我尝试将文件加载到列表框中:

path_to_json = './'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
self.profiles_print(json_files)

i can load the files into the list box, but they all load on one line as 1 item.我可以将文件加载到列表框中,但它们都作为 1 项加载在一行中。

How can i make it individual items?我怎样才能使它成为单独的项目?

Thanks, Dom谢谢,多姆

answered from other source:从其他来源回答:

path_to_json = './'
    json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
    for i in json_files:
        self.profiles_print(i)

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

相关问题 如何在 Python Tkinter 中绑定 ComboBox 的 ListBox - How do I bind the ListBox of a ComboBox in Python Tkinter 当我将名称从文本文件加载到 Combobox 时,为什么我的 function 会出现 OSError? - Why do I get an OSError with my function when I load names into a Combobox from a text file? 如何将 json 文件中的某些值添加到 python for 循环和列表框? - How do I add certain values from a json file to a python for loop and listbox? 如何使用Python对以数字文件名作为键的JSON文件名进行排序? - How do I sort a JSON file name that has numeric file names as the key using Python? 如何将json文件加载到mongoDB中? - How do I load a json file into mongoDB? 如何在Python中为文件创建扩展名而没有扩展名 - How to create an extension for a file without extension in Python 如何从 Python 中的路径获取不带扩展名的文件名? - How do I get the filename without the extension from a path in Python? 如何将* .corpus文件加载到Python中? - How do I load a *.corpus file into Python? 如何将文件加载到 python 控制台? - How do I load a file into the python console? 在 Python 3.8 中,如何从文件中加载图像数据以包含在 JSON object 中? - In Python 3.8, how do I load image data from a file for inclusion ina JSON object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM