Mailingliste - Einträge 2018
Die Mailingliste ist seit Juli 2022 geschlossen, dient aber weiterhin als Informationsarchiv zu QF-Test.
Wenn Sie über Neuerungen zu QF-Test informiert bleiben wollen, können Sie einfach unseren Newsletter abonnieren:
Newsletter abonnieren
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [QF-Test] How do I update and existing value in a CSV file?
Hi everyone, In order to update a value in an existing CSV file, you first need to read in the file the complete file, then change the wanted value and then write everything out ... so - in jython/python, this is looking something like this: import csv newCSVData = [] with open(r'C:\temp\foo.csv', 'rb') as csvfile: reader = csv.reader(csvfile, delimiter=';') for row in reader: if row[0] == 'CIVPart1': # the value to search row[1] = str(int(row[1]) + 1) newCSVData.append(row) with open(r'C:\temp\foo.csv', 'w') as csvfile: for line in newCSVData: csvfile.write(";".join(line)) csvfile.write("\n") The same in groovy (Please note that the groovy csv parser expect a "," instead of a ";" as delimiter): import org.apache.commons.csv.CSVParser; def newCSVData = [] parser = new CSVParser(new FileReader("C:/temp/foo.csv")); def fieldnames = parser.getLine(); newCSVData.add(fieldnames) for(int i = 0; i < parser.getLineNumber(); i++) { vals = parser.getLine(); if(vals != null) { if(vals[0] == "CIVPart1") { vals[1] = "" + (vals[1].toInteger() + 1) } newCSVData.add(vals) } } def file = new File("C:/temp/foo.csv"); file.newWriter(); for(vals in newCSVData) { file << vals[0] << "," << vals[1] << "\n"; } Greetings & Happy testing, Yann Am 20.09.2018 um 04:23 schrieb Mike Harper: Hi, I am very new to QF-Test, Groovy, JavaScript etc. and am finding it incredibly difficult finding out how I can update an existing value in a CSV file. I have searched the archives but can't find anything that shows me how to do this. My test uses a CSV Data File to pull in the CSV file values. The CSV data contains two rows: CIVPart1;CIVPart2 CIV-2018-025-;000001 These values are strung together then a SQL statement is used to see if the full CIV Number can be found in the Database. If found to exist, I add 1 to the CIVPart2 value and check again - doing this until a record is not found in the database. I then need to add 1 to the calculated CIVPart2 value and write it back to the CIV file so that when the test runs again, the SQL statement won't reuse values that have already been proven to exist. I am thinking I need to use aServer Script to achieve the required result. Have been using Groovy to date. So, can someone step me through the coderequired to update the existing CSV file so that it contains the new value please? (Am almost bald from pulling my hair out) Thanks in advance for your help. Mike _______________________________________________ qftest-list mailing list qftest-list@?.de https://movement.qfs.de/mailman/listinfo/qftest-list -- _______________________________________________________________ Get the most out of QF-Test - Support directly from the authors * Training & consulting: www.qfs.de/en/qftest/training.html * Phone & email support: www.qfs.de/en/qftest/support.html _______________________________________________________________ Yann Felix Spöri Support E: support@?.de T: +49 8171 38648-20 F: +49 8171 38648-16 Quality First Software GmbH | www.qfs.de Tulpenstr. 41 | 82538 Geretsried | Germany GF Gregor Schmid, Dr. Martina Schmid, Karlheinz Kellerer HRB München 140833
|
Wir verwenden Cookies zur anonymisierten Auswertung Ihres Besuchs auf unserer Webseite durch »Matomo«. Dafür benötigen wir Ihr Einverständnis, welches für zwölf Monate gilt. Ein Widerruf bzw. Opt-out ist jederzeit auf unser Datenschutz-Seite möglich.
1. Funktionale Cookies
Wir verwenden funktionale Cookies, um die Basisfunktionalität der Webseite zu gewährleisten.
2. Performance und Statistik Cookies
Wir verwenden Matomo zur Analyse und Optimierung unserer Webseite. Cookies erlauben eine anonyme Erfassung der Informationen und helfen uns, Ihnen einen benutzerfreundlichen Besuch unserer Webseite zu bieten.
Dieses Cookie enthält eine eindeutige jedoch pseudonymisierte Matomo-interne Besucher-ID zur Erkennung wiederkehrender Besucher.
Dieses Cookie wird verwendet, um zu tracken, von welcher Website der anonymisierte Benutzer auf die Website gekommen ist.
Das Session Cookie von Matomo wird verwendet, um die Seitenanforderungen des Besuchers während der Sitzung zu verfolgen.
wird erzeugt und versucht sofort wieder zu löschen (zur Prüfung, ob der Browser des Besuchers Cookies unterstützt).
Kurzzeit-Cookies für temporäre Besuchsdatenspeicherung.
Kurzzeit-Cookies für temporäre Besuchsdatenspeicherung.