python常用字符操作+verilog常用语法+sv语言常用操作+删除git库中untracked files

python常用字符操作

python转二进制

使用bin函数,此时会有0b前缀;使用格式化参数"{:b}".format(b),此时没有前缀。

a = 10
a_bin = bin(a)
print(a_bin)
# Output: 0b1010

a_bin = "{:b}".format(a)
print(a_bin)
# Output: 1010

python获取文件夹下所有文件

使用os.walk()或os.listdir()实现。前者打印的内容更完整。
https://blog.csdn.net/zhuzuwei/article/details/79925562
os.listdir

import os
filePath = '.'
print(os.listdir(filePath))

os.walk,i,j,k分别是当前文件夹名,下层文件夹名,和文件名

import os
filePath = '.'
for i,j,k in os.walk(filePath):
    print(i, " || ", j, " ||  ", k)

Python3通过writerow写入csv文件

有多余的空行通过newline=""去掉

headerRow = ['ISN', 'BUILD_PHASE']
oneRow = ['81E2-ESTTEST','PRE-PVT']
with open("test.csv","a+", newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(headerRow)
    writer.writerow(oneRow)

python对文件进行merge

gpt生成的代码,基本正确,

import difflib

def merge_files(file1_content, file2_content):
    differ = difflib.Differ()
    diff = list(differ.compare(file1_content.splitlines(), file2_content.splitlines()))

    merged_content = []
    for line in diff:
        if line.startswith('? '):  # Lines that are common to both files
            merged_content.append(line[2:])
        elif line.startswith('- '):  # Lines unique to file1
            merged_content.append(line[2:])
        elif line.startswith('+ '):  # Lines unique to file2
            merged_content.append(line[2:])
        else:  # Lines common to both files
            merged_content.append(line[2:])

    return '\n'.join(merged_content)

# 读取两个文件的内容
with open('file1.txt', 'r') as file1:
    file1_content = file1.read()

with open('file2.txt', 'r') as file2:
    file2_content = file2.read()

# 合并文件内容并显示
merged_content = merge_files(file1_content, file2_content)
print(merged_content)

verilog常用语法

verilog 全1写法

wire [N-1:0] all_ones;

assign all_ones = {N{1'b1}};

+:、-:的使用

https://blog.csdn.net/yigexuwang/article/details/128671038

2.“+:”
变量[起始地址 +: 数据位宽] <–等价于–> 变量[(起始地址+数据位宽-1):起始地址]
data[0 +: 8] <–等价于–> data[7:0]
data[15 +: 2] <–等价于–> data[16:15]

3.“-:”
变量[结束地址 -: 数据位宽] <–等价于–> 变量[结束地址:(结束地址-数据位宽+1)]
data[7 -: 8] <–等价于–> data[7:0]
data[15 -: 2] <–等价于–> data[15:14]

sv语言常用操作

sv为class填入随机数种子

https://blog.csdn.net/weixin_46022434/article/details/107722106
srandom()对象和进程随机化方法,在类方法内/外为随机数据发生器(RNG)添加随机种子。
类内添加seed:

class Packet;
  rand bit[15:0]  header;

  function new(int seed) ;
    this.srandom(seed) ;
    ...
  endfunction
endclass
Packet p=new(200) ;    //通过种子200,创建对象p
p.srandom(300) ;       //通过种子300,重新创建p

流操作

流操作主要是将多数据块的位宽更动

int h;
bit [7:0] j[4] = '{8'ha, 8'hb, 8'hc, 8'hd};
h  = {>>{j}}; // 将j合并送入到h中,送入的顺序是从左到右
h = {<<{j}}; //送入的顺序是从右到左

删除git库中untracked files

https://blog.csdn.net/RonnyJiang/article/details/53507306
首先要进入到指定的目录下,git不会进行非本文件夹的自动寻址。
然后执行以下命令:

git clean -f
posted @ 2024-03-27 08:52  大浪淘沙、  阅读(4)  评论(0编辑  收藏  举报