Most voted "python-3.x" questions
Python 3 is the latest version of the Python programming language and was formally released on December 3, 2008.
Learn more…3,274 questions
Sort by count of
-
2
votes2
answers507
viewsHow to Improve Maximum Common Divisor Algorithm - URI 1028
I’m solving this URI problem which basically calls for the maximum common divide between two values to be found. I originally resolved with the math.gcd in half a dozen lines, however, the code was…
-
2
votes2
answers860
viewsLambda in Python - Doubt
In study on python 3, what would be the function of lambda in Python, what it serves and when it is used?
-
2
votes1
answer1458
viewsRecursive function that returns the sum of the digits of a number
I need to create a recursive function that takes a number n integer and returns the sum of the digits of this number. I made the following code but it’s giving None: def somadig(n, s = 0): if n >…
-
2
votes2
answers130
viewsLocal variable declaration in a PYTHON function
def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() result-> 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 But if I declare the variables a and b in different…
python python-3.x function variables variable-declarationasked 6 years, 2 months ago Rafael Eduh 51 -
2
votes1
answer239
viewsPython processes
I’m studying the module multiprocessing and in all the examples in python documentation there is always a if verification in the examples, I know this checks whether the file is running directly or…
-
2
votes0
answers79
viewsDefault accents when passing data from a txt to a Python list
I have a python script that takes words from a ". txt" file through the open method and puts them in a list. However, if the word in the text file has some accent, when passed to the list in python…
-
2
votes1
answer1063
viewsNameerror : is not defined in python3
I have a simple problem, when I run this function it returns an error : Traceback (Most recent call last): file.py3 on line ? , in getUserOutputs userOutput = _runwwmdh(testInputs[i]) file.py3 on…
-
2
votes1
answer280
viewsHow do I intersect each position on my list?
I tried it in the following ways based on answers achieved here in the forum. First form: A = [[1,2,3,4,5,6,7,8,9,10],[1,3,5,7,8,9,10,20],[4,5,7,13,16,20,21,30]] B = [1,2,3,4,5,6,7,8,9] C =…
-
2
votes5
answers4459
viewsAccess dictionary within a Python list
I have the following list whose elements are dictionaries: [{'nome': 'ana', 'cpf': '1000', 'endereco': 'rua xxxx'}, {'nome': 'carlos', 'cpf': '7770', 'endereco': 'Rua aaaa'}] I want to do the search…
-
2
votes1
answer3253
views(Pandas) - Group and summarise by date
Hello, I’m a beginner in pandas and I caught in a problem that I didn’t find/understand how to solve in the documentation or other topics. Briefly I need to group the days of the observations from…
-
2
votes3
answers1165
viewsPass a variable from one function to another
Hi guys, okay? Next, how could I send the variablemts_quadrados of def prog( ) to be calculated in def prog_main( )? def prog(): print("Informe o valor: ") cli() mts_quadrados = int(input(":"))…
-
2
votes2
answers54
viewsHow to start waitress-server in Background?
I am trying to start the waitress-serve server in a Flask application. For this I use: waitress-serve --call --listen=0.0.0.0:5000 app:create_app However when the server starts it hangs the console…
python-3.xasked 5 years, 9 months ago Atmos Maciel 118 -
2
votes1
answer960
viewsHow to run a function after a certain time in Pygame?
I’m making a game with Python, in which character jumps obstacles and falls after a few seconds. In javascript I used the setTimeOut function for this. In Python I tried to do the same thing with…
-
2
votes1
answer261
viewsCode sum error starting with 0; Problem inserting data into.txt file
As you can see in the code below I have tried several ways to make each product inserted to create a new code with codigo += 1, but is returning: Unboundlocalerror: local variable 'code' referenced…
-
2
votes1
answer995
viewsHow to make Python 3.7 recognize the libraries installed in Python 3.6?
I have installed on my computer the Python 3.6 for some time now. Today I installed the Python 3.7.2. But when turning the import numpy as np, gave the following error: in the module named numpy In…
-
2
votes1
answer3640
viewsHow to check if there is an element in a Python list?
I’m trying to do an algorithm in Python to check if there’s an element in a certain list. If yes, the program will print on the screen, if not, it will add a new element in the list. My intention is…
-
2
votes1
answer1231
viewsOpencv error in Python:
Good afternoon Everybody, all right? I’m looking to learn about Face Detection in Python using Opencv, installed all necessary libs, however while running the file I come across the following error…
-
2
votes2
answers711
viewsSplit and rsplit methods, python
I made this little program to try to simulate the methods 'split' and 'rsplit' of Python, but when I run it does not print the last sentence of the string. For example, if in the string I type 'pao…
-
2
votes1
answer585
viewsError: "illegal target for variable Annotation" using "@Property"
Like pygame does not have a function similar to the library SFML -> View, I am developing a "camera" format to scroll the screen and preserve the positions of objects within the general…
-
2
votes1
answer1373
viewsHow to add values of a csv using Python?
I have a csv file similar to this, with all the information of all the municipalities of Brazil (I shortened the csv to not get too extensive): ESTADO,MUNICIPIO,HABITANTES,AREA…
-
2
votes1
answer1286
viewsHow to do after user use input not break line
Turns out I want to use an input, ie put a value but after hitting enter not break the line but continue in the place where I wrote the value, I have no idea how to do with the python input, I tried…
-
2
votes1
answer1160
viewsHow to make dynamic graphics in Python 3?
I’m doing a program for Raspberry Pi that scans temperature sensors and stores these readings in a buffer. I need to make a dynamic graph that shows the relationship between temperature and current…
python-3.xasked 6 years ago HelloWorld 843 -
2
votes2
answers253
viewsExtract content from "Name:" field until end of line
Given a string in the following format: 'a1in1iionia\n\nDados do cliente\nNome: Foo\nE-mail: [email protected]\n' I need to extract the full content from the "Name" field. For this I wrote the code:…
-
2
votes3
answers4406
viewsHow to comment on python3
I’m starting to learn programming, and I’ve already learned the basics of language c++, in this language there is the function of commenting the programming that can be accessed by //, but the same…
-
2
votes1
answer63
viewsHow to assemble a set of different data types into a named structure in python?
Good afternoon, I had a question about how to gather a set of different types of data in a structure named in Python. I’m in the process of migrating from Delphi to the Python language. But I want…
-
2
votes1
answer20
viewsWhy is my getbands returning 'L'?
I am working with images and am filtering images with transparency. I am using the function getbands() Pillow. But this image is returning : ('L',) while I just waited: ('R','G', 'B') and ('R','G',…
python-3.xasked 5 years, 6 months ago Vinicius Morais 1,293 -
2
votes3
answers4508
viewsSpace between result (Python)
So, I’m doing an exercise where the goal is for the machine to ask a number and then it type the number according to its value. For example, if I type "2" it gives me the answer "22", if I type "3"…
-
2
votes2
answers867
viewsReplace string with regex in python 3
I have a code that replaces certain string with whitespace dados =…
-
2
votes1
answer487
viewsProblems with additional files in Pyinstaller
I’m building a EXE with the way Onefile of Pyinstaller (by auto-py-to-exe). I need two files to be added, one .py from where the main will pull the functions and a jpeg image so that the computer…
-
2
votes1
answer52
viewsHow to make this class usable?
In the code below, I would like to return an instance of the class itself with the data filled through a text file. The lines are stored this way in the file: Yug…
-
2
votes3
answers78
viewsDifficulty with first code
This is my first code that doesn’t involve my class. My goal is to assemble a code that asks you to insert any chemical symbol and this will tell your group. Pretty simple concept, but I’m having a…
-
2
votes1
answer68
viewsSearching for a field contained in several models
I have a manager in my project, which is to make TAGS, and on the front of my system the user will search a tag, and it will return everything related to that tag. Follow the models.py: from…
-
2
votes1
answer835
viewsPython 3: Tkinter - Background image does not exist, "pyimage1" doesn’t exist
My code to display a background image: from tkinter import * def entrar(): #Janela Principal janela = Tk() janela.title("Salvadados") janela.geometry('400x600') #fotofundo back = Label(janela)…
-
2
votes1
answer2027
viewsPython - Run two scripts at once
In have a file x.py and the y.py, in another file I have the following code: import os os.system('py -3.7 x.py') os.system('py -3.7 y.py') But the problem is that the y.py only executes when…
-
2
votes1
answer376
viewsHow to eliminate noise in an image?
In relation to the image presented, I want to leave only visible the main trunk and the (secondary) branches of the plant (tomato). Depending on my attempts, what seems to me to give more…
-
2
votes1
answer540
viewsSeparating a dataframe by some python pandas criterio
I have a database that has 789 reviews of people on a particular product, it has the columns reviews and stars. I normalized the data to positive (star >= 3) 1 and negative 0. outputs =…
-
2
votes2
answers1148
views(Python + Pyqt5) How to close one window after opening another?
Hello. I’m having a problem with a login form. When you enter the correct credentials, the next form opens, but the login form remains open. How do I close the login form after opening the proximic…
-
2
votes2
answers1740
viewsComparing datetime with minutes interval
I need to compare 2 dates, these dates are in format %d/%m/%Y %H:%M:%S and one is obtained through the internet, and the other locally, however I am not able to compare the two with an interval of 2…
-
2
votes2
answers123
viewsPython functions + lists
When I try to create the function below I always get the first list value, it seems that it is not iterated. Someone could explain me why? Follows the code: novalista = [] def find_it(seq):…
-
2
votes1
answer166
viewsHow to use pandas styling properly?
Python code From the examples of documentation the following code has been created: import pandas as pd import os import webbrowser import io def highlight_max(s): ''' highlight the maximum in a…
-
2
votes0
answers28
viewsDoubt about inheritance in Python
Hi, I’m studying POO in Python and saw that you can inherit the attributes of a super class in two ways: Class nome_da_classe(nome_da_superclasse): def __init__(self, args):…
-
2
votes1
answer58
viewsRequesting Privileges in Windows with python
I have my python script, but, I need Administrator privileges to run a bug-free function ex.: delete a folder. How do I make my script ask for Windows privileges.
python-3.xasked 5 years, 3 months ago felipe caridade 29 -
2
votes2
answers902
viewsFunction Encode() and hash creation
I’m using Python 3.6 to make a program in which the person types an MD5 hash, then the program saves the hash in a variable, reads a txt file and plays the content inside a list, where each name…
-
2
votes2
answers962
viewsSearch Only the numbers of a String using Regex in python
I’m trying to clear a column of a process dataset and the number of processes come in various forms: 5080847-62.2018.4.04.7100 033/2.17.0001000-7 I want to leave only numbers and remove the other…
-
2
votes2
answers143
viewsConditional structure does not work
Several times, especially when the second price is higher than the others, the program accuses that it is the cheapest. #Faça um programa que pergunte o preço de três produtos e informe qual produto…
-
2
votes0
answers125
viewsHow to create a view in a Django project with Python? I’m having errors
I’m a beginner in Django. I’m continuing a ready-made project in Django. I’m looking to add a schedule to the project using Full Calendar. For this I already developed the template with the html…
-
2
votes1
answer598
viewsDjango request.GET
Is there any simpler way to do that? if "id_parada" in request.GET: id_parada = request.GET["id_parada"] else: id_parada = ''
-
2
votes1
answer273
viewsCancel button on a timer
Hello, I was doing a timer that went up to 100 and then to, and then I had the brilliant idea to put a cancel button on the count. I did some things only that when he says "To cancel type "c"" the…
-
2
votes2
answers241
viewsHow to manipulate audio volume in real time
How can I manipulate the volume of this audio in real time ? import time, pydub, numpy as np, sounddevice as sd, random file_path = '/path/to/file.mp3' def read(f, normalized=False): a =…
-
2
votes1
answer204
viewsHow to compare two values of two different classes in Django
Hi, I’m new to Django and I have the following problem, I have two classes in Django one of them is : class Apps(models.Model): id = models.UUIDField(db_column='ID', primary_key=True) # Field name…