Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joaquin Alzola Newsgroups: comp.lang.python Subject: RE: Howw to prevent the duplication of any value in a column within a CSV file (python) Date: Tue, 26 Apr 2016 19:05:37 +0000 Lines: 57 Message-ID: References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de opFiz8slW9SkQq6tKjfQjAQXa2qfIs6sbnPq81OZfoGA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'tries': 0.05; 'column': 0.07; 'subject:file': 0.07; 'tom': 0.07; 'csv': 0.09; 'subject:CSV': 0.09; 'python.': 0.11; 'skip:# 20': 0.13; 'subject:python': 0.14; 'message-----': 0.15; 'subject: \n ': 0.15; 'value.': 0.15; "'a')": 0.16; '(python)': 0.16; '1",': 0.16; '2",': 0.16; '2016': 0.16; '3",': 0.16; 'adam': 0.16; 'advance!': 0.16; 'file.close()': 0.16; 'found"': 0.16; 'helps.': 0.16; 'privilege.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 60': 0.16; 'writer': 0.16; 'wrote:': 0.16; 'example.': 0.18; 'pfxlen:0': 0.18; 'prevent': 0.20; 'to:name:python- list@python.org': 0.20; 'to:2**1': 0.21; 'header:In-Reply-To:1': 0.24; 'wondering': 0.25; 'entered': 0.27; 'have,': 0.27; 'function': 0.28; 'values': 0.28; '"no': 0.29; 'prints': 0.29; 'code:': 0.29; 'print': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'anyone': 0.32; 'url:python': 0.33; 'skip:j 20': 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'file': 0.34; 'sent:': 0.35; 'subject:': 0.35; 'but': 0.36; 'url:org': 0.36; 'created': 0.36; 'email addr:python.org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'thanks': 0.37; 'charset :us-ascii': 0.37; 'names': 0.38; 'skip:o 20': 0.38; 'does': 0.39; 'subject:the': 0.39; "didn't": 0.39; 'from:': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'called': 0.40; 'hope': 0.61; 'skip:n 10': 0.62; 'within': 0.64; 'contact': 0.66; 'python-list': 0.66; 'email name:python-list': 0.67; 'subject': 0.70; 'disclose': 0.71; 'as:': 0.79; 'duplication': 0.84; 'quiz': 0.84; 'subject:any': 0.84; 'subject:value': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebara.onmicrosoft.com; s=selector1-lebara-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CJHZ5u99fPh0Zv4iYzMY9X+9olBime2AkJCKMphrA4M=; b=NrL+dbt9UaZ3utnEFjnlFPSpxAEBxWohS9ag+5cSAo0wb3AZrnoIP1IVgpAZD78Kkg3Zszwr195xNY4MskE3WTcy855ecUGNSFGVQWsAssJrrRvf6wKXRyNqlmv4uWl6GRzJEzV8H2ueQ+rCk2d9bNnhdrN0GIiSgh2gMomsLxE= Thread-Topic: Howw to prevent the duplication of any value in a column within a CSV file (python) Thread-Index: AQHRn93OgXv+FqSVMUycropIKX1MNZ+cnIVg In-Reply-To: <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=lebara.com; x-originating-ip: [165.225.80.110] x-ms-office365-filtering-correlation-id: 46cd2db1-6990-4748-7c8b-08d36e05c0d6 x-microsoft-exchange-diagnostics: 1; HE1PR07MB1354; 5:uGwcuVA+3x7e4Q+gOh5jRXWJwqOJNnzp9se3CFJGZPzdWOrouvbvtP/nLAaUDjYPHFZnfroaQU2BZ4iyfayS7eYBo4jtZrqA/SUJqRyxiyl83cP+OHjVgA0FrZYxfuTrzxq+VXS9SiUyo7NUTdMj6Q==; 24:wqJ/vKRH0iEE1SGoEdFr2FMBjzgKvH+LZqB6jp1YaRet0K8fSfDS3QWP05h96wm/K6vx5KfAFOUZLO89il/eMBaUf/DcLHSuaq1rFRgfnyE=; 7:lwOUA4D4ttntTuYijD0sxMbVG2TC6qAfAtF0TIOGT74Hm9GUpcShHxhxc/B+SyiRoC7sKqrtXAr58OnkZl0vzSfq1TO5pxB8WpLjBMD1oUL4AiijIbOUfR24tkWOrgykFBXY99wsDhVEtvEVFvysegs5+D8Y8wpRZd0LyIyCW5p2xdihkM+x5ED6Ij0Vgo4R x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR07MB1354; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(9101521072)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:HE1PR07MB1354; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1354; x-forefront-prvs: 0924C6A0D5 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(51874003)(24454002)(6116002)(3846002)(33656002)(189998001)(1220700001)(1096002)(102836003)(2906002)(50986999)(54356999)(76176999)(5003600100002)(81166005)(5002640100001)(5001770100001)(76576001)(9686002)(586003)(3280700002)(106116001)(5008740100001)(5004730100002)(92566002)(3660700001)(107886002)(122556002)(77096005)(2501003)(19580405001)(19580395003)(66066001)(2900100001)(10400500002)(2950100001)(86362001)(74316001)(15975445007)(87936001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1354; H:HE1PR07MB1356.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM X-OriginatorOrg: lebara.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Apr 2016 19:05:37.6983 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d7093539-83cd-4991-b1b3-aacef74cf097 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR07MB1354 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> Xref: csiph.com comp.lang.python:107683 Just an example. Didn't use the csv but just hope that it helps. name=3D[] name_exist=3D"Dop" with open("dop.csv") as f: for line in f: line_split=3Dline.split(',') name.append(line_strip[0]) if name_exist in name: print "found name " + name_exist + " Can not append" else: file =3D open("dop.csv",'a') print "No name found" file.write(name_exist) file.close() -----Original Message----- From: Python-list [mailto:python-list-bounces+joaquin.alzola=3Dlebara.com@p= ython.org] On Behalf Of Adam Davis Sent: 26 April 2016 18:05 To: python-list@python.org Subject: Re: Howw to prevent the duplication of any value in a column withi= n a CSV file (python) On Tuesday, 26 April 2016 17:01:41 UTC+1, Adam Davis wrote: > I am wondering how to make my code function so it does not allow any of t= he same values to be entered into a column in my CSV file created through p= ython. So I need to read into the CSV file and check if any names have alre= ady been entered. If they have, the user must not be allowed to enter this = value. > > Thanks in advance! Here's my section of code: with open(class_code+".csv", 'a') as csvfile: fieldnames =3D ["Name", "Score 1", "Score 2", "Score 3", "Average"] writer =3D csv.DictWriter(csvfile, fieldnames=3Dfieldnames) #writer.writeheader() writer.writerow({"Name": name, "Score 1": score1, "Score 2": score2= , "Score 3": score3}) It prints when requested as: Adam,1,0,0,0.3333333333333333 Jake,9,10,6,8.333333333333334 Tom,5,3,3,3.6666666666666665 So basically, if anyone called Adam, Jake or Tom tries the quiz again, it w= ill not let them. Thanks -- https://mail.python.org/mailman/listinfo/python-list This email is confidential and may be subject to privilege. If you are not = the intended recipient, please do not copy or disclose its content but cont= act the sender immediately upon receipt.