woooee 814 Nearly a Posting Maven

The first iteration of the for loop runs, but nothing else.

That is because of the "if counter > 0"

    for counter,row in enumerate(reader):
        if counter > 8: 
            continue

You also have an extra semicolon at the end of this statement

   Cur.execute("INSERT INTO vulnerabilities(IP) VALUES ('vuln_0');")

I will try to look at this again tonight and provide a working example, so post back if you get it working before that.

woooee 814 Nearly a Posting Maven

A class is a prototype, i.e. it is only a potential object.

class HelloWorld :

        def __init__(self):

            print("Hi")

        def talk(self ,name):

            self.nameA = name
            print("Hello", self.nameA)

HW1=HelloWorld()     ## calls the class or creates an actual instance
HW2=HelloWorld()     ## a second, separate instance

HW1.talk("Name 1")
HW2.talk("Name Two")

print HW1.nameA
print HW2.nameA
woooee 814 Nearly a Posting Maven

Your question was already answered in this post with a demo of converting some words using a dictionary. You insist on using re which produces the undesired results, instead of a dictionary lookup. There is nothing that anyone can do to make bad code work.

woooee 814 Nearly a Posting Maven

Duplicate of this post

woooee 814 Nearly a Posting Maven

All widgets have config options, config options for the Label Click Here or Click Here Your code modified to show some other techniques.

import Tkinter as tk
from tkFileDialog import askopenfilename
import os

class En2De():
    def __init__(self):
        self.master=tk.Tk()
        self.master.geometry("+300+10")
        self.master.title('A Translater for Translating Documents From English to German')
        self.createWidgets()
        self.master.mainloop()

    def createWidgets(self):
        quitButton = tk.Button(self.master, text='Quit',
                          command=self.master.quit, bg="lightblue",
                          width=10)
        UploadButton = tk.Button(self.master,
                           text='UPLOAD FILES HERE',
                           command= self.uploadButton,
                           width=20)
        self.Label1=tk.Label(self.master)
        self.Label2 = tk.Label(self.master,text='Please Select a language:')
        self.optionlist = ('--Select--','Afrikaans','Albanian','English','French','German','Hindi','Tamil','Telugu')
        self.var=tk.StringVar()
        self.var.set(self.optionlist[0])
        self.om=tk.OptionMenu(self.master, self.var,*self.optionlist)#om=optionmenu
        #self.ConvertButton=tk.button(self, text'Convert Files',command=self.convertButton)
        #Registering it to the window
        quitButton.grid(row=4, sticky=tk.NE)
        UploadButton.grid(row=2)
        self.Label1.grid(row=3)
        self.Label2.grid(row=0)
        self.om.grid(row=1)


    def display_message(self, msg):

        def update_counter():
            lb.configure(text="%s\n %d" % (msg, self.ctr))
            self.ctr -= 1
            if self.ctr > -1:
                lb.after(1000, update_counter)
            else:
                tlv.destroy()

        tlv=tk.Toplevel(self.master, takefocus=True)
        tlv.geometry("+320+50")
        lb=tk.Label(tlv, bg="yellow")
        lb.grid()
        self.ctr = 5
        update_counter()

    def uploadButton(self):
        filename = askopenfilename(filetypes=(("Template Files","*.tplate"),("Portable Document File","*.pdf"),("Text File","*.txt"),("Word Document","*.docx"),("Word 97-2003 Document","*.doc"),("All Files","*.*")))
        if filename:
            option = self.var.get()
            if option != self.optionlist[0]:
                self.Label1.config(text=filename,
                                    fg="red", bg="white")
            else:
                self.display_message("First select a language")

Translater = En2De()
woooee 814 Nearly a Posting Maven

It is replacing every 'a" with "ein". A tutorial on using a dictionary to map from English to Spanish

## CamelCase is reserved for classes in Python
dic_word= {
    'a':'ein',
    'an':'eine',
    'able':'KOmmen',
    'about':'gegen',
    'above':'Uber',
    'absence':'Abwesenheit',
    'absent':'abwesend',
    'accent':'Betonung',
    'accept':'akzeptieren',
    'according':'nach',
    'acquainted':'kennen',
    'across':'uber'
}

for word in ["a", "able", "acquainted"]:
    print word, "-->", dic_word[word]
woooee 814 Nearly a Posting Maven

For starters you will have to load/open and read the file Post back when you have this coded (whether it works or not) with a sample of input and the output you would like.

woooee 814 Nearly a Posting Maven

use canvas.create_image instead of configure, and then place whatever objects on top of it.

woooee 814 Nearly a Posting Maven

Python does have a goto add on Click Here but it was an April Fool's joke so I don't know if it works or not (and don't care as I will not be using it).

woooee 814 Nearly a Posting Maven

Once you get the value it is a normal variable and you can do anything with it that you can do to a normal variable. I would suggest that you consider putting everything under one class instead of here's a function, there's a class, here's another function, etc.

try:
    import Tkinter as tk     ## Python 2.x
except ImportError:
    import tkinter as tk     ## Python 3.x

def another_function(input_var):
    print "another function", input_var

class TestClass():
    def __init__(self):
        root1 = tk.Tk()
        root1.title("Vreme")
        naziv = "Vreme"
        L1 = tk.Label(root1, text="Zadržavanje: ")
        L1.place(x=10, y=30)
        self.E1 = tk.Entry(root1, bd = 2)
        self.E1.insert(0, "Test string")
        self.E1.place(x=100, y=30)
        root1.geometry("300x100+300+200")
##    tk.Button(root1, text="OK", command = lambda: izmeni(E1.get(),root1,vreme1,naziv), width=10).place(x=130, y=65)
        tk.Button(root1, text="OK", command = self.izmeni, width=10).place(x=130, y=65)
        root1.mainloop()

    def izmeni(self):
        value = self.E1.get()
        print "izmeni -->", value
        another_function(value)
        self.function_in_class(value)

    def function_in_class(self, input_var):
        print "functionin_class -->", input_var

TC=TestClass()
woooee 814 Nearly a Posting Maven

There is a typo in get_average that you should be able to run down from the error messages, or at least begin to learn how. Using descriptive variable names would help you with this, as well as help us understand the program. Print the return from get_average and see if it can be summed. Note that get_average returns a kind of sum of averages, not the average. Also, you should loop through containers like a dictionary so your funtion can handle containers that have any number of items instead of

return average(p[1]) + average(p[2]) + average(p[3])

Usually we test programs with known values that should produce known results to tell if the program is calculating correctly or not, so what are the results supposed to be?.

woooee 814 Nearly a Posting Maven

First, remove punctuation (? , . etc). Next all words should be lower() case as an upper case word is different to the computer than a lower case word. To print use the dictionary's key as below, although this code does not do any of the other above suggestions

data="""I love the python programming
 How love the python programming?
 We love the python programming
 Do you like python for kids?
 I like Hello World Computer Programming for Kids and Other Beginners."""

count = {}
for word in data.split():
    if word not in count:
        count[word] = 0
    count[word] += 1

## access the dictionary by key
for word in count:
    print "The word", word, "was found", count[word], "times"

print "\nThere are %d unique words (if Upper and lower case," % (len(count))
print "and words with punctuation, are different words)"
woooee 814 Nearly a Posting Maven

You append everything to converted as one list, i.e. you have to use a sub-list and append it each time the list breaks.

eq= ['MPNRRRCKLSTAISTVATLAIASPCAYFLVYEPTASAKPAAKHYEFKQAASIADLPGEVLDAISQGLSQFGINL',
      'MQLVDRVRGAVTGMSRRLVVGAVGAALVSGLVGAVGGTATAGAFSRPGLPVEYLQVPSPSMGRSELPGWLQA',
      'GLVGLAGGAATAGAFSRPGLPVEYLQVPSPSMGRDIKVQFQSGGNNSPAVYLLDGLRAQDDYNGWDINTPAFEWACGKAGCQTYKWETFLTSELPQWLSANRAVKPTGSAAIGLSMAGSSAMILAAYHPQQFIYAGSLSALL']

polarity = { 'A': 0.000, 'R': 52.000, 'N':  3.380, 'D': 49.700, 'C':  1.480,  
             'Q': 3.530, 'E': 49.900, 'G':  0.000, 'H': 51.600, 'I':  0.130,  
             'L': 0.130, 'K': 49.500, 'M':  1.430, 'F':  0.350, 'P':  1.580,  
             'S': 1.670, 'T':  1.660, 'W':  2.100, 'Y':  1.610, 'V':  0.130, 
            }

each_list = []
for x in seq:
    converted = []  ## zero elements for each new "x"
    seq2 = x[0:39]   
    for y in seq2:
        converted.append(polarity[y]) 
    each_list.append(converted)  ## as sub-list
for convert in each_list:
    print convert
woooee 814 Nearly a Posting Maven

You do not test for the password for the user so if any user's password is found it will return True. This works for me but again will accept any user's password (and note the added print statements to see what is happening).

import crypt

line="victim: HX9LLTdc/jiDE: 503:100:Iama Victim:/home/victim:/bin/sh"
cryptPass = line.split(':')[1].strip(' ')
salt = cryptPass[0:2]
print "cryptPass",  cryptPass, salt

test_file="""apple
orange
egg
lemon
grapes
secret
strawberry
password"""

dictFile = test_file.split("\n")  
for word in dictFile:
    cryptWord = crypt.crypt(word, salt)
    print "     ", cryptWord, cryptPass,
    if cryptWord == cryptPass:
        print "FOUND",
    print
woooee 814 Nearly a Posting Maven

That is a little complicated because I get an error on the first test lookup at

e = self.shelve[key]

because the keys are not correct. If it works for you then there is possibly a difference because of the Python version being used. If it does not work for you, take another look at Doug Hellmann's page as to how he adds data to a shelve object. Deleting is just del self.shelve[key], but you also have to set writeback=True for the changes to take place in the db. Also, Python is already using "string" and "list" and so using them in your program "redefines" them so you can not convert something to a list for example because "list" no longer points to a function. Finally, "b" will never equal 4 because it is set to one on the previous line

    def phonemenu(b):
        b = 1
        if b != 4:
jeremywduncan commented: Thank you. This homework is hard without a tutor! +0
woooee 814 Nearly a Posting Maven

You have to set writeback=True for changes to be made to the db. Doug Hellmann has a nice write up Click Here

woooee 814 Nearly a Posting Maven
woooee 814 Nearly a Posting Maven

A hint

from string import ascii_lowercase as letters
print letters[-1:]
print letters[-2:]

print
location=25
print letters[location:]
location -= 1
print letters[location:]
woooee 814 Nearly a Posting Maven

Continuing on with the code you posted `

for row in xrange(height):
    for col in xrange(width):
         print row, col   
    print

This will print what is available. As you can see there is no 15 so it is impossible to change 15. First, check the input to see that it is not outside the range of the board. Then come up with a function to change a space based upon arguments passed to the function.

woooee 814 Nearly a Posting Maven

You don't have a [0, 15] in the example you posted, you have [0, 0] through [3, 3]. If you have a
board = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] --> 16 zeros
then you can access the 15th. Show us some code, especially the code that creates the board, for more info.

woooee 814 Nearly a Posting Maven

The easiest to understand is to Use a function

def get_one_salary(ctr):
    while True:  ##infinite loop
        salary=raw_input("enter the salary #%d: " % (ctr+1))
        try:
            salary = float(salary)
            return salary
        except ValueError:
            print "could you please enter the correct salary? "

n = int(raw_input("enter the number of employee: "))
salary = []
for ctr in xrange(n):
    input_value = get_one_salary(ctr)
    salary.append(input_value)
print salary
woooee 814 Nearly a Posting Maven

That would be just a simple
1. compare the first number with the remaining (2 in this case)
2. swap the first and second number and do again

You would continue swapping if there were more digits. You have not included enough actual code to really comment on so it is difficult to move on from where your code starts. Note that the input "self.word" is not being used anywhere so whatever result you get it will not include the digits from the input. Also note that 123 and 321 are sometimes condsidered the same combination. Present a simple example in a few lines where you combine and swap and perhaps we can help more.

woooee 814 Nearly a Posting Maven

"Better" is in the eye of the beholder. The first rule is that the program does what it is supposed to.

def in_order(t):
    for ctr in range(1, len(t)):
        if t[ctr-1] > t[ctr]:
            return False
    return True

for t in ([1,2,2], ['b','a'], [3, 1, 5, 2, 4],
          ['d', 'a', 'c', 'b'], ['a', 'b', 'b', 'd', 'e', 'e', 'f', 'g']):
    print t, in_order(t)
woooee 814 Nearly a Posting Maven

Once again, lists are mutable (passed by reference) so global is unnecessary. Another example :

def print_row():
   print rowA

rowA = ['*', '*', '*', '*', '*', '*', '*', '*']
print_row()

for ctr in [1, 3, 5]:
   rowA[ctr] = "X"
print_row()
woooee 814 Nearly a Posting Maven

Lists are mutable, which means they can be used without global. The problem is possibly in the code you use to update the list; it truncates the list also. Run the code example below. You are asking questions that are in most tutorials so you should start with a tutorial instead of asking us to answer questions that every beginner should know. A place to start = tutorial on lists Click Here Python Wiki list of tutorials Click Here

rowA = ['*', '*', '*', '*', '*', '*', '*', '*']
seat=5
rowA[0:int(seat)] = ['X']  ## copies up to "seat" only
print "update 1", rowA 
#
# instead
rowA[0]="Y"
rowA[2]="X"
print "update 2", rowA
#
for ctr in range(0, 3):
    rowA[ctr] = "Z"
print "update 3", rowA
woooee 814 Nearly a Posting Maven

As stated above, I would compare word to word instead of how you are doing it. Since the problem is obviously in the file, add "didn't" to the file or to the result of the read, and if it finds it this time then you know for sure that the file is the problem.

woooee 814 Nearly a Posting Maven

If finds "didn't" in the following test. Also, you do not strip the newline character(s) after reading the files, and because you use "in" instead of creating a dictionary or set of individual words and comparing word with word; the word "and" will be found, i.e. is in, when compared to the word "sandy"

#fullwords = open("Enwords.txt").read()
#contrwords = open("Encontract.txt").read()
fullwords=['accept', 'actually', 'again', 'ago', 'all', 'allow', 'already', 'always', 'and', 'another', 'apply', 'are', 'around', 'author', 'bang', 'be', 'believe', 'bible', 'big', 'billion', 'but', "can't", 'cannot', 'cause', 'caused', 'could', 'creation', 'description', 'do', 'does', "doesn't", 'exist', 'explained', 'for', 'genesis', 'god', 'have', 'he', 'here', 'i', 'if', 'in', 'incorrect', 'is', 'it', 'its', 'laws', 'likely', 'literally', 'malarky', 'mean', 'meant', 'most', 'no', 'not', 'of', 'okay', 'old', 'only', 'period', 'physics', 'put', 'responsible', 'say', 'simply', 'so', 'taken', 'that', 'the', 'then', 'there', 'think', 'this', 'those', 'thought', 'to', 'true', 'universe', 'way', 'what', 'which', 'wrong', 'years', 'you']
contrwords=["can't", "didn't", "doesn't"]
wordlist = []
nonwordlist = []
failedwords = []
string4 = "I have already explained this I thought. Okay here it is again. I beleive that the laws of physics apply to the universe and always have. Those laws do not allow the universe to be only 6000 years old. So the only way in which God could be responsible for the creation of the universe is if the bible is incorrect in its description of creation. That doesn't mean there is no God, but only that if he does exist, he is not the author of the bible if he meant …
woooee 814 Nearly a Posting Maven

Use a while loop to generate random numbers until a valid number occurs:
- Ships can't overlap --> keep track of the occupied squares in a list
- Ships must be within the gamegrid --> you can supply a range for rows and a range for columns
- Ships must be going down or across --> randomly choose 0 (across) or 1 (down) and then get a random number for column start or row start.

woooee 814 Nearly a Posting Maven

I can't tell what your code looks like because it is not indented.

doubler is now f(2) = return g so that is removed and the value from doubler(5) gets assigned to y that is why you get the x*y value and not "function g at blah blah" which is what the return g would print. Add some print statements

def f(x):
    print " f entered", x
    def g(y):
        print "g executed", y
        return x * y
     return g

doubler = f(2)
print doubler(5)


## if you want to look at it like this: doubler as f(2) =
x = 2
def g(y):
    return x * y
woooee 814 Nearly a Posting Maven

Take a look at the first code example Click Here especially how text is assigned so it appears on the button.

woooee 814 Nearly a Posting Maven

You have to capture the return from split() and iterate over each one. Using split eliminates the split characters so you can prepend them back or adjust the slice numbers by -2 as I have done below.

test_data=\
"7e001090007d33a200408b2e0c2db70100160057637e001090007d33a2004089e04a569d010016003885"

if test_data[0:2] == '7e':
    data_split=test_data.split('7e')
    print data_split
    for Data_in in data_split:
        print "=========================="
        print "Found Packet: " + Data_in

        begin=4
        if Data_in[begin:begin+2] == '90' and
           len(Data_in) > 36:
            print "Packet Type = ZgBee RX Packet"
            AH = Data_in [begin+6:begin+14]
            AL = Data_in [begin+14:begin+22]
            print "Device Address = ", AH, AL
            TH = Data_in [begin+30:begin+32]
            TL = Data_in [begin+34:begin+36]
            THc = int(TH, 16)
            TLc = int(TL, 16)
            print "Temperature: %d.%d" % (THc, TLc)
            print "=======================\n"
woooee 814 Nearly a Posting Maven

The "in" operater is used to look up a key in a dictionary --> dictionary tutorial http://www.greenteapress.com/thinkpython/html/thinkpython012.html Note rrashkin's advice above and store each item in a string or as an element of a sub-list so you can access them individually as (s)he has done. You should not post real phone numbers or e-mail addresses on a public forum.

key = input('Enter a contact information here: ')
if key in ab:
    print (ab[key])
else:
    print("name not found")
woooee 814 Nearly a Posting Maven

In order to save volunteers here from wasting time, this thread has been cross-posted on all of the other forums groups, Active State, python-list, python-forum, devshed, dreamincode, and maybe others, so decide for yourself if you want to spend any time on this or not.

woooee 814 Nearly a Posting Maven

As stated above, I would suggest you add a print statment (after the line quoted below) and compare the output to what it should be, calculated by hand. If it does not come out then break each part down and compare, i.e calculate minutes only and compare and subtract from what total milli-seconds should be if correct giving seconds and milli-seconds remaining, then you can compare seconds and do the same and then milli-seconds (you are dividing and multiplying by 1000 not 100 so milli-second is correct).

hundredths = int(60000 * minutes + 1000 * seconds + 0.001 * centesimos)

So the following, and obviously milliseconds is the problem but you have to get to what they should be verses what they are in some way.

    minutes = int(mins1) + int(mins2)

    ## for the 2nd test ('03:00:02', '02:00:00') = 2:30:01 as median
    ## = how many milliseconds should your program have
woooee 814 Nearly a Posting Maven

00:02:500 # should be 00:02:30

A half a second is 500 milliseconds so 2:500 (== 2.5) is correct

00:03:0 # should be 00:03:30

We don't know what code you are using so how do you expect someone to help? Take vegaseat's suggestion and print the variables total_seconds, millisec, minutes, micro_x, and seconds on the line following each calculation to determine where the error is occurring.

Also, you can use

t1 = lap1.split(":") 

def convert_to_int(lap):
    t = lap.split(":")
    return int(t[0]), int(t[1]), int(t[2])

def lap_average(lap1, lap2):
    print convert_to_int(lap1)
    print convert_to_int(lap2)

lap_average('03:40:00', '05:20:00') 

Print the "t" tuple if you don't know what it will contain.

woooee 814 Nearly a Posting Maven
cur.execute("""INSERT INTO TableX (itemID, sortID)
VALUES (%s, %s)""",
[plist[sid], lastQ[0] ] )

What type is plist[sid]? If it is a string you now have to cast it to a byte in Python3.x (encode it), possibly the cause is something in Python3.3.

woooee 814 Nearly a Posting Maven

And you can do this more compactly

BR1 = []
for ctr in range(2, 8):
    BR1.append(Resistance[ctr]

## replaces
BR1 = []
b1 = Resistance[2]
b2 = Resistance[3]
b3 = Resistance[4]
b4 = Resistance[5]
b5 = Resistance[6]
b6 = Resistance[7]
BR1.append(b1)
BR1.append(b2)
BR1.append(b3)
BR1.append(b4)
BR1.append(b5)
BR1.append(b6)
woooee 814 Nearly a Posting Maven

You should use a dictionary to store the e-mails in a dictionary if it is not already there. If it is there, then it is a duplicate. I would suggest that you store the original record and the duplicate because they may be different and you would want to keep the correct one, not the first one found.

woooee 814 Nearly a Posting Maven

You define text_list to point to the same block of memory as final.

final = text_list

If you want want a copy, use copy or deepcopy

In line 107 you append final to decode_list multiple times. Break the program down into small functions that you can test individually, as fixing one error will probably just lead to many more that you can not find because you can not test each group of code the way it is now. Like Tony, 157 lines of code is more than I care to wade through so post back if there are any other problems that you can not fix.

 decode_list.append(''.join( final ))
woooee 814 Nearly a Posting Maven

That is because "! =" does not equal "!=" (original code copied for reference).

    #-------------------------------------------------------------------------------
    # Name:        module1
    # Purpose:
    #
    # Author:      User
    #
    # Created:     18/12/2012
    # Copyright:   (c) User 2012
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    #tictactoe board

    import random

    board = [0,1,2,
             3,4,5,
             6,7,8]

    def game():
        print (board[0],'|',board[1],'|',board[2])
        print ('----------')
        print (board[3],'|',board[4],'|',board[5])
        print ('----------')
        print (board[6],'|',board[7],'|',board[8])

    def check(char, spot1, spot2, spot3):
        if board[spot1] == char and board[spot2] == char and board[spot3] == char:
            return True
    def checkAll (char):
        if check (char, 0, 1, 2):
            return True
        if check (char, 1, 4, 7):
            return True
        if check (char, 2, 5, 8):
            return True

        if check (char, 6, 7, 8):
            return True
        if check (char, 3, 4, 5):
            return True
        if check (char, 0, 1, 2):
            return True

        if check (char, 2, 4, 6):
            return True
        if check (char, 0, 4, 8):
            return True
    while True:
        p1 = input("Player 1, where do you want to place your marker?")
        p1 = int(p1)
        if str(board[p1]) ! = 'x' and str(board[p1]) ! = 'o':
            board[p1] = 'x'

    if checkAll('x') == True:
                print "Player 1 wins!"
                break
            break

    while True:
            p2 = input("Player 2, where would you like to place your marker?")
            p2 = int(p2)
            if str(board[p2]) ! = 'x' and str(board[p2]) ! = 'o':
                str(board[p2]) = 'o'

                if checkAll('o') == True:
                    print "Player 2 wins!"
                    break
            break

I made some additional changes to help you out and reduced the code in checkAll() by using a list, but the program …

woooee 814 Nearly a Posting Maven

Take check() out from under NAC()--capture the return from a function

def check(player):
    if player == Grid[0][0] == Grid[0][1] == Grid[0][2]:
        print("%s wins!", (player))
        return True

Please read the Python Style Guide to make your code readable. Functions and variable names are lower case with underscores.

You have redundant code in the if statements

if YourGo == '7':
    Grid[0][0] = 'X'
elif YourGo == '8':
    Grid[0][1] = 'X' #Player one's turn

DisplayGrid()
check()

Also, you can map the squares to the numbers and use a for loop or simpify like this

if YourGo == '7':
    Grid[0][0] = 'X'
elif YourGo == '8':
    Grid[0][1] = 'X'
elif YourGo == '9':
    Grid[0][2] = 'X'

#------------------------------------
# replace with
this_row ['7', '8', '9']:
if YourGo in this_row:
    row = 0
    col = this_row.index(YourGo)

Grid[row][col] = 'X'

Finally, turn the above into a function and send the player to it so you don't test separately for X and O, i.e. the same code twice.

aVar++ commented: Helped me alot! +0
woooee 814 Nearly a Posting Maven

Instead of calling the same class instance every time, you are creating a new class instance

 self.canvas.bind("<Button1>", win2(self.canvas))

As stated above, you should create one instance of each class in init() and use those.

woooee 814 Nearly a Posting Maven

You bind the button press to the return from the function=inn(), not the function=inn. The button call later on to "funct" is coded correctly so note the difference. Also, you still mix grid and pack which can cause problems.

woooee 814 Nearly a Posting Maven

Instead of

self.firstClass = firstClass
self.economy = economy
self.business = business

which is redundant, i.e. you always have all 3, use a "class" variable that you set to "first", "economy", or "business". Also you don't have number of people or name.

woooee 814 Nearly a Posting Maven

You could also have a list of win squares instead of checking for rows, diagonals, and columns separately. The following is pseudo-code:

def check_row(self, row):
    control=this_column[0]
    for column in row
        ## not occupied or not all the same
        if column == 0 or column != control:
            return False
    return True

def checkWin(self):
    ## check rows
    for j in range(self.rows)
        result = self.check_row(self.rows[j])  ## or just use for row in self.rows
        if result:
            print "Winner is player", self.player
            return result, self.player

    ## check_column would be the same as check_row, i.e. you could use
    ## the same function if you sent it a list of all rows[0] instead
    ## for example, and the same for diagonals
    result = check_column()   
    result = check_diagonal()
woooee 814 Nearly a Posting Maven

We are here to help. Post your code and any errors, and you probably have not read this thread

woooee 814 Nearly a Posting Maven

Any ideas why using the input file is causing problems?

No, because we have no idea what the problem is or what the output to the file actually is compared to what it should be. Add some print statements in "correct()" to see what it is doing differently. Also, note that files opened with

infile = open('C:\\Python26\\text.txt','r')

do not contain lists but a string or strings.

woooee 814 Nearly a Posting Maven

In addition to lambda, you can also use partial to pass a variable indicator to a function. Also, using pack() and grid() in the same program leads to unpredictable results.

from Tkinter import*
from functools import partial

root=Tk()
root.title("Replicate DNA yourself!")

def inn(variable_passed):
    positions = ((10, 10), (60, 50), (110, 110))
    xx, yy = positions[variable_passed]
    print "variable passed =", variable_passed, "----->", xx, yy

tophelicase=Toplevel(bg="green",bd=10)
Label(tophelicase,text="Where should helicase be placed?",bg="green").pack()
Radiobutton(tophelicase,text='1',bg="green",command=partial(inn, 0)).pack()
Radiobutton(tophelicase,text='2',bg="green",command=partial(inn, 1)).pack()
Radiobutton(tophelicase,text='3',bg="green",command=partial(inn, 2)).pack()

root.mainloop()
woooee 814 Nearly a Posting Maven

I don't know how to answer your question without knowing what you have tried so far.

woooee 814 Nearly a Posting Maven

bh1=Radiobutton(tophelicase,text='1',variable=position,value=1,bg="green",command=tophelicase.destroy).pack()

Print bh1 to see what it contains and you should see that there is no reason to store the return from pack(), i.e. just use

   Radiobutton(tophelicase,text='1',variable=position,value=1,bg="green",
               command=fhelicase).pack()