Python – How to edit txt.file of one class in another

I’m working on my first serious project in python using objects. I’m still beginner (1month in python) and after couple of tutorials and hours of checking/testing code, I have finally created quite fine bank app. The problem is that I’m struggling with edditing the txt file of one class in another class. let me explain what I need. I’ve created app where you can register your account and then log onto it. When you are logged in, bank menu displays where you can deposit and withdraw money (I will apply more options soon). As a database I have used file=option(xxx, “w”) so each user exists as the indenpendent txt. Each txt file contains three lines: login, password, security code. My goal is to add there forth line which will be balance, so the amount of money after deposit/withdraw will be saved after application is closed. I’m stuck on it and cannot figure it out and I’m getting slowly flustrated so I’ve decided to ask you for help. This is the code:

    import tkinter as tk     import os     import random     from tkinter import messagebox     from tkinter import font as tkfont     from banking import bank      class menu(tk.Tk):              def __init__(self):                 tk.Tk.__init__(self)                 tk.Tk.configure(self, bg="red")                 tk.Tk.geometry(self, "300x250")                 tk.Tk.title(self, "Smiglo Bank")                 tk.Label(self, text = "Welcome to Smiglo Bank", bg="pink", font = ("Algerian", 13)).pack()                 tk.Label(self, text = "").pack()                 tk.Button(self, text="Login", width=20, command=self.login).pack()                 tk.Label(self, text = "").pack()                 tk.Button(self, text="Register", width=20, command=self.register).pack()          # register system              def register_user(self):                 c = str(random.randint(1000, 9000))                  self.username_info = username.get()                 self.password_info = password.get()                 self.code_info = c                  file=open(self.username_info, "w")                 file.write(self.username_info+"\n")                 file.write(self.password_info+"\n")                 file.write(self.code_info)                 file.close                  self.username_entry.delete(0, tk.END)                 self.password_entry.delete(0, tk.END)                  tk.Label(self.screen1, text="Registration succes", fg="green", font=("calibri", 11)).pack()                 messagebox.showinfo("Success", "your security code is: "+self.code_info)          # register window              def register(self):                 global screen1                  self.screen1 = tk.Toplevel(self)                 self.screen1.title("register")                 self.screen1.geometry("300x250")                  global username                 global password                 global username_entry                 global password_entry                  username = tk.StringVar()                 password = tk.StringVar()                  tk.Label(self.screen1, text ="Please enter details").pack()                 tk.Label(self.screen1, text ="").pack()                  tk.Label(self.screen1, text ="Username *").pack()                 self.username_entry = tk.Entry(self.screen1, textvariable=username)                 self.username_entry.pack()                  tk.Label(self.screen1, text ="Password *").pack()                 self.password_entry = tk.Entry(self.screen1, textvariable=password)                 self.password_entry.pack()                  tk.Label(self.screen1, text ="").pack()                 tk.Button(self.screen1, text="register", width=20, command=self.register_user).pack()           #login system              def login_verify(self):                  self.login_details = self.username2.get()                 self.password_details = self.password2.get()                 self.security_code_details = self.security_code.get()                 self.username_entry2.delete(0, tk.END)                 self.password_entry2.delete(0, tk.END)                 self.security_code_entry.delete(0, tk.END)                  list_of_files = os.listdir()                 if self.login_details in list_of_files:                         file1 = open(self.login_details, "r")                         verify = file1.read().splitlines()                          if self.password_details in verify and self.security_code_details in verify:                                 print("login succes")                                 bank(self.login_details, self.password_details, self.security_code_details)                          elif self.password_details is not verify or self.security_code_details is not verify:                                 messagebox.showinfo("password/code error", "Password or code is incorrect")                 else:                         messagebox.showinfo("user error", "User not found")          #login window              def login(self):                 global screen2                  self.screen2 = tk.Toplevel(self)                 self.screen2.title("login")                 self.screen2.geometry("300x250")                  global username2                 global password2                 global security_code                 global username_entry2                 global password_entry2                 global security_code_entry                  self.username2 = tk.StringVar()                 self.password2 = tk.StringVar()                 self.security_code = tk.StringVar()                  tk.Label(self.screen2, text ="Username *").pack()                 self.username_entry2 = tk.Entry(self.screen2, textvariable=self.username2)                 self.username_entry2.pack()                  tk.Label(self.screen2, text ="Password *").pack()                 self.password_entry2 = tk.Entry(self.screen2, textvariable=self.password2)                 self.password_entry2.pack()                  tk.Label(self.screen2, text ="Security Code *").pack()                 self.security_code_entry = tk.Entry(self.screen2, textvariable=self.security_code)                 self.security_code_entry.pack()                  tk.Label(self.screen2, text ="").pack()                 tk.Button(self.screen2, text="login", width=20, command=self.login_verify).pack()   class bank(tk.Tk):      def __init__(self, name, password, code, balance=0):         self.balance = balance         self.name = name         self.password = password         self.code = code          tk.Tk.__init__(self)         tk.Tk.title(self, "Smiglo bank")         tk.Tk.geometry(self,"400x500")          tk.Label(self, text="").pack()         tk.Label(self, text="").pack()         tk.Button(self, text="deposit", bg="red", command=self.deposit).pack()         self.depo_entry = tk.Entry(self, bg="yellow")         self.depo_entry.pack()         tk.Button(self, text="withdraw", bg="red", command=self.withdraw).pack()         self.withh_entry = tk.Entry(self, bg="yellow")         self.withh_entry.pack()         tk.Label(self, text="").pack()         tk.Label(self, text="").pack()         tk.Button(self, text="Check balance", bg="red", command=self.check).pack()       def check(self):         bal = ("%s" % self.balance)         messagebox.showinfo("Balance status", "Current Balance: "+bal)      def deposit(self):         self.amt = int(self.depo_entry.get())          if self.amt < 0:             self.balance = self.balance             print("You cannot deposit negative amount")          else:             self.balance = self.balance + self.amt             var = ("%s" % int(self.balance))             file2 = open(self.login_details, "w")             file2.write(self.balance)             messagebox.showinfo("balance","your balance: "+var)       def withdraw(self):         self.amt = int(self.withh_entry.get())          if self.amt > self.balance:             self.balance = self.balance             print('insufficient funds')          elif self.amt < 0:             self.balance = self.balance             print(self.name, "You cannot withdraw negative amount")          else:             self.balance = self.balance - self.amt             print(self.name, 'balance after withdraw', self.balance) 

Python Tkinter how to make a text box scroll

I wrote the following code to quickly grab and display information from Wikipedia. It works great unless the Wiki summary contains more information than the box can display. I thought adding sticky = N+S+E+W would fix this but it doesn’t appear to be doing anything. How can I update this code to make it scroll if there is too much information to display in the text box all at once?

enter code here

import sys from tkinter import * import wikipedia  def search_wiki():     txt = text.get()           # Get what the user entered into the box     txt = wikipedia.page(txt)  # Search Wikipedia for results     txt = txt.summary          # Store the returned information     lblText = Label(main, text=txt,justify=LEFT,wraplength=600, fg='black',                     bg='white', font='times 12 bold').grid(row = 50,                     column = 1, sticky=N+S+E+W)  main = Tk() main.title("Search Wikipedia") main.geometry('750x750') main.configure(background='ivory3') text = StringVar()  lblSearch = Label(main, text = 'Search String:').grid(row = 0, column = 0,                                                       padx = 0, pady = 10) entSearch = Entry(main, textvariable = text, width = 50).grid(row = 0,                                                               column = 1)  btn = Button(main, text = 'Search', bg='ivory2', width = 10,              command = search_wiki).grid(row = 0, column = 10)   main.mainloop() 

Python xlrd not reading the cells with formula

I am using xlrd to read an excel workbook and to perform some operations on it. But the issue I am facing while reading the data is I am getting blank values where the cell contains else in the non-formula cell I am able to get the value.

for row in range(sheet.nrows):     for col in range(sheet.ncols):         print(sheet.cell_value(row, col)) 

How can I able to print those cell with formula value too. I am using Ubuntu, Python 3

Python equivalent of a MATLAB command (ss2sos)

I want to translate this 5-lines MATLAB code into Python, I did it for the first 4 lines, but I failed in the last one because I don’t know what is the equivalent of the ss2sos command.

MATLAB script:

n=2   %Filter_Order Wn=[0.4 0.6]  % Normalized cutoff frequencies  [b,a]= butter(n,Wn) % Transfer function coefficients of the filter   [A,B,C,D] = tf2ss(b,a)  % State-space representation of the filter   sos = ss2sos(A,B,C,D)   % Second-order sections form 

Python script:

import numpy as np from scipy import signal  n=2    Wn=np.array([0.4,0.6]) b, a = signal.butter(n, Wn, btype='band') A, B, C, D = signal.tf2ss(b, a) 

Генерация случайных чисел в Python по заданной функции распределения и мат ожиданию?

Как в питоне сгенерировать N случайных чисел, если нам известна функция распределения и мат ожидание? Что использовать? может SciPy или numpy?

Formatting sentence in Python to be in italic

I am trying to format some text that I am trying to add to a python script. It has two sentences and I would like to have the second sentence to be in italic.

Given below is the sentence:

'Key points include' + '\n' + 'Improved performance' 

I would like to have the phrase Improved performance to be in italic

Expected Output:

Key points include
Improved performance

How can I form in python this matrix to the corresponding graph?

im working in graph theory and sagemath or python.

for prove that R(3,3)=6 is necessary to find a counterexample of a graph where it has neither a triangle monochromatic red nor a K_3 blue, for this case, an adjacency matrix is designed with entries 1 and -1, where the entry in the matrix is 1 if the corresponding edge is red or -1 if the corresponding edge is blue, the main diagonal 0 since there are no edges.

I would like to know if it is possible to build the corresponding graph in sage with the adjacency matrix

Ex: part of the code says,

"""Subgraph"""  for k in range(2**10): G=CrearMatriz(k,5) if Encontrar_Subgrafo(G,3)==True:     print (str(k)+ " Passed")     k=k+1 else:     print(k)     U=CrearMatriz(k,5)     print (U)     break print("Done") 

where the counterexample is

 array([[ 0, -1, -1,  1,  1],         [-1,  0,  1, -1,  1],         [-1,  1,  0,  1, -1],         [ 1, -1,  1,  0, -1],         [ 1,  1, -1, -1,  0]]) 

How can I form in sage or python this matrix to the corresponding graph?

enter image description here

How to create a global RESTful API in python for a database?

I apologize in advance if the below-given information looks insufficient.

The programming language to be used throughout is python.

I am trying to understand the procedure to create an API for a database that can be accessed by anybody around the world. Like an API “https://testing.org/api/someendpoint” where there is a proper hostname and want to create a API like that, not like “http://localhost:5000/users” this as explained in the link “https://www.roytuts.com/python-rest-api-crud-example-using-flask-and-mysql/”.(please consider that i have no exp in making a API)

I also don’t know if i need to host my database(current location – local computer) somewhere else to create a global API.

So how do i go from making a local api link to a global api link.

The database is a normal database with a single table which contains information like name, id, sales info, time, etc.

Any help would be appreciated.