Python Forum
Remove double quotes from the list ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove double quotes from the list ?
#7
I am confused. You cannot do this: "How do I remove the double quotes keeping the data type as class (FieldStorage) and not (string)?". Everything that is printed is converted to a string, and the result is None with a side effect of drawing the characters to stdout. I occasionally see posts here where the author uses a print statement to display data and is concerned about an decorations that might be appended or removed by the print statement. The print statement is only displaying the result of __str__(thing) or __repr__(thing), and not the actual thing. Why do you think it is important to not have the quotes? Sure you can change how the string is constructed and avoid the quotes, but it is still a string.

To expand slightly on bolofred's example:
a = 'foo\'bar'
b = 'foobar'
print(a, b)
print([a, b])
print(f'[{a}, {b}]')
Output:
foo'bar foobar ["foo'bar", 'foobar'] [foo'bar, foobar]
When printing strings that are in a list, Python wraps the string in quotes. If the string includes a single quote Python wraps the string in double quotes. To remove the quotes you have to format the string yourself. The last print does not show quotes because it is not printing a list. It prints two strings surrounded by brackets. I don't know if this is applicable to your problem.
Reply


Messages In This Thread
Remove double quotes from the list ? - by PythonDev - Oct-31-2020, 01:12 AM
RE: Remove double quotes from the list ? - by deanhystad - Nov-01-2020, 02:23 AM
RE: Remove double quotes from the list ? - by buran - Nov-01-2020, 09:18 PM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 08:36 AM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 05:41 PM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 6,838 May-27-2024, 04:54 PM
Last Post: wardancer84
  unable to remove all elements from list based on a condition sg_python 3 1,838 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 4,019 Nov-13-2022, 01:27 AM
Last Post: menator01
  Reading list items without brackets and quotes jesse68 6 7,274 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Remove empty keys in a python list python_student 7 6,104 Jan-12-2022, 10:23 PM
Last Post: python_student
  Remove an item from a list contained in another item in python CompleteNewb 19 9,361 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 8,843 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 2,729 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  .remove() from a list - request for explanation InputOutput007 3 3,143 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  Remove specific elements from list with a pattern Xalagy 3 3,771 Oct-11-2020, 07:18 AM
Last Post: Xalagy

Forum Jump:

User Panel Messages

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