Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
4
votes2
answers4695
viewsHow to change the value of a variable by function in Python?
How can I change the value of a variable through a function? Here’s an example of what I’d like to do: def func(t): t = 2 + 3 t = 7 func(t) print(t) The output of the print(t) function returns me…
-
4
votes1
answer101
viewsRegex custom python time 3
I need to create a regex that accepts the following entries: 8:00 8 horas 8h 8h30 (8h 30) 8h30min (8h 30 min) 8h30minutos (8h 30 minutos) and I arrived at the following: ((\d{1,2}:\d{1,2}) |…
-
4
votes3
answers2297
viewsPython 3 make the program find out how much of a given digit is in a string or a number
It’s for python 3: I’m trying to make a very basic program to find out how much of a given digit is in a string or a number. For example, if the user writes 1200, I want to print-"your number has 2…
-
4
votes1
answer1266
viewsWeb Scraping Selenium + Python on JS-generated website = difficulty mapping elements
Good afternoon. I am developing a script that: accesses a system; within the environment, you will find certain information; generates a kind of report; creates a spreadsheet with the data. My…
-
4
votes2
answers1404
viewsWhat’s the "self" for?
I am studying Python to complement my programs in Nodejs. But why in Python, a language that values the speed of development and ease of code, is used the self? Simple self use example class…
-
4
votes1
answer135
viewsDoubt: how to use python scripts for web?
I want to make a web application that will read colors in RGB logos and create suggestions of color scales for websites. The algorithm will be in python, using Opencv. The client moves the image…
-
4
votes1
answer23147
views'Pip' is not recognized as an internal or external command, a operable program or a batch file
Know how to solve this problem have python and Pip installed when I type Pip and I hit enter appears this: 'Pip' is not recognized as an internal command or external, a operable program or a batch…
-
4
votes3
answers280
viewsHow do I block access to setting parameters in a class?
import math class Circulo(): def __init__(self): super() self.__raio = None def get_perimetro(self): return 2 * math.pi * self.raio def get_area(self): return math.pi * self.raio ** 2 @property def…
-
4
votes1
answer357
viewsDifferences between Python and Javascript in relation to arrays?
I’m having some difficulty because in Javascript it was possible to do this: const x = [] x[0] = 1 x[1] = 2 But in Python when I create an empty list and try to make a statement it says that the…
-
4
votes1
answer880
viewsView all values of an array
I wonder how I can see all the values of an array when I print this: ber_MFSK = M/2*qfunc(np.sqrt(k*ebno_theory)) print(ber_MFSK) and give me this: [ 1.58655254e-01 1.30927297e-01 1.04028637e-01…
pythonasked 7 years, 3 months ago Sergio Nunes 351 -
4
votes2
answers2633
viewsWhat is the difference between the MVC architecture and Django’s MTV?
I wonder if there is any difference in practice between these two architectures.
-
4
votes4
answers837
viewsProblems with conditional structures
I started programming a little while ago and I’m doing some Python exercises. The problem is that the result variable always returns "Approved" even when the concept is "D" or "E". I’ve broken my…
-
4
votes1
answer735
viewsLosing image quality while resizing in pygame
I have some pictures of cards in size 140x190 and am using the method pygame.trnasform.scale to resize to 105x143 which is a proportional value. But it is losing quality, while the images of the…
-
4
votes2
answers838
viewsBasic code error in Kivy(Python)
I made a very simple code using Kivy, but give this error that shows in the image below: The code is as follows:: import kivy kivy.require('1.0.6') from kivy.app import App from kivy.uix.button…
-
4
votes2
answers1296
viewsIs it possible to add more than one item to a list at once?
I would like to know if it is possible to add more than one element to a list, for example: a=[] a.append('abóbora', 'banana', 'maçã') or it will be necessary to use three lines, for example: a=[]…
-
4
votes3
answers9942
viewsRemove non-numeric characters from a Python string
Let’s say, I have: a = "0LÁM@UN@D0 I would like something to remove all letters (A-Z) and other characters, I just want to get the numbers, in the example, would be only 0 and 0 b = "A1B2C3"…
-
4
votes2
answers2096
viewsHow to make the system display an error message when it is not number?
How to make the system return some message like "This value must be numerical" in the problem below? (menu one and two have already been defined, this is just a cut) print("MENU PRINCIPAL") while…
pythonasked 7 years, 2 months ago Leonardo Alves 63 -
4
votes1
answer1498
viewsCount how many times a word of a file appears in another file
I would like to count how many times a word list (archive1) appears in another word list (archive2) with open("corpus.txt", "r") as f1, open("lexico.txt", "r") as f2: file1 = f1.read() file2 =…
-
4
votes3
answers510
viewsHow to make an error message for this situation?
arq=open('filmes.txt','r') filmes = arq.readlines() def buscaPorGenero(): genero=str(input("Digite o gênero do filme: ")) while(True): for linha in filmes: linha = linha.split(";") if genero in…
-
4
votes1
answer462
viewsSearch for disordered word sequence from a list in text
Is there any way to have a list of unordered words and look for if there is a sequence of them in a text? Example: lista = ["dia", "noite", "tarde", "é", "está", "bonito", "o", "a", "muito", "feio"]…
-
4
votes1
answer161
viewsWhat are other pass applications?
In the documentation the statement pass is defined pass is a null operation. When executed, nothing happens. Useful as a placeholder when syntactically a statement is required, but no code needs to…
-
4
votes2
answers130
viewsHow to store an operator?
I wonder if you have any way to store an operator in a variable, for example a = < if 5 a 5: pass
-
4
votes2
answers1159
viewsHow to make a "LIKE" in a DJANGO ORM query?
To make a query to get the data accurately in Django, I use the filter, thus: usuarios = Usuarios.objects.filter(nome='Jonh') This will generate an SQL similar to: SELECT * FROM usuarios wHERE nome…
-
4
votes3
answers858
viewsHow to make a Union of two queries using Django Filter
I was racking my brain to do union of two darlings using Django Filter and I ended up doing it on hand (Model.objects.raw("SELECT....")). How could I union with Django’s ORM? Note: I have 2…
-
4
votes4
answers6745
viewsHow to implement a recursive MDC calculation algorithm in Python?
Non-recurring version is below: def mdc(a,b): while b !=0: resto = a % b a = b b = resto return a print(mdc(50,2)) A recursive attempt would be: def mdc(a, b): if b == 0: return a resto = a % b a =…
-
4
votes3
answers551
viewsif and Else with almost equal blocks
In Python, suppose I have a function: def func(x): if x%2 == 0: j = x/2 print(j) else: j = x print(j) Don’t mind the logic of the code, it’s just a simple example. The if and Else blocks are almost…
-
4
votes1
answer181
viewsFunction to return the proper python source code name
Is there a function to return the source file name itself? The intention would be to create a log file, which one of the data would have the name of the source that is generating that log. If you…
pythonasked 6 years, 8 months ago Rodrigo Saito 88 -
4
votes2
answers1153
viewsHow to transform integers into byte in the Python language?
I’m using the pyserial module to send serial data, so I have a list of values like: Valores = [10,20,30,40,50,60,70,80,90,100] I need to transform the values of the list into bytes to send, because…
-
4
votes1
answer850
viewsHow to integrate an Android application with a Python+DB server?
Good afternoon to you all! I am a student of Computer Science, but I haven’t had the opportunity to have a deeper experience with programming, involving the necessary integrations in applications…
-
4
votes1
answer553
viewsIs there a better way to build a graph?
I have a list of articles with their respective tags: artigo1 ['a','b','c'] artigo2 ['a','d','f'] artigo3 ['z','d','f'] ... I need to create a graph that will relate all articles by tags. In the end…
-
4
votes1
answer6347
viewsHow to modify an element within a Python list?
I have the following list: pessoa=("Filipe", 40, True) I write the print command for each element: print(pessoa[0]) print(pessoa[1]) print(pessoa[2]) the answers are: Filipe 40 True When I try to…
-
4
votes2
answers477
viewsWhy is the variable not modified?
I have the following code below: #!/usr/bin/python3 # VARIÁVEIS variavel = 0 def valores(): if ( variavel == 0): variavel = 100 elif (variavel == 1): variavel = 200 elif (variavel == 2): variavel =…
-
4
votes1
answer6892
viewsHow to save figure in Python with matplotlib?
Any figure I try to save in Jupyter Notebook saves a blank file, what kind of error might be occurring as it does not accuse any error? import numpy as np import matplotlib.pyplot as plt data1 =…
-
4
votes2
answers475
viewsWhy in Python 0.03 % 0.01 = 0.009999999999998 and not 0?
>>> 0.03 % 0.01 0.009999999999999998 Why gives this result, the rest of the division being 0? And also, instead of 3, give: >>> 0.03 // 0.01 2.0…
-
4
votes1
answer904
viewsWhat would be the equivalent of find for lists in python?
What would be the equivalent of find used in strings to use in lists? For example, if it is a=['a','b','c'], as return to position 1 of 'b'?
-
4
votes3
answers16658
viewsHow to round up with Python?
Is there a native Python way to top up? Example: 10/3 resulting 4. What I’m wearing now is a parole: x=10 if x % 3 != 0: x += 1 But that’s not very practical.…
-
4
votes2
answers1213
viewsIs there any way to connect Python to a Websocket as a client?
Modern browsers own the object Websocket, which allows you to make a connection to a Websocket server, allowing real-time communication. My question is this:: Is there any library, in Python, that…
-
4
votes2
answers1611
viewsWord count using dictionary
I need to count the occurrences of words in a text using as reference a list of predetermined words. I turned the text into a list of string, the words are in a set (set) palavras_procuradas =…
-
4
votes1
answer377
viewsIf possible, how can I work with integer values of 1 million digits or more in python?
I am running some experiments with primes and needed to process huge integer numbers, but when trying to process a small routine there is an error in the following line: Overflowerror: int Too large…
-
4
votes2
answers11353
viewsHow to format dates in python?
When I do so: data = input('data [d/m/Y]: ') print(data) data2 = datetime.strptime(data, "%d/%m/%Y") print(data2) returns to me like this: data [d/m/Y]: 17/08/2018 17/08/2018 2018-08-17 00:00:00 how…
pythonasked 6 years, 4 months ago Natanael Junior 53 -
4
votes2
answers659
viewssummation multiplication algorithm
I’m doing a job that I need to create an algorithm that turns product into sum or difference and I can only use the signals +, - and the commands else, if, print, while and input. I was able to make…
-
4
votes1
answer3271
viewsWhat are environment variables?
I have seen many questions, articles and even some modules in the standard Python library where a term is introduced which is "environment variables". Here at Stackoverflow there are many questions…
-
4
votes1
answer353
viewsWhat is the function of Python descriptors?
In Python there is the protocol of the descriptors which is basically to define a class to control the access to the attributes of another, but my question is, would this be the real functionality…
-
4
votes1
answer202
viewsImplement a blink counter in the face detection
As q do to display the amount of flashes of people detected at the time. The code below detects face with Haar Cascade, where it displays a face counter. from __future__ import print_function…
-
4
votes5
answers286
viewsRegex to capture dimensions of a product with unit of measure
I have a python function to capture the dimensions of a product in Lxcxa format but I can’t make it work for cases where the unit of measure between the values appears, regex is this one: def…
-
4
votes1
answer1486
viewsEncoding problem in Python
At one point in my code I receive a variable var of type str containing SENTEN\u00c7A. in making var2 = var.encode() print(var2) is printed b'SENTEN\\u00c7A' The original word would be 'SENTENCE' In…
-
4
votes3
answers2117
viewsRegular expression to return text between keys
I have this String: str = "Eu sou uma string {dentro de uma string {dentro de outra} }" What regular expression can I use to get just: dentro de uma string {dentro de outra}…
-
4
votes3
answers1001
views(Python) Find words with total vowels being even
I’d like to ask for your help. I have a code in Python where a part is missing: parse the words of a sentence and save the ones that have an even number of vowels. Example: "I came home and went to…
-
4
votes1
answer678
viewsBubblesort Complexity Calculation
I would like to know how I can demonstrate by induction calculation the complexity of the bubblesort algorithm, both in the best case and in the worst case. def bubble_Sort(alist): for numc in…
-
4
votes2
answers6030
viewsCompare dates in Python
Good afternoon ! I need to solve the following scenario in python: I have one or more files . txt in a folder, but I want to return only the files that have the modification date according to the…