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
-
2
votes2
answers199
viewsHow to reduce formula . replace in Python
I’m with a dataframe where you would like to replace the 0.1 encoding by yes and no. Some columns of the df have this encoding and so I wrote the following command: dados_trabalho =…
-
2
votes1
answer4515
viewsPython data output formatting
My question is about formatting output data from the program. I’m solving one of the exercises wiki.python.org, whose data entry is as follows:: alexandre 456123789 anderson 1245698456 antonio…
-
2
votes0
answers206
viewsError with Python Nmap
I’m trying to make a script on python using the Python nmap, but I keep getting an error on the console when I try to run the script! My code: import nmap import os nmScan = nmap.PortScanner() def…
-
2
votes1
answer400
viewsHow to count the elements of a list
I have a list that stores data: [(pizzas, 'COMIDA'), (1, 'QUANTIDADE'), (chocolate, 'SABOR'), (1, 'QUANTIDADE'), (catupiry, 'SABOR'), (1, 'QUANTIDADE'), (morango, 'SABOR')] I’d like to check what’s…
-
2
votes2
answers2151
viewsHow to avoid "Missing 1 required positional argument" error when one of the parameters is omitted
I have this function in Python: def v(m1,m2): print(m1) print(m2) It gives an error when I do not enter one of the parameters, for example inserted m1 = [1,2,3] and omitting m2: v([1,2,3]) Missing 1…
-
2
votes1
answer2321
viewsWhat is None in Python?
I am using the online IDE repl.it. A part of the code has this user input opcao = input(print('Digite:\n1- Acertei\n0-Errei\n\n=')) what gives the exit: Digite: 1- Acertei 0-Errei = None It doesn’t…
-
2
votes1
answer61
viewsPrint the name of a dictionary in Python
Follows the code: layla = {'tipo':'cachorro', 'nome_dono':'lucas'} ratata = {'tipo':'rato', 'nome_dono': 'Dante'} pikachu = {'tipo': 'furão', 'nome_dono':'Ash'} pets = [layla, ratata, pikachu] for…
python-3.xasked 5 years ago Di0nk3r_. 41 -
2
votes3
answers92
viewsCounting letters in a string
I need to make a Python script that takes a string and returns the sum of the letters of that string in a list of tuples, as follows: Example: banana -----> [('b', 1), ('a', 3), ('n', 2)] My show…
python-3.xasked 4 years, 12 months ago LFRF 21 -
2
votes2
answers432
viewsHow to compare two identical`strings, but different encoded strings?
I want to compare two strings, which are equal but have different encoding. G%C3%A9rard Depardieu and Gérard Depardieu I need to make several comparisons in two lists, but I came across this. The…
-
2
votes0
answers128
viewsError permission denied in python
I was writing a code to try to connect to my wi-fi network using python. I used the following code: from wi - fi import Cell, Scheme try: cell = Cell.all('wlan0') except: print(Exception) passkey =…
-
2
votes1
answer232
viewsError: Collections.defaultdict' Object has in Python iteritems attribute
When executing the code below the compiler returns the following message: collections.defaultdict' object has no attribute 'iteritems' I’m using version 3.6.5 of Python. Follows the code: import…
-
2
votes2
answers98
viewsWhat is the difference between a string defined within a text file and another defined as a variable?
Imagine the following: texto = "They fly quickly over the snow in their sledges; the motion is pleasant, and, in my opinion, far more agreeable than that of an English stagecoach" texto1 =…
-
2
votes2
answers1020
viewsHow to balance classes in a machine Learning regression problem with Python?
Problem using the dataset of the book "Hands-On Machine Learning with Scikit-Learn and Tensorflow" https://github.com/ageron/handson-ml dataset of house prices. Objective: to create a model of house…
-
2
votes3
answers17023
viewsDo while in python
Is there a similar command to while de c and Java in python? I am entering the language now and already developing in java then I got this doubt
-
2
votes1
answer1491
viewsBrowse and count records from a JSON
I have a Python code that I can display on the screen all JSON records, only I need to bring only the field 'Nome' and the count of each. First he brings with [] (list format) and I need the…
-
2
votes1
answer1934
viewsPygame does not run a.mp3 file and returns pygame-error
I was touching the Pygame and when performing a program that plays music: from pygame import mixer mixer.init() mixer.music.load('ex021.mp3') # Dark Souls III Soundtrack OST - Main Theme.mp3…
-
2
votes2
answers689
viewsUsing self-free method in Python
I saw in other topics some discussions about passing the self as argument. But it was not very clear to me. Even though my function has no argument to be started I still need to pass the self as a…
-
2
votes0
answers54
viewsRaspberry Pi3 + Raspbian - Python serial driver problem cp210x
Hello, I would like if possible, help/tips on the following problem: I am connecting my device using cp210x driver to my raspberryPi3 using Raspbian system, through USB-Serial communication, but…
-
2
votes1
answer286
viewsHow to fire an automatic email through Django when you receive a new value in the database?
Hello, my system is monitoring a server services, when a service fails I get a new value in the database with status "8" which means error, I would like to send an email to some user stating this…
-
2
votes3
answers4009
viewsHow does the python sys module work and what is it for?
I am following a book, and I am not able to understand a part about Command line parameters, on this page he is using the sys module and working with the arqv list: import sys print(f"Número de…
python-3.xasked 4 years, 9 months ago Maicon 43 -
2
votes2
answers2695
viewsHow to select a Python file using Tkinter
I have the following Python code using the library tkinter: from tkinter import * class Application: def __init__(self, master=None): self.widget1 = Frame(master) self.widget1.pack() self.msg =…
-
2
votes1
answer104
viewsHow to capture each key pressed in an entry with Tkinter?
Using the library Tkinter, i would like to perform a database search with each key pressed by the user in an entry, so that the result is automatically shown in a Listbox as I type. How can I do it…
-
2
votes0
answers37
viewsWhat is the main use of decorators in classes
I would like to understand more about decorators with classes, what their main advantage within a class, which decorators are most used, if there is any alternative to them, and how to know when to…
python-3.xasked 4 years, 8 months ago Maicon 43 -
2
votes3
answers1958
viewsHow to print list elements in reverse order?
I created a program that takes integers from the user and prints them back in the reverse order that received them, however my program is not returning all integers it receives. When I enter 9…
-
2
votes1
answer189
viewsHow to convert an Object to integer in Pyton 3?
I imported some data in Wikipedia and imported to Pyton. However the data that were to be integer is in the form of Object as in the image below. import pandas as pd import requests url =…
python-3.xasked 5 years, 7 months ago Fidel Henrique Fernandes 119 -
2
votes1
answer46
viewsUpside down widgets in Kivy
I have a problem running any Kivy screen, because it always appears upside down. This problem is only with this specific library, the other ones I use work normally. A simple code like: from…
-
2
votes2
answers172
viewsI would like to know how to write >>> print("Size = %4.2f cm" % Size) and what does %4.2f mean
I’m doing a college assignment and I’d like to know what the %4.2f in >>> print("Tamanho = %4.2f cm" % Tamanho) and how a value (8.47826) is represented by following this parameter after…
-
2
votes1
answer702
viewsPython3 - How to get back folder?
My file main py. is in the root directory of my project, example: "C:\Projetos\PyValidacao\main.py" With the module os I can take the real path of main py., but I need to make you create a folder…
python-3.xasked 4 years, 7 months ago Cleber Nandi 137 -
2
votes1
answer194
viewsHow many times has the highest number been read?
I have the following problem: the user enters with the amount of numbers to be read, later I want the largest among this quantity 'X' of numbers to be displayed and also how many times this higher…
-
2
votes1
answer82
viewsWhat is the bincount method of numpy for/what?
I read the documentation but I don’t understand what it does: print(np.bincount(np.array([0, 1, 1, 1, 2, 3, 7]))) The exit is: [1 3 1 1 0 0 0 1]…
-
2
votes2
answers61
viewsPass X function as parameter to Y function, but only define X parameter within Y
Does anyone know how to make the code below work? Or some alternative that works, but follows the principle. def f_numbers(number='no'): if number == 'no': return 'Você não definiu um número' else:…
-
2
votes0
answers38
viewsHow to display the content slowly when using the print function without breaking line?
PYTHON 3 import time for i in range (1, 11): time.sleep(1) print (i) RESULT: Screen output every second. Based on the above instructions, every time the condition is true a result will be printed on…
-
2
votes2
answers96
viewsWhy does readlines display an empty list even with the file having data?
f = open("grades.txt", "r") for record in f.readlines(): print(f"grade : {record} ") print(f"readlines: {f.readlines()}") f.close() The.txt grid file exists and has the following content: 10 9.8 .6…
-
2
votes2
answers103
viewsWhy is this loop infinite?
I wanted to stop the loop when t is at 5. So I counted -1, but it does not go back to while to check the condition and turns a loop infinite. text = 'abcdefghij' t = 10 while t != 5: for i in text:…
-
2
votes1
answer331
viewsTop 3 the biggest numbers in the list and their indexes
I have the list [5, 7, 2]. I need to create another list containing the indexes in this list, ordered so that the first index corresponds to the largest element in the list, the second corresponds…
-
2
votes2
answers103
viewsNegative print, it only prints the postives
Write a program that reads whole numbers from the standard input until a negative number is reported. At each reading the number read should be written in the standard output. n1 = int(input())…
-
2
votes1
answer49
viewsDoubt with print and with for
for l in arquivo: Print(l) In this file are the name information, IP and Hostname. I need to print the name, IP and Hostname, however in this format: Name space of 10 characters Ip space of 10…
-
2
votes1
answer89
viewsPrint even numbers in a list
I’m trying to get the code to print only as many even numbers as it finds and not list all the numbers it found. What I’m trying to make it appear on the screen: 5 números pares What is appearing on…
-
2
votes1
answer384
viewsPython: Web Scraping in Dynamic Page
I am researching on web scraping. I have found dozens of pages, however, in none of them found how to extract information from dynamic pages. Well, I’m trying to get the value of the LTCBRL…
python-3.xasked 5 years, 7 months ago Wilson Junior 182 -
2
votes2
answers773
viewsHow to subtract several elements from a list?
I am making a calculator and would like to subtract several elements from a list, this because the list can have as many elements as the user wants. See my code: lista = [10, 5] subt = lista[0] for…
-
2
votes3
answers99
viewsReplace all arguments (of all strings) that exist in a Dict with . format
I wonder if there is any pythonica way to replace all the arguments (of all strings) that exist in dictionary with . format . For example: dicionario = {"nome": "{nome_usuario}", "idade": 26,…
-
2
votes0
answers29
viewsProblem while deleting a file
I made a small log manager. It’s for something simple, so how is it fit. every day I want to delete and generate a new one, but my code is showing the following error: The file is already being used…
-
2
votes1
answer888
viewsThe sum of the N first prime numbers
Write a program that reads a non-negative integer and print the sum of the N first prime numbers. I am not able to add the N first prime numbers but add up to the prime number typed. If I type 5 for…
-
2
votes1
answer989
viewsHow to quickly calculate the sum of dividers in Python?
I would like to know how to quickly calculate the sum of the divisors of a natural number n, where 2 <= n < 109. For small numbers, I perform this operation quietly with the following code: n…
-
2
votes1
answer256
viewsScroll through a list inside another List
Hello I’m a beginner in Python and I wonder if there is how to scroll through a list within another list, I tried to make an example, but is giving this error: "Typeerror: 'int' Object is not…
-
2
votes1
answer235
viewsCapture typed key using Python 3
Below I have a code in Python that capture typed key, only I need to get the name of the program where he typed such key. How can I do that? from pynput.keyboard import Key, Listener import logging…
-
2
votes5
answers135
viewsProblems with arrays in a Python password generator
I’m making a generator of passwords and I’m not able to join letters that are separated into one array. from random import choice minusculas = ['a','b','c','d','f','g','h'] maiusculas =…
-
2
votes1
answer81
viewsHow do I print the name of an instance in Python?
class Panzer(): def __init__(self): self.life = 100 self.blin = 100 drogo = Panzer() cabal = Panzer() sirius = Panzer() group = [drogo, cabal, sirius] for i in group: print() What should I put on…
-
2
votes1
answer352
viewsHow to save a function, with predefined parameters, in a python variable?
Currently I can save functions in variables as follows: def somar_iguais(lista, referencia): resultado = 0 for x in lista: if lista[x] == referencia: resultado += referencia return resultado SOMAR =…
-
2
votes3
answers75
viewsAdd Character at the end of the line
Greetings, when I add a ";" to the end of the file, even if I specify that it is not to add if I am done with it, it is still added: newf="" with open('teste.txt','r') as f: for line in f: lastchar…