Posts by Éder Garcia • 785 points
44 posts
-
1
votes1
answer92
viewsQ: npyscreen with accessibility
I am helping a colleague who is blind to programming in Python! It uses the notepad and a screen reader called nvda (python). We are having difficulty with the registration form because the nvda is…
python-3.xasked Éder Garcia 785 -
0
votes1
answer719
viewsA: Calling functions using buttons
I tried to keep the most of your code. Basically I created the function exbir_botao it receives as parameters var which is a value of dict rotulo and x which will be used to determine where the…
-
3
votes3
answers1079
viewsA: transform list items into separate columns or extend dataframe to the end
If you need to merge the list elements inventory in a single string can do it this way: inventory = ["dagger","nobles's clothing","cloak", "backpack","rations for a week","waterskin", "potion of…
-
0
votes3
answers115
viewsA: Show a dictionary inside a class created by an external function
I understand that the label is the key to the dictionary. I made few changes: 1) I removed the list personagens that "I was left". 2) I replaced the method exibePersonagem by function…
pythonanswered Éder Garcia 785 -
1
votes3
answers484
viewsA: I can’t make the Pygame window close button work
Follows a basic code to complement the response of Henrique Seta. In this example the while will be executed while sair is equal to False. Note that inside the for if the event QUIT the variable is…
-
1
votes3
answers1086
viewsA: Select "Open with" with . bat command
I use Windows 10 and remember that one of the first things I did was to change the program to view image to look like Windows 7. In my case, I had no difficulty following these two steps: 1) Click…
batanswered Éder Garcia 785 -
0
votes2
answers122
viewsA: Treating a string input when I hit enter without typing anything
The solution I found was to split the script into two functions continuar and fazer. I suggest that first test in this way without making any changes and then increment the method fazer. resposta =…
-
0
votes2
answers257
viewsA: How to recover a specific chunk of text
To test my answer save your configuration file as config.txt and the code that follows saves as extrair_trecho.py In the variables inicio and fim you put the strings that marks the beginning and the…
-
0
votes1
answer43
viewsA: Repeat result when reading local xml
The solution I found was to use a dictionary feriados where the key is to data.text. I used this structure because dictionaries work with unique keys. import xml.etree.ElementTree as ET tree =…
-
0
votes1
answer33
viewsA: add value to a list inside a file
I understood that you need to save the contents of a list to a file. If this is the case follow an example of a function salvar_lista that receives the parameters lista and arquivo. To test simply…
python-3.xanswered Éder Garcia 785 -
1
votes1
answer555
viewsA: Problems with Python3 in connection with Firebird2.5
The error that is returning: "The location of the Firebird client library could not be determined." Try to install the library again this way: Enter the prompt windows command. Enter the folder…
-
1
votes1
answer72
viewsA: edit local variable out of function
In the variable valor you can pass a string retrieved from a text file, as long as it is a numeric value or pass this string directly as a parameter in the function calcular_total. This function…
-
1
votes1
answer48
viewsA: Output values are leaving without space
I added a else when the letra not in the dictionary he put a space. if letra in dic: frase += dic.get(letra) else: frase += " " Follow the full code: def…
-
0
votes1
answer72
viewsA: Unicodedecorror in "Pip upgrade" and "install pywinusb"
You can try updating Python to a more current version (type version 3.7). With Python updated and configured on path If you need to keep version 2.7 for any reason you can use the virtualenv.…
-
2
votes1
answer253
viewsA: pass input data to mysql database table
In your INSERT has an extra space at the beginning of the string. In the table name there should be no quotes. In addition you are using crase where should be single quotes. See this example and…
-
1
votes1
answer66
viewsA: How do I import a library that prints something off the Internet and shows it on Tkinter?
Modify the function previsao to return only the values of the weather forecast and then display these variables in the property text widget Label tkinter. To test this code save on a…
-
0
votes1
answer1504
viewsA: Create buttons for each item in a python list using Tkinter
I was able to solve by creating a function to display the buttons inside the loop while. The parameters i and valor are used to retrieve the key and value of the dictionary dia. from tkinter import…
-
0
votes1
answer70
viewsA: Can I create a list inside a python object?
In the following example I declared a list ex_proprietarios within the class Veiculo. The method add_ex_proprietarios adds names to the list. The method exibir_veiculo prints all attributes. class…
pythonanswered Éder Garcia 785 -
0
votes1
answer983
viewsA: Python + Tkinter Screen Management
The solution I found was to open a main window with the system menu displaying the two buttons with the create and edit user options. When one of the buttons is pressed the main window is destroyed…
-
0
votes2
answers745
viewsA: take a string string string string string string string [PYTHON]
You can use the replace to remove the tags in this way: linha1 = "<p>Conceito <span>e</span> <span>Signi</span>ficado<span> </span>de…
-
0
votes1
answer223
viewsA: How to identify files in the same name pattern, which are in a given directory, using Python?
You can do with pathlib. This code returns a list called path of all files in the specified location. Within the for you can test whether the nome_arquivo exists. See more details on documentation.…
-
0
votes1
answer63
viewsA: str.replace with Indexerror: list index out of range
You can use the linha.strip("\n") to remove line break. If you need split the syntax is linha.split() to remove the space. for linha in ref_arquivo: valor = linha.strip("\n") # remove a quebra de…
pythonanswered Éder Garcia 785 -
1
votes1
answer189
viewsA: How to correlate 2 different txt in python?
I understand that you need to join two (or more) txt files. I thought of this way: First read the arquivo_1 and save in a lista_1. Then read the arquivo_2 and save in a lista_2. Lastly merge_lista…
pythonanswered Éder Garcia 785 -
0
votes4
answers2357
viewsA: Python - Higher value of a dictionary per key
You can use the sorted with the parameter reverse=True if you want a list in descending order. lista = 1.2, 2.8, 3.9, 4.1, 5.8 print(sorted(lista, reverse=True)) Exit: [5.8, 4.1, 3.9, 2.8, 1.2]…
python-3.xanswered Éder Garcia 785 -
1
votes1
answer24
viewsA: Adaptation of csv columns with DB fields other than hard code?
You can use the dictionary coluna where the key is the field name and the value would be the desired column. Then insert you use colunas.get("nome") for example. colunas = {"nome":row[2],…
-
0
votes4
answers2181
viewsA: Check file extensions in Python
You can do with the pathlib. This code returns the path of the files at the specified location. import pathlib path = list(pathlib.Path(".").glob("*")) for nome_arquivo in path: print(nome_arquivo)…
-
0
votes1
answer66
viewsA: Split returning Indexerror
Assuming you only want to separate the value between the brackets. Read each line of arquivo.txt and slicing into the desired column. Then just add the cut extracted from the line into a list.…
-
0
votes2
answers3274
viewsA: How to convert monetary number to extended number in Python
You can use a dictionary where the key will be the number and the value will be the number in full. numero = {1:'um', 2:'dois', 3:'três'} print(numero.get(1)) print(numero.get(2))…
-
1
votes2
answers63
viewsA: How to Catch the Smallest Value of a Series of Inputs
I’d make a dictionary produto where the key is the code and the value is the price. Every passage in the while i would add a pedido in a list whenever the user responds s. When the answer is n the…
-
3
votes1
answer295
viewsA: Ordinal numbers
If you turn the list to int will need to convert the linha for string before concatenating and printing. Also change the comparison values in commands if. The conclusion is that you can convert, it…
pythonanswered Éder Garcia 785 -
1
votes1
answer21
viewsA: When a repetition is made in case there is no answer, no change is made! pq?
Is that the method input returns a string. You were testing if parcelax == 1: as if parcelax be a whole. Option 1: Then either you switch to if parcelax == '1': test the value as string. Option 2:…
-
0
votes1
answer146
viewsA: Use Variable in Button Attributes
You can add style, see this example: from tkinter import * from tkinter.ttk import * root = Tk() root.geometry('300x180') style = Style() # Irá adicionar estilo a todos os botões disponíveis # mesmo…
-
0
votes3
answers693
viewsA: I can’t make the sum of the first 100 prime numbers, where am I wrong?
Follow my solution, please test. Basically I test if a number is prime and if it is added to the list primos. When the list primos has 100 elements the loop ends and displays the sum of all elements…
-
0
votes2
answers427
viewsA: python 3, exercise with prime numbers
Unfortunately, I haven’t come up with a solution yet, but I rewrote parts of your code in a way that made it easier to understand, without affecting the results. n = int(input('n: ')) z = 2 m = 1…
pythonanswered Éder Garcia 785 -
3
votes2
answers213
viewsA: Death Note in Python - Loop Sentinel of Death
The code was almost right. The condition if morte == '': didn’t work because it was double-spaced. I removed the conversion of input because the return is already a string. I added the while to loop…
pythonanswered Éder Garcia 785 -
1
votes2
answers2495
viewsA: How to make an array with attributes or objects of a class?
Follow an example of the class Esqueleto with the construction method. To test save this code in the file esqueleto.py. class Esqueleto(): def __init__(self, nome, produto, preco): self.nome = nome…
-
2
votes3
answers4508
viewsA: Space between result (Python)
In the second row the variable int(n) is converted to whole before being multiplied by n which is a string. Otherwise it would return an error. The method join concatenates a space between…
-
1
votes2
answers57
viewsA: Problem with list creation
Greetings by Bruno Boff, In the first function you were calculating the number of list elements and not the number of characters you had in each element. I didn’t understand the second function, but…
-
1
votes1
answer69
viewsA: I’m trying to use the . split() in a def and I don’t know why it’s not working someone can help me?
Greetings Eric Verschoor, I made some adjustments to the drawing method. Follow the lines that have been modified and next to them is a comment for you to compare as was before my changes. nomes =…
-
1
votes1
answer320
viewsA: Python - Read data to demarcation point
Greetings Retronietzsche, To test this code, first create the "test.txt" file with the following content: Python é uma linguagem de programação de alto nível, interpretada, de script, imperativa,…
python-3.xanswered Éder Garcia 785 -
2
votes1
answer327
viewsA: Ordering cards in Python
The "Sorted" method returns the sorted deck list in ascending order. The "enumerate" method returns the index and the elements of the deck list. Variables "k" and "v" receive the index and the list…
-
1
votes2
answers1240
viewsA: How to add characters in a string according to a predefined condition?
I implemented the "second case", suggested in Anthony Accioly’s comment. Please try it, hug! entrada = "abaabaaaabab" cont = 0 ant = "" saida = "" for c in entrada: saida += c if c == ant: cont += 1…
pythonanswered Éder Garcia 785 -
2
votes1
answer107
viewsA: How do I let a list with multiple indexes turn into a list with only one index in Python
Complementing the solution of camillaBim: lista = ["testando", "este", "aplicativo"] texto = (' ').join(lista) print(texto)
-
1
votes1
answer75
viewsA: Remove tags within tag using Beautiful Soup
linha1 = "<p>Conceito <span>e</span> <span>Signi</span>ficado<span> </span>de <span>Tex</span>to.</p>" linha2 =…