How to find parenthesis bound strings in python
<p>I'm learning Python and wanted to automate one of my assignments in a cybersecurity class.
I'm trying to figure out how I would look for the contents of a file that are bound by a set of parenthesis. The contents of the (.txt) file look like:</p>

<pre><code>cow.jpg : jphide[v5](asdfl;kj88876)
fish.jpg : jphide[v5](65498ghjk;0-)
snake.jpg : jphide[v5](poi098*/8!@#)
test_practice_0707.jpg : jphide[v5](sJ*=tT@&amp;Ve!2)
test_practice_0101.jpg : jphide[v5](nKFdFX+C!:V9)
test_practice_0808.jpg : jphide[v5](!~rFX3FXszx6)
test_practice_0202.jpg : jphide[v5](X&amp;aC$|mg!wC2)
test_practice_0505.jpg : jphide[v5](pe8f%yC$V6Z3)
dog.jpg : negative`
</code></pre>

<p>And here is my code so far:
</p>

<pre><code>import sys, os, subprocess, glob, shutil

# Finding the .jpg files that will be copied.
sourcepath = os.getcwd() + '\\imgs\\'
destpath = 'stegdetect'
rawjpg = glob.glob(sourcepath + '*.jpg')

# Copying the said .jpg files into the destpath variable
for filename in rawjpg:
    shutil.copy(filename, destpath)

# Asks user for what password file they want to use.
passwords = raw_input("Enter your password file with the .txt extension:")
shutil.copy(passwords, 'stegdetect')

# Navigating to stegdetect. Feel like this could be abstracted.
os.chdir('stegdetect')

# Preparing the arguments then using subprocess to run
args = "stegbreak.exe -r rules.ini -f " + passwords + " -t p *.jpg"

# Uses open to open the output file, and then write the results to the file.
with open('cracks.txt', 'w') as f: # opens cracks.txt and prepares to w
        subprocess.call(args, stdout=f)

# Processing whats in the new file.
f = open('cracks.txt')
</code></pre>

<blockquote>
  <p>I'm learning Python</p>
</blockquote>

<p>If you are learning you should consider alternative implementations, not only regexps. </p>

<p>TO iterate line by line of a text file you just open the file and for over the file handle:</p>

<pre><code>with open('file.txt') as f:
    for line in f:
        do_something(line)
</code></pre>

<p>Each line is a string with the line contents, including the end-of-line char '/n'. To find the start index of a specific substring in a string you can use find:</p>

<pre><code>&gt;&gt;&gt; A = "hello (world)"
&gt;&gt;&gt; A.find('(')
6
&gt;&gt;&gt; A.find(')')
12
</code></pre>

<p>To get a substring from the string you can use the slice notation in the form:</p>

<pre><code>&gt;&gt;&gt; A[6:12]
'(world'
</code></pre>

python