Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
••
IT Nachrichten25. September(25.09.2026 um 00:05 Uhr)
•
IT NachrichtenCI-Solution GmbH von Crossware übernommen(25.09.2026 um 00:01 Uhr)
•
IT NachrichtenInsta360 GO Ultra erhält KI-Sprachassistenten mit Gemini(24.09.2026 um 21:30 Uhr)
••
AI & KI NachrichtenMaryland Governor Draws New Boundaries for Data Centers(25.09.2026 um 00:04 Uhr)
••••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
••
IT Nachrichten25. September(25.09.2026 um 00:05 Uhr)
•
IT NachrichtenCI-Solution GmbH von Crossware übernommen(25.09.2026 um 00:01 Uhr)
•
IT NachrichtenInsta360 GO Ultra erhält KI-Sprachassistenten mit Gemini(24.09.2026 um 21:30 Uhr)
••
AI & KI NachrichtenMaryland Governor Draws New Boundaries for Data Centers(25.09.2026 um 00:04 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

csv module in Python

The csvmodule provide tools for working with and manipulating csv(comma separated values) files. csv files are used to store tabular data in plain text formats. csv data consists of records and each record is made up of fields. Normally,…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

The csvmodule provide tools for working with and manipulating csv(comma separated values) files.


csv files are used to store tabular data in plain text formats. csv data consists of records and each record is made up of fields. Normally, a line in a csv file represents a single record while fields in a record are separated by commas.



The following is an example of csv data.





first_name,last_name,age,gender
John,Main,30,male
Jane,Doe,24,female
Morrison,Smith,22,male
Brian,Gates,32,male
Mary,Reagan,25,female






Typically, files with a .csvextension are normally associated with csv data.






Reading csv data



To read data from a csv file, use the reader()function. The function has the following basic syntax:





csv.reader(iterable)






The reader()function takes any iterable that yields a line during each iteration. This can be a file object, a list or any other iterable made of lines. It returns an iterator of lists, where each list represents a record in the csv data.



Consider if the previous csv data exists in a file called demo.csv.





import csv

with open('demo.csv') as file:
reader = csv.reader(file)

for row in reader:
print(row)






['first_name', 'last_name', 'age', 'gender']


['John', 'Main', '30', 'male']


['Jane', 'Doe', '24', 'female']


['Morrison', 'Smith', '22', 'male']


['Brian', 'Gates', '32', 'male']


['Mary', 'Reagan', '25', 'female']



In the above example, we used data stored in a file object but as earlier mentioned, you can literally use any iterable. In the following example, we use a list instead of a file object.





import csv

data = """first_name,last_name,age,gender
John,Main,30,male
Jane,Doe,24,female
Morrison,Smith,22,male
Brian,Gates,32,male
Mary,Reagan,25,female"""

reader = csv.reader(data.splitlines())
for row in reader:
print(row)






['first_name', 'last_name', 'age', 'gender']


['John', 'Main', '30', 'male']


['Jane', 'Doe', '24', 'female']


['Morrison', 'Smith', '22', 'male']


['Brian', 'Gates', '32', 'male']


['Mary', 'Reagan', '25', 'female']





Writing csv data



The writer() function creates an object for writing csv data. It has the following basic syntax:





csv.writer(fileobj)






Where the fileobjis the opened file where the csv data will be written to.



After creating the writer object, we can then usewriterow() method to write a single record into the file or writerows() to write multiple rows at once.





import csv

with open('demo.csv', 'a') as file:
writer = csv.writer(file)

writer.writerow(('Ruth', 'Miller', 24, 'female'))
writer.writerow(('Brandy', 'Jones', 22, 'male'))






Note that in the above example, we opened the demo.csv file with the "a" mode. This ensures that the new rows are appended to the file, if we had used the "w" mode instead, the existing rows would have been overwritten.





import csv

with open('demo.csv') as file:
print(file.read())






first_name,last_name,age,gender


John,Main,30,male


Jane,Doe,24,female


Morrison,Smith,22,male


Brian,Gates,32,male


Mary,Reagan,25,female


Ruth,Miller,24,female



Brandy,Jones,22,male



As you can see above, the new records have been added successfully.



To add multiple rows at once, use the writer.writerows() method.





import csv

rows = [
('Stephen', 'King', 32, 'male'),
('Molly', 'Jones', 22, 'female')
]

with open('demo.csv', 'a') as file:
writer = csv.writer(file)
writer.writerows(rows)









Quoting behavior



In cases where you want records of certain types to be stored in quotes, you can specify the quotingflag when creating the writer object. For example, if you want string items to be in quotes but numeric values not to be, you can specify the quoting parameter as csv.QUOTE_NONNUMERIC.





import csv

rows = [
('Stephen', 'King', 32, 'male'),
('Molly', 'Jones', 22, 'female')
]

with open('demo.csv', 'w') as file:
writer = csv.writer(file, quoting = csv.QUOTE_NONNUMERIC)
writer.writerows(rows)






If you open thedemo.csvfile, you will see that in the written records , string fields are quoted.





import csv

with open('demo.csv') as file:
print(file.read())






"Stephen","King",32,"male"



"Molly","Jones",22,"female"



All the quoting options are as shown in the following table:



| QUOTE_ALL | Quote any field regardless of type |

| QUOTE_NONE | Don't quote any field. |

| QUOTE_MINIMAL | Quote only fields containing some special characters. This is the default quoting behavior. |

| QUOTE_NONNUMERIC | Quote all fields except those with numeric values like integers and floats. |





csv dialects



Separating csv fields with a comma is just the popular convention, there is really no well defined standard on csv format. For example, you could as well separate the fields with spaces instead of commas. This means that any csv parser needs to be very flexible when dealing with csv delimiters.



Dialects allow us to specify to the parser the delimiter and other important parameters that will be used when parsing the csv files. The csv.list_dialects() function returns a list of the registered dialects.





import csv

print(csv.list_dialects())






['excel', 'excel-tab', 'unix']



The default dialect is excel, in which the fields are delimited with commas.



If for example, you have csv data in which the fields are delimited by a pipe character"|" or any other character instead of a comma, as shown below:





first_name|last_name|age|gender
John|Main|30|male
Jane|Doe|24|female
Morrison|Smith|22|male
Brian|Gates|32|male
Mary|Reagan|25|female






You can register a new dialect using thecsv.register_dialect(). You can then use the registered dialect with readerand writerobjects.





import csv

data = """first_name|last_name|age|gender
John|Main|30|male
Jane|Doe|24|female
Morrison|Smith|22|male
Brian|Gates|32|male
Mary|Reagan|25|female"""

csv.register_dialect('pipe', delimiter = '|')
print("Dialects: ", csv.list_dialects())

reader = csv.reader(data.splitlines(), dialect = 'pipe') #use the dialect

for row in reader:
print(row)







Apart from delimiter, you can specify other dialect parameters depending on the nature of your csv data. The supported parameters are shown in the following tables:











































parameter default value description
delimiter , Field separator.
quotechar " The character to enclose fields where quoting is allowed.
lineterminator \r \n The string/character used to terminate a line
doublequote True Whether quotchar parameters are doubled.
escapechar None Character used to indicate an escape sequence
skipintialspace False Ignore whitespace after the delimiter





Automatic dialect detection



In cases where the csv format is not well known, we can use the csv.Snifferclass, which automatically constructs a dialect object given a sample of csv data.



Consider if we have the following csv data.





​first_name&last_name&age&gender
John&Main&30&male
Jane&Doe&24&female
Morrison&Smith&22&male
Brian&Gates&32&male
Mary&Reagan&25&female






In the above example, we used the "&"character as the delimiter.





import csv

data="""first_name&last_name&age&gender
John&Main&30&male
Jane&Doe&24&female
Morrison&Smith&22&male
Brian&Gates&32&male
Mary&Reagan&25&female"""

sniffer=csv.Sniffer()
dialect=sniffer.sniff(sample=data)

print("delimiter: ", dialect.delimiter)

reader = csv.reader(data.splitlines(), dialect = dialect)
for row in reader:
print(row)






As you can see, the sniffer correctly detected that "&" is used as the delimiter character. However, you should keep in mind that the sniffer is not always correct, it can only be said to be making educated guesses.






Using named fields



You can usecsv.DictReader and csv.DictWriterclasses to use named fields when reading or writing csv data.



The two classes allows you to specify in advance a list of field names to alias the fields in the csv data.






csv.DictReader



The DictReaderclass allows you to read rows with the fields having an alias name.



Consider the following example:





import csv

data = """first_name,last_name,age,gender
John,Main,30,male
Jane,Doe,24,female
Morrison,Smith,22,male
Brian,Gates,32,male
Mary,Reagan,25,female"""

fields = 'fname', 'lname', 'age', 'gender'

reader = csv.DictReader(data.splitlines(), fieldnames = fields)
for row in reader:
print(row['fname'], row['lname'])






Iterating through the DictReaderobject will yield a list of dictionaries, where each dictionary represents a row in the csv data.






csv.DictWriter



DictWriter objects writes data into a csv file with argument given as dictionaries. Consider the following example:





import csv

fields = 'fname', 'lname', 'age', 'gender'
data_to_wite = [
{'fname':'Stephen', 'lname':'King', 'age':32, 'gender':'male'},
{'age':22, 'lname':'Jones', 'fname':'Molly', 'gender':'female'},
]

with open('pynerds.txt', 'w') as file:
writer = csv.DictWriter(file, fieldnames = fields)
writer.writerows(data_to_wite)






As shown above, when using named fields, the order is not important as long as the field names are correct.





import csv

with open('demo.csv') as file:
print(file.read())






Stephen,King,32,male



Molly,Jones,22,female






SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - csv module in Python
id: dd397230-fd28-4d37-b75d-c8559d221596
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "csv module in Python" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("csv module in Python")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*csv module in Python*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "csv module in Python"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich csv module in Python.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten csv module in Python

Thematisch verwandte Begriffe: module, Python · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-82585 | The Botslab G980H dash camera firmware transmits sensitive information o…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle