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


Groups > comp.lang.python > #107694

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

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Dennis Lee Bieber <wlfraed@ix.netcom.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 20:10:05 -0400
Organization IISS Elusive Unicorn
Lines 55
Message-ID <mailman.133.1461715819.32212.python-list@python.org> (permalink)
References <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <CAPM-O+yQKdR4-7QT3-Ru7gyfOP9xCFMpZgtGYZWVFDN9v7o1vg@mail.gmail.com> <mailman.112.1461686936.32212.python-list@python.org> <25b35d39-4163-414c-9495-f2ed4a2a90a8@googlegroups.com> <s600iblpm156397jugal51f2thd36sfh0e@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de simfejtjojugqgwr6g0HeAqc0r6xI1bBdJ0ky0qeo+YA==
Return-Path <python-python-list@m.gmane.org>
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; 'tries': 0.05; 'subject:file': 0.07; 'tom': 0.07; 'compute': 0.09; 'csv': 0.09; 'message-id:@4ax.com': 0.09; 'name)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:CSV': 0.09; 'skip:# 20': 0.13; 'syntax': 0.13; 'subject:python': 0.14; "'a')": 0.16; '1",': 0.16; '2",': 0.16; '2016': 0.16; '3",': 0.16; 'adam': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'retrieving': 0.16; 'skip:> 20': 0.16; 'sqlite3': 0.16; 'writer': 0.16; 'duplicate': 0.18; 'url:home': 0.18; '(the': 0.22; 'select': 0.23; '(this': 0.24; 'header:X-Complaints-To:1': 0.26; 'identifies': 0.29; 'key,': 0.29; 'prints': 0.29; 'code:': 0.29; "i'd": 0.31; 'primary': 0.31; 'probably': 0.31; 'anyone': 0.32; 'skip:_ 10': 0.32; '-0700': 0.33; 'tue,': 0.34; 'file': 0.34; 'add': 0.34; 'something': 0.35; 'data.': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'drop': 0.38; 'skip:o 20': 0.38; 'test': 0.39; 'subject:the': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'called': 0.40; "you'll": 0.61; 'more': 0.63; 'foreign': 0.69; 'score': 0.76; 'as:': 0.79; '>with': 0.84; 'quiz': 0.84; 'subject:any': 0.84; 'subject:value': 0.84; 'composite': 0.91; 'dennis': 0.91; 'scores': 0.91; 'average': 0.93; 'received:108': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host adsl-108-79-218-66.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
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 <s600iblpm156397jugal51f2thd36sfh0e@4ax.com>
X-Mailman-Original-References <75e5d8dc-e15b-4350-95e8-490abd4aa14f@googlegroups.com> <CAPM-O+yQKdR4-7QT3-Ru7gyfOP9xCFMpZgtGYZWVFDN9v7o1vg@mail.gmail.com> <mailman.112.1461686936.32212.python-list@python.org> <25b35d39-4163-414c-9495-f2ed4a2a90a8@googlegroups.com>
Xref csiph.com comp.lang.python:107694

Show key headers only | View raw


On Tue, 26 Apr 2016 10:05:00 -0700 (PDT), Adam Davis
<peakgraphicz@gmail.com> declaimed the following:

>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

	Probably not what you want, but...

	I'd drop the CSV file -- create an SQLite3 database with two tables:

TestTaker(*ID*, Name)

and

Scores(*ID*, _testTakerID_, TestID, Score)

where *ID* is the primary key -- autoincrement integer; _testTakeID_ is a
foreign key (the ID of the TestTaker); no need to store the average, you'll
compute that when retrieving data.

	If you set up (_testTakerID_, TestID) as a composite unique key, the
database system will object when you try to add a duplicate of those two
fields. 

	This design is not limited to only three scores (since TestID
identifies which score you can easily add more tests).

	You'd get the average by something like (this is off the cuff, I'd have
to test to get the syntax fully correct):

select TestTaker.Name, avg(Score) from 
TestTake inner join Scores
on TestTaker.ID = Scores.testTakerID
group by TestTaker.ID
order by TestTaker.Name


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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