<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toCSV(pdl,out=None,write_field_names=True):

 """Conversion from the PyDbLite Base instance pdl to the file object out
 open for writing in binary mode
 If out is not specified, the field name is the same as the PyDbLite
 file with extension .csv
 If write_field_names is True, field names are written at the top
 of the CSV file"""

    import csv
    if out is None:
        file_name = os.path.splitext(pdl.name)[0]+".csv"
        out = open(file_name,"wb")
    fields = ["__id__","__version__"]+pdl.fields
    writer = csv.DictWriter(out,fields)
    # write field names
    if write_field_names:
        writer.writerow(dict([(k,k) for k in fields])) 
    # write values
    writer.writerows(pdl())
    return file_name