0

I am creating a tournament scoring system application. There are many sections to this app, for example, Participants, Team, Events and Award points. Right now I am working on the team section. I was able to create something that will allow the user to create teams. The code looks like this.

teamname = input("Team Name: ").title()
First_member = input("First Member Full Name: ").title()
if any(i.isdigit() for i in First_member):
print("Invalid Entry")
else:

There can only be 5 members in each team. This is how the data is saved

combine = '\''+teamname+'\' : \''+First_member+'\', \''+Second_member+'\', 
\''+Third_member+'\',  \''+Forth_member+'\',  \''+Fifth_member+'\'',                                  

myfile = open("teams.txt", "a+")
myfile.writelines(combine)
myfile.writelines('\n')
myfile.close()

Now If I want to remove a team how do I do that?

Apologies if you feel like i am wasting your time but still thanks for stopping by. If you want to see everything please check out this link

https://repl.it/@DaxitMahendra/pythoncode>

2 Answers2

0

If text file creation is in your hand then you should just have proper YAML format of file. Your format is fairly similar to YAML.

Once you have YAML you can use PyYAML: https://pyyaml.org/wiki/PyYAMLDocumentation

This answer: YAML parsing and Python? has example of the format and how to parse as well.

enator
  • 2,431
  • 2
  • 28
  • 46
0

you have to do a quick fix, please change your "combine" variable format to a valid "dict" format, then you can use the "ast" module, here a example

#proxy items
teamname,First_member,Second_member,Third_member,Forth_member,Fifth_member = [str(temp_name).zfill(3) for temp_name in range(6)]

#add "{" and "}" to start/end and add your values into a list "key":["value1", "value2",...]
combine = '{\''+teamname+'\' : [\''+First_member+'\', \''+Second_member+'\', \''+Third_member+'\',  \''+Forth_member+'\',  \''+Fifth_member+'\']}'

import ast
dict = ast.literal_eval(combine)
print dict.keys(), type(dict)
>>['000'] <type 'dict'>

for your case,

#change the "combine" variable
combine = '{\''+teamname+'\' : [\''+First_member+'\', \''+Second_member+'\', \''+Third_member+'\',  \''+Forth_member+'\',  \''+Fifth_member+'\']}'
Ari Gold
  • 1,528
  • 11
  • 18
  • I have added those things. printed this dict_keys(['000']) and when i looked at the file there was this {'000' : ['001', '002', '003', '004', '005']} – Daxit Mahendra Dec 26 '17 at 21:59
  • this adding these numbers but not the details of members after adding the code – Daxit Mahendra Dec 26 '17 at 22:02
  • Its only a example, please change it for your case....there Are Proxy items, Remove the line – Ari Gold Dec 26 '17 at 22:29
  • Honestly, man, I don't know what I am doing and the example you gave me makes no sense to me. its been 1 month. Just getting started with python and this is already taking a piss. I don't expected my self-passing this ******* unit – Daxit Mahendra Dec 27 '17 at 15:34