I want to read below inputs from the console: name and date combination seperated by a comma. For example:
Allegan,11-12-2013
Douglas,29-12-2016
Junkers,27-03-2017
Biruinta,10-04-2014
ABC,27-03-2017
You can simply use split(",")
. Just take input and split it.
name, date = input("Enter something: "). split(",")
print("Name: " + name + " and Date:" + date)
Input: Allegan,11-12-2013
Output: Name: Allegan and Date:11-12-2013
It looks like your reading a csv file ( Comma-separated values ) over stdin. If that is the case you could use the csv module like this:
from sys import stdin
import csv
for row in csv.reader(stdin):
print(row)
['Allegan', '11-12-2013']
['Douglas', '29-12-2016']
['Junkers', '27-03-2017']
['Biruinta', '10-04-2014']
['ABC', '27-03-2017']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.