Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107683

RE: Howw to prevent the duplication of any value in a column within a CSV file (python)

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Joaquin Alzola <Joaquin.Alzola@lebara.com>
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 <mailman.125.1461697547.32212.python-list@python.org> (permalink)
References <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <531e2dda-c522-4b11-a030-f3f37078f344@googlegroups.com> <HE1PR07MB13561533B5D2DEE4B31F9AA9F0630@HE1PR07MB1356.eurprd07.prod.outlook.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 <Joaquin.Alzola@lebara.com>
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 <HE1PR07MB13541F32AA07B0F245977FCEF0630@HE1PR07MB1354.eurprd07.prod.outlook.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <HE1PR07MB13561533B5D2DEE4B31F9AA9F0630@HE1PR07MB1356.eurprd07.prod.outlook.com>
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

Show key headers only | View raw


Just an example. Didn't use the csv but just hope that it helps.

name=[]
name_exist="Dop"

with open("dop.csv") as f:
        for line in f:
                line_split=line.split(',')
                name.append(line_strip[0])
        if name_exist in name:
                print "found name " + name_exist + " Can not append"
        else:
                file = 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=lebara.com@python.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 within 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 the same values to be entered into a column in my CSV file created through python. So I need to read into the CSV file and check if any names have already 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 = ["Name", "Score 1", "Score 2", "Score 3", "Average"]
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        #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 will 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 contact the sender immediately upon receipt.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Howw to prevent the duplication of any value in a column within a CSV file (python) peakgraphicz@gmail.com - 2016-04-26 09:01 -0700
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Joel Goldstick <joel.goldstick@gmail.com> - 2016-04-26 12:08 -0400
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:05 -0700
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-26 20:10 -0400
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 10:13 -0600
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:00 -0700
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 13:50 -0600
  Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 10:05 -0700
    RE: Howw to prevent the duplication of any value in a column within a CSV file (python) Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-26 19:05 +0000
    Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 13:51 -0600
      Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 13:07 -0700
        Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-26 14:19 -0600
          Re: Private message regarding: Howw to prevent the duplication of any value in a column within a CSV file (python) Ian Kelly <ian.g.kelly@gmail.com> - 2016-05-02 07:47 -0600
        Re: Howw to prevent the duplication of any value in a column within a CSV file (python) MRAB <python@mrabarnett.plus.com> - 2016-04-26 21:23 +0100
          Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-26 23:26 -0700
            Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Chris Angelico <rosuav@gmail.com> - 2016-04-27 16:37 +1000
              Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Adam Davis <peakgraphicz@gmail.com> - 2016-04-27 05:23 -0700
                Re: Howw to prevent the duplication of any value in a column within a CSV file (python) Andrew Ongko <andrew.ongko@gmail.com> - 2016-04-27 19:57 +0700
                Re: Howw to prevent the duplication of any value in a column within a CSV file (python) darnold <darnold992000@yahoo.com> - 2016-04-27 08:49 -0700
  RE: Howw to prevent the duplication of any value in a column within a CSV file (python) Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-04-26 16:07 +0000

csiph-web