Python Forum

Full Version: Variable flag vs code outside of for loop?(Disregard)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
No need for flag, mode code around and works like a champ. Big Grin

So i have the following logic and would like to add a flag or setup in a way that once the for loop is complete, then re-open the new file to remove key rows

    for line in file_in:
        match = datetime_rx.match(line)
        if match:
            file2.write(str(match.groups()[0]) + ',' + match.groups()[1] + '\n')
        else:
            print(line)
Is it better to have some variable that is set once the "if match" is complete or is it safe to just put the next logic outside of the "for line in file_in:"

This above logic, goes thru my raw data file and removed rows that are invalid and creates a new file with just valid rows, now from that file, i need to remove certain rows based on another post i did yesterday..
Are you using pandas for this now? Looks like it would be a great fit. Read file. Filter out non-matching elements and write to file. Filter out remaining elements before the date cutoff, write to a different file.
yep, forgot how cool pandas was.. currently using it and about to post another extension question in my post from yesterday.