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
#4
I found the solution - the real issue is that the file had 'smart quotes' in it, not just straight quotes.  Finally narrowed it down to that, and the below code with the smart quote in the replace argument worked.  Thanks for the replies.

import os


mypath = 'C:\\csv\\'
myoutputpath = '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(u'\u201d', ''))# Remove each " and write the line
        
        infile.close()
        outfile.close()
Reply


Messages In This Thread
RE: Double Quotes will not go away, must be missing something - by smiths87 - May-03-2017, 11:45 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,096 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 1,981 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  Remove double quotes from the list ? PythonDev 22 9,204 Nov-05-2020, 04:53 PM
Last Post: snippsat
  Quotes vs. no quotes around numbers Mark17 6 3,254 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup soothsayerpg 5 7,216 Oct-27-2019, 09:53 AM
Last Post: newbieAuggie2019
  Replace all alpha characters within double quotes with underscores? walterbyrd 1 2,823 Nov-26-2017, 01:13 AM
Last Post: Larz60+
  replace string inside double quotes jmpatx 10 16,911 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