woooee 814 Nearly a Posting Maven

You want a separate string to hold the time

now=time.asctime()
now=now.replace(":", " ")
print now

TimeStr = [ "The time is currently " + now, "Right now its " + now, "It's " + now, now ]
 
if phrase == "whats the time":
    speech.say(random.choice(TimeStr))
#
##   you can also use datetime and access month, day, hour, etc individually
now = datetime.datetime.today()
print "\n", now
print now.year, now.hour
woooee 814 Nearly a Posting Maven

Tix, additional widgets for tkinter, has a notebook that may or may not help. The code is available from here http://tix.sourceforge.net/dist/current/man/html/TixCmd/TixIntro.htm#M28

woooee 814 Nearly a Posting Maven

The problem they are running into is replacing "the" with "xxx" for example, but not finding and replacing "then" with "xxxn". I would suggest using split() to get the words, only replacing exact matches, and join() to reconstruct the sentence. If there are punctuation marks like commas in the phrase then that also has to be taken into account. But you are 90% there from the last two posts and that is enough.

woooee 814 Nearly a Posting Maven

I wondered why this has been asked many many times in the last few days both here and on python-forum. At least you are honest enough to admit that it is homework. You should be able to find this asked and answered many times already. If you do want help, you'll have to make an effort and post some code to be critiqued.

woooee 814 Nearly a Posting Maven

With Python you would use a list of lists for each group of records. Hopefully there is a similiar method in scipy. (If you were very, very lucky, each group would have the same number of records, you can use a counter to split them)

data_list=[
"#BEGIN 1",
"1 .1 .2",
"2 .8 .3",
"3 .9 .5",
"#END",
"",
"#BEGIN 2",
"1 .1 .3",
"2 .8 .4",
"3 .9 .6",
"#END",
"",
"#BEGIN 3",
"1 .1 .4",
"2 .8 .5",
"3 .9 .7",
"#END"]

group_list=[]
junk_list=[]
for rec in data_list:
   if rec.strip().startswith("#BEGIN") and (len(junk_list)):
      group_list.append(junk_list)
      junk_list=[]

   else:
      if (len(rec)) and (not rec.startswith("#")):
         junk_list.append(rec)
if len(junk_list):     ##   final group
   group_list.append(junk_list)
for group in group_list:
   print group
woooee 814 Nearly a Posting Maven

In pseudo-code it would be something like this assuming a class format (ignoring case for now)

def __init__(self):
          self.orig_list=[ "Original", "words", "you", "want", "to", "test"]
          self.new_list = orig_list[:]  ## first pass - to be used by test_list

     def compare_when_text_changed():
          test_list=self.new_list[:]
          self.new_list=[]
          for word in test_list:
             if word.startswith(self.entered_in_qt_edit_box):
                  self.new_list.append(word)

          ## self.new_list now contains the words that match so far
          ## update list box from self.new_list

     ## not necessary to return anything since self. is used.

I thought that someone would have posted code to do this, but coding this could become so funky that no one wants to put it out there on the internet I guess.

woooee 814 Nearly a Posting Maven

list = file.readlines()

List is a reserved word in python and should not be used as a variable's name. Use something like data_list = file.readlines()

woooee 814 Nearly a Posting Maven

A Google codesearch came up with only the do it yourself, the gist of which used textChanged. This snippet was in one of the hits

searchLabel = QtGui.QLabel(" Search", self)
        hLayout.addWidget(searchLabel)
        self.searchText = QtGui.QLineEdit()
        searchLabel.setBuddy(self.searchText)
        hLayout.addWidget(self.searchText)

        self.treeWidget = self.createTreeWidget()
        vLayout.addWidget(self.treeWidget)

        self.connect(self.searchText,
                     QtCore.SIGNAL('textChanged(QString)'),
                     self.treeWidget.searchItemName)
woooee 814 Nearly a Posting Maven

readline reads until it hits a line termination, (\n=decimal 10 in ascii, or \r\n=decimal 13 & 10, depending on the OS). Decimal 26 is generally used in ascii for end of file, which would terminate a file read also. So a byte is read and if it is not a termination character it is stored in a string and another byte is read, etc. We could do this ourselves but it's nice to have these internals handled for us.

woooee 814 Nearly a Posting Maven

python.org also has a tutorial. Try them all. Some parts of one will make more sense, and in another part, one of the other tutorials will be better. http://docs.python.org/tut/tut.html

woooee 814 Nearly a Posting Maven

I will only give you a hint since the answer is obvious. The variable is named self.tab_1.

woooee 814 Nearly a Posting Maven

And os.path.isfile(name) will work for a file. Note that name is the full name, so include the full path.

woooee 814 Nearly a Posting Maven

I'm still using qt3, but it should be somewhere in the vicinity of this

self.tab_1 = QWidget()
        self.tab_1.setObjectName("Create Tab")
        self.tabs.addTab(self.tab_1, "")
        self.layout.addWidget(self.tabs)
woooee 814 Nearly a Posting Maven

There is not enough code here or enough of the error message to help you. If you are not using a class,

the "self." will yield errors. This is an example using QVBoxLayout that hopefully will help.

#****************************************************************************
#** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 phil Exp $
#**
#** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
#**
#** This file is part of an example program for PyQt.  This example
#** program may be used, distributed and modified without limitation.
#**
#*****************************************************************************/

import sys
from qt import *

class LineEdits(QGroupBox):
    def __init__(self, parent = None, name = None):
        QGroupBox.__init__(self, 0, Qt.Horizontal, "Line Edits", parent, name)

        self.setMargin(10)
        
        vbox = QVBoxLayout(self.layout())
        
        row1 = QHBoxLayout(vbox)
        row1.setMargin(5)

        label = QLabel("Echo Mode: ", self)
        row1.addWidget(label)

        combo1 = QComboBox(False, self) 
        row1.addWidget(combo1)
        combo1.insertItem("Normal", -1) 
        combo1.insertItem("Password", -1) 
        combo1.insertItem("No Echo", -1)

        self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged)
        self.lined1 = QLineEdit(self)
        vbox.addWidget(self.lined1)

        row2 = QHBoxLayout(vbox)
        row2.setMargin(5)

        label = QLabel("Validator: ", self)
        row2.addWidget(label)

        combo2 = QComboBox(False, self)
        row2.addWidget(combo2)
        combo2.insertItem("No Validator", -1)
        combo2.insertItem("Integer Validator", -1)
        combo2.insertItem("Double Validator", -1)
        
        self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged)

        self.lined2 = QLineEdit(self)
        vbox.addWidget(self.lined2)

        row3 = QHBoxLayout(vbox)
        row3.setMargin(5)

        label = QLabel("Alignment: ", self)
        row3.addWidget(label)

        combo3 = QComboBox(False, self)
        row3.addWidget(combo3)
        combo3.insertItem("Left", -1)
        combo3.insertItem("Centered", -1)
        combo3.insertItem("Right", -1)

        self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged)
        self.lined3 = QLineEdit(self)
        vbox.addWidget(self.lined3)

        row4 = QHBox(self)
        vbox.addWidget(row4)
        row4.setMargin(5)

        QLabel("Read-Only: ", row4)

        combo4 = QComboBox(True, row4)
        combo4.insertItem("False", -1)
        combo4.insertItem("True", -1)

        self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged)

        self.lined4 = QLineEdit(self)
        vbox.addWidget(self.lined4)

        self.lined1.setFocus()

    def slotEchoChanged(self, i):
        if i == 0:
            self.lined1.setEchoMode(QLineEdit.Normal)
        elif i == 1:
            self.lined1.setEchoMode(QLineEdit.Password)
        elif i == 2:
            self.lined1.setEchoMode(QLineEdit.NoEcho)

        self.lined1.setFocus()

    def slotValidatorChanged(self, i):
        if i == …
woooee 814 Nearly a Posting Maven

There are various tutorials on the web as well as on python.org . Try one of the tutorials so you can present some code that we can help you with.
http://www.faqts.com/knowledge_base/view.phtml/aid/23158/fid/552

woooee 814 Nearly a Posting Maven

I get no returned rows. I use the following SQL code to query:
SELECT * FROM fdi.fdiresults;

fdi.fdiresults seems odd for a table name. Try "SELECT tablename FROM pg_tables where tablename not like 'pg_%'" and see what it gives you for a table name. (Note that semicolons are not used in Python.) I am not familiar with PostGIS, but generally a select statement is more like 'cur.execute( "SELECT * FROM tablename")'.

PoovenM commented: Thank you for the tip :) +2
woooee 814 Nearly a Posting Maven

Pypy is the faster Python. I have never tried it though. http://codespeak.net/pypy/dist/pypy/doc/home.html

woooee 814 Nearly a Posting Maven

Which GUI toolkit are you using?

woooee 814 Nearly a Posting Maven

If you are using raw_input or the variable is already a string, then try isdigit(). This of course assumes that you aren't using floating point numbers. If you are then you will have to use a try/except converting the string to a float.

get_num=raw_input("Enter a number ")
print get_num,
if get_num.isdigit():
   if int(get_num) > 0:
      print "is integer and is positive"
   else:
      print "is integer and is NOT positive"
## this will never execute since a minus sign, "-", is not a digit
else:
   print "is NOT a number"
woooee 814 Nearly a Posting Maven

You can use a while loop if you prefer

list2 = [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98] 
 
stop = len(list2)
ctr = 0
while ctr < stop:
   print "%-5d " % (list2[ctr]),
   ctr += 1
   if 0 == ctr % 3:   ## new line
      print 
print
woooee 814 Nearly a Posting Maven

First
while list2[k] != -1:
will never exit because -1 is not in list2 so you will always exceed the limits of the loop. Generally, this is done with a for loop.

list2 = [23, 764, 12, 54, 83, 2, 543, 890, 1235, 453, 98] 
 
stop = len(list2)
for k in range(0, stop, 3):   ## step=3
   for m in range(0,3):        ##  print 3 per line
      this_el = m+k            ##  k + 0-->2 = this element in list2
      if this_el < stop:
##                minus 5d=left justified
         print "%-5d " % (list2[this_el]),   ## note the comma at the end
   print                                          ## new line
woooee 814 Nearly a Posting Maven

Try one of the online books or tutorials. This is a link to the "Dive Into Python" chapter on string formatting http://diveintopython.org/native_data_types/formatting_strings.html

woooee 814 Nearly a Posting Maven

And if you are using a list, then the individual variable for each random number isn't necessary.

computer_list = []
for j in range(0, 4):
   computer_list.append(random.randint(0, 30))
print "The computer's numbers are", computer_list
#
#
#    To enter all 4 numbers on one line, use the split method
numbers = raw_input("Enter 4 numbers between 0-30 separated by a space ")
numbers_list = numbers.split()
if len(numbers_list) != 4:
   print "4 numbers were not entered"
else:
   lit = "Loser"
   for number in numbers_list:
      if int(number) in computer_list:
         lit = "You found number " + number
   print lit
woooee 814 Nearly a Posting Maven

You may also want to look at the radiobutton widget. A slight modification of one of Grayson's examples

from Tkinter import *

root = Tk()
root.title('Radiobutton')

fruit=[('Passion fruit\nSecond line', 1), ('Loganberries', 2), 
        ('Mangoes\nin syrup', 3), ('Oranges', 4), 
        ('Apples', 5), ('Grapefruit', 6)]
var = IntVar()
for text, value in fruit:
    Radiobutton(root, text=text, value=value, variable=var).pack(anchor=W)
var.set(3)
root.mainloop()
woooee 814 Nearly a Posting Maven

You can put as many lines as you want into a listbox. If there are more lines than the listbox will display, then you also want to add a scrollbar.

import Tkinter                                                                  
                                                                                
top = Tkinter.Tk()                                                              
top.geometry( "100x100+10+10" )                                                 
top.minsize( 200, 200 )                                                         
                                                                                
listbox = Tkinter.Listbox( top, height=6, width=20, font=('Fixed', 14) )        
scrolly = Tkinter.Scrollbar( top, command=listbox.yview )                       
listbox.configure(yscrollcommand=scrolly.set)                                   
                                                                                
scrollx = Tkinter.Scrollbar( top, orient=Tkinter.HORIZONTAL, command=listbox.xvi
listbox.configure(xscrollcommand=scrollx.set)                                   
                                                                                
lit = [ "aaa", "bbbbb", "ccccccc", "dd", "e", \                                 
        "fff", "ggggg", "hhhhhhh", "jj", "m", "nn" ]                            
for item in range(10):                                                          
    this_lit = lit[item]                                                        
    new_item = "%(item)d  %(this_lit)-10s  %(this_lit)-10s  %(this_lit)-10s" % v
    listbox.insert(Tkinter.END, new_item)                                       
                                                                                
cont = Tkinter.Button(top, text='CONTINUE',                                     
       command=top.quit, bg='red', fg='white' )                                 
cont.pack(side="bottom", fill=Tkinter.X, expand=1)                              
scrolly.pack(side="right", fill="y")                                            
scrollx.pack(side="bottom", fill=Tkinter.X, expand=1)                           
listbox.pack(side="left")                                                       
                                                                                
top.mainloop()
woooee 814 Nearly a Posting Maven

Use a dictionary with the key="ABCD". If the key is found in the dictionary compare the values. If the current rec has a lower value, replace the rec for that dictionary item.

woooee 814 Nearly a Posting Maven

What you have done is the easiest way to do it because you have control. Remember that you have to parse the string no matter what the method. Even when Python has a method to do it, the string still has to be parsed, so you should have no problem with doing it yourself. It would be slightly more efficient to find the second "\" and slice there, but is more trouble than it is worth.

woooee 814 Nearly a Posting Maven

out_file = open("address.txt", "w")

Change this to
out_file = open("address.txt", "a")
You want to "a"=append to, not "w"=write over. And to start you out

if choice == 2:
    in_file = open("address.txt", "r")
    text = in_file.readlines()
    in_file.close()
    print text
woooee 814 Nearly a Posting Maven

The dictionary principle remains the same. It doesn't matter if there are multiple words or just one word.
dictionary key = what is in file = Store2 "Soap of Marseille" --> look up "Soap of Marseille"
so store_dic["Soap of Marseille"] = "SOM"
If you are unsure of punctuation, use isalpha to eliminate spaces, etc for both the key and the look up phrase.
To print the dictionary:
.for key in store_dic.keys():
......print store_dic[key], key --> "SOM Soap of Marseille"
If this doesn't explain it, post your code. It is more difficult to explain in the abstract.

woooee 814 Nearly a Posting Maven

You could also replace the following:

reducedList = [n for n in listParagraph if len(n) == len(word)]
## replace with this
reduced_list = [n for n in list_paragraph if word == n.lower()]
if len(reduced_list):
    print "The word", "'" + word + "'", "occurs", len(reduced_list), "times in this section."
else:
    print "The word", "'" + word + "'", "does not occur in this section of text."
#
# anyway, here is another solution
#
paragraph = '''This is a test sentence.  We will look for hi in this sentence.
If we find 'hi', we want to keep count of it.  Remember, hi
can be Hi or hi.  Hi can also have characters before or
after it ie (hi. hi, hi:).  There should be a total of 10 'hi'
in this sentence, not any more for words like 'this' or
'hippo' or 'hiccups' '''

word='hi'
p_list = paragraph.split()
ctr=0
for p_word in p_list:
   p_word = p_word.lower()
   if p_word == word:
      ctr += 1
   elif not p_word.isalpha():     ## has non-alpha characters
      new_word = ""
      for chr in p_word:
         if chr.isalpha():
            new_word += chr
      if new_word == word:
         ctr += 1
print "The word '%s' was found %d times" % (word, ctr)
woooee 814 Nearly a Posting Maven

Sorry for the late post. I just noticed this. Your button line should read
self.connect(button, SIGNAL("clicked()"), self, SLOT("close()"))
I'm thinking of doing a PyQt tutorial, or at least a list to links on using PyQt(4), thread on DaniWeb. Do you have any links that might be of interest?

woooee 814 Nearly a Posting Maven

Use the datetime module. Note that using the separate variable, start_time, is not necessary.
start_time = datetime.datetime(2008, 06, 03, 12, 30, 00)
diff_time = datetime.datetime(2008, 06, 03, 12, 50, 00) - start_time
print diff_time.seconds, type(diff_time)
print "duration in minutes =", diff_time.seconds/60
http://effbot.org/librarybook/datetime.htm
http://blog.doughellmann.com/2008/03/pymotw-datetime.html

woooee 814 Nearly a Posting Maven

if file_nm.endswith(".dbf") # assumes no dirs end with dbf
requires a colon at the end
if file_nm.endswith(".dbf"):

recs = read_file_recs_using_dbfpy(file_nm)
is just a pseudo-code statement for any routine that will read the dbf file and return the data in some form that can be used by the program.

woooee 814 Nearly a Posting Maven

Sorry, I meant slice, rec[begin:end], not rec.split(). Also, you possibly want a separate program file for 'read the dbf' and then would import it into 'read the XML' to keep it from getting too confusing as can happen when everything is in one file.

woooee 814 Nearly a Posting Maven

I have a .dbf file which contains three fields: an id (1), a Mapsheet # (455626) and finally a Mapsheet Name that corresponds to the Mapsheet# ( Big Lake ).

I assume you are using something like dbfpy to read the file, so populating the dictionary would be fairly simple. The following is just pseudo code.

import os

class test_class:
   def __init__(self, dbf_dir):
      self.map_dic={}
      file_names = os.listdir(dbf_dir)
      for file_nm in file_names:
         if file_nm.endswith(".dbf")     ## assumes no dirs end with '.dbf'
            self.read_dbf(file_nm)
      print self.map_dic()

   def read_dbf(self, file_nm):
      recs = read_file_recs_using_dbfpy(file_nm)
      for rec in recs:
         mapsheet_name = rec[1]     ## or whatever the form
         mapsheet_num = rec[3] 
         self.map_dic[mapsheet_num] = mapsheet_name

TC=test_class( "dbf_dir_name" )

What I want to do is read in each .xml file, search for this line:
<title Sync="TRUE">4555626.tif</title>
And replace the 4555626.tif text with the matching record from the .dbf table - (Big Lake)

So you want to use rec.find('<title Sync="TRUE">') and rec.find("</title>"). If both are found then this is the correct record and you can then calculate the beginning and end positions for a rec.split(). You can then look the number up in self.map_dic and use the corresponding name.

woooee 814 Nearly a Posting Maven

This will traverse all of the subdirectories and do what I think you want it to do. I have added some print statements which is probably enough by itself to answer your question as is shows what the root, dirs, and files contain. If you want to limit it to 3 levels, then you will want to store root and the first 2 dirs and pass them as basedir and then just use the files for that particular directory. If you are on a Linux system, pipe the output to a file if there are a lot of files and dirs. It will be easier to read. There are other ways of doing this using an os.path.walk() callback but I assume you want to continue down this road as you are following the book.

import os, os.path, stat, time
from datetime import date, timedelta

dirsNotUsed = []
def getdirs(basedir, age):
    for root, dirs, files in os.walk(basedir):
        print "root =", root
        print "dirs =", dirs
        print "files =", files

        found = 1
        for file in files:
           found_file = datecheck(root, file, age)
           if not found_file :             #At least one file is not old enough
               found = 0

           """ or backup all of the files that are old enough
           if found_file:
              backup_list.append(os.path.join(root, file))
           """

        if found:
           archive(root, files)

def datecheck(root, file, age):
    basedate = date.today() - timedelta(days=age)
    fname = os.path.join(root, file)
    used = os.stat(fname).st_mtime    # st_mtime=modified, st_atime=accessed
    year, day, month = time.localtime(used)[:3]
    lastused = date(year, day, month)
    if lastused < basedate:             #Gets …
woooee 814 Nearly a Posting Maven

One advantage of the class structure is that you don't use globals but self.var_name.

import random
class Cards(object):
    def __init__(self):
        self.cards = {2:4,3:4,4:4,5:4,6:4,7:4,8:4,9:4,10:16,'ace':4}
        self.player = []
        self.playert = 0
        self.comp_tot=0
        self.comp = []
        print self.playert,'hi'
        print "The Game is Blackjack"
    def draw(self):
        f = self.cards.keys()
        a = random.choice(self.cards.keys())
        self.cards[a]-=1
        if self.cards[a] == 0:
            del self.cards[a]
            if len(self.cards)==0:
                print "out of cards"
                return False
        return a
    def First_turn(self):
        print self.comp_tot
        print self.cards
        print self.player
        print self.playert
        card1=self.draw()
        card2=self.draw()
        card2='ace'
        if card1 is not 'ace' and card2 is not 'ace':
            self.player.append(card1)
            self.player.append(card2)
            value=card1+card2
            print "your cards are:",card1,"and",card2
            print value
            playert+=value
        else:
            self.player.append(card1)
            self.player.append(card2)
            count =0
            if card1 =='ace':
                count = 'c1'
                if self.playert+11>21:
                    val = 1
                else:
                    val=11
            elif card2 == 'ace':
                count ='c2'
                if self.playert + 11 >21:
                    val = 1
                else:
                    val = 11
            
                

c = Cards()
c.First_turn()
woooee 814 Nearly a Posting Maven

You can also use the var.find("-s") method for strings and then slice it. It depends on if -s"password" is the only thing in that record or not.

woooee 814 Nearly a Posting Maven

To work the way you want, your original code would have been
c=lasin ()
sum, pile=dela(c)
ordna(pile)
If the function returns two variables, but the calling line only receives one variable, then python returns one tuple, because you only have one block of memory allocated for the return.

woooee 814 Nearly a Posting Maven

We had a topic like this a short while ago. The easiest/most efficient method is to use two sets and compare with set1.difference(set_2) and vice-versa. Also, python has difflib which may or may not be more than you want. http://docs.python.org/lib/differ-examples.html

woooee 814 Nearly a Posting Maven

It might be helpful to take a look at the "Starting Python" at the top of this forum. There are 5 pages, so don't have to wade through 100's of pages to get you started.

woooee 814 Nearly a Posting Maven

Obviously this is not a list of numbers, so you want to take a look at the function that returns this. Add print statements to see what is going on throughout the program until you understand what is happening

woooee 814 Nearly a Posting Maven

You best bet would be to ask the person on python-forum.org who wrote this program. They would understand it better than anyone else. No one wants to spend their time answering a question that has already been answered on another forum.

woooee 814 Nearly a Posting Maven

You are probably calling self.Recite without an if statement. An example

class LawRecite:
   def __init__(self):
      self.ThreeLaws = False
      ## only if ThreeLaws is True
      if self.ThreeLaws:
         self.Recite()
woooee 814 Nearly a Posting Maven

AttributeError: LawRecite instance has no attribute 'ThreeLaws'
Is the program searching for a definition for "ThreeLaws"?

It is searching for self.ThreeLaws in the LawsRecite class. I just ran the test snippet that I posted and it works fine so check the spellings for self.ThreeLaws and LawRecite on your end. Also, you will avoid potential problems if you don't use spaces in directory or file names. "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py",

woooee 814 Nearly a Posting Maven

If it is a self.variable_name, then it is global throughout the class. I'm too tired to test this snippet so if there are other problems, post back.

class LawRecite:
   def __init__(self):
      self.ThreeLaws = False
      self.Recite()

   def Recite(self):
      ##speaker.Speak(LOR1)
      ##speaker.Speak(LOR2)
      ##speaker.Speak(LOR3)
      ##speaker.Speak(random.choice(LOR4))
      print "ThreeLaws original =", self.ThreeLaws

      self.ThreeLaws=True
      print "ThreeLaws changed =", self.ThreeLaws

      self.ThreeLaws=3
 
LR = LawRecite()
print "after changing to 3 =", LR.ThreeLaws
woooee 814 Nearly a Posting Maven

You may have more than one block of memory named "LawRecite". If you assign True in a loop or function then it is local to that loop/function and will be destroyed when you exit unless you return the value from the function. Change any variable names that are in a function and are the same as any outside the function/loop. That should clear things up. Also, "if True" and "while True" are redundant as vegaseat already pointed out. It should be

if LawRecite == True:
    print 'Lets talk about the three laws of Robotics'
    ## while LawRecite == True:   redundant
    speaker.Speak(LOR1)
    speaker.Speak(LOR2)
    speaker.Speak(LOR3)
    speaker.Speak(random.choice(LOR4))
else:
    speaker.Speak('Yes please what?')

If this doesn't help, please post more of the code in context.

Edit: This should definitely be a class. Then you can use self.LawRecite throughout and it will be the same variable. If the program is not using a class, someone here will probably help rearrange the code into the class structure.

woooee 814 Nearly a Posting Maven

The problem is I need to take the names of the images in Directory A and apply them to the images in Directory B.

What does this mean? Rename a file with some unknown name combination? See if a name in is both dirs?

woooee 814 Nearly a Posting Maven

And apparently a variable as well
readLines = readLines(line,lines,lineNumber)
isPageValid = isPageValid(testLine,validPages)

Try this instead

def isPageValid(testLine,  validPages_list):
   ##isPageValid = False    <----- Not Used
   for valid_page in validPages_list:
      if testLine in valid_page:     ## or do you want
                                     ## if valid_page in testLine ?
         return True
   return False
woooee 814 Nearly a Posting Maven

To copy a list you would use
a3 = a[:]
print a3

If you don't want an exact copy you would append to another list

a=['city','village','town','capital']
a3=[]
for x in a:
   print "x in a =", x
   if x.startswith( "c" ):
      print "     appending", x, "to a3"
      a3.append(x)
print a3