Error iterating through file - Python
Question: I'm trying to iterate through a txt file with a long string and deleting the
double quotes(") and commas(,) and writing it in a new file but it keeps
getting a error. Please help.

Code:

    
    
    from sys import argv
    
    script, filename = argv
    
    long_String = ""
    
    for line in filename.readline():
        long_String += line
        long_String += " "
    
    
    for x in long_String:
        if (x = '\"'):
            x = ""
    
        if x = ",":
            x = ""
    
    filename2 = "print.txt"
    
    target = open (filename2, 'a')
    target.write(long_string)
    target.close()
    


Answer: You have some errors:

    
    
    target.write(long_string)
    

Should be :

    
    
    target.write(long_String)
    

and

    
    
    if (x = '\"'):
    

should be:

    
    
    if (x == '\"'):
    

Same with :

    
    
    if x = ",":
    

Otherwise, you can easily do with
[re.sub](https://docs.python.org/2/library/re.html#re.sub)

    
    
        for line in filename.readline():
            my_string += re.sub(r'\"\'', '', line)
    

