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
answer417
viewsChange a user’s password in Django, and check that the data provided is correct
I am working on a project in Django for didactic purposes and I am having trouble changing user password in Django. However I already managed to change the password through a form as below: These…
-
0
votes1
answer134
viewsClass error in Python
I created the code below but it’s giving me error: Pessoa = Empregados('joao') TypeError: Empregados() takes no arguments. What I might have done wrong? class Empregados: def __int__(self, nome,…
-
0
votes1
answer305
viewsProblems running Tkinter program in Spyder IDE
I am writing a python code (3.7) using the Tkinter library, I am also using Spyder IDE (py-3) | Anaconda (3) to write the code. When I run it, the IDE only shows the [in] (runfile) in the ipython…
-
0
votes1
answer21
viewsHow to convert all_timezones to another format
I need to convert the timezones pytz to the following format below, but I’m having trouble doing this with python. How does this type of conversion work? from pytz import all_timezones time_zones =…
-
0
votes1
answer87
viewsPython rest_framework how to change URL?
How can I change the urls in rest_framework on Django? The router defaults to using the creature ID in the URL ex. /api/Creatures/1/ I want instead of appearing the ID, appear the name of the…
-
0
votes2
answers766
viewsLoad image in html from saved path in Django database
I’m trying to make a newspaper using Django and Mysql database and now I need to list the news images: In my database I have saved the image path, because I thought it would have a better…
-
0
votes0
answers55
viewsI created an Eternal Object, but I can’t explain why it works
Hello, everybody. I am solving a list of Python exercises (3.7) and in the first exercise I was asked, in item A), to create a generating function that scans a string for the desired substring and,…
-
0
votes1
answer45
viewsIterate over an array and save to a Dict
Given that array: array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=uint8) I’m…
pythonasked 5 years, 7 months ago Gabriel Serrão 1 -
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
answer2103
viewsInstalling and importing the Pygame module in Vscode
I am learning to program python through Vscode and found it difficult to import the pygame module. import pygame pygame.init() pygame.mixer.music.load('nomedamusica.mp3') pygame.mixer.music.play()…
-
0
votes1
answer448
viewsI’m having trouble creating a Chatbot in Python
from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer chatbot = ChatBot('HiAsda') #Cria um novo treinador para o bot trainer = ChatterBotCorpusTrainer(chatbot)…
-
0
votes1
answer49
viewsHelp with nested loop
yhat_tr is a column of 500 items. d_tr, tb with 500 elements, is another column, which I loaded separately from the first, are different sources, but with the same indexes. My code is this: TP, FP,…
-
0
votes2
answers1240
viewsHow to add characters in a string according to a predefined condition?
My question is the following, after receiving a string (can be numbers or letters), return this string with the addition of a SE character within this string there are repeated characters in…
pythonasked 5 years, 7 months ago Jhonathan Cavalcante 3 -
0
votes0
answers269
viewsclear python buffer each time it sends the value
I have an Raspberry sending data every 15 seconds, however I have a value that takes time to update, will cleaning the buffer every iteration in while True solve the problem? my code is as follows::…
-
0
votes2
answers51
viewsCalling function teething variable
How I call a variable created outside a function within a Python function For example: variavel=2 def test(): variavel=variavel+1 if variavel==3: print(variavel) test()…
pythonasked 4 years, 6 months ago Pedro Henrique 53 -
0
votes1
answer34
viewsFunction randint does not return a value
I wanted to make the randint call a random number, save the value of that number, open a question to the user and if; the user’s answer is equal to the number, say that he hit, if different, say he…
pythonasked 4 years, 6 months ago Pedro Henrique 53 -
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
answers232
viewsBlack screen when running a simple interface made in Kivy - Python
I’m learning about using multiple screens in the kivy (using Screenmanager). However, when I run the code below I come across a black screen. No error occurs, but I could not find out which error.…
-
0
votes0
answers26
viewsDoubt when using xlsx2csv inside Python
I am using the xlsx2csv available in: https://github.com/dilshod/xlsx2csv from xlsx2csv import Xlsx2csv Xlsx2csv("myfile.xlsx", outputencoding="utf-8").convert("myfile.csv") Someone who already used…
-
0
votes0
answers238
viewsChatterbot from chatterbot import Chatbot Modulenotfounderror: No module named 'chatterbot'
from chatterbot import ChatBot ModuleNotFoundError: No module named 'chatterbot' I’ve updated the library chatterbot and the pip, I’ve also changed the address of path for…
-
0
votes1
answer43
viewsHow to rescue specific parts of a txt?
I am trying to recover specific data from a txt, for example from the following: Cod: 275 Nome: xxxxxxxxxxxxxxxx Funcao: xxxxxxxxxxxxxxxxxxxx Dep.IR: 0 | Admissão: 27/08/2012 Situação:Ativo…
pythonasked 5 years, 7 months ago Gustavo Halmer 11 -
0
votes0
answers35
viewsError: name 'self' is not defined
I’m a beginner in Python and I’m developing my first program. It’s like this: from tkinter import * from tkinter import font class Application(Frame): def __init__(self, master=None): pass self.msg…
-
0
votes0
answers92
viewsHow to resolve txt special character error
I’m using the library requests and the following code in Python to take data from Receita-WS and to JSON in a TXT. for i in lista_empresa: url = "https://www.receitaws.com.br/v1/cnpj/" + (i['cnpj'])…
-
0
votes2
answers452
viewsHow to get a template that’s in another app on Django
Hey, guys, you okay? So people are starting now to program in Django I’m really enjoying, only a question arose, I wonder if you have how to leave the template html base. as "Universal" what I mean…
-
0
votes1
answer41
viewsI can’t get the comparison into Elif
I need to make a pair or odd game with the computer, I tried to make the comparison of if to know if I chose pair or odd with 'Pp' and 'Ii' so I wasn’t getting it, I tried to use Lower() and I…
pythonasked 5 years, 7 months ago João Eduardo 9 -
0
votes1
answer99
viewsHow do you fix this code?
When I press the keyboard, for example the "w" to go forward, the robot goes forward and sometimes another motor turns on together. When I press a command and keep pressed, when stopping pressing…
-
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
votes0
answers250
viewsChatterbot import error
Using the library manual chatterbot I tried to make a simple chatbot, however, when I have it run on the console of pycharm appears the following error: Modulenotfounderror: No module named 'pytz'…
-
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
votes2
answers100
viewsProblem inserting data into CSV file
I am inserting the data into the file correctly, but when I open the file in Excel, the data is all in the same field in the table. Follows the code: import csv dados = open('DATA.csv','w') try:…
-
0
votes2
answers48
viewsI’m trying to make a show that gets an n number and returns all the cousins up to n, but I don’t know what’s going wrong
numero = int(input('Digite um número: ')) lista_numeros = list(range(1, numero + 1)) primos = [] divisores = 0 for n in lista_numeros: for count in range…
-
0
votes5
answers842
viewsFind a file type within several folders and save the hierarchy
I have the following situation, I have a folder that contains several projects, within each project has an automation folder, and within folder automation several folders type: Game_play, Menu,…
pythonasked 5 years, 7 months ago Tiago TF Dias 45 -
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
answer144
viewsRun a python script in javascript
client.on("chat", function(channel, user, message, self){ if(message === 'Olá'){ client.action("ythezack", user["display-name"] + " Seja bem vindo!");} if(message === '!Nick'){…
-
0
votes2
answers2625
viewsInner Join with two keys with python
I have two tables, one for consultation and one for examinations, both with the date of execution and the code of the beneficiary. Want to make a third table with people who have had exams and…
-
0
votes2
answers3879
viewsHow to separate the year from a date with Python and Pandas?
I have a student database with a Ticket Date column in the dd/mm/aa format. I need to generate an Ano_ticket column only with the year of the date of each record. import pandas as pd df =…
-
0
votes2
answers93
viewsHow to remove a certain key and value in a dictionary with composite data (Keys and Values) in Python?
I made a composite dictionary (Keys and Values) of alchemists of the anime Fullmetal Alchemist Brotherhood with the following keys: Nickname and patent and wanted to know how to erase the patent key…
pythonasked 5 years, 6 months ago user141036 -
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
answer67
viewsEntire division returning a different result than expected
I’m having a problem with the entire division in python and R. The language returns a value other than "correct" in the entire division of 327 by 3.27 and the rest (%) different from 0 in these…
-
0
votes1
answer382
viewsRemove empty list in Python
os.chdir(pasta) lista = [] for air in os.walk('.'): if lista != []: lista.append(air) print(lista) Could someone tell me why I can’t print the folders? If I take the if, folders appears, but also…
-
0
votes0
answers90
viewsDelete data from a db using sqlite3 and Bottle (python)
I am trying to make, using the Bottlepy framework, a CRUD in the Todo format (as in the example shown in the Bottle documentation itself https://bottlepy.org/docs/dev/tutorial_app.html). So far the…
-
0
votes3
answers1952
viewsSum of the main diagonal of a matrix in Python
I’m making an array[3][3] in Python where I’m summing the main diagonal elements in the matrix plus it’s giving an error. i = 0 # linha j = 0 # coluna soma = 0 matriz = int (input("Digite a matriz…
pythonasked 5 years, 6 months ago user140745 -
0
votes1
answer48
viewsjinja2 error: jinja2.exceptions.Templatesyntaxerror: Unexpected '%'
My code is generating a " Unexpected '%' error", all symbols being properly correct. I have a route to show the companies Cnpjs in a list, follows function of the listing below:…
-
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
votes1
answer77
viewsHow to distribute inputs in lists randomly?
How do I input nome + numero + outro in one thing and then place them in one of those lists (A, B, C ,D) randomly in the Python language? A = [] B = [] C = [] D = [] for k in range(12): nome =…
-
0
votes1
answer60
viewsFunction to import file. py?
Good afternoon, I created a file called test.py with code that fetches information from a database and turns it into a Dataframe. I’m having trouble creating a function and import this file, follow…
-
0
votes2
answers85
viewsHow to make the user re-enter the numbers at the beginning of the program?
Create a program that calculates two values. (DONE) Ask if the user wants to know if the sum, subtraction, multplication or the average of the values. (DONE) Then tell if it is even or odd if the…
-
0
votes1
answer108
viewsSearch problem using Django queryset when editing
I am glad for the help, because I am not able to carry out this search, even performing the search, returns me the right id (id_sector and id_company) but Django does not recognize or I am doing…
-
0
votes4
answers747
viewsGet the most frequent and least frequent element from a list, plus the largest and smallest
How can I find the highest and lowest number, the most frequent and the least frequent, in any list? Current code: import random maiorNumero = 0 menorNumero = 100 arrayNumeros = [] print("Os numeros…