Posts by de_python • 269 points
19 posts
-
1
votes5
answers821
viewsA: Avoid blank input data
Unused while or if, the best you can do for short is to force input typing. If you will only receive numbers, use int() or float() as a wrap of input() returns an error as below variavel_1 =…
-
0
votes0
answers369
viewsQ: Pyodbc Error: ('HY000', 'The driver Did not Supply an error!')
I’m having a little trouble using the pyodbc to connect to an MS Access. Until a few days ago, everything was operating normally, but after updating my Anaconda, a persistent error occurred in the…
-
0
votes2
answers170
viewsA: How to exit a function and go to another function within a class, python?
You can create a function with this specification, it can be up to a function called parte_1, example: class MinhaClasse: def __init__(self, atributo1, atributo2): self.atributo = atributo1…
-
3
votes1
answer118
viewsA: Object Orientation (SUPER HELP)
Come on: You have the class Pessoa, that means you are a "builder" of people. You can do: maria = Pessoa() joao = Pessoa() dom_pedro_segundo = Pessoa() So maria will have all the characteristics…
-
2
votes1
answer91
viewsQ: pop-up with python progress bar
I am currently migrating a system to python and it has a window that opens making the progress bar. In my migration I used the tqdm to generate a progress bar on the system, but in another part of…
-
0
votes1
answer182
viewsA: Rounding of decimal places float python
The part of your code, try: def raiz_d(): a=float(eda.get()) b=float(edb.get()) c=float(edc.get()) rd=((b**2-4*a*c)**0.5) rd = round(rd,2) lb_rdelta['text']=rd In a direct test (passing the values…
-
0
votes1
answer59
viewsA: Keysorting using Ordereddict?
So, it doesn’t make much sense this order, but if that’s the case, follow the code: class Produto: def __init__(self): self.text = self.show_weird_order(self.prod()) def prod(self): estoque = [] t =…
-
0
votes2
answers629
viewsA: How to implement a priority queue that still meets other requirements?
You can use the from itertools import cycle, in this case, you can make it stay permanently running over a list, using the function next(iter). So you can move on to a list of patients (for example)…
-
0
votes3
answers67
viewsA: How to not execute lines of code when the name is not in the list
You might try to do something like: def verifica_cliente(resposta): lista_convidados = ['arthur', 'maria', 'roberto', 'naime', 'letícia'] if resposta in lista_convidados: print(f'Seja bem-vindo…
-
0
votes2
answers672
viewsA: Edit a file name using Python
OPTION 1: You can try something like: import os def change_file_name(sufix, path): for file in os.listdir(path): prefix = path.split("\\")[-1] + "_" #Armazena o nome da pasta atual if…
-
2
votes2
answers239
views -
-1
votes2
answers1295
viewsA: Selenium Select Boot
from selenium import webdriver from time import sleep browser = webdriver.Chrome(r'').sleep(0.5) al = browser.find_element_by_link_text('ALLOW') al.click() Follows a possible solution.…
-
1
votes2
answers426
viewsA: union of lists
You can try def uniao(l1,l2): return list(set(l1+l2)) In this case, you join the two lists, make a set() on them (which will make it have only unique values, but in the {} format) and then move into…
-
0
votes1
answer66
viewsA: Find equal names(string) in two distinct dataframes and add a column in the second data frame with another data from the first
You can try something like: def insert_rank2(df1, df2): if not 'rank' in df2.columns: df2['rank'] = pd.Series() for team in df1.name: index = df2[df2['team1'] == team].index df2.iloc[index]['rank']…
-
1
votes1
answer279
views -
-1
votes2
answers783
viewsA: How to implement the cosine function using Taylor series in Python?
The only thing I would do is to isolate the "x²k" formula = (((-1)**n)*(x**2*n))/math.factorial(2*n) # o teu formula = (((-1)**n)*(x**(2*n)))/math.factorial(2*n) #isolado Thus avoids any…
-
2
votes2
answers339
viewsA: How to save the result of this code in a list?
You can use the following functions: def salvar(filename, info): file = open('{}.txt'.format(filename),'a', encoding='UTF-8') file.write(info+'\n') file.close() def ler(filename): file =…
-
0
votes2
answers351
viewsA: Compare Dataframes and show different information between them
In this case, if you duplicate the first df as code below: df_c = df_a.append(df_a) Dataframe 'df_c' will be duplicated df_a. If you use drop_duplicates, it will return only the dataframe header. To…
-
0
votes2
answers1354
viewsA: Swap lyrics of a Python phrase
try to do the following: def troca(quero_trocar, trocar_por, frase): frase = frase.replace(quero_trocar, trocar_por, len(frase)) return frase In this case, 'Len(phrase)' causes the 'replace'…