Re: [Tutor] reading complex data types from text file

2009-07-19 Thread Chris Castillo
okay so I figured my program out. I am posting the final version so if someone else is having problems with something like this it may benefit the community. (comments are included to help those who might not understand the code) -

Re: [Tutor] reading complex data types from text file

2009-07-18 Thread Chris Castillo
so could I also replace the score of each bowler (key value) in the dictionary with a new key such as "below average" or "above average" according to each if-elif-else structure and then write to a text file in the following format? Jim Above Average SueBelow Average BobPerfect score

Re: [Tutor] reading complex data types from text file

2009-07-17 Thread bob gailer
Chris Castillo wrote: how would i go about adding the names to a dictionary as a key and the scores as a value in this code? # refactored for better use of Python, correct logic, and flow scores = {} # empty dictionary total = 0 for line in open("bowlingscores.txt", "r"): if line.strip().

Re: [Tutor] reading complex data types from text file

2009-07-16 Thread bob gailer
Chris Castillo wrote: *so far I have this and the format is what i want:* -- # Set all necessary variables name = None fileOut = open('outputFile.txt', 'w') total = 0 averageScore = 0 numofScores = 0 score =

Re: [Tutor] reading complex data types from text file

2009-07-16 Thread Chris Castillo
*so far I have this and the format is what i want:* -- # Set all necessary variables name = None fileOut = open('outputFile.txt', 'w') total = 0 averageScore = 0 numofScores = 0 score = 0 # Header for output f

Re: [Tutor] reading complex data types from text file

2009-07-16 Thread Glen Zangirolami
All lines that come back from a text file come back as strings. You can use string methods to detect the data like so: f = open('test.txt') lines = f.readlines() numbers = [] strings = [] for line in lines: if line.strip().isdigit(): numbers.append(int(line)) else: strings.

Re: [Tutor] reading complex data types from text file

2009-07-16 Thread Christian Witts
Chris Castillo wrote: Oh okay. gotcha. so I have what I want basically. I just need to check to see if each number meets a certain criteria and output something like the following to a text file. Should I be going about this a different way or should I still use lists? bob below average sue

Re: [Tutor] reading complex data types from text file

2009-07-16 Thread Christian Witts
Chris Castillo wrote: why does your 3rd and fourth lines have brackets? On Thu, Jul 16, 2009 at 1:08 AM, Christian Witts mailto:cwi...@compuscan.co.za>> wrote: Chris Castillo wrote: I'm having some trouble reading multiple data types from a single text file. say

Re: [Tutor] reading complex data types from text file

2009-07-15 Thread Christian Witts
Chris Castillo wrote: I'm having some trouble reading multiple data types from a single text file. say I had a file with names and numbers: bob 100 sue 250 jim 300 I have a few problems. I know how to convert the lines into an integer but I don't know how to iterate through all the lines and

Re: [Tutor] reading complex data types from text file

2009-07-15 Thread Michiel Overtoom
Chris Castillo wrote: I don't know how to iterate through all the lines and just get the integers and store them or iterate through the lines and just get the names and store them. You could use the int() function to try to convert a line to an integer, and if that fails with a ValueError ex