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
-
0
votes1
answer132
viewsDo not select in case of null value in the database field (Django)
Eae guys, I’m having a problem, I’m making a script that randomly selects database users: select = User.objects.filter(status=0,…
-
0
votes2
answers360
viewsExtract information from a tuple and place in different variables
I’m beginner and I’m caught in a problem I don’t even know how to research right. This is what happens: My code needs to select data from a database table (so far so good), and then need to separate…
-
0
votes5
answers312
viewsMake a function that calculates the following sum:
S = 10/1! - 9/2! + 8/3! ... - 1/10! def soma(): fat = 1 somar = 0.0 for i in range(1, 11): fat *= i for k in range(i, 0, -1): somar += k/fat return round(somar, 2) I arrived at this code but the…
-
0
votes1
answer59
viewsHow to use round in lambda function
I want to understand how I can include the round in the following role: lstNumerosF = [10.01, 7.03, 2.23] lstMapa = list(map(lambda x: x ** 2, lstNumerosF)) print(lstMapa) I wanted to use inside the…
-
0
votes0
answers27
viewsPlace Objective Functions on the same scale(0,1)?
I have this code for the generation of fitness function, but I need the values resulting from F1, F2 and F3 functions to be calculated in such a way that their values are always on the same scale as…
pythonasked 5 years, 4 months ago andgualberto 27 -
0
votes2
answers46
viewsPrint a new vector by changing the order of the elements of the original vector
How do I change the order of the elements of a vector v1 printing a new vector v2 with these changes? You can write a function def? Example: v1 = [2,51,68,10] v2 = [10,2,51,68]…
-
0
votes1
answer83
viewsAutomate get from a list of tuples to JSON variables
I have a code that searches for information in a list of tuple, the code is very simple, it is searching the info in Index [0] and putting in my variables for the POST. I’d need to automate it so he…
-
0
votes1
answer45
viewsMy Tkinter library buttons/buttons are not showing
I am studying the Tkinter library a little while ago,I started to create this code, when I create the first function "start" the code until it opens the window, but the Labels and button q I declare…
-
0
votes1
answer346
viewsCheck the file extension and change its directory
I’m having trouble with a python script that checks if there are files with a specific extension in the directory and moves the whole directory to another destination This is a test to automate the…
-
0
votes0
answers47
viewsProblem with flag or string?
In this simple code the program should exit the loop when I type the word quit. msg = 'Que lugar gostaria de visitar?' active = True while active == True: Here the input is assigned to place and…
-
0
votes1
answer20
viewsspeech_recognition worthless
I made a program to open apps from a folder, and in this case it works perfectly, the problem is that it gives error if I say nothing, and my goal was to let the program running in the background…
pythonasked 4 years, 1 month ago Bernardo Mayer 13 -
0
votes0
answers45
viewsWebscraping of pictures in comments
I’m working on a web scraper that needs to redeem comments in a forum that allows the upload images. The text and author of the commentary was able to obtain using a findAll in Beautiful Soup, but I…
-
0
votes1
answer799
viewsDoubt Filling a Combo-Box with Selenium and Python
I’m trying to automate a routine but I’m not getting ahead on a part I have to select a combobox from a page with Selenium. The field I want to fill in is as follows, In all fields until I got here,…
-
0
votes1
answer79
viewsDoubt about Python List
I have these lists: data_list_com_todos_os_dados = [x for x in queryset_data if x not in data_list_all] data_list_ que conta_repetições = { y:data_list_3.count(y) for y in set(data_list_3)} that…
pythonasked 5 years, 4 months ago MARCELO PEREIRA DA SILVA 31 -
0
votes1
answer54
viewsDoubt about openCV training
In a machine learning one must separate the data in 3 sets, one for training, another for validation and another for tests with relative quantity to 70%, 15% and 15% respectively. However my doubt…
-
0
votes1
answer56
viewsPython Unsupported operand type pyppeteer
I’m trying to use pyppeteer (a port from Puppeteer to python, with basically the same syntax). When I try await page.mouse.click('.jfk-button-narrow', { 'button': 'left' }), the error arises File…
-
0
votes1
answer719
viewsCalling functions using buttons
In the code below I created a graphical interface with some buttons, but when I click on the buttons they do not call the function. I didn’t find the error, I ask for help. # Importando a biblioteca…
-
0
votes2
answers932
viewsHow to store values of a list in individual variables without knowing its size?
I need to assign each integer value within a list of at least 1 item and at most 10 items to a separate variable. Then decrease 1 of each item, add them and print the result. These numerical values…
-
0
votes1
answer274
viewsKivy: Screenmanager() to Clear Widgets before screen transition
I’m building an application with Python and Kivy. To toggle the screens use Kivy’s Screenmanager. Ex.: Button: text: 'Sair de Tela 2 e voltar para Tela 1' size_hint_y: None height: 100 on_press:…
-
0
votes1
answer276
viewsHow to use print in the graphical interface?
I need the result of the function print((randint(0,700)) appear on the label (label) of my program window (created with Py’s own Qt Designer), and not in the interpreter, but only know the command…
-
0
votes1
answer61
views3d graph with dimension error
I’m trying to plot a graph in 3d. I already have in 2d. All quiet there. It is a matrix with the values of the amplitudes of a wave propagating in a tab. But I would plot the values of the matrix as…
-
0
votes1
answer32
viewsre.search also validates invalid emails
I’m having some problems with this email validation. Any text I put in it validates and accepts. What causes this? import re def email_validation(email): regex =…
-
0
votes1
answer88
viewsSave files via upload to the folder configured with the stipulated name
I am in development environment, and would like to record an image by placing it after upload in a folder that I have configured locally on my machine like this: MEDIA_URL = '/media/' MEDIA_ROOT =…
-
0
votes1
answer219
viewsHow to take only the time of a Timestamp
Using the command below: pd.to_datetime(1490195805, unit='s') The return is: Timestamp('2017-03-22 15:16:45') How do I extract only the time: 15:16:45?…
-
0
votes1
answer32
viewsSystem to Python Client queue error
I’m programming a queue system but there’s an error I can’t fix python --------------------------------------------------------------- if command == supervisor : positivo = 'sim' negativo = 'nao'…
pythonasked 5 years, 4 months ago Eduardo Ferreira 15 -
0
votes1
answer81
viewsSelenium Python IE 11 Runtime Problem
I have a problem running Selenium on IE 11. from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.python.org") assert…
-
0
votes0
answers24
viewsAsync Live API
Can an API in Flask that fetches the live games from a website and returns them. However, this search takes about 40 seconds to be done (getDados() function), but I would like the user to receive…
-
0
votes0
answers76
viewsPython control.Python lsim
I’m trying to get the system response by inserting a sinusoidal input function, but the code below gives the following error: Valueerror: Parameter T: time values must be equally Spaced. from…
-
0
votes1
answer603
viewsHow to extract information from a 'cnab' file using python?
I need to extract the information from a cnab file (which is a text file), be able to read the file using python.read but I don’t know how to progress. Contents of the file: 39900000…
-
0
votes1
answer454
viewsInsert values to a 3D numpy array
Hello. I created the following array numpy as below: import numpy as np x = [350, 500, 800, 900, 1000] y = [1100, 900, 1250, 650, 1200] z = [50, 150, 300, 200, 500] arr_2d = np.array(list(zip(x,…
-
0
votes0
answers467
viewsHow do I add 2 (binary)? Python
I want to add 2 to a binary number that the user enters and then add 2 binary values. EX: 111001 - 110001, I make the complement of 2 in the second number and then I make the sum of these values, I…
-
0
votes2
answers434
viewsGet the maximum value of each row in a grouped pandas dataframe
I have a pandas dataframe with UF, Municipio, Classe_acidente, Total. In this dataframe each municipality appears three times, one for each accident class (there are 3 classes) and I need to obtain…
-
0
votes0
answers140
viewsProblem running facial recognition test with Python - Opencv
When executing the following test code: import cv2 import os import numpy as np from PIL import Image detector_face =…
-
0
votes1
answer222
viewsPandas package not recognized in notebook jupyter
Hello, can anyone help understand why the notebook jupyter does not recognize the panda package? created a virtual environment and installed the packages to analyze a set of Enem data, but when…
-
0
votes1
answer182
viewsHow to download ALL files from a folder with requests?
I found several articles on the internet about how to download a single file, but I always need to specify the name and directory of the file. The program I would like to do needs to download all…
pythonasked 4 years ago Danillo Araújo 21 -
0
votes1
answer68
viewsHow do I get the input to be on the same line?
I wish that when someone comes in, the input stays on the same line, I tried using the 'split' command, but I could not. D = int(input()) R = int(input()) L = int(input()) P = int(input()) G =…
-
0
votes0
answers293
viewsHow to implement a python socket code without using while true?
I’m doing a chat in Phyton that has the Guis implemented with Tkinter, according to the errors I had and by what I researched about the Text module of Tkinter (module where the messages will be…
-
0
votes0
answers24
viewsReverse spectrogram
I am trying to plot a spectrogram with the data provided to me, however, the result seems "inverted". Someone’s been through the same thing? The frame in which the signal appears matches my original…
-
0
votes1
answer93
viewsI’m trying to put a timer in my python code
In this code I intend to put a timer before each click, this timer needs to wait 2 to 5 seconds and the time should be random, for example 2.4 seconds, 3.1 seconds, always a random time before each…
pythonasked 5 years, 3 months ago jonas scott 1 -
0
votes1
answer1389
viewsProblem to convert ANSI to UTF-8 in Python 3
I’ve got some files that have ANSI encoding and accents and "ç" and everything. I need to convert these various files to UTF-8 encoding. Some files get UTF-8 encoding and others don’t, why? The code…
-
0
votes0
answers303
viewsSet value in form field (or string input)
I have a form field that contains a built-in Javascript, which works dynamically. <input type="text" id="txtPreferencia" title="Tecla de atalho: Alt+R" name="txtPreferencia" class="infraText…
-
0
votes1
answer361
viewsError trying to initialize a cloned Django project from github (Modulenotfounderror: No module named 'django_filters')
I am trying to run on my pc a Django project that I cloned from github, but if I try to run the command 'python Manage.py' returns me the following error: File "Manage.py", line 16 ) from exc…
-
0
votes1
answer283
viewsMap function with lambda in a list of Python dictionaries
Good evening, I’m taking the data via API and turning it into a . JSON to record in a list:. Inside this info is a list of dictionaries called custom_fields, so I used map with lambda function to…
-
0
votes1
answer267
viewsSerialize Python Objects in JSON
Does anyone know how to serialize in YAML or JSON a class that contains attributes that contain other classes? Class player has the Spellbook attribute (class that returns a magic list) and the…
-
0
votes1
answer270
viewsHow to iterate with Python 3 dictionaries?
I have two files and need to generate a third from them. First file called "de_para". de_to.txt Inside this file I have the following sample content: Ordem Campo_para Campo_de 1 nome_emp RAZA 2…
-
0
votes1
answer83
viewsError in python exec command
I’m trying to accomplish an action through command exec(): import asyncio from pyppeteer import launch async def main(a): #função que executará o comando exec(a) c="""browser = await launch()…
-
0
votes1
answer22
viewsError of procedure call
I’m having a problem calling one procedure within a function in the SQL. When I call the function CHECK_LOGIN for SGBD, does the operation without any problem, but I need to do this operation by a…
-
0
votes1
answer45
viewsHow to expand a dataframe based on a condition
I have the following dataframe : df = pd.DataFrame({ 'left_bound' : ['1', '4', '10', '25'], 'right_bound' : ['3', '9', '24', '50'], 'code' : ['a', 'b', 'c', 'd'], }) And I wanted to convert her to…
-
0
votes2
answers136
viewsHow to do continuous firing in python?
Good afternoon. I am developing a project where I need to make two cameras to take sequences of photos and stop only after a pre-defined command. In my current code you need to decide the number of…
-
0
votes2
answers67
viewsShorten condition that checks if value is one of several possible
Is there any way to shorten the if a == 1 or a == 2 or a == 3 of the code below? a = int(input('Digite um número: ')) if a == 1 or a == 2 or a == 3: print('O Número digitado está entre 1 a 3') else:…