python生成文件图片列表

本文介绍了一个使用Python编写的简单脚本,该脚本用于遍历指定目录(这里是'jpg'文件夹)中的所有.jpg文件,并将它们的名字(不包含扩展名)按字母顺序排序后写入到一个txt文件中。此脚本适用于需要快速整理文件列表的场景。
生成文件图片列表
import os

my_files = os.listdir("jpg");
print(my_files)

listFiles = []
for files in my_files:
    if "jpg" in files:
        #print(files)
        listFiles.append(files[:-4])

listFiles.sort()
fo = open("jpg.txt", "w")
for fileName in listFiles:
    fo.write(fileName + "\n")
    print(fileName)
fo.close()
转载请注明: http://blog.youkuaiyun.com/forest_world
### 使用Python创建COE文件 为了满足FPGA配置或图像处理的需求,可以利用Python编写脚本来生成COE文件。此方法能够提高开发效率并减少手动操作带来的潜在错误[^2]。 #### Python代码实现 下面是一个简单的例子来展示如何使用Python创建一个适用于FPGA的COE文件: ```python def write_coe_file(filename, data_width, addr_depth, data_list): with open(filename, 'w') as f: # Write header information f.write(f"; Memory Initialization File\n") f.write(f"; Data Width={data_width}\n") f.write(f"; Address Depth={addr_depth}\n") f.write("memory_initialization_radix=16;\n") # Use hexadecimal format f.write("memory_initialization_vector=\n") # Write the actual data values separated by commas and add a semicolon at end for i in range(len(data_list)): value_str = format(int(data_list[i]), '0{}x'.format(data_width//4)) if i != len(data_list)-1: f.write(value_str+',\n') else: f.write(value_str+';\n') # Example usage of function to create COE file example_data = [i % 256 for i in range(10)] # Generate some example data points (8-bit width) write_coe_file('example.coe', 8, len(example_data), example_data) ``` 上述代码定义了一个`write_coe_file()`函数,该函数接收目标文件名、数据宽度、地址深度以及要写入的数据列表作为参数,并按照指定格式写出相应的COE文件内容。这里假设输入的数据是以整数形式给出;如果原始数据来自其他源(比如二进制文件),则需要先将其转换为适合的形式再调用这个函数[^1]。 对于从BIN文件转换而来的场景,则可以通过读取BIN文件中的字节流并将它们解析成十六进制字符串的方式准备所需的数据列表。之后就可以像上面的例子那样调用`write_coe_file()`完成整个过程了。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值