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
-
1
votes0
answers87
viewsWhat is an alternative to creating spreadsheets with random numbers in Python ? using CSV
When creating spreadsheets with random values in Python, I used a script containing the library openpyxl (see below). I want to increase the speed of creating random spreadsheets in python because…
pythonasked 5 years, 11 months ago cbe-user-99263 121 -
1
votes1
answer661
viewsHow to reduce the runtime of a python script?
I have been for a few days trying to solve a programming problem that involves searching to find the union and the intersection between sets. I managed to solve the problem with small sets, but when…
-
1
votes2
answers2327
viewsPython code error - Syntaxerror: can’t assign to Function call
I’m doing a futsal game with POO, and I went to do a function outside the class and in the global scope assigns the vector lista_team = [], only when I’m trying to run the stage where the code is,…
-
1
votes2
answers69
viewsFind out if a timedelta object has any negative attribute
I have a function that takes a parameter of type timedelta. I’m looking for ways to know if the object passed by parameter has any of its attributes (days=0, seconds=0, microseconds=0,…
-
1
votes1
answer57
viewsindex(find) + Len(find) Valueerror: substring not found Crawler Python
Guys, I need some help with the code on Python searching results of the internet. Python 3.6 The first of Bitcoin worked out, the second that presents error. from urllib import request url =…
-
1
votes1
answer48
viewsPass Descriptor by parameter to another Descriptor
Let’s imagine that in a class I have two properties of the Scriptor type. The first of them ensures that the property in question is negative the second must ensure that the property associated with…
-
1
votes1
answer115
viewsHow to find the lists that have a certain desired item
I would like to check if a specific item in a list is equal to "Aberta". def mostrar(): with open("ficheiro2.txt") as arquivo: i=0 for linha in arquivo: linha = eval(linha) if linha[i][2]=="Aberta":…
-
1
votes2
answers1459
viewsTraverse two arrays in parallel
Want to traverse two arrays in parallel by adding : among them: Arrays NOME = ['CARLOS','JOAO','PEDRO'] IDADE ['30','25','22'] DESIRED OUTPUT CARLOS:30 JOAO:25 PEDRO:22 Trying rows = len(NOME) for i…
-
1
votes3
answers65
viewsHow to join the score with the last word on the left?
It may sound like a silly question, but I really didn’t find an answer in my readings. I created a program whose purpose is to calculate my Coefficient of Performance and the percentage of the…
-
1
votes1
answer76
viewsWhen I hit the word, an input still appears at the end
I’m developing a guessing game in Python, but when I hit the word at the end still continues to appear a input. CODE: import random…
-
1
votes2
answers658
viewsWhat is a Python hash map?
I’m a beginner in Python, and I’m doing an exercise that says the following: Considering a string, "We will keep a hash map (set) to track the unique characters we find. Footsteps: Scan each…
-
1
votes0
answers51
viewsOpen large images with python Opencv
I am working on a software that processes very large images, between 10GB and 30GB. The images are too heavy to open at once. I would like to know if there is any way to use Opencv to open the image…
-
1
votes1
answer5197
viewsRequest Python form/data
Guys I made this request in Python but not enough data in API, made in Postman works perfectly. API_URL = "https://api-us.faceplusplus.com/facepp/v3/detect" api_key = "7Z...uC" api_secret =…
-
1
votes1
answer812
viewsIs it possible to have a split() with two or more conditions in Python?
Good afternoon staff, developing a code, I came across a question: I would like to realize a split() with n conditions? Or any efficient way to do? For example: I am requesting for a user to enter…
-
1
votes1
answer34
viewsAverage of 2 values followed by a list
I have one question: I’m trying to solve an exercise for learning, which is the following: inform a list. Ex: [1, 3, 5, 1, -10], and return the average between the number and the next number. In…
-
1
votes2
answers1354
viewsSwap lyrics of a Python phrase
I have a problem with my code, the letter is not being replaced. def troca(quero_trocar, trocar_por, frase): for letra in frase: if(letra == quero_trocar): letra = trocar_por return frase I tried to…
pythonasked 5 years, 1 month ago Yasmin Yuriko 23 -
1
votes2
answers82
viewsInstantiate class by passing only a few parameters in Python 3
Good afternoon, everyone I created a very simple python class with a constructor __init__. The constructor expects to receive 3 parameters, and the 3 have default value. I would like to know how to…
-
1
votes1
answer235
viewsWord repetition
I’m developing an algorithm that sings the elephant’s music, I think everyone knows it. Who doesn’t, it works like this: a) For the first elephant, write in the singular. b) For the second elephant…
-
1
votes1
answer495
viewsIndexerror: list assignment index out of range
I tried to solve the exercise https://python.nilo.pro.br/exercicios/capitulo%2007/exercicio-07-09.html and even the template presents an error: Traceback (most recent call last): File "teste.py",…
-
1
votes1
answer513
viewsObject counter by an infrared sensor on Raspberry with Python
Hello friends I made an object counter using an infrared sensor and Python, but would like help to refine the code. Because this counter of mine has a problem, if the object stops in front of the…
-
1
votes4
answers568
viewsWrite in a file numbers separated by a certain character
I have to make a program that writes on disk a file with ordered numbers increasing from 1 to 100. Each number shall be separated by ;. The file should be called "growing.txt". I did so: arquivo=…
pythonasked 5 years ago igor roberto 29 -
1
votes1
answer300
viewsUrllib.request or Request?
I am studying web scraping and in many guides I have seen examples where they are used urllib.request and request.get. From what I’ve tested and understood the two do the same thing. So what’s the…
-
1
votes0
answers67
viewsDecode Qrcode
I’m studying a little Iot and I’m trying to create a "door opener" by Qrcode(when someone shows a Qrcode to camera, it will identify and open the door) But the camera I have at home is a Logitech…
-
1
votes0
answers50
viewsProblem saving number of items read in variable
The code has the idea of only reading how many times the highest array value repeats. num_velas = int(input('Número de velas: ')) alturaVelas = [] alturaVelas = input('Qual a altura das…
-
1
votes0
answers108
viewsCaptuar properties of a dynamically added Kivy boot
I have a problem, I have an app created in Python and Kivy that has a screen that as soon as it is accessed creates some buttons dynamically. I would like to know how to capture the text of the…
-
1
votes0
answers37
viewsHow can I automate a dowload of an excel file on the web?
Hello guys I’m having a problem, I wanted to automate a routine would download an Excel file on a certain site, if possible using Python or java, I wonder if there is already a program/code that…
-
1
votes1
answer62
viewsThis is the iteration of a nested loop
How to use generators/iterators to achieve the generic iteration of a nested loop? I have the following function implemented in an extremely inefficient way. from pprint import pprint def center(i,…
-
1
votes0
answers29
viewsaccess database data from a specific colula
I have a database with a list_students table, str(name) field and str(serie) field, someone can explain me why I can’t access the names that contain only the series I passed? conn =…
-
1
votes2
answers242
viewsWhat is In[]: and Out[]:?
For some time I am writing some basic scripts with Python, in some tutorials sometimes I come across In []: and Out[], Usually equal values appear to the forehead. Below is a small example. In [24]:…
-
1
votes1
answer59
viewsDoubt with matrix in Python
I have the following code: matrix = [[0 for x in range(2)] for y in range(10)] I’m trying to implement this in another language, in which there is no such structure above for matrix creation. I…
-
1
votes2
answers563
viewsSelenium (list of elements of a class)
Greetings ! I want to open all the elements (not repeated) of a class, each in a new tab, how do I do it ? My attempt: lista_elementos = driver.find_elements_by_class_name('card-action') for i in…
-
1
votes1
answer47
viewsInvalid block tag
I’m new in Django and I’m having a problem with the tags Template My code: {% load static %} {% block content %} <div> {{ questao.afirmativa }} </div> {% alternativas =…
-
1
votes1
answer95
viewsRun Videos with parameters
Staff I’m having difficulties in creating a relatively simple script. I have some files . mp4 and wanted to try to run them in order (with loop) and on Full Screen I have that code: class…
pythonasked 5 years, 10 months ago Erick Vieira 51 -
1
votes2
answers73
viewsError in a function that returns an AND of two variables in python
I made a function in Python that in theory should return a and of each element of two variables, however the result is not being expected. The answer would be [0, 1, 0, 0, 1, 1, 0, 0], but is…
-
1
votes1
answer133
viewsCreate dialog in Django
I am trying to create a dialog to remove a client in Django (I created the dialog with Materialize), but when trying to remove it does not execute the view function inside the html page. Could…
-
1
votes1
answer175
viewsHow to select ALL lines that have a value exceeding 3 or -3 in a pandas dataframe?
Be it: data = pd.DataFrame(np.random.randn(1000, 4)) I found the following to select ALL lines that have a value exceeding 3 or -3: data[(np.abs(data) >3).any(1)] I didn’t understand Any’s…
-
1
votes2
answers1413
viewsHow to turn list into array
I have a csv which contains 2 columns one with a list of 200 numbers (0.3,0.4,08...) and the other a name. This file has 50 rows of this type. I would like to turn this list of number lists into an…
-
1
votes1
answer80
viewsDoubt Python Code and Opencv2
In this code I can do facial detection from a webcan. I use my notebook camera. I want this code to send a text message, for example "Detected Person" every time it detects a face. I tried to put an…
-
1
votes2
answers783
viewsHow to implement the cosine function using Taylor series in Python?
Guys, I have the following problem: Until then I made the following code: import math def cos(x, n): soma = 1 formula = (((-1)**n)*(x**2*n))/math.factorial(2*n) for i in range(n): soma += formula…
-
1
votes3
answers73
viewsKey-value dictionary
Suppose I have the following dictionary: dicionario = {'exemplo1':1, 'exemplo2':2, 'exemplo3':3} How do I add a key-value without changing the ones already added? In case I want it to stay that way:…
-
1
votes1
answer34
viewsDjango form for single key
Good afternoon, everyone. I have a model in Django with a field - phone - which is a unique key: phone = models.CharField(max_length=11, unique=True) I’m trying to generate a form in which the user…
-
1
votes0
answers68
viewsissue 23 project Euler
'''A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the appropriate 28 divisors would be 1 + 2 + 4 + 7 + 14 = 28, which…
pythonasked 5 years, 9 months ago Gustavo Bahia 11 -
1
votes1
answer190
viewsAttributeerror: module 'plotly.validators.layout.template.data' has no attribute 'Isosurfacesvalidator'
I have an interactive graph in python. The code below works in Azure Notebook, but I had to migrate my code to Jupyterlab and it shows the following error: Attributeerror: module…
-
1
votes1
answer213
viewsWhat is Validation_data for in Keras fit() function
I’ve researched, but I couldn’t quite understand what the benefit of using validation_data is. And it’s only used for test samples? history = model.fit(X_train, Y_train, validation_data=(X_test,…
-
1
votes0
answers28
viewsDoubts about the float and encoding error
# coding: utf-8 peso = float(input('Qual o seu peso? (quilos)' )) altura = float(input('Qual o seu tamanho? (metros)')) imc = peso/altura**2 print('seu IMC é de', imc) What is your weight? (kilos)…
pythonasked 4 years, 11 months ago user171132 -
1
votes1
answer98
viewsShow value, not form ID
I’m making a system using Python and Django. At one point, I’m showing a table with database information. Follow my html: <tbody> {% for oportunidade in all_oportunidades %} <tr…
-
1
votes1
answer36
viewsHow to leave Choices field with no default value
I currently have this class with a field Choice, tried to leave by default "deufault=None" can it remains bringing the field filled with Royal Flush, if I move to another existing City he accepts,…
-
1
votes2
answers323
viewsPython-based web Scrapping does not provide complete html page information
Personal greetings, I’m trying to use python to get the information from the page http://www.nfce.se.gov.br/portal/painelMonitor.jsp , is a page from Faz where it has the ping status of NFC-e…
-
1
votes1
answer671
viewsHow to create a user with Abstractbaseuser or Abstractuser. (Login errors)
I’m trying to use my class Pessoa as a user in models.py. Meanwhile I tried to use AbstractUser and AbstractBaseUser. Both return me errors in the part where I try to log in, I tried several ways…
-
1
votes2
answers1086
viewsAdding list elements during a Python loop always returns the same value
I have the following code: current = [0, 1] someList = [] while True: for n in range(0, 2): current[n] += 1 print(current) # [1,2] and [2,3] someList.append(current) if current == [2, 3]: break…