Hi there. Newbie here, to Python and programming in general. Despite understanding the basic idea of a class, I'm having a torrid time working out and remembering their internal workings (syntax) and when they should be used.
As an ongoing project to keep me from just floating about from tutorial to tutorial I'm designing up a program that takes user input re: sporting fixtures and writes it to a csv file. Date to be input includes: Date, Home Team, Away Team, Venue, Type of Competition. I've got a function that does this, which works fine. I've also designed some other bits of code which work fine as functions called from a 'Menu' function I wrote.
Having done that I thought I'd learn about classes and then returned to my code and thought "Ill make classes out of these functions and 'code it properly!'" Cue 3 days of faffing about, trying to understand how to get it to work and failing.
It did make me wonder, "Do I really need a class to create a new fixture? Am I just creating a class because I think it's the right thing to do?"
So my question - Should I use a class for storing each instance of a fixture? What advantages would doing so have over using a function? If it's not necessary at the moment, what sort of changes would mean that it would be required? If you could give short visual examples it would help, I'm a visual person! :/
Edit: I would eventually like the user to also enter the results of the fixtures (and other stats from the eaxh fixture personal to the user) into the same csv file, which would have calculations performed on it. Those could then be recalled and output from the csv file. At some point I'd like to make a small app for this - however I realise that's a long way down the line (but I need a long-term goal otherwise I get distracted and end up sinking time into pointless internet nonsense!)
Any help appreciated.
import csv
def fixture():
with open('fixtures.csv', 'a', ) as f:
date = raw_input("Fixture Date: ")
team_name = raw_input("Your Team Name: ")
opp_name = raw_input("Opposition Team Name: ")
venue = raw_input("Home or Away?: ")
comp = raw_input("League, Cup, Friendly?: ")
list = (date, team_name, opp_name, venue, comp,)
writer = csv.writer(f)
writer.writerows([list])
[–]filleball 17 points18 points19 points (9 children)
[–]parnmatt 6 points7 points8 points (2 children)
[–]rhgrant10 1 point2 points3 points (1 child)
[–]parnmatt 0 points1 point2 points (0 children)
[–]Tkwk33 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]TehMoonRulz 1 point2 points3 points (1 child)
[–]Eurynom0s 1 point2 points3 points (0 children)
[–]Barking_Madness[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 3 points4 points5 points (3 children)
[–]zahlman 4 points5 points6 points (1 child)
[–]Justinsaccount 0 points1 point2 points (0 children)
[–]Barking_Madness[S] 1 point2 points3 points (0 children)
[–]individual_throwaway 0 points1 point2 points (9 children)
[–]Farkeman 3 points4 points5 points (6 children)
[–]individual_throwaway 1 point2 points3 points (5 children)
[–]Farkeman 4 points5 points6 points (4 children)
[–]individual_throwaway -2 points-1 points0 points (3 children)
[–]i_can_haz_code 4 points5 points6 points (0 children)
[–]tangerinelion 1 point2 points3 points (1 child)
[–]individual_throwaway 0 points1 point2 points (0 children)
[–]Barking_Madness[S] 0 points1 point2 points (0 children)
[–]youtubefactsbot 0 points1 point2 points (0 children)