【问题标题】:Creating A CSV file on ubuntu server using cocotb使用 cocotb 在 ubuntu 服务器上创建 CSV 文件
【发布时间】:2022-11-15 06:21:54
【问题描述】:

在这里,我想在 cocotb 上创建一个 csv 文件,但以下代码适用于 Google Colab,它运行良好。

import cocotb
from cocotb.triggers import Timer
import random
import pyuvm
import pandas as pd
from pandas import Series, DataFrame
import os
from google.colab import drive
drive.mount('/content/drive')
os.chdir('/content/drive/My Drive/Colab Notebooks')

Now i have generated random numbers and then append them in a list, also generated random op_code.
@cocotb.test()
async def CODE_AA(dut):
 
 listA = []
 listB = []
 listC = []
 ALU_CONTROL = ['00', '01', '10', '11'] #['0', '1', '2', '3']

for i in range(10):
 A = random.randint(0, 1000)
 listA.append(A)
await Timer(20, units = "ns")
print(A)
 
 B = random.randint(0, 1000)
 listB.append(B)
await Timer(20, units = "ns")
print(B)
 
  #C = random.randint(0, 3)
 listC.append(random.choice(ALU_CONTROL))
print(listC)
 
DICT= {'A': listA, 'B': listB, 'C': listC}
dfA = pd.DataFrame.from_dict(DICT)
dfA_Transposed = dfA.T
print(dfA)

dfA.to_csv('basic_py.csv')
DICT = {'A': listA, 'B': listB, 'C': listC}
dfA = pd.DataFrame.from_dict(DICT) 
print(dfA)

我现在想使用 cocotb 在 Ubuntu 服务器上制作 CSV 文件,这段代码在 Google Colab 上运行完美。请指导我解决这个问题

【问题讨论】:

    标签: python python-3.x csv ubuntu


    【解决方案1】:

    您可能只想忽略导入 google 驱动器库:

    # from google.colab import drive
    # drive.mount('/content/drive')
    # os.chdir('/content/drive/My Drive/Colab Notebooks')
    
    # Change directory to somewhere you have access on the server
    os.chdir('~/content/collab_notebooks')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      相关资源
      最近更新 更多