Python : Splitting a value into two and assigning into two different variable
<p>I am trying to get a string from a file that has a start and end date range as below:</p>

<pre><code>"Date Range = January 1, 2001 to December 24, 2008"
</code></pre>

<p>I have to pick this date range (January 1, 2001 to December 24, 2008) and split it and assign it into 2 different variables. I am able to fetch the date range and split them, but when assigning I get an error.</p>

<pre><code>file_path = open("C:\\Users\\vinnu\\Desktop\\ARF_LS00006493_339313_Tremont.txt")
content = file_path.read()

#find and pick the date range
size = len(content)
start =0
while start &lt; size:
    start = content.find("Date Range: ",start)
    start = start if start != -1 else size
    #fetch only till the end of line
    end = content.find("\n", start)
    end = end if end != -1 else size
    date_range = (content[start+12:end])
    start = end + 1
    #printing test
    print (date_range)

    #split
    date1,date2= date_range.split(' to ')
    print (date1)
    print (date2)
</code></pre>

<p>I get the below output with an error:</p>

<pre><code>January 1, 2001 to December 24, 2008
January 1, 2001
December 24, 2008

Traceback (most recent call last):
  File "C:/Users/vinnu/Desktop/split_eg3.py", line 19, in &lt;module&gt;
    date1,date2= date_range.split(' to ')
ValueError: not enough values to unpack (expected 2, got 1)
</code></pre>