On 2013-10-30, Victor Hooi wrote:
> Hi,
>
> I have a CSV file that I will repeatedly appending to.
>
> I'm using the following to open the file:
>
> with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') as
> output:
> fieldnames = (...)
> csv_writer = DictWriter
Op 30-10-13 02:02, Victor Hooi schreef:
> Hi,
>
> I have a CSV file that I will repeatedly appending to.
>
> I'm using the following to open the file:
>
> with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') as
> output:
> fieldnames = (...)
> csv_writer = Di
Hi,
In theory, it *should* just be our script writing to the output CSV file.
However, I wanted it to be robust - e.g. in case somebody spins up two copies
of this script running concurrently.
I suppose the timing would have to be pretty unlucky to hit a race condition
there, right?
As in, so
> Like Victor says, that opens him up to race conditions.
Slim chance, it's no more possible than it happening in the time try/except
takes to recover an alternative procedure.
with open('in_file') as in_file, open('out_file', 'ab') as outfile_file:
if os.path.getsize('out_file'):
pri
On 29/10/2013 21:42, Joseph L. Casale wrote:
You forgot the attribution line: "Victor says"
>> with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') as
>> output:
>> fieldnames = (...)
>> csv_writer = DictWriter(output, filednames)
>> # Call csv_writer.w
> with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') as
> output:
> fieldnames = (...)
> csv_writer = DictWriter(output, filednames)
> # Call csv_writer.writeheader() if file is new.
> csv_writer.writerows(my_dict)
>
> I'm wondering what's the