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
-
2
votes1
answer380
viewsDjango does not validate changed fields in the client by JS
My project has a form that one of the fields is object list (Courses), but these objects are being passed from another list (Courses of the area) through Javascript, only that the values allocated…
-
2
votes2
answers37
viewsWhy does entering a value in a list become None?
valores = [] valor1 = valores.append(int(input('Valor 1: '))) valor2 = valores.append(int(input('Valor 2: '))) if valor1 in valores > 0: print(valor1, 'é positivo') else: print(valor1, 'é…
-
2
votes2
answers263
viewsIn Python, search a string from the information of a column?
I’m at Jupyter Notebook working with Python. Has a dataframe with the name and text fields, in the text, which is a txt loaded, I want to search if there is the string that is exactly the value in…
-
2
votes1
answer32
viewsDiscord bot python - async def picks up a sentence and the ID
I wanted to know how to send several sentences at once, example ?Say Hello World (Idchannel) what happens is that I can only send a sentence and then the ID, I wanted to add as many phrases as I…
pythonasked 3 years, 10 months ago ChickChuck2 51 -
2
votes1
answer68
viewsLapis design effect with opencv and python
I want to get the result of the image further to the right, so I can only get to the middle image using a Canny filter and a Gaussian filter. Does anyone know how I can get this result? import cv2…
-
2
votes1
answer23
viewsHow can I line a Pandas dataframe from a list that contains variables?
So guys, I’m having a problem that basically works in a simplified way like this # Eu criei um DataFrame a partir do pandas import pandas as pd Colunas = ["A","B","C","D"] df = pd.DataFrame(columns…
-
2
votes2
answers62
viewsPerform a previous values calculation in column on R
I would like to assemble a column according to the result of 2 lines of another column, follows the formula below, I have no idea how to assemble this in R or Python and would like a collaboration…
-
2
votes2
answers85
viewsHow to use methods of an object within "with" in Python?
Hello, I am studying a little more about the best practices of using Python and I came across a command that I do not know very well, the with, so I decided to study a little bit better about how it…
-
2
votes1
answer52
viewsIn a list list, how to sum each item of each list with the item of its respective position?
For ex my list is: x = [[1,2,3,4,5],[6,7,8,9]] How can I create a new list so that its elements are the sums of the corresponding elements in each list? y = [1+6,2+7,3+8,4+9,5+0]…
-
2
votes1
answer480
viewsProblem "List index out of range"
In a Python code I have several conditions that filter my data, and this data is connected to a position counter i. But within one of these specific conditions I need to record the position of the…
-
2
votes2
answers133
viewsHow to create two y points for a same x?
Hello, I would like to create a python routine to create "double points", where a same value of x would assume two values of y for any situation. Using the following data sequence for example: 1;5…
-
2
votes1
answer157
viewsHow to open a browser with Python, Selenium and geckodriver?
I wrote an automation to follow people on instagram, but when I put Run in the code, it returns me in the log with no error, and still doesn’t open the browser for me to test the code. I think…
python selenium browser instagram geckodriverasked 3 years, 9 months ago Gleidson Marques dos Santos 21 -
2
votes1
answer125
viewsI need help on the if and Else structure
I created two 'if and Else' structures to make the program write to the user using the plural correctly and as you can see below, I created two variables within the structures to assign the plural…
-
2
votes1
answer720
viewsHelp with simple while summation program
Gentlemen, I started to introduce the programming and the master is requesting an exercise as follows: Write a Python script that asks the user to enter an integer, n, and computes the sum 1 + 2 +…
-
2
votes0
answers281
viewsNeed to change a dataframe column according to the value found in another column in Python. How to do?
I need the value of a column PERTMINIST is changed from a set of words found in the column SIGLA. For example you can have in the column NOME_ORGAO the words UFJF, UFTM and update in the same row in…
-
2
votes3
answers141
viewsShouldn’t Python none be semantically equal to SQL Null?
That makes sense: >>> if True==True: ... print ('True') ... True That too: >>> if False==False: ... print ('True') ... True But that for me should return nothing, but returns…
-
2
votes1
answer641
viewsHow to create maximize minimize and close buttons in Tkinter (Python3)
I would like to know how to create the maximize, minimize, and close buttons in Python (Tkinter). After the title bar is removed, new buttons must be created to customize the window and leave it…
-
2
votes1
answer455
viewsHow to install Jupyter Notebook autocomplete?
How do I install the extension that suggests the following code for Jupyter Notebook? For VS Code there is this Code Runner that is very good, but my work is done in Jupyter. Does anyone know?…
-
2
votes2
answers1157
viewsPrint the open range between two numbers in descending order
In the code below, I can make it not show variable value a, but the variable b ends up in the print. The expected response would be the open interval ]A..B[. Ex: variable a = 10 and variable b = 5.…
-
2
votes1
answer205
viewsPython error using Tkinter
So I’m doing a little program for the mothers of students to calculate the average of their children however today I went to do a Gui with Tkinter and I only find old video to do a text or in case a…
-
2
votes1
answer107
viewsOperator problem not in the condition of a while loop
I made a program to train txt manipulation: def escreve(): BancodeDados = open("Base.txt", "a") continua=True k=1 while continua: nome = input("Nome do cliente: ") idade = input("Idade do cliente:…
-
2
votes3
answers134
viewsStarting in Python
I made a program to see which team gets the last relegation position in the Brazilian championship. In the end when I put to order the results, they come out logically by results. How to go back to…
-
2
votes2
answers3780
viewsHow to get the index value of a list in Python?
I’m trying to find a way to fit in a salary amount, which is my variable sal, at an interval. I have 8 intervals: $200 - $299 $300 - $399 $400 - $499 $500 - $599 $600 - $699 $700 - $799 $800 - $899…
pythonasked 5 years, 1 month ago Ana Carolina Esteves 71 -
2
votes2
answers120
viewsCapture time range in UNIX
I am trying to capture in UNIX data format the 1 day time range: #!/usr/bin/python # -*- coding: utf-8 -*- import time import datetime from datetime import datetime now = datetime.now() dateNow = ''…
-
2
votes0
answers61
viewsButton does not perform a function when clicked
Good night I’m working with the TKINTER library and OS in Python. And I want that when I click the RUN button, the.py program will run my.BAT file. But the.BAT file runs as soon as the.py program…
pythonasked 5 years ago Bruno de jesus da costa 21 -
2
votes1
answer59
viewsReturn to category the RGB difference is smaller
I’m having a doubt, that I’m probably trying to "reinvent the wheel", but I couldn’t come up with a result. I have a color matrix (in RGB): { "muito-clara": [248,299,218], "clara": [243,209,180],…
-
2
votes4
answers620
viewsHow to delete files and folders recursively safely with Python?
Guys, I’m trying to create a script to delete my files and folders in a safe way, just like it does the shred, srm, etc...but I would like to do this with Python script. I was able to find a…
-
2
votes3
answers4032
viewsPython, even and odd number counting
Create a program in Python that, for any list of integer values, gets (through functions) and prints on the screen. The number of even and odd values in the list. I’m doing a program like this, but…
-
2
votes2
answers99
viewsWhy is it necessary to instantiate a Python class when I can call it directly?
class People: def talk(): print('hello') p1 = People p1.talk() What is the need of instance it if I may call you directly? class People: def talk(): print('hello') People.talk()…
-
2
votes1
answer83
viewsHow can I run a function when user registers Django
I am developing a server using Django and wanted when a user registers to run a function that would create a directory with the user name. The folder with the new user name will be stored in…
-
2
votes1
answer60
viewsWhat’s the difference between using input() and using sys.stdin.readline()?
What’s the difference between using the input() and use sys.stdin.readline()?
-
2
votes1
answer74
viewsCustomized translation of Humanize Django 2.2.x
I realized that the version 2.2.7 from Django came up with the wrong humanize translation. I’m having a problem where my naturaltime is returning: 6mesesatrás and the stream would be 6 meses atrás.…
-
2
votes1
answer49
viewsRegex checking if there is no character on a line
I’m having trouble putting together a Regex that checks if there isn’t a character at any point in a row after a pattern. I have the following log: 3/9/18, 17:47 - Pessoa 1: Oi gente! 3/10/18, 22:59…
-
2
votes0
answers210
viewsError trying to compile python (kivy) in apk for android (using buildozer)
# Check configuration tokens # Ensure build layout # Check configuration tokens # Preparing build # Check requirements for android # Install platform # Apache ANT found at…
-
2
votes1
answer284
viewsI try to run a python function and it returns me None
Sorry if my question seems silly I’m still novice but it’s the following, I created a python function that should return me a list with this character in "~". Here is the function: def…
-
2
votes2
answers76
viewsHow to add images to a program generated by Pyinstaller?
I am creating an executable using the Python programming language and its pyinstaller library. To create the interface, I am using the Tkinter library. In the executable interface I put an image…
-
2
votes3
answers344
viewsHow to read a text file and generate a dictionary?
Write the function símbolo() who accepts a string (the name of a file: Nasdaq.txt) as input. The archive will have company names and stock symbols. In this file, a company name will occupy a line…
-
2
votes1
answer98
viewsTO BE executed asynchronously
Is there any way to execute a FOR asynchronously? What happens is this, my program recovers a large number of data from the database, processes it and returns the result to the user. I’m doing it…
-
2
votes1
answer138
viewsMultiply column with Manytomany Count() from the same Model Django
I have a model called Notificacoes and it has the following structure: Notificacoes(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) users_interacting =…
-
2
votes1
answer56
viewsHow to stop running Python code for time?
How can I make a chunk of code run for x seconds and then stop? In the specific case, I’m expecting a response from a page using request, but if it takes longer than 5 seconds, I want to stop and…
-
2
votes2
answers672
viewsEdit a file name using Python
I am working with hundreds of pdf files, I have to rename them with the folder name where they are allocated. for example: pasta |--- pastajoão |-- celular.pdf |--- pastamaria |-- caderno.pdf has…
pythonasked 4 years, 11 months ago user172268 -
2
votes3
answers2524
viewsDivide date (day, month, year) into new columns - Dataframe Pandas
I have a DataFrame and needed to give a split in his date field to later add month and day columns. The problem is that the field data Dataframe is not the type str, so I can’t use the method split.…
-
2
votes1
answer185
viewsSearch within csv and bring other row columns - Python
Well I have a Python application that generates a csv file of 7000 lines and 4 columns, for example: Mesa,Entrada,Saida,Conta "P",21:00,22:00,95.00 "A",14:00,18:00,195.00 "C",18:00,21:00,75.00…
-
2
votes1
answer74
viewsHow do I build attributes based on values defined in the __init__ method in my class?
I wrote the following class: class Words(): def __init__(self, value, g_class, first_meaning = True): self.value = value self.g_class = g_class self.first_meaning = first_meaning #attribute meaning…
-
2
votes2
answers250
viewsReferencing Python Variables
I’m learning programming on my own and no matter how I look online, I can’t understand exactly why the following reference doesn’t work as I imagine it would work. Let’s say I created a function to…
-
2
votes1
answer737
viewsDjango: How to set MEDIA_URL, MEDIA_ROOT and upload_to correctly?
I’m having a hard time with my Django project. I have a template to upload the images, where I have a field to add a description for each one, and another to search all the images with this…
-
2
votes2
answers124
viewsCount letter occurrences in a case insensitive sentence
I wanted to be able to leave the variables of input as lower/upper to count equivalent letters in the sentence. Only the variable is as iterable, and when I add the .lower() she changes to str and…
-
2
votes1
answer70
viewsWorking with static methods/variables
Expensive, When calling a python class, the variables of that class will always be restarted? What happens is this: I’m working with the parallelization of my code. I receive the data returned from…
-
2
votes2
answers343
viewsGetting maximum value of each grouping with groupby pandas
Hello, i have the DF below which I would like to group by 'country' and get the maximum population value: df = pd.DataFrame({'pais': ['Brasil', 'Brasil' , 'EUA', 'EUA'], 'cidade': ['Santos', 'São…
-
2
votes1
answer938
viewsTake values from a column of a dataframe and create a column in another with the corresponding values
I have two df1 and df2 dataframes, both have team column, but only df2 have the numeral column that every day changes, wanted the values of the numeral column to turn a column in df1, but always in…