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
-
3
votes2
answers179
viewsWhy should we import Messagebox explicitly into Tkinter even if it matters with the asterisk?
Whenever I see programs using tkinter and messagebox see the following two lines at the beginning of the code: from tkinter import * from tkinter import messagebox If we use from tkinter import * we…
-
3
votes5
answers6310
viewsHow to stop the end='' command in Python
I got a problem every time I use the remote end='' he does not stop! Example: tabela = ('Palmeiras', 'Flamengo', 'Internacional') for time in tabela: print(time, end=' ') print('=-' * 20) Execution:…
-
3
votes2
answers512
viewsHow to simplify the if command in python?
Is there any way I can simplify this line of code in Python: if X = 1 or X = 2 or X = 3 or X = 4: I was trying this way: if X = {1 or 2 or 3 or 4}: But trying like that makes a mistake.…
-
3
votes1
answer527
viewsProblem with special python characters
I have a bot made in Python with the Selenium webdriver, which takes some data from Tesouro Direto and generates a json, however I am facing a problem, which occurs when a special character appears.…
-
3
votes2
answers82
viewsDictionary error
What’s wrong with this dictionary? Dados = {'Alunos': { {'Nome': 'Jon', 'Notas':[8,9,6]}, {'Nome': 'Giglio', 'Notas':[7,6,5]}, {'Nome': 'Antony', 'Notas':[5,6,9]} } } for nome, info in…
-
3
votes1
answer894
viewsPython Unicodedecodeerro in jupyter notebook. Working with . csv
I’m learning to manipulate files .csv in Python with the jupyter notebook. I extracted a file from the system, in csv, separated by commas, but when I opened I received this error: arqsb2 =…
-
3
votes2
answers301
viewsChanging data types in a Python list
I have a list x, with 10 numbers, being all of them whole. I’d like to turn them all into numbers like float, but I can’t perform that conversion. Code: lista = [1,2,3,4,5,6,7,8,9,10] for i in acs:…
-
3
votes3
answers1564
viewsPython variable reference return
When we define a variable, basically we are naming a memory address, follows a script that represents my doubt: class Spam: _value = [] @classmethod def value(cls): return cls._value >>>…
-
3
votes1
answer856
viewsDjango + Python how to update a table item
Hey, guys, I have a registration flow where in a first step save the student and then the data of the responsible, however, after that I need the student to make a description and this description…
-
3
votes1
answer5613
viewsError List index out of range
I’m developing a quiz with Python And I have a problem that I think is simple but I’m having trouble solving. When the person completes the quiz the message that was to appear does not appear and…
-
3
votes1
answer5459
viewsDjango: Reverse for '' not found. '' is not a Valid view Function or Pattern name
I am trying to put a url based on my views.py but it returns me the error: Reverse for 'create_student' not found. 'create_student' is not a Valid view Function or Pattern name. py urls of the…
-
3
votes2
answers120
viewsTable grouping
I have this table and would like to put together a list or another table users_ID_User Material Rating 0 A "Hey Pogo!...from citation to fulltext" 5 1 B "Hey Pogo!...from citation to fulltext" 4 2 C…
-
3
votes1
answer713
viewsFind most repeated value
I’m trying to analyze some shoe sales data, but I’m having a hard time creating a function to find out which number the customer bought the most in the previous year. I have a table with this data:…
-
3
votes1
answer173
viewsHow to make python only read the file when it is complete
I’m doing a program that reads a file. txt that updates itself in the execution of another program in Fortran and creates a real-time animation of the temperature map of a board, however it is…
-
3
votes2
answers679
viewsWhat determines a variable as a Python array?
I’m studying about lines in Python and I’m using the object deque module Collections. So, in Python I can access the values of an array by simply writing: array = [1, 2, 3] arra[0] # 1 However, the…
-
3
votes2
answers389
viewsPython, matrices/vectors and dictionaries
Hello, I’m new to python and I don’t know how it should be done: 1) I have a 2x6 matrix generated by random numbers, for example: matriz = [11, 4, 50, 8, 9, 78] [10, 33, 44, 57, 80, 90] What I need…
-
3
votes4
answers361
viewsPython Code - Conditional Structure
As I do in Python to receive the value of the base salary and the sales value of this seller, the employee’s basic salary should be up to R $ 700.00 with a 4.5% bonus on their sales and if the sales…
-
3
votes2
answers487
viewsClosing a loop, with enter
I’m looking to close one while True: pressing a key, in case simply pressing enter without writing anything. while True: key = input("Press enter") if key == " ": break else: #loop How can I do it?…
-
3
votes2
answers1897
viewsDjango - Null and Blank Difference
I’m having a hard time understanding the real difference between null and blank on Django, For example: In this code, to my understanding the name field will be NOTNULL in the database, but what…
-
3
votes4
answers2298
viewsPrinting a number odd sequence on a list
How do I make my code display the sequence of odd numbers in reverse mode of a number typed by the user: My code: number = int (input()) if(number >= 2): listseq = list(range(0, number, 1))…
-
3
votes2
answers3465
viewsHow to invert the order of columns of a Dataframe with Python
Oops, I wonder how I can invert entire columns with using python. FRUTA | VITAMINA | PREÇO LARANJA | C | 2.00 MAÇÃ | B1 | 2.00 BANANA | B2 | 1.00 I would like to know how I can transform the…
-
3
votes1
answer109
viewsWhat is the functionality of this line of code?
I’m trying to translate the following code to C++: https://github.com/JohanLink/Ball-Balancing-PID-System/blob/master/pythonCodes/interface.py I wanted to understand what the following line does:…
-
3
votes2
answers724
viewsConcatenate variables in the Django template
Talk guys, good morning, I have a problem. I’m walking through a lista but I want to concatenar my list I’m calling on template as {{ list }} and {{ forloop.counter0 }} so that in mine is only…
python django list django-templates string-concatenationasked 6 years, 1 month ago Raphael Melo De Lima 461 -
3
votes1
answer973
viewsWhy doesn’t Python use 100% of the processor?
I’m developing a Python application where in some parts, it requires a lot of CPU for calculations. However, I realize that even at these "bottleneck" points, the CPU never reaches more than 50% of…
-
3
votes1
answer554
viewsWhat does the f = Fernet(key) code represent when using the cryptography.Fernet library?
The program consists of encrypting a message with a key and then decrypting. from cryptography.fernet import Fernet key = Fernet.generate_key() f = Fernet(key) token = f.encrypt(b"my deep dark…
-
3
votes2
answers335
viewsRemove cmd/dos window when calling Python App
I made a script in Python that has an interface, but when I run it, the Python interpreter window appears together. How to remove this CMD window that opens together with the application? Follow the…
-
3
votes2
answers1349
viewsRecord runtime in python
In Python, I need to do something like: timer.start() ***Imagine um código de várias linhas aqui*** timer.stop() print("Tempo de execução: " + timer) It can be in seconds, minutes anything, someone…
-
3
votes1
answer52
viewsHow to remove the OS user name
I’m making a terminal and I have a question, how do I remove the user name behind the message? exemplo: "C:/USERS/GUSTAVO/DESKTOP" How do I leave: example: "DESKTOP" I’m using the OS library to get…
-
3
votes1
answer1172
viewsWhat are file descriptors and directories?
I’m studying the módulo os of the standard library of Python and I realize that in many cases a function is allowed to receive as a parameter a descritor de arquivo ou diretório some examples are:…
-
3
votes1
answer49
viewsSimplficando chained comparisons
According to pycharm (which is with the default settings for pep8) says it is possible to simplify this line. elif student['averange'] >= 5 and student['averange'] < 7: student['situation'] =…
-
3
votes1
answer79
viewsAdding to a list itself. What happens?
l1 = [1, 2, 3] l2 = l1 l1.append(l2) print(l1) Why does this algorithm return a three-point list? What does this new list mean?
-
3
votes1
answer4431
viewsHow to remove a line in python txt file
Good evening, I am having problems while removing a line from a txt file, the deleting function of the code is responsible for removing a user, however while trying to remove the entire file is…
-
3
votes1
answer651
viewsPython - Dismembering text file
Good night, I need to separate some lines from the file and according to the add line in another file. That is, a file that contains 6 words will be written according to the word for a specific…
-
3
votes1
answer160
viewsFormat a number with a certain number of decimals
How do I make the user choose the number of decimals of a number? EX: from math import pi x = int(input('número de casas decimais de pi: ')) I want to be able to print on the screen pi formatted…
pythonasked 5 years, 4 months ago rafael gonçalves filho 31 -
3
votes1
answer59
viewsCreate a key/value association from user-informed data
8) Write an algorithm capable of receiving a variable amount of parameters that are associated with a key. Then print on the screen the name of the key and its value: def…
-
3
votes2
answers9963
viewsInvert the words of a sentence, keeping their order in the sentence
I made this algorithm in Python to invert a sentence, in a way it worked, but I need it to reverse the sentence keeping the order of the words. For example: OI TUDO BEM would have to stay IO ODUT…
-
3
votes1
answer1797
viewsHow to use the if block with variable types in Python?
I am creating a program in Python and need that necessarily the data of the ID field are integer numbers. Basically I want to enter the block if depending on the type of variable I get. Example: ID…
-
3
votes1
answer223
viewsOverride Property() in Child Class
A few days ago I asked a similar question to this, however, the method employed in creating the property was via decorators (@property and @name.setter). Here I am creating the property via function…
-
3
votes1
answer193
viewsSome Python codes display "__class__" when creating certain classes. What is it for?
I realized that in certain codes in Python is used a __class__. What good is the same? Example: class abstract1 (object): def __init__(self): if self.__class__ == abstract1: raise…
-
3
votes1
answer85
viewsArray always getting the same value [Loop in two matrices simultaneously]
My program scans an image and assigns color values R,G, B the variables that were compared with matrices containing the colors R,G, B asphalt and earth called auxAsfalto and auxTerra. The point is,…
-
3
votes2
answers838
viewsHow to check if server is available before request.urlopen in Python?
I have the following HTTP request code on my server in my python code: import urllib.request import json url= urllib.request.urlopen('http://ENDERECOIP/pasta/arquivo.php') x= url.read() y =…
-
3
votes1
answer602
viewsWhen to use map() and filter() in Python?
Good afternoon , I have a question regarding these functions I will give as an example some codes: numeros = list(map(lambda x: x-1 , [2, 3, 4, 5])) print(numbers) Output: [1, 2, 3, 4] Here in this…
pythonasked 5 years, 1 month ago Paulo Lopes 31 -
3
votes3
answers6692
viewsRounding down in Python
I’m writing a program in Python and I came up with a question here. Before coming to ask I searched for "Python Rounding" here on Sopt and found two old questions with the subject, but both did not…
-
3
votes3
answers1422
viewsSearch for words that contain a certain letter
I need to search the library re for when I pass a letter, return the whole word containing the letter. text = "Texto de busca por palavras contendo a letra z, como por exemplo zebra, zoologico. A…
-
3
votes1
answer946
viewsDate format in python
How to take the current date and format in Brazilian format '28/10/2019'
-
3
votes1
answer65
viewsproblem with Random.radint(1, 6) and if conditional
Friends, I am starting out in programming, so I apologize if it is too banal my question. My guess is that something happens in the if string, because never the winning message is read, the program…
-
3
votes1
answer1303
viewsColors in cmd using Python?
Guys I’m doing a game for college and I decided to put some colors in the code to look cute. I wanted to know how to make the colors of the strings appear in the cmd of windows. I tried to use the…
-
3
votes1
answer153
viewsAny more pythonic way to solve the problem below?
Create a function that returns the expression value: 2/3 + 3/5 + 4/7 + 5/9 + ... + n/m, to a user-defined value of n. Check that the user-defined n value is positive and, if not, request another…
-
3
votes3
answers398
viewsIntersection between pandas columns
Considering two dataframes like the ones below: import pandas as pd df = pd.DataFrame({'id':[3,6,9,12,15]}) df1 = pd.DataFrame({'id': [2,4,6,8,10,12,14]}) How to account for the intersection between…
-
3
votes1
answer248
viewsFormatted printing that replaces the use of . format() in python versions from 3.6 onwards. How to use?
We know that: "{0}:{1}:{2}".format(hora,minuto, segundo) is equivalent to: f"{hora}:{minuto}:{segundo}" What is the equivalent of the expression below using the notation f" " ?…