I have a script that reads in the contents of a CSV file where I then merge it with other data with the goal of creating an output CSV file that has the combined data. I have the CSV file creating working fine and all of the data makes it into the output file. My issue is with formatting specific to a cell of data that contains many fields that are already quoted. I have messed around with the CSV options and cannot find a configuration that doesn't make me use single quotes around everything (which the import into Dokan will accept but not process properly) or that doesn't double double quote everything which also breaks the import mechanism with Dokan.
Here is what the data element looks like (not pretty): Note that there are many | delimited fields prior to this and after - this is just a single field called "dokan_profile_setting"
'a:19:{s:10:"store_name";s:12:"vendor100";s:6:"social";a:8:{s:2:"fb";s:0:"";s:5:"gplus";s:0:"";s:7:"twitter";s:0:"";s:9:"pinterest";s:0:"";s:8:"linkedin";s:0:"";s:7:"youtube";s:0:"";s:9:"instagram";s:0:"";s:6:"flickr";s:0:"";}s:7:"payment";a:2:{s:6:"paypal";a:1:{i:0;s:5:"email";}s:4:"bank";a:0:{}}s:5:"phone";s:10:"1231231234";s:10:"show_email";s:2:"no";s:7:"address";a:6:{s:8:"street_1";s:21:"2160 South Lipan Street";s:8:"street_2";s:9:"";s:4:"city";s:6:"Denver";s:3:"zip";s:5:"80223";s:7:"country";s:2:"US";s:5:"state";s:2:"CO";}s:8:"location";s:0:"";s:6:"banner";i:0;s:4:"icon";i:0;s:8:"gravatar";i:0;s:14:"show_more_ptab";s:3:"yes";s:9:"store_ppp";i:10;s:10:"enable_tnc";s:3:"off";s:9:"store_tnc";s:0:"";s:23:"show_min_order_discount";s:2:"no";s:9:"store_seo";a:0:{}s:24:"dokan_store_time_enabled";s:3:"yes";s:23:"dokan_store_open_notice";s:0:"";s:24:"dokan_store_close_notice";s:0:"";}'
If the quotes are clean - as above - and not doubled (see below) the import and usage works fine but i cannot seem to get the CSV creation to leave these quotes along while affecting others in the row that legit need to be quoted.
Here is a single row after output by CSV filewriter - Note the doubled quotes
"100"|"vendor100"|"vendor100@demotech.com"|"Piper"|"Smith"|"vendor100"|"vendor100"|"This is the imported shop data for XYZ LLC"|""|"no"|"a:19:{s:10:""store_name"";s:12:""vendor100"";s:6:""social"";a:8:{s:2:""fb"";s:0:"""";s:5:""gplus"";s:0:"""";s:7:""twitter"";s:0:"""";s:9:""pinterest"";s:0:"""";s:8:""linkedin"";s:0:"""";s:7:""youtube"";s:0:"""";s:9:""instagram"";s:0:"""";s:6:""flickr"";s:0:"""";}s:7:""payment"";a:2:{s:6:""paypal"";a:1:{i:0;s:5:""email"";}s:4:""bank"";a:0:{}}s:5:""phone"";s:10:""1231231234"";s:10:""show_email"";s:2:""no"";s:7:""address"";a:6:{s:8:""street_1"";s:21:""2160 South Lipan Street"";s:8:""street_2"";s:9:"""";s:4:""city"";s:6:""Denver"";s:3:""zip"";s:5:""80223"";s:7:""country"";s:2:""US"";s:5:""state"";s:2:""CO"";}s:8:""location"";s:0:"""";s:6:""banner"";i:0;s:4:""icon"";i:0;s:8:""gravatar"";i:0;s:14:""show_more_ptab"";s:3:""yes"";s:9:""store_ppp"";i:10;s:10:""enable_tnc"";s:3:""off"";s:9:""store_tnc"";s:0:"""";s:23:""show_min_order_discount"";s:2:""no"";s:9:""store_seo"";a:0:{}s:24:""dokan_store_time_enabled"";s:3:""yes"";s:23:""dokan_store_open_notice"";s:0:"""";s:24:""dokan_store_close_notice"";s:0:"""";}"|"vendor100"|"no"|"Piper"|"Smith"|"XYZ LLC 100"|"2160 South Lipan Street"|""|"Denver"|"CO"|"80223"|"US"|"vendor100@demotech.com"|"(123) 123-1234"|""|"percentage"|"yes"|"39.6773216"|"-105.0014567"|"1"|"2160 South Lipan Street, Denver, CO, 80223, USA"|""|""|""|"yes"|"yes"|"CO"|"404-00411"|"vendor100"|"1231231234"|"a:6:{s:8:""street_1"";s:15:""2160 South Lipan Street"";s:8:""street_2"";s:0:"""";s:4:""city"";s:6:""Denver"";s:5:""state"";s:2:""CO"";s:3:""zip"";s:5:""80223"";s:14:""country_select"";s:2:""US"";}"|""|"seller"|"$P$B8l8bYi8oIwINynO/x3Lb/80vOUfGD."|"0"
Here is the current config of my csv writer but i have been through many diff configs. This is just the current one that generated the output above:
with open(demo_co_vendors, 'w', newline='', encoding='utf-8') as csvfile:
filewriter = csv.writer(csvfile, delimiter='|', quoting=csv.QUOTE_ALL, quotechar='"', doublequote="false", escapechar='\\')
Any advice or help are appreciated.