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
votes1
answer34
viewsFunction does not work in all test cases
I need to do a function to check if a matrix is square: def eh_quadrada(matriz): '''Função que verifica se uma matriz é quadrada. list->bool''' if len(matriz)==len(matriz[0]): return True else:…
-
0
votes0
answers13
viewshow to install an internal package of requeriment.txt in python?
For example, I have a python code that uses the library import geocoder. In my machine I’ve used the pip install geocoder, but when a colleague made a git-clone it didn’t run for lack of this…
-
0
votes2
answers46
viewsCalling 3-column CSV file in Python
I’m trying to call the file temperature.csv in Python but shows with errors, IE, I wanted to appear the three columns. The code I made was this:: import pandas as pd dataset=…
-
0
votes0
answers52
viewsWhat is the asterisk for as "parameter" in Python functions?
I was reading the documentation of version 3.8 of Python, in the part of the new syntax for positional parameters, and found the following function: def f(a, b, /, c, d, *, e, f): print(a, b, c, d,…
-
0
votes1
answer196
viewsPython error with Django on_delete
I’m a beginner in the Django platform and the Python language and I’m developing a website in Django 2.2 and Python 3.7.3, and I have a problem with my code on models.py from my app "Courses". class…
-
0
votes1
answer28
viewsUnexpected return of the method
I am learning POO in python, I have created a client class that has three attributes; name, Cpf and age. And I also created a method that stores these attributes inside a tuple and returns this…
-
0
votes4
answers197
viewsPython, how to calculate the average of a list of 5 in 5 elements?
I have a problem where I need to calculate the average of 5 out of 5 elements in a list, for example, average the first 5 elements, then average the next 5 elements and so on. I tried using list…
-
0
votes1
answer89
viewsAdding a number to an array gives an index problem
I have tried everything and could not add the number 1 at the bottom of the list predictors. Gives the following error: new_inputs[i] = np.append(inputs[i],one[i]) Indexerror: list assignment index…
-
0
votes1
answer1380
viewsIndexerror: list index out of range in python
With the comoda configuration input and output the number of inaccessible drawers . I have this code now configuração = [] lista = [] aberto = 0 gavetas = int(input('Quantas Gavetas ? --> '))…
-
0
votes1
answer47
viewsPython input problem
My program is working correctly for a test case but when more than one error occurs shown in the image. The following code: alfabeto = dict() entradas = input() i = 0 for i in entradas: texto =…
-
0
votes1
answer105
viewsI’m having trouble showing my Manytomany field models on the Django template
I wonder how I can show my Manytomany field on my table, follow the code below. My Model: class Instrutor(models.Model): id = models.AutoField(primary_key=True) registro_instrutor =…
-
0
votes1
answer43
viewsHow to add a number to an array?
Hello! All right with you? I’m making a code and I needed to define a function: def sigmoid (v): return 1/(1+np.exp(-v)) Only what I’m assigning to the function is an array 2d. My question is: in…
-
0
votes1
answer747
viewsHow to save to a specific directory (python)?
Hello. I would like to know how to create a folder every time the program is run and save to a specific location. Currently it saves the file where the code is. This is my current code: import cv2…
-
0
votes2
answers295
viewsForeignkey using User in other models
I’m developing a quotation site for language study purposes. I have customized the User models and it includes other attributes such as address and city for example. The problem now is to write the…
-
0
votes2
answers69
viewsHow to replace file extensions?
I am learning python in Oursera, and came across the following exercise. My question refers to how to change string extensions .hpp to .h inside the list comprehension: filenames = ["program.c",…
-
0
votes1
answer78
viewsI want to know how to show, for the user, Yes or No instead of True or False, respectively
Below is an example of what I’m trying to do: lm = input ('Digite uma letra ') print ('essa é uma letra minúscula? {}' .format(lm.islower())) I’ve tried to put True = Sim and False = Não.…
-
0
votes3
answers104
viewsHow do I make Python not turn to the upper or lower case letters of the code?
Code: while(1): x= str (input ('Meu avô tinha dois cachorros, um se chamava Pet e o outro se chamava Repete, o Pet morreu, quem é que ficou?')) if x != 'Repete': print("Errado!") break The idea of…
-
0
votes1
answer2434
viewsPython3 Typeerror: Unsupported operand type(s) for +: 'int' and 'list'
Gentlemen, starting in python and cracking my head here... I have a cvs file with hundreds of lines, (I know that pandas would be ideal for this, but as I said I’m starting, and I need to understand…
python-3.xasked 5 years, 3 months ago Claudinei Miller 29 -
0
votes0
answers68
viewsCorrect way to use Try except
I am working for the first time with an API and need to return an error if it occurs, follow my code with the clearest and simplest way I found to notify errors: if request.method == 'POST': try:…
-
0
votes0
answers262
viewsHow to convert communication form from Java to Python
Good Afternoon, I have a Java scrip that communicates between the Java application and the MIO Commbox controller. My question is how to convert this Java script to Python, summarizing, need to…
-
0
votes0
answers24
viewsWhat is the difference between Thread and Threading in python
I’m using Python 3.7.x When I call a thread through the command: t = Thread(target=.... In VS Code shows the thread list in CALL STACK (Call Stack) and runs normal. But when I call through command:…
-
0
votes0
answers14
viewsUsing Pyinstaller in Ubuntu
Good morning good people In my Ubuntu 20.04 created a file . py and tried to package using pyinstaller. a = "Deu certo" print(a) He created but when I went to dist and ran the operating system…
-
0
votes0
answers19
views[@action Django restframework ]: execute commands when a new client is registered
good night. I am developing a customer registration API, and I would like it that every time a new client is registered, runs something, and I tested a code and it didn’t work. someone can help me?…
-
0
votes0
answers27
viewsDunder Name and Dunder Main is the best method to avoid conflict between modules?
if __name__ == '__main__': # execução do código This is the best way to avoid unwanted information when importing one module to another?
python-3.xasked 3 years, 6 months ago Carlos Oliveira 1 -
0
votes1
answer209
viewsCheck if there is object in instantancy
I wonder how I check for variable object in Python. I tried so: try: select_me = User.select_me(request) select_random = User.select_random(request, 3) me = select_me.username random =…
-
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
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
votes2
answers67
viewsProblem when declaring 2 variables
The problem is this, I need to do a function to sum 2 numbers that the user must insert by separating them through commas, eg: 2.3, for such values 2 + 3 = 5, so the result should show 5 as a…
-
0
votes1
answer225
viewsHow can I manipulate data from a form in Django?
I’m a beginner in Django and wanted to know how I can manipulate data sent by the form. I have the following form: class CreateNewUser(forms.Form): Nome = forms.CharField(max_length=200) email =…
-
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
answer79
viewsHow can I get access to deleted objects in Django?
I’m developing a parking management system in Django that registers the 'Vehicle' object according to its time of entry, and calculates the value as it goes, but I need to develop a reporting system…
-
0
votes1
answer31
viewsHow do I set an event to run when the app ends in Pyqt5?
I am creating an application in Pyqt5 and need to run a code when the application is finishing. For that, I thought about overwriting the method quit class QApplication: class MyApp(QApplication):…
-
0
votes1
answer328
viewsKeyerror: 'A secret key is required to use CSRF.'
My application is showing error "Keyerror: 'A secret key is required to use CSRF.'", however in my config.py file I have the key created. What else could I check to remedy this error? File…
-
0
votes2
answers66
viewsVIEW DICTIONARY ALPHABETICALLY - PYTHON
I have a dictionary that has 2 keys (name, age), within each there is a list of values. I need to put the names in alphabetical order and that the ages accompany the respective owners. That’s the…
python python-3.x classification dictionaryasked 3 years, 5 months ago Henrique Marvin Souza da Silva 28 -
0
votes0
answers36
viewsHow to count occurrences of a number in a matrix?
I need to do a function that counts how many times a number appears in a matrix, example: ocorrencias(9,[[9,7,6,9,8,8]]) Must return 2 My code: def ocorrencias(numero,matriz): cont = 0 for elemento…
-
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
answer31
viewsHow to remove the blue background from the table item when selected?
I have a QTableWidget and I need all items in the table to have the same background color. The problem is that when an item is selected, it gets the background blue. I tried the following code on…
-
0
votes1
answer49
viewsPython command does not work
As you can see, I cannot access python from the terminal I’ve checked the system variables…
-
0
votes1
answer19
viewspython3 Tkinter flaw in the allocation of butons
good afternoon, I am trying to develop a graphical interface with python and for that I am using Tkinter but this arises a problem, whenever I try to assign a function to a button of the two one or…
-
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
answer244
viewsHelp with Chromium webdriver Selenium python3
I recently fixed a pi4 Raspberry and installed the corresponding webdriver but it is giving an error. ERROR Traceback (most recent call last): File "Bump.py", line 4, in <module> from…
-
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
votes1
answer27
viewsHow to make a Window always stay above the others in PYQT5?
I am creating a small application and need the main window to always be above the others, which attribute to use in pyqt 5 ? From now on I thank
-
0
votes0
answers32
viewsHow to search for full name in List with name "incomplete"?
I wanted to do a Python program to find specific name in List: Example using random names: nomes = ['Melissa Renata Peixoto', 'Bruna Carla Henry Gomes', 'Carla Rosângela Brito', 'Carla Letícia…
-
0
votes1
answer32
viewsWhen creating a new pair in a dictionary lose the previous data?
I’m creating a Dict from scratch, but when I add some new pair, the old pair gets lost. If I try to print 'name' for example, it gives error. cidade = { 'nome': 'São Paulo', 'estado': 'São Paulo' }…
-
0
votes1
answer83
viewsHow to Insert in Postgresql based on data from a Dataframe
I am trying to make an Index of the data I have in a Dataframe (regastei via API GET) for a table I created in Postgresql. I searched a lot but I could not get a return. Someone can help me?…
-
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
votes2
answers241
viewsTkinter - pass argument to function
I have the following code: class Tela: def __init__(self, master=None): self.fontePadrao = ("Arial", "10") master = Toplevel(self.root) self.primeiroContainer = Frame(master)…
-
0
votes0
answers13
viewsHow do I interrupt a python function?
The problem is this: I want to make a function not make its execution complete if a certain condition is met. Example: a = 1 def function(): if a is 1: pass #aqui seria o local onde que a função…