Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = """
- 'charmander',12
- 'bulbasaur',7
- 'squirtle',13"""
- with open("data.txt","w") as f:
- f.write(t)
- pokemons = []
- with open("data.txt") as f:
- for line in f:
- line = line.strip() # remove n and other whitespaces
- if line: # only process non empty lines
- try:
- poke, lvl = line.split(",")
- except ValueError:
- print("Unable to split line into 2 parts: ", line)
- continue
- poke=poke.strip("'")
- pokemons.append( [poke,int(lvl)] )
- if len(pokemons) == 6:
- break
- print(pokemons)
- [['charmander', 12], ['bulbasaur', 7], ['squirtle', 13]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement