-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilereader.py
More file actions
38 lines (31 loc) · 975 Bytes
/
filereader.py
File metadata and controls
38 lines (31 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
class Gamedata:
def __init__(self, name, port, players):
self.name = name
self.port = port
self.players = players
def read(file):
names = []
ports = []
players = []
with open(file, 'r') as f:
newgame = True
gamenum = 0
for line in f:
if newgame and line.strip() != "":
newgame = False
data = line.split(',')
names.append(data[0])
ports.append(int(data[1]))
players.append({})
elif line.strip() == "":
if not newgame:
gamenum += 1
newgame = True
else:
data = line.split(',')
players[gamenum][data[0].strip()] = data[1].strip()
games = []
for i in range(gamenum + 1):
games.append(Gamedata(names[i], ports[i], players[i]))
return games