Apr-30-2024, 11:26 AM
I am meeting a problem with 2 functions The 1st one the first function job: clean a string and at the end, it calls the function def pi_digits(): in order to recover the value of pi . This sequence gives a message <generator object pi_digits at 0x00000223B0738580> which I cannot manage [python] #---------------------------------- init mytestr = "Afdc ERFGDS 12547 éàè,;:!) " fenet_1.insert("1.0",mytestr) DIGITS = 200 drapo_trim = False #================== def trim() :#-----------------------------------------------------nettoyer la chaine vers concatené source=fenet_1.get("1.0", 'end-1c') #---------------ponctu spunct = re.sub(r'[^\w\s]', '', source) fenet_2.insert("1.0",spunct) #--------------- accents aks = unidecode.unidecode(spunct) #--------------- maju majstr=aks.upper() #--------------- ote chiffres res = ''.join([i for i in majstr if not i.isdigit()]) #-------------- Concatene ote espaces resf = res.replace(' ','') fenet_2.delete("1.0","end") fenet_2.insert("1.0",resf) #finex pour- resf - chaine ok # on developpe la chaine -texte plain l_resf =len(resf)# calcul de sa longueur bin_res = ''.join(format(ord(i), '08b') for i in resf) # on convertit en binaire print((bin_res) , " print du texte clair en binaire - ligne 99") # binaire du texte clair idem drapo_trim = True bin_pi=pi_digits() print ((bin_pi), "retour de fn") #================================================================ def pi_digits(): print("into pi_digits") k,a,b,a1,b1 = 2,4,1,12,4 while x > 0: p,q,k = k * k, 2 * k + 1, k + 1 a,b,a1,b1 = a1, b1, p*a + q*a1, p*b + q*b1 d,d1 = a/b, a1/b1 while d == d1 and x > 0: yield int(d) x -= 1 a,a1 = 10*(a % b), 10*(a1 % b1) d,d1 = a/b, a1/b1 digits = [str(n) for n in list(pi_digits(DIGITS))] str_pi='{}.{}'.format(digits.pop(0), "".join(digits)) context = decimal.Context(prec=100) decimal.setcontext(context) pi = decimal.Decimal(str_pi) # return pi.lstrip(pi[0:4]) ## print((pi) , " = pi en binaire - lig 123") return pi # the return gives # <generator object pi_digits at 0x00000223B0738580>However the 'creation function of pi' as follow is working alone and ives
the right value - who has a clue
many thanks?
#-------------------------------- from tkinter import * import tkinter as tk from unidecode import unidecode from tkinter import filedialog,END from tkinter.filedialog import asksaveasfilename, askopenfilename from tkinter.ttk import Label, LabelFrame from PIL import Image, ImageTk from tkinter import messagebox from tkinter.scrolledtext import ScrolledText import decimal import unidecode import re root = tk.Tk() DIGITS = 200 def pi_digits(x): k,a,b,a1,b1 = 2,4,1,12,4 while x > 0: p,q,k = k * k, 2 * k + 1, k + 1 a,b,a1,b1 = a1, b1, p*a + q*a1, p*b + q*b1 d,d1 = a/b, a1/b1 while d == d1 and x > 0: yield int(d) x -= 1 a,a1 = 10*(a % b), 10*(a1 % b1) d,d1 = a/b, a1/b1 digits = [str(n) for n in list(pi_digits(DIGITS))] str_pi='{}.{}'.format(digits.pop(0), "".join(digits)) context = decimal.Context(prec=100) decimal.setcontext(context) pi = decimal.Decimal(str_pi) print(pi) #-------------------------------- bouton go button1 = Button(root, text = "go ", width=8, height=1, fg='white', font=('Helvetica 12 bold'), background="#762123" ,command=pi_digits) button1.place(x=740, y=36) #--------------------------------hope you undersatand my problem
many thanks