Python Forum
Double Quotes will not go away, must be missing something
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Double Quotes will not go away, must be missing something
#1
I've tried using the below, and various 'csv import' machinations, and no matter what I do the double quotes are present when I open the file in notepad++, notepad, etc.  And when I bulk insert to sql serve there are coming over as an 'o' with an umlaut at the beginning and end of every column.  I'm oviously missing something with my lack of Python knowledge, but I'm at wits end as to why they just won't go away.  (They are hex value 94 if it makes a difference).  Originally opened as a csv file with excel, then format was changed to quote all but integers, and now I'm where I am.  If anybody can offer a take on that or a link, or anything,  I would appreciate it, thanks.

import os

mypath = r'C:\\csv\\'
myoutputpath = r'C:\\csv\\output\\'

for file in os.listdir(mypath): # This will loop through every file in the folder
    if '.csv' in file:  # Check if it's a csv file
        fpath = os.path.join(mypath, file)
        fpath_out = os.path.join(myoutputpath, file) #+ '_output' # Create an output file with a similar name to the input file
        with open(fpath) as infile:
            lines = infile.readlines()  # Read all lines
        with open(fpath_out, 'w') as outfile:
            for line in lines:  # One line at a time
                outfile.write(line.replace('"', '')) # Remove each " and write the line
Reply


Messages In This Thread
Double Quotes will not go away, must be missing something - by smiths87 - May-03-2017, 08:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 7,034 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 1,944 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  Remove double quotes from the list ? PythonDev 22 9,015 Nov-05-2020, 04:53 PM
Last Post: snippsat
  Quotes vs. no quotes around numbers Mark17 6 3,183 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup soothsayerpg 5 7,166 Oct-27-2019, 09:53 AM
Last Post: newbieAuggie2019
  Replace all alpha characters within double quotes with underscores? walterbyrd 1 2,789 Nov-26-2017, 01:13 AM
Last Post: Larz60+
  replace string inside double quotes jmpatx 10 16,736 Apr-26-2017, 05:27 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020