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
answer101
viewsPython - multithreading + csv
I’m trying to write csv files using a Thread for each file. Code iterates a list generated by groupby and calls a thread for each group. Calling the function directly files are saved normally:…
-
0
votes1
answer170
viewsImportarror: No module named 'openpyxl'...python Raspberry...appears this error in Raspberry on my micro works well...what can it be?
I made a small program in python in my note to use with Raspberry, tested and worked well.... when step pro Raspberry it does not find the file openpyxl...has installed the openpyxl in Raspberry by…
-
0
votes1
answer87
viewsInsert line break based on number of characters avoiding cutting words
I’m starting in Python and I’m struggling with something relatively simple that I’m not able to accomplish, I’d like to add a line break in a string every 13 characters without cutting the words in…
-
0
votes1
answer103
viewsFind div id with variations - Web Scraping - Beautifulsoup
Assuming I have the following div ids <div id='post_message_12932087> <p>random text</p> </div> <div id='post_message_21390123> <p>random text2</p>…
-
0
votes1
answer183
viewsDefault values in the model - Django
I am studying Jango and trying to set a standard value for a field when makemigrations is executed, would inform that such field would receive a default value like 0 models.IntegerField(default=0)…
-
0
votes1
answer203
viewsTake database data by session with Django
Start my session request.session['username'] = 'usuario' request.session['password'] = 'senha' Here is the following, if there is a session username, password and there is no session Challenge, i…
-
0
votes1
answer44
viewsHow do I apply a condition to a line that skips the next line? (python beginner)
I’m very beginner in python and I’m making a simple calculator, but I have a question that I can’t find anywhere. I want to make a condition for, if the chosen operation is */ (what I used to…
-
0
votes1
answer104
viewsVS Code - Flake8
Good afternoon, In the code below, from and radius ** 2 are not being recognized. When checking the error with from, the following message appears. Does anyone have any idea what this problem might…
-
0
votes1
answer118
viewsAttributeerror- Sqlalchemy Flask
'str' Object has no attribute 'contains' I am trying to create a query using Flask-Sqlalchemy Flask should return me a list of books according to the user’s search. It selects 4 search options and…
-
0
votes1
answer850
viewsCalculate average with final exam if I fail standard grades
Read the values of four bimonthly school grades of a student represented by the variables N1,N2,N3,N4. Calculate the arithmetic mean (variable MD1) of that student and display the message "Approved…
-
0
votes1
answer66
viewsVS Code opens pycharm during code execution
Good afternoon, Running the command below on the VSCODE terminal, it opens pycharm to execute such a command, not running on VSCODE itself. I’ve already uninstalled the test pycharm. Then when…
-
0
votes1
answer322
viewsExtract data from all rows of a file and create a dataframe
I have a file . txt with 2000 lines (Whatsapp chat) from where I need to extract to a pandas dataframe the date, time and sender of the message. I can do this with the function below: def…
-
0
votes0
answers845
viewsForeign key relationship on Jango
I have two tables in the Client and Animal model, where animal has a foreign key for Client, I can list all the animals related to the client in the table, but customers who do not have animals…
-
0
votes4
answers140
viewsHow to print more than a maximum number of a list
Guys the exercise of my college is as follows: Write a program that receives the names of 5 students and put in a list and their respective notes in another list. The exercise asks to print the…
-
0
votes1
answer72
viewsHow to receive a user value to be calculated in a function using Sympy?
I am using the Python Sympy Library, however, I did not find a way to calculate the result of a function using it, IE, I have my function that will be typed by the user, and the value of x that will…
-
0
votes1
answer103
viewsScript to detect prime numbers in Python
I decided to create a script to detect prime numbers, but in order to really understand what I’m doing I created something from scratch, something I thought. At first my program worked, but I…
-
0
votes2
answers46
viewsUnrecognised error
I have to do a function where I present the result of the mean and standard deviation: def challenge2(*args): """return average and standard deviation""" t=0 for i in lista: t=i**2…
-
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
votes1
answer102
viewsRead/manipulate file name error: Attributeerror: 'list' Object has no attribute 'Seek'
Hello ! I am trying to create a code in which to read a zipped file and extract all the folders inside this zip. The first point is that this downloaded zip file always comes with a random name of…
-
0
votes1
answer65
viewsHow to save an image obtained with: pyautogui.hotkey('Alt','printscreen')?
I need to save image obtained by pyautogui.hotkey('Alt','printscreen') In the example below I used pyautogui.screenshot(), but I wanted to catch one print of active window only. time.sleep(2); foto…
pythonasked 4 years, 1 month ago luis ricardo 79 -
0
votes1
answer465
viewsHow to save a work in python so you don’t have to run everything every time you open the script?
I’m working on a jupyter data analysis project, working with about 5 different data frames (which are imported from Csvs) and related through one key or another, from these Dfs and their…
pythonasked 5 years, 5 months ago Paulo Pasquale 13 -
0
votes3
answers575
viewsConstruct a program to read positive integer n and print all primes in the range [2, n]
I need to create an algorithm that reads a number and tells you if it’s prime, and then print in a list all primes smaller than or equal to the read number. I made an algorithm that says if you’re…
-
0
votes1
answer112
viewsHow do I delete lines by cell specific content in pandas
I am preprocessing my data using the Python pandas library. This is a project to train an algorithm to predict "roles" This is the result I get when I run. print(vagas.role_name.value_counts())…
-
0
votes1
answer62
viewsUsing two webdrives in Selenium
I need to develop a script for automation of a website. I get a list of URLs I pass this list on a for that for each item in the list a new one is created webdriver and it asks to login to the site.…
-
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
answer107
viewsWhy does the class accept parameter and the method does not?
I’m studying classes in Python and I don’t understand one thing: considering the last two command lines below, why the value 4 is accepted in the class Operators and not in the method metade()? Do…
-
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
answer74
viewsHow to save peak detection outputs (Z-score algorithm) to a single file?
I would like the output of my program to be saved in a txt file with two columns, no parentheses. I tried to use a append (in the for, I believe on line 98 of the code) to join the outputs in a…
-
0
votes2
answers1329
viewsChange size of Plot area
I generated a Plot scatter, but I can’t change the size of the screen it appears on my laptop. Can anyone help me with this? plt.scatter(X,Y,label='Y(X)'); # sacater plot plt.xlabel('X');…
-
0
votes1
answer64
viewsRemove specific characters from a list
My question is this, is there any way to remove the comma from a list? I’m using the . strip to remove the brackets, but when setting the comma as parameter does not work, I tried . replace but…
-
0
votes3
answers115
viewsShow a dictionary inside a class created by an external function
I’m trying to create an RPG plug simulator, but I’m having trouble properly displaying the labels. Creation runs through the function criaPersonagem() creating an object in dictionary format (at…
-
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
answer88
viewsHow to treat columns with the same name in csv file
I have the following problem, I received a database in csv file and I need to analyze this data, but it has a lot of columns with the same name and I wanted to know if you have any way to treat…
-
0
votes1
answer62
viewsWhile loop being ignored
Hello I would like to get help to a question I haven’t found answer, I have 2 loops while being ignored without any explanation (it doesn’t give error simply it passes to the next), the user must…
pythonasked 5 years, 4 months ago Alexandre Caribé 19 -
0
votes1
answer424
viewsHow to check if a data exists in the table before inserting Mysql + Python
I’m trying to verify if a data already exists in the database before entering. My code is like this: nome = input("Insira seu usuario: ") seleciona = "SELECT nomes FROM slogin"…
-
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
answer39
viewsResult - . find() - Different from expected
When I spin that code: fname = input('File name: ') fhand = open(fname) count = 0 for line in fhand: if line.find('Subject:'): count = count + 1 print('There were', count, 'subjects lines in ',…
pythonasked 4 years, 1 month ago Henrique Hott 317 -
0
votes1
answer500
viewsHow to simulate pressing a key for a certain time?
I was trying to make a Python BOT that held the z key for 4 seconds and then released, I tried to use the pynput, but when using the keyboard.press('z'), the command clicked only once and did not…
-
0
votes0
answers35
viewsDoubt about functions
Good evening, sorry if anything related was posted at any time. I tried to search but did not succeed. I am trying to do a function and in the result, be printed the data of the variables, but…
pythonasked 4 years, 1 month ago Vinicius Araújo 13 -
0
votes2
answers30
viewsDoubt called function by loop
Good afternoon, I’m starting programming and I’m having a question about calling function through loop. I created the function and I’m trying to put so that at the end, ask if you want to continue,…
pythonasked 4 years, 1 month ago Vinicius Araújo 13 -
0
votes2
answers43
viewsdoubts in the creation of dataframe pandas
I have a question in creating a dataframe as an example dicionario = {'pais': 'brasil', 'capital': 'Brasilia', 'climate': 'tropical'} pd.Dataframe(dictionary) back index error but put some value on…
-
0
votes2
answers78
viewsDoubt replace in pandas
Doubt in replace in dataframe pandas texto = 'Vírus de computadores são uma lenda urbana.' dado = {'texto': [texto]} df = pd.DataFrame(dado) df['nova_coluna'] = df.texto.str.replace('urbana', '') By…
-
0
votes3
answers1079
viewstransform list items into separate columns or extend dataframe to the end
I have a class with an element that is a list I’m trying to display in a pandas dataframe this list in a single line to represent the character’s inventory. assignment of items in the list: if…
-
0
votes0
answers67
viewsApi does not return JSON correctly
I am trying to request a list that should contain the indices 'asks' and 'bids' but I can only 'bids', I don’t know if there is a limit to the size of the request in python, I can’t handle this…
-
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
votes0
answers38
viewsDoubt about Selenium and python
I’m making a bot for instagram, comes certain part of the page I have a list of people with the "follow" button on the side. made that code: bot = self.bot…
-
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
votes1
answer33
viewsGraph is generated but does not show data, matplotlib
I’m a beginner in Python, I’m not finding the reason for the graph to be generated blank. How can I declare this for plt?…
-
0
votes1
answer59
viewsPython encapsulation
I wonder if I can encapsulate a function that is not in a class, like, just a function in the same code, so that it is only accessed inside the file, and when I import this file I can’t access this…
-
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…