Re: iterate start at second row in file not first
On May 20, 7:34 pm, [EMAIL PROTECTED] wrote: i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can check but i dont want to check for every line in the whole file, quite unnecessary when i only need to chekc the first line. so the question is, when dealign with iterators like: mov = open(afile) for line in mov: do y how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? import itertools mov = open(afile) for line in itertools.islice(mov, 1, None): do y -- Paul Hanin -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate start at second row in file not first
On May 20, 8:34 pm, [EMAIL PROTECTED] wrote: i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can check but i dont want to check for every line in the whole file, quite unnecessary when i only need to chekc the first line. so the question is, when dealign with iterators like: mov = open(afile) for line in mov: do y how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? mov = open(afile) for i,line in enumerate(mov): if not i: # Enumeration starts at zero so it is the first line continue # Use continue to just move to the next iteration if you # don't want/need to do anything # or you can do a check for what you were looking for if ':' in line: break # Alternatively you could do it as if not i and ':' in line: break # Perform your normal operations on the file, not exactly clear what you # want to perform -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate start at second row in file not first
On May 20, 1:34 pm, [EMAIL PROTECTED] wrote: i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can check but i dont want to check for every line in the whole file, quite unnecessary when i only need to chekc the first line. so the question is, when dealign with iterators like: mov = open(afile) for line in mov: do y how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? How about this? mov = open(afile) first = mov.next() # check first for ':' and do whatever you need to do # including the 'y' processing from below if required for line in mov: do y ... Jay Graves -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate start at second row in file not first
On May 20, 12:34 pm, [EMAIL PROTECTED] wrote: how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? To simply bypass the first line, do a readline() on the file object before starting to process the file. To filter out particular lines throughout the file, you can either do a check in the for loop and continue if it is true, or create a generator which filters out unwanted content. untested: fd = open(some_file) fi = (x for x in fd if (x.search(':') 0)) for line in fi: pass It gets a bit more complicated if you want to actually split on sentences, not lines. -- http://mail.python.org/mailman/listinfo/python-list
iterate start at second row in file not first
i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can check but i dont want to check for every line in the whole file, quite unnecessary when i only need to chekc the first line. so the question is, when dealign with iterators like: mov = open(afile) for line in mov: do y how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate start at second row in file not first
How about: mov = open(afile) line = mov.readline() ...(process your ':' line) for line in mov.readlines(): ... On May 20, 1:34 pm, [EMAIL PROTECTED] wrote: i have a big file with sentences, the first file of each sentence contains a colon(:) somewher eon that line i want to jump past that sentence. if all(x != ':' for x in line): this way i can check but i dont want to check for every line in the whole file, quite unnecessary when i only need to chekc the first line. so the question is, when dealign with iterators like: mov = open(afile) for line in mov: do y how do i jump the first step there? i dont want to iterate the first row...how do i start at the second? -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate start at second row in file not first
Mark d. wrote: How about: mov = open(afile) line = mov.readline() ...(process your ':' line) for line in mov.readlines(): ... The problem here is that you read the entire file in in the call to readlines. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list