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 ?
#12
I have zero experience with CGI, but the way you rebuild script looks very specific. I wrote something equally specific but use f'string.

It appears that all you are trying to do is get the key and value for the MiniFieldStorage, and it looks like there will always be two MiniFieldStorage objects in the list. Instead of trying to replace the parts that are formatted wrong I approached this by getting the parts I am interested in and building the string from fresh.
array_input = "FieldStorage None, None, [MiniFieldStorage 'v_name', 'John' , MiniFieldStorage 'v_sname', 'Aguiar' ]"
 
fields = array_input.replace('FieldStorage None, None, [', '')  # throw away stuff we don't care about
fields = fields.replace('MiniFieldStorage', '').replace(']', '').replace(' ', '')
fields = fields.split(',')  # Get the things we want

# Rebuild the string
vbuild = f'FieldStorage(None, None, [MiniFieldStorage({fields[0]}, {fields[1]}), MiniFieldStorage({fields[2]},{fields[3]})]'
print(vbuild)
Im sure this could be made much better using regular expressions to find MiniFieldStorage and then getting the next two strings.

The end result is still a string, but hopefully a string in the right format for parsing.
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, 08:30 PM
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,757 May-27-2024, 04:54 PM
Last Post: wardancer84
  unable to remove all elements from list based on a condition sg_python 3 1,832 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 3,997 Nov-13-2022, 01:27 AM
Last Post: menator01
  Reading list items without brackets and quotes jesse68 6 7,239 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Remove empty keys in a python list python_student 7 6,061 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,303 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,824 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 2,722 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  .remove() from a list - request for explanation InputOutput007 3 3,128 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  Remove specific elements from list with a pattern Xalagy 3 3,765 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