使用文件中的類和對象獲取信息 (Get info using class and object from file)


問題描述

使用文件中的類和對象獲取信息 (Get info using class and object from file)

我有這個代碼可以正常工作。但我想知道是否可以從保存在 main.py 中的 CSV 文件中為特定行提取相同的信息。例如。如果用戶想通過使用“類”來了解誰在 IT 部門工作?和“對象” 保存的 csv 文件中的方法。我們怎麼能做到這一點,甚至有可能嗎?謝謝

class person:
name = "name"
email = "email"
deptt = "deptt"
def init(self,name,email,deptt):
self.name = name
self.email = email
self.deptt = deptt

def staff(self):
return f" this person name {self.name} and id is {self.email} and she works in {self.deptt} department "

p1 = person("Hannah","hannah.jones@lycos.com", "admin")

print(p1.staff())
</code></pre>


參考解法

方法 1:

You can use pandas to read CSV files.

import pandas as pd
df = pd.read_csv('filename.csv')

(by GhostwhiteActualCompilersdavid190810)

參考文件

  1. Get info using class and object from file (CC BY‑SA 2.5/3.0/4.0)

#file-handling #Python #object #class






相關問題

c語言使用文件操作創建數據庫 (Create database using file operation in c language)

使用jsp瀏覽文件和文件夾 (browsing files and folders using jsp)

在 rails/paperclip 中處理一系列圖像 (handling an array of images in rails/paperclip)

Java 並行文件處理 (Java Parallel File Processing)

Perl 隱式關閉重置 $. 多變的 (Perl implicit close resets the $. variable)

更換和存放 (Replacing and Storing)

逐行讀取文件並基於它將換行符寫入同一文件 - nodejs (Reading a file line by line and based on it write newlines to same file - nodejs)

使用 PHP 將數據放到服務器上(新的 DOMdocument 不起作用) (Use PHP to put data onto server ( new DOMdocument not working))

表示“目錄”或“文件”的詞是什麼? (What is the word that means "directory" or "file"?)

如何在我的計算機上保存我用 Python 編輯的 CSV 文件? (How do I save a CSV file on my computer which i have edited in Python?)

使用文件中的類和對象獲取信息 (Get info using class and object from file)

使用 putw() 時在文件中獲取亂碼 (Getting gibberish values in files when putw() is used)







留言討論