Overview of Delimited Strings¶
Let us get an overview of delimited strings. As part of this topic we will primarily deal with Python objects (not the data in the files).
- At times, we read the text files and the text files might contain delimited lines.
- Also, we might want to read the data from a database or a REST API into the text files. Each line might be delimited records.
- In both the scenarios, we deal with strings. The strings typically contain multiple attribute values separated by a delimiter or separator.
- Comma separated or delimited string –
1,2013-07-25 00:00:00.0,11599,CLOSED
- Pipe
|
separated or delimited string –1|2013-07-25 00:00:00.0|11599|CLOSED
- Tab separated or delimited string –
1\t2013-07-25 00:00:00.0\t11599\tCLOSED
- Tab is special character. When we open the file, we will not see
\t
, instead we see some spaces. We will see an example at a later point in time. But we use\t
to create tab delimited strings
In [1]:
comma_separated = '1,2013-07-25 00:00:00.0,11599,CLOSED'
In [2]:
print(comma_separated)
1,2013-07-25 00:00:00.0,11599,CLOSED
In [3]:
type(comma_separated)
Out[3]:
str
In [4]:
pipe_separated = '1|2013-07-25 00:00:00.0|11599|CLOSED'
In [5]:
print(pipe_separated)
1|2013-07-25 00:00:00.0|11599|CLOSED
In [6]:
type(pipe_separated)
Out[6]:
str
In [7]:
tab_separated = '1\t2013-07-25 00:00:00.0\t11599\tCLOSED'
In [8]:
print(tab_separated)
1 2013-07-25 00:00:00.0 11599 CLOSED
In [9]:
type(tab_separated)
Out[9]:
str