Q:

Replace value from CSV with Python

I have to replace values in a large CSV file and decided for Python as programming language I want to use. 
The value I need to change is the first on each line in my comma separated CSV:
ToReplace, a1, a2, ..., aN
1, ab, cd, ..., xy
80, ka, kl, ..., df

It's always a number, the amount if digits isn't fixed, though. 
I've got two ideas at the moment: Process the data line by line and ... 

Use a regular expression to match the number
Use the CSV component to parse the line

As I'm very new to Python there are some questions that came to mind:

Considering the file's size (> 50GB; ~ 10 million lines), which method is faster? 
How to implement it without wasting lots of resources? 

A:

If you want to replace the first column that always contains a number then you could use a string method instead of a more general csv module, to avoid parsing the whole line:
#! /usr/bin/env python

def main():
    with open('50gb_file', 'rb') as file, open('output', 'wb') as output_file:
        for line in file:
            number, sep, rest = line.partition(b',')
            try:
                number = int(number)*2 #XXX replace number here
            except ValueError:
                pass # don't replace the number
            else:
                line = bytes(number) + sep + rest
            output_file.write(line)

main()

