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
-
1
votes2
answers1857
viewsIn which folder should I add the files to be read by Jupyter Notebook
I’m learning to use Jupiter Notebook to study Data Analysis, but I’m encountering a problem using it. In the lesson I am doing, we should read some data provided with the extension .csv. However,…
pythonasked 5 years, 11 months ago Andressa Amaral 21 -
1
votes1
answer1437
viewsAttributeerror: __enter__ in context manager implementation
I’m trying to understand the workings of gerenciadores de contexto Python, implementing a contextmanager. Here follows the script: class contextmanager(object): def __init__(self, func): self._func…
-
1
votes2
answers941
viewshelp with storing value of a local variable in python
Hello, well, I am writing an application using SQLITE and Python, everything was going well until I had a problem that I am not able to solve, it happens that I have a db of the fipe, so I need to…
-
1
votes1
answer468
viewsmodule 'cv2.cv2' has no attribute 'COLOR_BRG2GRAY'
I am resizing images from a folder and am encountering the following error: module 'cv2.cv2' has no attribute 'COLOR_BRG2GRAY' Code: pathC = './cityscape/' dirs = os.listdir(pathC) #Resize para o…
-
1
votes1
answer226
viewsHow to detect a click or other mouse event in win32gui’s Notifyicon?
I’m trying to modify the library win10toast so that I can pass a callback that runs when the user clicks on the Windows 10 notification that I show. The "meat" of the library, which I’ve mastered as…
-
1
votes0
answers40
viewsHow to declare objective function in Python containing the same variable but for different ranges?
I have a binary variable x[i][j][t] defined in the range for i in dat.I for j in dat.I if i != j for t in range(len(dat.H[0]) + 1) I need such a variable to be multiplied by a -Lambda[i][t]…
-
1
votes1
answer149
viewsCircular import
To doc of Flask, despite using in its examples, warns at the end of the page about the bad practice of using circular imports. Another thing that bothers me is creating "global objects" inside a…
-
1
votes1
answer1547
viewsmultiple commands with python subprocess
I am developing a system (college work) that consists of a website for the use of a certain board. The problem is that to run the code on the board, I need to run a bunch of commands. Currently my…
-
1
votes1
answer2558
views -
1
votes0
answers37
viewspython sigint and Ctrl c have different effects
Hello, I need to run an executable done in c,this executable performs operations on a board and writes to a file, the problem is that the write event occurs when the program receives a Ctrl+c. I…
-
1
votes1
answer860
viewsUsing screens in Tkinter-Python
You guys all right? So, I’m doing a screen test program, its function would be just a test consisting of: Open a screen (called by a button) and close the one that was open. I don’t know how to do…
-
1
votes1
answer103
viewsProblem in python print
I have 2 inputs that receive the first and last name of a person, then is informed the values typed and is asked the age of the same, but the print is showing the name information between "Square…
-
1
votes1
answer149
viewsUser type 15 random numbers, program returns the average, numbers larger than average and those smaller than average!
num = [] soma = 0 media = 0 for i in range(1, 16): num = int(input('Digite um número: ')) soma += num media = soma / 15 if num[i] > media: print('Maires que a…
-
1
votes3
answers85
viewsError searching string inside another python string
I’m running some tests and the code seems to be correct logically, but when I use an example, "what day is it today?" as self.phrase it only returns me the first if (of the hours), if I put as…
-
1
votes1
answer104
views"Arraylist" in Django
I am developing an application for reporting optical fiber certifications, and such reports are produced by importing XML and TXT files. The question is as follows: A certification is made within a…
-
1
votes0
answers549
viewsChange screen by python file in kivy
I need to change the screen inside the file .py, I can’t do it for .Kv because I have to use the ButtonBehavior and it does not work in .Kv. from kivy.app import App from kivy.uix.boxlayout import…
-
1
votes2
answers126
viewsPython Pandas - How to check if a "tuple" of two Series elements is contained in a set?
I have a "set" of "tuples" as follows set = {(2, 3), (2, 4), (5, 5)} My Dataframe is like this: df = pd.DataFrame( {'one': [1,2,4,1], 'two' : [5,3,2,2]}) I want to check if in each row the "tuple"…
-
1
votes3
answers840
viewsReplace word list in text
I always have a hard time with replace and sub. I know how they work, but with me it’s never right. I have a list of words and am trying to replace these words in a text: Text: Brazil, officially…
-
1
votes1
answer121
viewsProblem passing argument via Python command line
I am a beginner in Python and am facing the following problem to pass an argument via Python command line. from math import pi import sys def circulo(r): return pi * float(r) ** 2 if __name__ ==…
-
1
votes1
answer935
viewspylint E1101:Class 'User' has no 'Objects' Member
I am using vscode together with Djangorestframework and it is error in the following line: res = User.objects.filter(user_nome=value) However the code runs correctly, the error that the editor shows…
-
1
votes1
answer37
viewsDefinitions and their use in classes
When I create a "def" from what I understand is different from __init__ right? If I create an object in the __init__ it is possible to access it from other def's? In some codes I noticed they use…
-
1
votes1
answer29
viewsTensorflow and Xgboost library via Pip
How do I install the Tensorflow and Xgboost libraries via Pip in Python version 3.7.2? I’m not getting it. I researched and the information I got was that they only work in previous versions of…
-
1
votes1
answer122
viewsMean between positions of two vectors
Guys, how can I average between n vector positions? For example, given an input form vector vet = [[10,10,10,10],[10,20,10,10],[10,15,10,10]] I need the function to return a new vector with the…
pythonasked 5 years, 10 months ago Rafael Alencar 23 -
1
votes1
answer641
viewsPython-Tkinter. how to close a window using the code and not the close button?
there is some way to close the window created (container = Tk()) other than the button close? wanted to create by code, example: a login screen, when the login is done, the login screen closes and…
-
1
votes1
answer974
viewsHow to insert a try counter within an exception (except Valueerror) of Python 3
Hello. I am a beginner in programming and have been trying to develop on my own programs that I learned in programming book exercises. I made my version of the classic "Guess the number", where the…
-
1
votes1
answer285
viewsHow to create a regex in Python to get a specific text?
For example, I want to take the string below: TEXT ABOVE MR. DR. DR. JUDGE OF LAW SPECIAL COURT CIVIL DISTRICT OF THE CAPITAL TEXT BELOW The word DEAR. may be replaced by EXCELLENCY and the word…
-
1
votes1
answer92
viewsList as function input
In Python 3.7 items of a list can be arguments of a function? def media(x,y,z): lista = [7,8,9]
-
1
votes2
answers1709
viewsModulenotfounderror: No module named 'wordcloud'
I’m using the Microsoft Azure with Jupyter notebook and I need to use the word cloud. However when executing the code: from wordcloud import WordCloud it presents the error No module named…
-
1
votes0
answers49
viewsDo training using Tensorflow
I have a question about Tensorflow. I have some files in csv that I need to do training, but when I go to see the documentation of tensorflow, there are several options in Train, I don’t know which…
-
1
votes1
answer61
viewsHow to make a Sorted by a specific csv column?
I have a file. csv and need to make a Sorted by a specific column ('salary' column) and list by the column 'name' the top 10 salaries without using PANDAS. Can you help me? Thanks in advance.…
-
1
votes2
answers406
viewsPython calling super() in class that does not implement inheritance
I’m developing some middleware and as I delved into Django’s source code I came across the following: class MiddlewareMixin: def __init__(self, get_response=None): self.get_response = get_response…
-
1
votes1
answer202
viewsError in python print
Hello, I have a little problem, I think it’s simple and I’ll get help here. I have a code that gets a name, check if it is 'Elves', if it’s printa 'welcome', if it’s not printa 'unauthorized'. The…
-
1
votes1
answer1358
viewsAccess Denied when trying to delete directory with PYTHON
I have several folders, and within these, several other folders, and I need to enter one in order to delete other folders (Yes, there are many nested folders). The name of the folders that I should…
-
1
votes2
answers5265
viewsScientific notation in Python
I thought about making an electrostatic formula that would give the result in scientific notation, but I don’t know how to leave it in scientific notation. Is there a library for that? n =…
-
1
votes0
answers214
viewsBhaskara Calculator functionality in PYTHON
Hello, I am still a student and I would like to know if some way to make more compact is Bhaskara calculator that I made. I’d like one that shows every step as she does. print('BHASKARA SOLVER')…
-
1
votes2
answers262
viewsGuess Game Python Tkinter
I created a code in Python to present a puzzle game of numbers between 1 and 100. I wanted to implement this game in a graphical interface, using the Tkinter module. I had an idea, I created a code…
-
1
votes1
answer1121
viewsHow to read txt file separated by "|" using Python with the Pandas library?
I have a txt file with the following structure: ----------------------------------- |SKU. |DT.Compra|Dt.Chegada|SKTD| |---------------------------------| |100312 |20171202 |20180105 | 27 | |89721…
-
1
votes1
answer75
viewsFunction to pick a row from an Excel table and slice
You can take a row from the table and divide it into as many pieces as you want? I can take cell by cell from the table using an approach I learned here on the forum in an already answered question,…
-
1
votes1
answer178
viewsHow to indent a yaml file using regular expression?
PROD ="IND" LOCATION ="NY" LOLO ="abc" yaml_content = """ MAIN : PROD : {} LOCATION : {} EXTRA : LOLO : {} """.format(PROD, LOCATION, LOLO) yaml_content = re.sub("\n\s", "\n", yaml_content.strip())…
-
1
votes0
answers310
viewshow to capture specific tokens in python requests
I need to capture specific cookies from a python code and pass them on later, the problem is, if I set cookies manually they work for a while but after a few days they expire. I can pick up a…
-
1
votes1
answer262
viewsHow can I get the color of a pixel using python3
I would like to know how I can, using python, get the color of a pixel from the web? I’m trying to make a bot and I need it to collect the color of the web page and not an image of the following…
-
1
votes2
answers154
viewsSorted returns white space inside the Array
I want the program to receive 2 numbers and show them in ascending order: a = input() x = a print(sorted(x)) But with that when I write 3 2, he shows [" ", "2", "3"]. How do I eliminate space?…
-
1
votes1
answer205
viewsColumn Python function for a list
I need to create a function that adds columns from one list to another list in the same order by following this structure here (you can use FOR). def column_to_list(data, index): column_list = [] #…
-
1
votes1
answer98
viewsProblems starting methods in a python class?
I’m new to python and started with classes now, tried to start a class but for some reason always gives error, the error changes but always gives, at the moment I am with the code this way : class…
-
1
votes1
answer89
viewsTkinter Python stopping the script
Good afternoon, I would like to create a window with the words "Application running" and tried the following: from Tkinter import * root = Tk() T = Text(root, height=2, width=30) T.pack()…
-
1
votes1
answer78
viewsprogram that puts people on a list
someone can explain the mistake? quantidadePessoas = int(input('quantas pessoas estarão na festa?')) lista = [] for pessoa in range(quantidadePessoas): nome = input('inscreva uma pessoa')…
pythonasked 5 years, 9 months ago Silas Paixão 35 -
1
votes1
answer429
viewsCreate a table with initial data in Django
I want to create a table with the names/ types of a template, in this case, are documents, I have this template code class Document(models.Model): hash = models.CharField(max_length=256) name =…
-
1
votes1
answer78
viewsUse await with object that implements the __await__method
From the Python 3.5 was introduced async/await I am implementing some objects long-awaited but I am met with doubts follows an example: #!usr/bin/python3 # -*- coding: utf-8 -*- import asyncio class…
-
1
votes3
answers252
viewsNumber of odd numbers
I created a function that returns the odd numbers. How do I return the amount of numbers, for example 4 odd, 3 odd, and so on? lista = [1,3,5,7,2,4] impar =[] def ehImpar(impar): for impar in lista:…
-
1
votes0
answers139
viewsProblems with neural network input data with scikit Learn
I would like to create a neural network that returns 1 (one) to a specific case and 0 (zero) to all others. The idea would be: import numpy as np import pandas as pd from sklearn.preprocessing…