AttributeError: Problem in python
<p>Here is a brief summary of my aims. I have a list of data in the data text file that are basically names or identifiers. The list of names is all on one line and seperated by a space. I want to make each data a seperate line. These data are identifiers. If for instance one name from the original data text file in also present in the big file I want to have that line of data in the big file, i.e. the name and some additional information all on the same line written to a smaller data file. </p>

<p>This is the program that I have started to attempt such a feat. Perhaps this is pushing the limits of my skills but I hope to be able to complete this. </p>

<pre><code>datafile = open ('C:\\datatext.txt', 'r')

line = [item for item in open('C:\\datatext.txt', 'r').read().split(' ') 
                  if item.startswith("name") or item.startswith("name2")]

line_list = line.split(" ")

completedataset = open('C:\\bigfile.txt', 'r')
smallerdataset = open('C:\\smallerdataset.txt', 'w')

trials = [ line_list ]


for line in completedataset:
    for t in trials: 
       if t in line:
           smallerdataset.write(line)

completedataset.close()
smallerdataset.close()
</code></pre>

<p>Here is the error that i receive when i run the program in python:</p>

<pre><code>Traceback (most recent call last):
  File "C:/program3.py", line 7, in &lt;module&gt;
    line_list = line.split(" ")
AttributeError: 'list' object has no attribute 'split'
</code></pre>

<p>I have tried to be very thourough and look forward to your comments. If you have additional questions I will elaborate as needed promptly. All the best and enjoy the rainy weather. </p>

<p>EDIT:</p>

<p>I have made some changes to the program based on suggestions. I have this as my program now:</p>

<pre><code>with open('C:\\datatext.txt', 'r') as datafile:
  lines = datafile.read().split(' ')
matchedLines = [item for item in lines if item.startswith("name1") or item.startswith("othername")]


completedataset = open('C:\\bigfile.txt', 'r')
smallerdataset = open('C:\\smallerdataset.txt', 'w')

trials = [ matchedLines ]


for line in completedataset:
    for t in trials: 
       if t in line:
           smallerdataset.write(line)

completedataset.close()
smallerdataset.close()
</code></pre>

<p>and i'm getting this error now:</p>

<pre>
Traceback (most recent call last):
  File "C:/program5.py", line 17, in 
    if t in line:
TypeError: 'in ' requires string as left operand, not list
>>> 
</pre>

<p>Thank you for you're continued help in this matter. </p>

<p>EDIT 2:</p>

<p>I have made several changes and now I'm getting this error:</p>

<pre>
Traceback (most recent call last):
  File "C:/program6.py", line 9, in 
    open('C:\\smallerdataset.txt', 'w')) as (completedataset, smallerdataset):
AttributeError: 'tuple' object has no attribute '__exit__'
</pre>

<p>Here is my program as it stands now:</p>

<pre><code>with open('C:\\datatext.txt', 'r') as datafile:
  lines = datafile.read().split(' ')
matchedLines = [item for item in lines if item.startswith("nam1") or item.startswith("ndname")]


with (open('C:\\bigfile.txt', 'r'),
      open('C:\\smallerdataset.txt', 'w')) as (completedataset, smallerdataset):
  for line in completedataset:
    for t in matchedLines:
      if t in line:
        smallerdataset.write(line)

completedataset.close()
smallerdataset.close()
</code></pre>

<p>How can I get around this hurdle?</p>
