Python and PyQt string can't print - python
So, I'm using Python with PyQt and I have a very strange problem. A string that prints OK at one point doesn't print OK after a few lines of code! Here's my code:
name = str(self.lineEdit.text().toUtf8())
self.let_change = Search()
name_no_ind = self.let_change.indentation(name)
print(name_no_ind)
name_cap = self.let_change.capital(name)
name_low = self.let_change.lower(name)
print(name_no_ind, name_cap, name_low)
col = self.combobox.currentIndex()
row = 0
for i in range(0, self.tableWidget.rowCount()):
try:
find_no_ind = self.let_change.indentation(self.tableWidget.item(row, col).text())
find_cap = self.let_change.capital(self.tableWidget.item(row, col).text())
find_lower = self.let_change.lower(self.tableWidget.item(row, col).text())
if name_no_ind or name_cap or name_low in find_no_ind or find_cap or find_lower:
self.tableWidget.setItemSelected(self.tableWidget.item(row, col), True)
print("Item found in %d, %d" % (row,col))
row += 1
except AttributeError:
row += 1
And here's what I get:
Αντωνης
('\xce\x91\xce\xbd\xcf\x84\xcf\x89\xce\xbd\xce\xb7\xcf\x82', '\xce\x91\xce\x9d\xce\xa4\xcf\x8e\xce\x9d\xce\x97\xce\xa3', '\xce\xb1\xce\xbd\xcf\x84\xcf\x8e\xce\xbd\xce\xb7\xcf\x82')
Item found in 0, 0
Isn't that strange? It prints OK and then it doesn't. Does anybody know what can I do?
P.S.: Here are the functions:
# -*- coding: utf-8 -*-
class Search():
#A function that removes indentations:
def indentation(self, name):
a = name
b = ["ά", "Ά", "ή", "Ή", "ώ", "Ώ", "έ", "Έ", "ύ", "Ύ", "ί", "Ί", "ό", "Ό"]
c = ['α', 'Α', 'η', 'Η', 'ω', 'Ω', 'ε', 'Ε', 'υ', 'Υ', 'ι', 'Ι', 'ο', 'Ο']
for i in b:
a = a.replace(i, c[b.index(i)])
return a
# A function that makes letters capital:
def capital(self, name):
a = name
greek_small = ["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "ς"]
greek_capital = ["Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "Σ"]
for i in greek_small:
a = a.replace(i, greek_capital[greek_small.index(i)])
return a
#A function that makes letters lower:
def lower(self, name):
a = name
greek_small = ["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "ς"]
greek_capital = ["Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω", "Σ"]
for i in greek_capital:
a = a.replace(i, greek_small[greek_capital.index(i)])
return a
Basically, it capitalizes or lowers Greek characters...
SOLUTION!!!:
Steve solved the initial problem and based on what he said, I came up with this that solves everything:
name = str(self.lineEdit.text().toUtf8())
self.let_change = Search()
name_no_ind = self.let_change.indentation(name)
name_cap = self.let_change.capital(name)
name_low = self.let_change.lower(name)
name_list = [name, name_no_ind, name_cap, name_low]
col = self.combobox.currentIndex()
row = 0
for i in range(0, self.tableWidget.rowCount()):
try:
item_ = str(self.tableWidget.item(row, col).text().toUtf8())
find_no_ind = self.let_change.indentation(item_)
find_cap = self.let_change.capital(item_)
find_lower = self.let_change.lower(item_)
item_list = [find_no_ind, find_cap, find_lower]
for x in name_list:
for y in item_list:
if x in y:
self.tableWidget.setItemSelected(self.tableWidget.item(row, col), True)
row += 1
except AttributeError:
row += 1
I would say that one r both of self.let_change.capital(name) or self.let_change.lower(name) is overwriting it by using the name of the input parameter or possibly changing the encoding. Since you have not posted the code for them I can not be sure.
Sorry, they are not the problem. The problem is that you are printing them differently:
>>> print(capital(name))
ΑΝΤΩΝΗΣ
>>> print(capital(name), name)
('\xce\x91\xce\x9d\xce\xa4\xce\xa9\xce\x9d\xce\x97\xce\xa3', '\xce\x91\xce\xbd\xcf\x84\xcf\x89\xce\xbd\xce\xb7\xcf\x82')
>>> print(capital(name))
ΑΝΤΩΝΗΣ
>>> print(name, name)
('\xce\x91\xce\xbd\xcf\x84\xcf\x89\xce\xbd\xce\xb7\xcf\x82', '\xce\x91\xce\xbd\xcf\x84\xcf\x89\xce\xbd\xce\xb7\xcf\x82')
>>> print(name,)
('\xce\x91\xce\xbd\xcf\x84\xcf\x89\xce\xbd\xce\xb7\xcf\x82',)
>>> print(name)
Αντωνης
>>> print("%s = %s" % (name, capital(name)))
Αντωνης = ΑΝΤΩΝΗΣ
>>>
So you either need separate print statements or the use of a format string.
Related
Is there anyway these 2 almost similar functions can be squished into 1 general function?
I have these 2 functions that are really similar except for the different format of log it will receive and return. One look and return 4 values when the other return 3. Is there any way I can make 1 general function for these 2? Thank you > - Borrow book: B#<day>#<Student Name>#<Book name>#<days borrowed for> > - Return book: R#<day>#<Student Name>#<Book name> def read_borrow_log(log): borrow_day = [] borrow_student = [] borrow_book = [] borrow_duration = [] for line in log: hash_func = line.find("#") hash_day = line.find("#", hash_func+1) hash_student = line.find("#", hash_day+1) hash_book = line.find("#", hash_student+1) hash_duration = line.find("#", hash_book+1) borrow_day.append(int(line[(hash_func+1):(hash_day)])) borrow_student.append(line[(hash_day+1):(hash_student)]) borrow_book.append(line[(hash_student+1):(hash_duration)]) borrow_duration.append(line[(hash_duration+1):]) return borrow_day, borrow_student, borrow_book, borrow_duration def read_return_log(log): return_day = [] return_student = [] return_book = [] for line in log: hash_func = line.find("#") hash_day = line.find("#", hash_func+1) hash_student = line.find("#", hash_day+1) return_day.append(int(line[(hash_func+1):(hash_day)])) return_student.append(line[(hash_day+1):(hash_student)]) return_book.append(line[(hash_student+1):]) return return_day, return_student, return_book def main(): borrow_day, borrow_student, borrow_book, borrow_duration = read_borrow_log(borrow_log) return_day, return_student, return_book = read_return_log(return_log)
Try using python's built-in string split: def extract_log_parts(log): recs = [] for line in log: recs.append(line.split('#')) # we want the record *columns* -- transpose the table return tuple(map(list, zip(*recs)))
one thing you might do is to make the 'extra' work done only when a certain optional parameter is passed in as shown: def read_borrow_log(log,borrow_log=True): borrow_day = [] borrow_student = [] borrow_book = [] if borrow_log is True: borrow_duration = [] for line in log: hash_func = line.find("#") hash_day = line.find("#", hash_func + 1) hash_student = line.find("#", hash_day + 1) if borrow_log is True: hash_book = line.find("#", hash_student + 1) hash_duration = line.find("#", hash_book + 1) borrow_day.append(int(line[(hash_func + 1):(hash_day)])) borrow_student.append(line[(hash_day + 1):(hash_student)]) borrow_book.append(line[(hash_student + 1):(hash_duration)]) if borrow_log is True: borrow_duration.append(line[(hash_duration + 1):]) if borrow_log is True: return borrow_day, borrow_student, borrow_book, borrow_duration else: return borrow_day, borrow_student, borrow_book def main(): borrow_day, borrow_student, borrow_book, borrow_duration = read_borrow_log(borrow_log) return_day, return_student, return_book = read_borrow_log(return_log,borrow_log=False) however you might want to rethink the naming convention used since this function will now do more than one thing, which is bad for documentation purposes (and is generally a bad practice to have functions do more than one thing, bad enough that i should downvote my own answer if i can)
Replacing each character/string in a list one at a time with python
I have a string "MQADKVMEPT" and the desired output I want is: .QADKVMEPT M.ADKVMEPT MQ.DKVMEPT MQA.KVMEPT MQAD.VMEPT MQADK.MEPT MQADKV.EPT MQADKVM.PT MQADKVME.T MQADKVMEP. Using this code: motif = 'MQADKVMEPT' motiflist = list(motif) pos = 0 for aa in motiflist: motiflist[pos] = '.' pos += 1 str = '' for a in motiflist: str += a print(str) My output is: .QADKVMEPT ..ADKVMEPT ...DKVMEPT ....KVMEPT .....VMEPT ......MEPT .......EPT ........PT .........T .......... How do I reinitialize the original motiflist so that it doesn't give me this output?
"Quick" fix would be copy the original list. Using your code: motif = "MQADKVMEPT" motiflist = list(motif) pos = 0 for aa in motiflist: motiflist_copy = motiflist.copy() # <--- copy the original list motiflist_copy[pos] = "." pos += 1 s = "" for a in motiflist_copy: s += a print(s) Prints: .QADKVMEPT M.ADKVMEPT MQ.DKVMEPT MQA.KVMEPT MQAD.VMEPT MQADK.MEPT MQADKV.EPT MQADKVM.PT MQADKVME.T MQADKVMEP. Shorter solution: motif = "MQADKVMEPT" for i in range(len(motif)): s = motif[:i] + "." + motif[i + 1 :] print(s)
The program adds "" to the string I'm indexing
Im using this piece of code shares_one = [(None,), ('200 # 496',), ('200 # 486',)] print(shares_one) variable_one = StringVar(add_sale_quantity_selector) variable_one.set(shares_one[1]) # default value y = OptionMenu(add_sale_quantity_selector, variable_one, *shares_one) y.place(x=25, y=40) x = (variable_one.get()) bad_chars = ['"'] for i in bad_chars: test_string = x.replace(i, '') print (test_string) index = shares_one.index(test_string) print(index) but it gives me the following error ValueError: "('200 # 496',)" is not in list for the line index = shares_one.index(test_string) whats the possible solution, sorry if anythings out of the picture.
How to convert text table to dataframe
I am trying to scrape the "PRINCIPAL STOCKHOLDERS" table from the linktext fileand convert it to a csv file. Right now I am only half successful. Namely, I can locate the table and parse it but somehow I cannot convert the text table to a standard one. My code is attached. Can someone help me with it? url = r'https://www.sec.gov/Archives/edgar/data/1034239/0000950124-97-003372.txt' # Different approach, the first approach does not work filing_url = requests.get(url) content = filing_url.text splited_data = content.split('\n') table_title = 'PRINCIPAL STOCKHOLDERS' END_TABLE_LINE = '- ------------------------' def find_no_line_start_table(table_title,splited_data): found_no_lines = [] for index, line in enumerate(splited_data): if table_title in line: found_no_lines.append(index) return found_no_lines table_start = find_no_line_start_table(table_title,splited_data) # I need help with locating the table. If I locate the table use the above function, it will return two locations and I have to manually choose the correct one. table_start = table_start[1] def get_start_data_table(table_start, splited_data): for index, row in enumerate(splited_data[table_start:]): if '<C>' in row: return table_start + index def get_end_table(start_table_data, splited_data ): for index, row in enumerate(splited_data[start_table_data:]): if END_TABLE_LINE in row: return start_table_data + index def row(l): l = l.split() number_columns = 8 if len(l) >= number_columns: data_row = [''] * number_columns first_column_done = False index = 0 for w in l: if not first_column_done: data_row[0] = ' '.join([data_row[0], w]) if ':' in w: first_column_done = True else: index += 1 data_row[index] = w return data_row start_line = get_start_data_table(table_start, splited_data) end_line = get_end_table(start_line, splited_data) table = splited_data[start_line : end_line] # I also need help with convert the text table to a CSV file, somehow the following function does not #recognize my column. def take_table(table): owner = [] Num_share = [] middle = [] middle_1 = [] middle_2 = [] middle_3 = [] prior_offering = [] after_offering = [] for r in table: data_row = row(r) if data_row: col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8 = data_row owner.append(col_1) Num_share.append(col_2) middle.append(col_3) middle_1.append(col_4) middle_2.append(col_5) middle_3.append(col_6) prior_offering.append(col_7) after_offering.append(col_8) table_data = {'owner': owner, 'Num_share': Num_share, 'middle': middle, 'middle_1': middle_1, 'middle_2': middle_2, 'middle_3': middle_3, 'prior_offering': prior_offering, 'after_offering': after_offering} return table_data #print (table) dict_table = take_table(table) a = pd.DataFrame(dict_table) a.to_csv('trail.csv')
I think what you need to do is pd.DataFrame.from_dict(dict_table) instead of pd.DataFrame(dict_table)
Reference to value of the function
At beginning i wanna say i'm newbie in use Python and everything I learned it came from tutorials. My problem concerning reference to the value. I'm writing some script which is scrapping some information from web sites. I defined some function: def MatchPattern(count): sock = urllib.urlopen(Link+str(count)) htmlSource = sock.read() sock.close() root = etree.HTML(htmlSource) root = etree.HTML(htmlSource) result = etree.tostring(root, pretty_print=True, method="html") expr1 = check_reg(root) expr2 = check_practice(root) D_expr1 = no_ks(root) D_expr2 = Registred_by(root) D_expr3 = Name_doctor(root) D_expr4 = Registration_no(root) D_expr5 = PWZL(root) D_expr6 = NIP(root) D_expr7 = Spec(root) D_expr8 = Start_date(root) #-----Reg_practice----- R_expr1 = Name_of_practise(root) R_expr2 = TERYT(root) R_expr3 = Street(root) R_expr4 = House_no(root) R_expr5 = Flat_no(root) R_expr6 = Post_code(root) R_expr7 = City(root) R_expr8 = Practice_no(root) R_expr9 = Kind_of_practice(root) #------Serv_practice ----- S_expr1 = TERYT2(root) S_expr2 = Street2(root) S_expr3 = House_no2(root) S_expr4 = Flat_no2(root) S_expr5 = Post_code2(root) S_expr6 = City2(root) S_expr7 = Phone_no(root) return expr1 return expr2 return D_expr1 return D_expr2 return D_expr3 return D_expr4 return D_expr5 return D_expr6 return D_expr7 return D_expr8 #-----Reg_practice----- return R_expr1 return R_expr2 return R_expr3 return R_expr4 return R_expr5 return R_expr6 return R_expr7 return R_expr8 return R_expr9 #------Serv_practice ----- return S_expr1 return S_expr2 return S_expr3 return S_expr4 return S_expr5 return S_expr6 return S_expr7 So now inside the script I wanna check value of the expr1 returned by my fynction. I don't know how to do that. Can u guys help me ? Is my function written correct ? EDIT: I can't add answer so I edit my current post This is my all script. Some comments are in my native language but i add some in english #! /usr/bin/env python #encoding:UTF-8- # ----------------------------- importujemy potrzebne biblioteki i skrypty ----------------------- # ------------------------------------------------------------------------------------------------ import urllib from lxml import etree, html import sys import re import MySQLdb as mdb from TOR_connections import * from XPathSelection import * import os # ------------------------------ Definiuje xPathSelectors ------------------------------------------ # -------------------------------------------------------------------------------------------------- # -------Doctors ----- check_reg = etree.XPath("string(//html/body/div/table[1]/tr[3]/td[2]/text())") #warunek Lekarz check_practice = etree.XPath("string(//html/body/div/table[3]/tr[4]/td[2]/text())") #warunek praktyka no_ks = etree.XPath("string(//html/body/div/table[1]/tr[1]/td[2]/text())") Registred_by = etree.XPath("string(//html/body/div/table[1]/tr[4]/td[2]/text())") Name_doctor = etree.XPath("string(//html/body/div/table[2]/tr[2]/td[2]/text())") Registration_no = etree.XPath("string(//html/body/div/table[2]/tr[3]/td[2]/text())") PWZL = etree.XPath("string(//html/body/div/table[2]/tr[4]/td[2]/text())") NIP = etree.XPath("string(//html/body/div/table[2]/tr[5]/td[2]/text())") Spec = etree.XPath("string(//html/body/div/table[2]/tr[18]/td[2]/text())") Start_date = etree.XPath("string(//html/body/div/table[2]/tr[20]/td[2]/text())") #-----Reg_practice----- Name_of_practise = etree.XPath("string(//html/body/div/table[2]/tr[1]/td[2]/text())") TERYT = etree.XPath("string(//html/body/div/table[2]/tr[7]/td[2]/*/text())") Street = etree.XPath("string(//html/body/div/table[2]/tr[8]/td[2]/text())") House_no = etree.XPath("string(//html/body/div/table[2]/tr[9]/td[2]/*/text())") Flat_no = etree.XPath("string(//html/body/div/table[2]/tr[10]/td[2]/*/text())") Post_code = etree.XPath("string(//html/body/div/table[2]/tr[11]/td[2]/*/text())") City = etree.XPath("string(//html/body/div/table[2]/tr[12]/td[2]/*/text())") Practice_no = etree.XPath("string(//html/body/div/table[3]/tr[4]/td[2]/text())") Kind_of_practice = etree.XPath("string(//html/body/div/table[3]/tr[5]/td[2]/text())") #------Serv_practice ----- TERYT2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[2]/td[2]/*/text())") Street2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[3]/td[2]/text())") House_no2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[4]/td[2]/*/text())") Flat_no2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[5]/td[2]/i/text())") Post_code2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[6]/td[2]/*/text())") City2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[7]/td[2]/*/text())") Phone_no = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[8]/td[2]/text())") # --------------------------- deklaracje zmiennych globalnych ---------------------------------- # ---------------------------------------------------------------------------------------------- decrease = 9 No = 1 Link = "http://rpwdl.csioz.gov.pl/rpz/druk/wyswietlKsiegaServletPub?idKsiega=" # --------------------------- funkcje zdefiniowane ---------------------------------- # ---------------------------------------------------------------------------------------------- def MatchPattern(count): sock = urllib.urlopen(Link+str(count)) htmlSource = sock.read() sock.close() root = etree.HTML(htmlSource) root = etree.HTML(htmlSource) result = etree.tostring(root, pretty_print=True, method="html") expr1 = check_reg(root) expr2 = check_practice(root) D_expr1 = no_ks(root) D_expr2 = Registred_by(root) D_expr3 = Name_doctor(root) D_expr4 = Registration_no(root) D_expr5 = PWZL(root) D_expr6 = NIP(root) D_expr7 = Spec(root) D_expr8 = Start_date(root) #-----Reg_practice----- R_expr1 = Name_of_practise(root) R_expr2 = TERYT(root) R_expr3 = Street(root) R_expr4 = House_no(root) R_expr5 = Flat_no(root) R_expr6 = Post_code(root) R_expr7 = City(root) R_expr8 = Practice_no(root) R_expr9 = Kind_of_practice(root) #------Serv_practice ----- S_expr1 = TERYT2(root) S_expr2 = Street2(root) S_expr3 = House_no2(root) S_expr4 = Flat_no2(root) S_expr5 = Post_code2(root) S_expr6 = City2(root) S_expr7 = Phone_no(root) return expr1 return expr2 return D_expr1 return D_expr2 return D_expr3 return D_expr4 return D_expr5 return D_expr6 return D_expr7 return D_expr8 #-----Reg_practice----- return R_expr1 return R_expr2 return R_expr3 return R_expr4 return R_expr5 return R_expr6 return R_expr7 return R_expr8 return R_expr9 #------Serv_practice ----- return S_expr1 return S_expr2 return S_expr3 return S_expr4 return S_expr5 return S_expr6 return S_expr7 # --------------------------- ustanawiamy polaczenie z baza danych ----------------------------- # ---------------------------------------------------------------------------------------------- con = mdb.connect('localhost', 'root', '******', 'SANBROKER', charset='utf8'); # ---------------------------- początek programu ----------------------------------------------- # ---------------------------------------------------------------------------------------------- with con: cur = con.cursor() cur.execute("SELECT Old_num FROM SANBROKER.Number_of_records;") Old_num = cur.fetchone() count = Old_num[0] counter = input("Input number of rows: ") # ----------------------- pierwsze połączenie z TORem ------------------------------------ # ---------------------------------------------------------------------------------------- #connectTor() #conn = httplib.HTTPConnection("my-ip.heroku.com") #conn.request("GET", "/") #response = conn.getresponse() #print(response.read()) while count <= counter: # co dziesiata liczba # --------------- pierwsze wpisanie do bazy danych do Archive -------------------- with con: cur = con.cursor() cur.execute("UPDATE SANBROKER.Number_of_records SET Archive_num=%s",(count)) # --------------------------------------------------------------------------------- if decrease == 0: MatchPattern(count) # Now I wanna check some expresions (2 or 3) # After that i wanna write all the values into my database #------- ostatnie czynności: percentage = count / 100 print "rekordów: " + str(count) + " z: " + str(counter) + " procent dodanych: " + str(percentage) + "%" with con: cur = con.cursor() cur.execute("UPDATE SANBROKER.Number_of_records SET Old_num=%s",(count)) decrease = 10-1 count +=1 else: MatchPattern(count) # Now I wanna check some expresions (2 or 3) # After that i wanna write all the values into my database # ------ ostatnie czynności: percentage = count / 100 print "rekordów: " + str(count) + " z: " + str(counter) + " procent dodanych: " + str(percentage) + "%" with con: cur = con.cursor() cur.execute("UPDATE SANBROKER.Number_of_records SET Old_num=%s",(count)) decrease -=1 count +=1
Well, I'm assuming check_reg is a function that returns a boolean (either True or False). If that's the case, to check the return: if expr1: print "True." else: print "False" There's more than one way to do it, but basically, if expr1: is all you need to do the checking.
To capture the return value of a function, assign the function to a name with an equal sign, like this: return_value = somefunction(some_value) print('The return value is ',return_value) Keep in mind that when the first return statement is encountered, the function will exit. So if you have more than one return statement after each other, only the first will execute. If you want to return multiple things, add them to a list and then return the list. Here is an improved version of your function: def match_pattern(count): sock = urllib.urlopen(Link+str(count)) htmlsource = sock.read() sock.close() root = etree.HTML(htmlSource) # root = etree.HTML(htmlSource) - duplicate line # result = etree.tostring(root, pretty_print=True, method="html") function_names = [check_reg, check_practice, no_ks, Registered_by, \ Name_doctor, Registration_no, PWZL, NIP, Spec, Start_date, \ Name_of_practise, TERYT, Street, House_no2, Flat_no, \ Post_code2, City2, Phone_no] results = [] for function in function_names: results.append(function(root)) return results r = match_pattern(1) print r[0] # this will be the result of check_reg(root)
The code you have posted is quite ambigous. Can you please fix the ident to let us know what belongs to the function and which part is the script. A function can returns only one value. You cannot do : return something return something_else return ... The function will ends when first value will be returned. What you can do is returning a list, tuple or dict containing all your values. For instance : return (something,something_else,...) or return [something,something_else,...] In your case, it seems better to create a class that would have all values you want as attributes, and turn this function into a method that would set the attributes values. class Example(object): def __init__ ( self , link , count ): sock = urllib.urlopen(link+str(count)) htmlSource = sock.read() sock.close() root = etree.HTML(htmlSource) root = etree.HTML(htmlSource) result = etree.tostring(root, pretty_print=True, method="html") self.expr1 = check_reg(root) self.expr2 = check_practice(root) self.D_expr1 = no_ks(root) ... self.D_expr8 = Start_date(root) #-----Reg_practice----- self.R_expr1 = Name_of_practise(root) ... self.R_expr9 = Kind_of_practice(root) #------Serv_practice ----- self.S_expr1 = TERYT2(root) ... self.S_expr7 = Phone_no(root) Then you will be able to use this class like : exampleInstance = Example ( "link you want to use" , 4 ) # the second argument is your 'count' value # Now you can use attributes of your class to get the values you want print exampleInstance . expr1 print exampleInstance . S_expr7