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
-
7
votes3
answers4863
viewsInstall with PIP through the Resets.txt file inside Virtualenv?
I learned these days that through command pip freeze > requirements.txt, i can generate a list of dependencies of a specific project where I am using VirtualEnv. How do I install all the…
-
7
votes6
answers49406
viewshow to search for an element in a list that is inside another list?
I have the following list composed of lists. [['julian', '0', '5'], ['ana', '10', '4']] and I need to use a function that tells me the position of any element within that list, I tried to use:…
-
7
votes1
answer3710
viewsWhy use static python methods
I’m studying about the subject of the title and I can’t get the idea with the explanation on video and the Stk I found, so when and why we use static method @staticmethod in python, one has some…
-
7
votes3
answers4993
viewsPython Virtual Assistant - Efficiency
I’m creating a virtual assistant in Python, and I want it to be more "human". I want her to interpret my request, and not just compare what I said to a string. So my question is: To cover all…
pythonasked 7 years, 8 months ago Denis Callau 306 -
7
votes4
answers7124
viewsAccept only numerics in input
nota = -1 while nota < 0 or nota > 10: nota = int(input("Informe a nota entre 0 e 10: ")) if nota < 0 or nota > 10: print("Valor inválido") I need to include this validation code to, if…
-
7
votes2
answers2160
viewsHow to install Pip for a particular version of Python?
I have Ubuntu 17.10 installed and it came with Python 2.7 and 3.6. I installed Python 3.4 but I can’t install Pip on it, it always goes to the latest version with pip3 which is 3.6 How can I install…
-
7
votes3
answers1500
viewsWhen to use blank lines in a Python program?
Skipping lines is one of the aspects that make a program well indented? If so, what is the criteria used to skip lines?
-
7
votes1
answer182
viewsPython: is not turning my regex’s Character class into negative
I’m learning Regexes by the Automate the Boring Stuff w/ Python. In one of the titles of chapter 7, the book teaches about character classes. So far quiet. I have created Character classes for…
-
7
votes2
answers254
views"Deep Copy" without importing the "copy" module?
Is there any other way to perform a "Deep Copy" of Python objects without using method deepcopy() of the standard library copy ? The code below could be written differently ? import copy class Xpto:…
-
7
votes2
answers11799
viewsWhat does float("Nan") and float("inf") mean in Python?
I’ve seen a code like this: def _min(*args): res = float('inf') for value in args: if value < res: res = value return res I would like to know what is a float("inf") and a float("Nan").…
-
7
votes2
answers3036
viewsHow to check which file is the latest in a Python folder?
Suppose you have a folder with several files .txt, with different names, I need to know the latest file. How do I do this using Python?
-
7
votes2
answers770
viewsWhat is the difference between namedtuple and Namedtuple?
To module documentation typing states that the two code snippets below are equivalent. Using typing.NamedTuple: from typing import NamedTuple class Employee(NamedTuple): name: str id: int Using…
-
7
votes2
answers99
viewsWhy split this operation into two cause result changes?
I made a simple algorithm that solved Fibonacci in 2 logical operations within the loop. I decided to look for a better way and found a version that makes in only 1 calculation inside the loop. It…
-
7
votes3
answers4852
viewsHow to remove accents with regular expressions in Python?
I am developing a regular expression to try to replace accents and characters with normal characters Example: á = a ç = c é = e But mine regex is just eliminating some hint? import re string_velha =…
-
7
votes2
answers2508
viewsDifference between commands to stop execution
I found that there are several ways to interrupt an execution. Basically what is the difference between using the commands: break; sys.Exit() ( From the module sys); os. _Exit() ( From the module…
-
7
votes1
answer526
viewsHow to Force Finish a Thread in Python?
How to force a Thread to terminate in Python? Example: import threading def funcao(): print("Função executando em tarefa paralela.") print("Função executando em tarefa paralela.") print("Existem…
pythonasked 6 years, 7 months ago user110265 -
7
votes3
answers1494
viewsWhy is Python so current?
I noticed that the world’s leading sites (Google, Facebook, Youtube) still use Python. I found in several sites the advantages of using Python (simplicity, robustness...), but I still follow with…
pythonasked 6 years ago Luiz Augusto 2,482 -
7
votes1
answer926
viewsWhat would be WSGI?
I was reading about the term WSGI to understand a little more the operation of web applications in Python, and I realized that some microframeworks like Flask uses this technology. However, I still…
-
7
votes4
answers4137
viewsIs there a "main()" function in Python?
In some languages, as in C, we have the function main() which is usually the default entry point of the program. There is something similar in Python?
-
7
votes1
answer2734
viewsWhat is the difference between r+ and w+ modes in Python?
I need to open a file to read and write at the same time, I was in doubt to choose between access modes. If I open the file like this: open('output.txt', mode='r+') Or open like this:…
pythonasked 5 years, 10 months ago Thiago Krempser 1,878 -
7
votes2
answers1315
viewsPython and Opencv add points and Houghline
I’m doing my TCC in electrical engineering, where I have to automate a quadricoptero to take pictures of plantations, so far so good. The problem is that my teacher asked me to make a code in python…
-
7
votes1
answer2289
viewsHow to remove image noises using opencv - python?
I am working with skin images, in the recognition of skin spots, and due to the presence of noises, mainly by the presence of hair, it is more complicated this work. I have an example image in which…
-
7
votes4
answers388
viewsHow can I add a hyphen between all even numbers of a value?
Good morning, could someone help me with a code please, I need to insert a hyphen (-) between two even numbers. For example, if you receive the number 02368859 as input, the output of the program…
-
7
votes1
answer513
viewsHow to remove noises and hairy image lines?
I’m working on hair removal on skin images. Researching the literature, the means to achieve my goal, applying some techniques of segmentation and removal of noise in images. Which I’m applying to.…
-
7
votes2
answers602
viewsError splitting image in half using Python
I’m trying to split an image in half using the code below, but I’m having a feedback error. Code: import cv2 import numpy as np # Read the image img = cv2.imread("IMD015.png") width = img.shape #…
-
7
votes1
answer309
viewsRunning time of an algorithm
def isprime(n): # 0 and 1 are not prime if n < 2: return False # 2 is prime if n == 2: return True # even numbers are not prime if n % 2 == 0: return False # test if any odd number between 3 and…
pythonasked 5 years, 5 months ago mayconrralves 73 -
7
votes4
answers138
viewsCount inside an array with values from another array
I would like to realize a Count of the values contained within the array1 with the array values nomes, but he’s returning me an output with the strange values SCRIPT array1 = [ 'VALUE1', 'VALUE1',…
pythonasked 5 years, 5 months ago Luis Henrique 697 -
7
votes3
answers1161
viewsHanoi Tower - How does this recursive solution work?
Could someone explain to me the logic of this recursive function? I’m not getting the idea from if down. The code solves the problem of the Tower of Hanoi: def toweOFhanoi(disc,ori,dest,aux): if…
-
7
votes2
answers634
viewsHow to use different . Kv files in a Kivy application?
I am trying to create a game using Kivy in Python language and I would like to know how I can use different files .kv to be used in the application as levels for the game. Example: main.py game.kv…
-
7
votes1
answer73
viewsLimiting the number of regex Matches with Python
I’m having a little trouble, I’d like to create a for in the Python to return a specific amount of match of regex. The way I did, he’s returning all the links that exist and that meet the defined…
-
7
votes3
answers557
viewsContinue loop if input is’S'
I tried to make a loop, that while the input is’S' it comes back and prompts again (it’s just for me to learn), if the input is 'N' it comes out of the loop, but is in loop infinite. continuar =…
-
7
votes2
answers1109
viewsDo if by denying a boolean in Python
How do I make for the if check a boolean negation, as below: self.senha = Gugu_0099 for i in self.senha: if i.isdigit() and i.isalpha(): total_simbolos += 1 I want you to get into this if if the…
-
7
votes2
answers94
viewsProblem when typing str in Python
I wrote that code: while True: try: n1 = int(input('Digite o número 1/5: ')) except ValueError as e: print("Digite um número:",) if ValueError: n1 = int(input('Digite o número 1/5: ')) try: n2 =…
-
7
votes2
answers707
viewsAre class methods recreated for each instance in Python?
By what I observed when generating an instance of a class all class methods are recreated in a different memory position as in the excerpt below: class Foo(): def __init__ (self): self.x = 10 def…
-
7
votes3
answers1292
viewsHow to loop 'for' in 1 line?
The following code did not work: rank = [1, 2, 3, 4] print(rank[c] for c in range(4)) If you can make use of for in a row would like to know.
-
7
votes2
answers283
viewsUse of empty "print()" in place of " n" before conditions
Have a problem using print() before conditions instead of using \n. For example let’s say I have something basic like: `idade = int(input('Quantos anos você tem?')) if idade > 0 and idade <…
-
7
votes1
answer94
viewsWhat are the differences between ways of manipulating huge strings with Python?
When it is necessary to work with strings very large it is normal to see approaches that seek to optimize the process in some way. Of the approaches I have seen are using: io.StringIO or io.BytesIO…
-
7
votes1
answer198
viewsHow to put emoji in a string?
I know that in a string I can put any characters you want, ex: string = "qualquer coisa! @#$%ª太陽" But what if I want to put one emoji in a string, how do I? Has any specific way? Can I put it right…
-
7
votes6
answers19845
viewsHow to change the name of the pandas dataframe column?
I am using pandas to process a CSV file in the following structure: nome;idade Fulano;28 Joao da Silva;27 Maria;29 The reading of the file is done as follows: import pandas as pd df =…
-
7
votes3
answers162
viewsAnother alternative to not repeat this "function" three times?
Make a program that reads three vectors with 10 elements each. Generate a fourth vector of 30 elements, whose values should be composed of the interspersed elements of the three other vectors.…
-
7
votes2
answers195
viewsQuestion about entering items in a list with indexes inside Python brackets
You can insert items into a list using methods such as, append(), extend(), or insert(). But it is also possible to insert through indexes in square brackets, normally used to replace items and not…
-
7
votes1
answer126
viewsHow to change the color when drawing a line segment that belongs to a circle?
I’m trying to draw in an image 400 × 400. The first drawing is a line defined by the equation ax + by + c = 0. When to replace x and y and the result is 0 the point belongs to straight, then change…
-
7
votes2
answers87
viewsWhat is the relationship between unhashable and mutable?
I always use strings as keys in dictionaries, but, studying the theme, I noticed that it is possible to use any immutable object. So, in addition to strings, dictionaries accept as keys objects such…
-
7
votes2
answers141
viewsHow to Split by Capital Letters and Numbers at the same time?
How can I separate a string by letters and numbers at the same time? For example if I have strings: composto1 = 'H2SO4' composto2 = 'CaCO2' composto3 = 'C20H17' I’ve tried to do: import re…
-
7
votes2
answers80
viewsHow to understand mapping (map) of functions list in Python?
lista = [0, 1, 2, 3, 4] def square(y): return (y**2) def cube(y): return (y**3) funcs = [square, cube] for i in lista: valor = map(lambda x: x(i), funcs) print(list((valor))) Exit: [0, 0] [1, 1] [4,…
-
6
votes3
answers11827
viewsUse list as dictionary value using Python append() method
I have some python dictionary, and I want to assign a list as a value for each dictionary key, but I need to use the append() method to add elements, but after adding the elements to the list, the…
-
6
votes2
answers7033
views -
6
votes3
answers456
viewsWhy does IDLE not finish running the program automatically?
I think it’s more of a curiosity. Unlike other IDE’s, IDLE keeps the program "open" even after the end of its run, while in other IDE’s I need to put something like 'input()' at the end so the…
-
6
votes1
answer291
viewsHow to build a Web2py query by quantifying the difference between days
I’m using Web2py (Python), query using the DAL I wonder if it’s possible to pick up the difference in days, something close to that Example #!/usr/bin/env python # -*- coding: utf-8 -*- resultado =…
-
6
votes1
answer3700
viewsHow to make a POST request in Python?
I’d like to know how to make a request POST in this URL, and then arrive on that page. Where I have to spend the year at div of the tax body without signature.…