In: Computer Science
So currently I am working on some SQL with python which is linked to my database and I am stuck on a split problem. So in the program it connects to the database and then next you input either list, add, update, remove or allocate. So lets say I want to add a new data into the database you just need to write: update -name='Ava - #2' -class=2.
After you type this there is a variable called val which does the strip and split.
So as of right now what I have done is:
val = input('> ').strip().lower() parts = val.split(' ') print(parts)
So if I input the following: update -name="Nile Adam" -class=2
I expect the following output: ['update', '-name="Nile Adam"', '-class=2']
However the output I get is: ['update', '-name="Nile', 'Adam"', '-class=2']
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
# If you want to get it in lower case, use lower() here
val = input('> ').strip()
parts = val.split(' ')
# We can use regex for this problem but it's too complex.
# We can simply go for appending the first and last names as
follows
# Get the name here
name = parts[1]+" "+parts[2]
# Create the parts as required
parts = [parts[0], name , parts[3]]
print(parts)
===============================
If you want it in lower case...