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
-
0
votes2
answers60
viewsHow to create variables dynamically (Speech_recognition)
I need to transcribe a 21 minute audio using speech_recognition and recognize_google the problem is that the api does not allow any audio size, I do not know exactly which but it is greater than 30…
-
0
votes1
answer86
viewsHow to sort elements from a list using Selection Sort?
I implemented Selection Sort to sort the text of a . txt that I made into a list. The problem is that it only orders field 1 and field 3, field 2 it did not order, as seen in the output: 10, 100, 2,…
-
0
votes1
answer601
viewsConvert number to binary
I’m having trouble with the logic of my code: dec = (10) dup = dec co = 2 exp = 0 res = (tuple) while True: dup = dec dec = int(dec / co) exp += dup * co print(f'dec {dec} dup {dup} exp {exp}') if…
-
0
votes1
answer23
viewsPrint only the negatives
lista = [12, -2, 4, 8, 29, 45, 78, 36, -17, 2, 12, 8, 3, 3, -52] for n in lista: if n < 0: soma_dos_negativos = sum(n) print('A soma dos elementos negativos é igual a…
python-3.xasked 4 years, 5 months ago Lucas Lima 17 -
0
votes1
answer350
viewsUpdate in a specific field in Django 2.0
I have the following Model: class Venda(models.Model): id = models.AutoField(u'AÇAIEX', primary_key=True) hora_saida = models.TimeField(max_length=6) responsavel_frete =…
-
0
votes1
answer76
viewsGuessing minigame telling wrong
Total hits and kicks do not appear correct, if I change "hits" and "totalguess" to 0 the first hit or kick counts as 0 and wanted as 1 from random import randint acertos = 1 totalguess = 1 while…
-
0
votes1
answer38
viewsBubblesort in key 3 of a tuple?
I own a tuple with the following values: ('beringela', 10, 1.99) ('arroz', 5, 4.99) ('peixe', 2, 9.99) ('abacaxi', 100, 3.99) I must order it by the third column, but I cannot use Builtin…
python-3.xasked 5 years, 6 months ago Caio Tracera 55 -
0
votes3
answers69
viewsSQL syntax error in a Flask application
I am developing a game display system, with user login necessary to add games to this list, but when I try to run the query, I get a syntax error. It follows the code that prepares the database (has…
-
0
votes1
answer161
viewsDjango Runserver
Greetings Galera, Ando having a problem with the Django framework: initially could climb the server normally, but after a while, when running Manage.py, the server does not "go up" and the command…
-
0
votes2
answers1113
viewsComparison of python string inside if
My comparison of relatively simple strings doesn’t work and I can’t find the reason. # -*- coding: UTF-8 -*- import csv import os def sortKeywords(): keyw = [] sheetsList = os.listdir('.') for sheet…
-
0
votes3
answers62
viewsFunction returns value only the first time it is executed
This is my code: import conector_modbus as conector_modbus import leitor_csv as leitor_csv address_file = 'address.csv' dados = leitor_csv.leitor(address_file,"dicionario") def coletar_dados(): for…
python-3.xasked 5 years, 6 months ago JonP 5 -
0
votes0
answers20
viewsRequests in flask for fields with the same name
<div> {% if filmes|length > 0 %} {% for f in filmes %} <form action="/pesquisa_filmes_id", method="POST"> <input type="hidden" id="id_filme", name="id_filme" ,value="{{f}}">…
-
0
votes1
answer130
viewsHow to create a PDF from a list
want to create a PDF from a list but this resulting the following error: C:\Users\nicperei\Desktop\pyCodes>py web.py Traceback (most recent call last): File "web.py", line 22, in <module>…
-
0
votes0
answers69
viewsDash Problem in Python
I’m trying to run this application on my laptop (Macbook air), and when I go to Terminal it does not run, but when it runs on a windows PC I have no problems import dash import dash_core_components…
-
0
votes1
answer55
viewsDjango - Charfield creates Int field in BD
I have a simple project here, with two models that contain an attribute called phone in both. class Medico (models.Model): nome = models.CharField(max_length=50) endereco =…
-
0
votes0
answers25
viewsHow do I make this script work?
I know that the variable will always be str but I wanted to put a value there and if it was of the whole type then check otherwise it gave the message "You have to type a NUMERIC age and not a text…
-
0
votes1
answer120
viewsHow to display or extract all "cookie" information from a python page?
I’m trying to extract the cookie from a page but I can only get information from the NID: import requests session = requests.Session() response = session.get('https://www.google.com/')…
-
0
votes2
answers91
viewsError performing @pytest.mark.parametrize
Where am I going wrong? Bhaskara.py import math class Bhaskara: def delta(self, a, b, c): return b**2 -4*a*c def main(self): a_digitado =float(input()) b_digitado =float(input()) c_digitado…
python-3.xasked 5 years, 6 months ago Daniel Lawand 1 -
0
votes1
answer363
viewsError initializing PYGAME
I’m creating a simple replica of the game Space Invaders in Python3.7, at first I was creating the screen all with Turtle, but the game entered in a kind of infinite loop and did not execute the…
-
0
votes1
answer1037
viewsCreate successive sum multiplication program in Python
The requirements are: solve positive and negative numbers; Do twice the one million, never a million times the 2, ie always the fewest sums; use the Try and ask for new execution. Like I’m trying to…
-
0
votes1
answer42
viewsHow do I resolve a problem of renaming ENCODED URL files?
How to troubleshoot this problem of renaming ENCODED URL files? When converting a list of URL ENCODED files through the following code from urllib.parse import unquote import os, shutil cwd =…
-
0
votes1
answer23
viewsHow can I compare a variable within a list of lists by reading/changing their content in Python?
board=[['1','2','3'], ['4','5','6'], ['7','8','9']] p_move = input('Enter your move: ')) # p_move = '4' for row in board: for column in row: if p_move ==…
-
0
votes0
answers41
viewsAscii problems running script
Good afternoon, I am developing a simple script that needs to take data from an ascii encoded database, however I am getting an error message regarding utf-8 formatting. code snippet:…
-
0
votes1
answer110
viewsHow to add to each value of a list, a number that depends on another random?
I have a list of 21 terms and a value that goes from 0 to a random number that varies from zero to the number typed by the user. I need to divide this random number into smaller numbers that add up…
-
0
votes1
answer1068
viewsList and Access Python subdirectories
Good afternoon guys, I’m trying to create a very simple text file management system, but in some of the difficulties I am found is accessing and manipulating files in subdirectories. Below I have…
-
0
votes1
answer193
viewsManipulating String while true PYTHON
I’m doing a student grade exercise, receiving a str with the student’s name, then int to know the grades(n1,N2,N3,N4). I made a while true, so it will always ask, until the user asks to quit,…
-
0
votes2
answers172
viewsDelete a row and column range in python?
Hello. I want to delete rows and columns from a csv file, and just keep the lines in the 15212 to 21777 range, from a file with more than 23,000 lines. The columns I managed to delete in the way I…
-
0
votes1
answer39
viewsHow to calculate the frequency the data appears on Django?
Hi, I’m making a search bar with filters, in it the user can choose whether to sort by frequency or sort by another field (which is ordering everything right), what gives problem is when searching…
-
0
votes0
answers52
viewsCalculate the weight of each class of an unbalanced multi-label dataset
I would like to calculate the weight of each class of a dataset multi-label to pass to fit_generator of Keras the parameter class_weight. In the case of a dataset single label, as my output is…
-
0
votes1
answer705
viewsLast record of each Django object
I am developing a web application in Python, Django and Sqlite. I have two models, one for "Seller" and one for "Orders". I need to take the last order of each seller and I’m not able to do this…
-
0
votes1
answer388
viewsRemoving duplicate lines
I’m developing my TCC, My TCC, it searches emails in google collection, makes bulk sending etc, I’m having a problem, In this search for emails he collects repeated emails and invalid emails, then…
python python-3.x python-2.7 python-requests python-kivyasked 5 years, 6 months ago Allan Petersen 3 -
0
votes0
answers76
viewsAccess from a dictionary in flask via POST
How could I access a dictionary element using POST in flask? I have lists to simulate a comic and through the POST, I would like to try to access them. Function code:…
-
0
votes1
answer208
viewsMake attachment system with my python email sender
So, I’m developing a mass mailing, Only I’m not getting to use attachment in this shipment. The Code is found like this: #!/usr/bin/python3 import smtplib import os as sistema import getpass…
-
0
votes2
answers76
viewsHow do I remove alphabetic characters from a column of a pd. Series? (Python)
My question is quite simple. Given a pd.Series as described below, how do I remove "YEARS" and "MONTHS" characters from it? I looked at the documentation of Pandas but unfortunately I could not find…
-
0
votes1
answer292
viewshow to get the minimum average and maximum time of a timeseries with pandas, based on a column where the value is boleano?
I’m analyzing a timeseries returned with pandas ex: index----valor------timestamp <br> ----0 -------0-------- 2019-04-23 16:14:34.142540+00:00<br> ----1 -------0-------- 2019-04-23…
-
0
votes1
answer303
viewsBlack background python image
I’m using pdf2image to export the pdf pages and join in just one jpg, one page at the bottom of the other forming a "gut", but my whole file gets black bg. #!/usr/bin/env python # coding: UTF-8…
-
0
votes0
answers317
viewsDoubt on "continue" (Syntaxerror: 'continue' not properly in loop)
I’m starting in python and I can’t figure out why the error below, could help me? def SecretNumber(): GotIt = False while GotIt == False: One = int(input("Type a number between 1 and 10: ")) Two =…
python-3.xasked 5 years, 6 months ago Osvaldo Oliveira 1 -
0
votes1
answer69
viewsDoubt in the kivy documentation, Textinput
In kivy textinput documentation you have the following code snippet def on_enter(instance, value): print('User pressed enter in', instance) textinput = TextInput(text='Hello world', multiline=False)…
-
0
votes1
answer79
viewsBy loading my xlsx file into pandas, the rows have become column indexes. How to set a new input for columns?
I would like to know how to set new index for columns. data = pd.read_excel('numero_automoveis_vendidos.xlsx') data.columns Index([7, 5, 9, 11, 10, 8, '9.1', 6, '8.1', '10.1'], dtype='object')…
-
0
votes1
answer23
viewsHow do I make it appear in the same folder as the file that creates it?
I create this database in python3 but it appears in a previous folder import sqlite3 nome_banco = 'banco_escola.db' banco = sqlite3.connect(nome_banco)
-
0
votes0
answers21
viewsDjango - Upload image is not working
On the site already have some questions related to this, but none of them solved my problem in fact. I have a table in the database with a FK table User, in this table I put my image that would be…
-
0
votes1
answer75
viewsHow to use the Time module together with the Sys module
I have a problem using the time.Sleep module together with the sys module. You’re not taking the break I put on the team.. import random import time import sys cores = {'fim': '\033[m', 'vermelho':…
-
0
votes2
answers60
viewsIs there any way to use methods within other python methods?
I wonder if in Python it is possible to create a loop for within a format()? Example #Considerando: z=(1,2,3,4) print(f'''os números pares foram { for i%2==0 in z: print(i,end='são números pares')…
-
0
votes1
answer32
viewsPython: How to apply mock in dataclass?
I have following code : import unittest import unittest.mock as mock from dataclasses import dataclass @dataclass class Config: system: str = platform.system().lower() class…
-
0
votes1
answer873
viewsUnzip file . gz with Python
I’m using the code below that I took at this address. But I’m not able to unzip files .gz. I’ve tried the library tarfile, but without success. Follow the code below: from io import BytesIO from…
-
0
votes1
answer422
viewsX-axis customization in matplotlib
Good morning, I have the code:import pandas as pd from matplotlib import pyplot as plt server250_mar19 = pd.read_csv('dbnode2_mar19.csv') plt.plot(server250_mar19.Date, server250_mar19.CPU_pct)…
-
0
votes1
answer562
viewsUndefined variable with import python
I am having problems with the inheritance of attributes between a mother class and a daughter class that are in two different files. When using them in the same file no error is displayed:…
python-3.xasked 5 years, 6 months ago piresthiago10 39 -
0
votes1
answer78
viewsOpa friends, I wonder why in the code below the answer only comes out right if before writing the word (holy) I give a space. : /
cidade = str(input('Digite o nome da sua cidade: ')).title() p = cidade.find('Santo') if p == True: print('A sua cidade começa com Santo.') else: print('A sua cidade não começa…
python-3.xasked 4 years, 1 month ago Diogo Bomfim 21 -
0
votes0
answers31
viewsIf there is no option, how to repeat the question in python?
How do I repeat the above question in case the answer does not get any of the options within the function if and elif? parcelax = int(input('Qual formato de parcelamento? \n 1) Á Vista \n 2) 12x \n…
-
0
votes2
answers313
viewsFill list and finish python loop
I need help on a problem that asks me to fill in by adding data to a list until it is declared 'end'. E=[] i=0 E.append(input('Nome do elemento?')) while (i!=fim): E.append(input('Nome do…