How to reference this function?

This is the place for queries that don't fit in any of the other categories.

How to reference this function?

Postby leoChristofoli » Thu Aug 22, 2013 2:02 pm

Hi guys.

Its a simple question but I'm wasting all my day looking for the solution.
Could you help me please?

How do I use this those vars, 'arq' and 'arq1' on the prod function?

Code: Select all
def get(self):
        arq = askopenfilename() 
        print(arq)     
        if arq:
            return arq
       
    def get1(self):   
        arq1 = askopenfilename()
        print(arq1)
        if arq1:
            return arq1
   
   
    def prod(self):
     
        file = self.get
        print(file)
        file1 = self.get1
        print(file1)
       
        oldPath = open(file)
        newPath = open(file1)
       
        oldLines = oldPath.read().split('\n')
        newLines = newPath.read().split('\n')
               
        oldLset = set(oldLines)
        newLset = set(newLines)
               
        oldAdd = oldLset - newLset
        oldRe = newLset - oldLset   
       
        funcCompara.text1(oldPath, newPath, oldLines, newLines, oldLset, newLset, oldAdd, oldRe)
   
        return


if you see the print on get, its right, but on the prod its not returning the file, just the function's address.

I have tried many things, but no one works.

I'm using a tkinter interface to call those functions.

Thank you.
leoChristofoli
 
Posts: 9
Joined: Tue Aug 13, 2013 2:51 pm

Re: How to reference this function?

Postby stranac » Thu Aug 22, 2013 3:45 pm

You need to call the functions:
Code: Select all
file = self.get()


Also, file and get are pretty bad names.
file is even the name of a built-in function.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1112
Joined: Thu Feb 07, 2013 3:42 pm

Re: How to reference this function?

Postby leoChristofoli » Fri Aug 23, 2013 12:15 pm

stranac wrote:You need to call the functions:
Code: Select all
file = self.get()


Also, file and get are pretty bad names.
file is even the name of a built-in function.


You are right, bad choice, I changed it.
But still with same problem :(
leoChristofoli
 
Posts: 9
Joined: Tue Aug 13, 2013 2:51 pm

Re: How to reference this function?

Postby stranac » Fri Aug 23, 2013 12:49 pm

Show your full code.
It's hard to understand what's going on without being able to run it.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1112
Joined: Thu Feb 07, 2013 3:42 pm

Re: How to reference this function?

Postby leoChristofoli » Mon Aug 26, 2013 12:35 pm

stranac wrote:Show your full code.
It's hard to understand what's going on without being able to run it.


Code: Select all
from tkinter import *
import funcCompara
import funcAtribui
from tkinter.filedialog import askopenfilename

class Application(Frame):

    def createWidgets(self):

        self.btn2 = Button(command=self.quit)
        self.btn2["text"]="QUIT"
        self.btn2.place(bordermode=OUTSIDE, x=100, y=100)
        self.btn2.pack(side="left")

        self.textf = Entry()
        self.textf.place(bordermode=OUTSIDE, x=500,y=500)
        self.textf.pack(side="left")

        self.btn4 = Button(command = self.prod)
        self.btn4["text"] = "compara"
        self.btn4.pack(side = "left")

        #here I call the function
        self.btn5 = Button()
        self.btn5["text"] = "open arquivo 1"
        self.btn5["command"] = self.func_get
        self.btn5.pack(side = "left")

        self.btn6 = Button()
        self.btn6["text"] = "open arquivo 2"
        self.btn6.pack(side = "left")
        self.btn6["command"] = self.func_get1

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.place()
        self.createWidgets()

    def callback_func(self):
        funcAtribui.texter()

    def func_get(self):
        arq = askopenfilename()
        print(arq)
        if arq:
            return arq

    def func_get1(self):
        arq1 = askopenfilename()
        print(arq1)
        if arq1:
            return arq1


    def prod(self):

        oldPath = open('original.txt')
        newPath = open('new.txt')

        oldLines = oldPath.readlines()
        newLines = newPath.readlines()

        oldLset = set(oldLines)
        newLset = set(newLines)

        oldAdd = oldLset - newLset
        oldRe = newLset - oldLset

        funcCompara.text1(oldPath, newPath, oldLines, newLines, oldLset, newLset, oldAdd, oldRe)

        return


root = Tk()
root.geometry("500x300+300+300")
app = Application(master=root)
app.mainloop()
root.destroy()


Module which compare the files
Code: Select all
def text1 (oldPath, newPath, oldLines, newLines, oldLset, newLset, oldAdd, oldRe):
   
       
    for line in oldLines:
        if line in oldAdd:
            print ('-',line.strip())   
        elif line in oldRe:
            print ('+')
                         
    for line in newLines:
        if line in oldAdd:
            print ('-', line.strip())           
        elif line in oldRe:
            print ('+', line.strip())               


thanks
leoChristofoli
 
Posts: 9
Joined: Tue Aug 13, 2013 2:51 pm

Re: How to reference this function?

Postby stranac » Mon Aug 26, 2013 1:40 pm

I have no idea how to reproduce the problem.
Can you give me step-by-step instructions?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1112
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: W3C [Linkcheck] and 2 guests