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
votes2
answers17879
views(Python) Sort lists without Sort()
how to sort a list without using Sort()? The code below is correct, but the teacher does not want you to use Sort(). The code has the following instruction: "Make a program that, when filling a list…
-
2
votes2
answers1186
viewsHow do I resolve these libpng errors in pygame?
These errors are shown when I close the game: libpng Warning: iCCP: known incorrect sRGB profile libpng Warning: iCCP: cHRM Chunk does not match sRGB These mistakes happen because I’m using it:…
-
2
votes1
answer3717
viewsWays to find out which is the largest and smallest number typed in the user input in a for
Well briefly I have a doubt whether there is a way to make this code otherwise more "simple". The code itself is already simple but wanted to know if there is another way using fewer lines or…
-
2
votes0
answers201
viewsCounting the number of connections per IP to a web server on port 80. Is regex correct?
I would like to count the number of connections per IP per second (at port 80) to a web server whose IP is 192.168.1.216. The input for the count is a network dump file in the PCAP (.pcap file)…
-
2
votes1
answer379
viewsProblem to run file. Feature in Pycharm
I’m having trouble in my environment to run files .feature. I am creating a Behave + Selenium and every time I run my file .feature he makes the following mistake: C:\Python\Python36-32\python.exe…
-
2
votes1
answer129
viewsFunction adding values within the list
I have a problem and I need to create a function that adds the values that are inside a list. I have already done this and the code is below, however, Python returns me the value 3 as a result, when…
pythonasked 7 years ago GratefullyDead 373 -
2
votes1
answer988
viewsPython - invalid literal for float()
I have an array that looks like this training_set = [['03/11/2017' '16,94'] ['01/11/2017' '16,90'] ['31/10/2017' '16,77'] ... However, I cannot manipulate the numbers because they are in the form of…
-
2
votes1
answer527
viewsRuntimeerror: maximum number of recursive calls exceeded - python
fibonacci_cache = {} def fibonacci(n): if n in fibonacci_cache: return fibonacci_cache[n] if n==1: value=1 elif n==2: value=1 elif n>2: value=fibonacci(n-1) + fibonacci(n-2)…
-
2
votes1
answer1043
viewsRead Data from a. csv file and pass line values to Tuple
The data in the.csv cities file is organized as follows: Lisbon,Madrid,600 Madrid, Paris,650 import csv with open('cidades.csv', 'r') as f: # Somente r para leitura do arquivo list1 =…
-
2
votes1
answer187
viewsHow could I make an app that works in the background with python and kivy?
I’m trying to make a kivy app that takes information from a database in the background, and when a change occurs in the database, send a notification to the user. Someone would know to tell me if…
-
2
votes3
answers8998
viewsHow to call, in Python, a function whose name is stored in a variable?
You have 99 different definitions of functions: def Fun_1(): ... def Fun_2(): ... def Fun_3(): ... ... ... def Fun_99(): ... the value of the variable x is obtained at random between 1 and 99: x =…
-
2
votes0
answers153
viewsHow to grab text and images from pdf file
I need to get text and images from a pdf file. I tried to use Pypdf2, but with it I’m only able to get the text. Can someone help me ?
-
2
votes2
answers2266
viewsHow to find the name of the key in a dictionary by the value contained in it?
Here is an example. dicio = {'pizza': {'massa', 'ketchup'}, 'feijoada': {'feijão', 'linguiça'}} user_input = 'feijão', 'linguiça' #Input How to check if this input is in the values of this list and…
pythonasked 7 years ago Lorran Rosa 83 -
2
votes3
answers1265
viewsAsk for n python entries
I’m having a hard time with this exercise: "Do a program that asks n people your age, at the end the program should check if the average age of the class varies between 0 and 25, 26 and 60 and above…
-
2
votes2
answers1647
viewsUse of def function
I would like to create a function def to the first input and then return it in the third line. Example: def se(): sex = input('Digite seu sexo:') while sex != 'M' and sex != 'F': #não sei como se…
-
2
votes1
answer525
viewsMethod of choice with while
I have two options and the program should say which one was chosen, if the input is wrong should ask to repeat the request. Problems: Option 2 repeats 2 times until right. Option 1 does not say a…
-
2
votes2
answers233
viewsHow to extract all td names in order?
I need to extract all the names of people on this site: Camara.gov.br I wrote this code in Python3: from urllib.request import urlopen from bs4 import BeautifulSoup import urllib.request,…
-
2
votes2
answers991
viewsHow to read numbers separated by hyphens in a text file?
Let’s say I have a text file where its configuration is: 1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20...-999 How do I read the file and go saving each number this is separated by -?…
-
2
votes1
answer277
views"rank" array in Python
I’m having a problem and I’m having trouble solving it, the following is I have a list of the kind : ['Words', 4], ['evidenced', 3], ['presented', 2], ['showed', 2], ['second', 1], ['treaties', 1],…
-
2
votes2
answers26379
viewsReturning only the highest value of a Python list
I have the list ['4', '07', '08', '2017', '364', '355673087875675'] and would like to re a formula to return the higher value, which in this case would be the '355673087875675', tried to use the…
-
2
votes1
answer637
viewsCan you make an auto-executable script in Python? (Autorun)
Hello, I’m starting to learn Python, I know only the basics, I wanted to make a script self executable (autorun), but I searched all over the internet and I couldn’t find anywhere to do an autorun…
-
2
votes1
answer70
viewsHow to pass Keywords Arguments in python in a simpler way?
I’m trying to create the class button and trying to get the arguments I can pass pro rect, only if some argument is None and I pass for example self.rect = pygame.Rect(x=x) and the x for None of…
-
2
votes1
answer225
viewsProblems with PEP8 indentation rules
I’m using the autopep8 extension in sublime text 3 and it suggests to me that the following line looks like this: self.buttons = [Button(self.fonts["alfa_slab_one_regular_40"], "JOGAR",…
-
2
votes2
answers394
viewsMeaning of these nomenclatures in Python and other languages, if the names are universal
I would like to know the meaning with examples, if necessary, of the following names: Class Object Attribute Method
-
2
votes3
answers1185
viewsThere is no library called Math
Why when I care sqrt bookstore math He says there is no bookstore called math, but still the code works? No error works well, but it is underlined in math and sqrt. To "heal" while I can’t find the…
-
2
votes1
answer358
viewsHow do I use Firebase as a database in a Django application?
I just created a Django project and would like to use Firebase instead of sqlite as a database. I looked in several places but could not find anywhere how to do the integration. Someone could help…
-
2
votes0
answers324
viewsNewton-Raphson method together with Horner
I’m having trouble implementing Horner’s method to decrease the computational cost of polynomial calculations and, having done so, using Newton’s method to find the root of the polynomial In the…
-
2
votes2
answers7513
viewsHow can I use the results of one function within another in python
Good afternoon, I’m studying python alone and I’m trying to do a little programming with lists and functions, the program it will receive 10 names and store in a list, then 10 notes and store in…
-
2
votes2
answers2868
viewsHow to know which libraries are being used in a python project?
I did an installation of an application made in Python, it works basically as follows, it installs Python, the program and at the end the installation copies the folder with the libraries for the…
-
2
votes1
answer815
viewsInput read more than one string line
I’m having a problem, my code needs to read a string that contains more than one line, however it reads the first and to, as if when the line is skipped, it interprets as a "enter". def…
-
2
votes1
answer110
viewsError: "Selenium.common.exceptions.Webdriverexception: Message: Unknown error: Element is not clickable at point"
I’m setting a series of "checkboxes" in a variable lista. Then I run the variable through a loop so that only a few of them are clicked. But when the checkbox is not visible on the screen, Selenium…
python python-3.x selenium selenium-webdriver webdriverasked 7 years, 1 month ago Bergo de Almeida 181 -
2
votes1
answer76
viewsVariable creation
How do I create a variable and add the type as integer, but without having any value set? I need this variable to do this: a = int(input()) b = int(input()) x = int # tentei colocar o tipo da…
-
2
votes2
answers4478
viewsList of objects in Python
I’m doing a function that returns an object list. Snippet from the code: def guarda_word(lista_palavras,lista_objeto,indice): for i in lista_palavras: if bool(lista_objeto) == True: # a list de…
-
2
votes3
answers1084
viewslist value to a variable, Python
I want to create a list, and assign to a variable the value referring to the positioning of that list For example list = ["a", "b", "c"] Let’s say the priest gives me the letter "c" I want a…
-
2
votes1
answer308
viewshow to remove CMD window after using.system in python
I have a Python 2.7 code that opens a PDF with os.system('meuarquivo.pdf') and it opens right. But when opening the file it also opens an empty CMD window. Is there any way I can close this window…
-
2
votes1
answer112
viewsOverload of the Sort method
Studying polymorphism in python. I am trying to overload the Sort method of the list class that was inherited by my group class. It turns out that the ordering is not coming out right. I don’t think…
-
2
votes1
answer408
viewsUsing kivy Urlrequest
How exactly do you use kivy’s Urlrequest? In this case you would like to download a page that returns a json file. Using the python requests library I can do this easily, but when running the…
-
2
votes2
answers409
viewsHow does Python keep the same memory reference as a list after resizing it?
We know the objects of the type list, because they are based on dynamic vectors, it has a maximum internal capacity. We also know that when this total capacity is reached and we want to insert a new…
-
2
votes1
answer263
viewsEuro banknote sorting program? Python
def Dinheiro_vivo(x): while x > 0.00: if x>=50.0: print( x//50,('notas de 50 euros')) n = x % 50 elif x<50 and x >=20: print (y//20,('notas de 20 euros')) x= x %20 elif x<20 and x…
pythonasked 7 years, 1 month ago Renato David 21 -
2
votes2
answers5930
viewsList input
I have to receive input (10 integers) from the user and put them in a list but not allow repeated numbers to be entered. I tried but the program sees that the numbers are repeated does not insert…
-
2
votes1
answer95
viewsParallelize with just one core?
I want to parallelize an application, in this case a 'Cosine similarity' calculation, but the machine I am working on has only one core. Parallelizing this calculation with just one core will have…
-
2
votes1
answer400
viewsIs it possible to make connections with Python without using the language packages?
I use several modules to connect to Python sites, such as socket and the urllib, but without the modules, how would this connection be made? I am aware that this is a complex procedure involving…
-
2
votes1
answer233
viewsOperation of the push method
In the code: import heapq class PriorityQueue: def __init__(self): self._queue = [] self._index = 0 def push(self, item, priority): heapq.heappush(self._queue, (-priority, self._index, item))…
-
2
votes1
answer182
viewsdifferences between for...in JS and in Python
in the following code in Python... string = "abcd" for i in string: print(i) --------------- output: a b c d and in Javascript string = "abcd" for(i in string) console.log(i) --------------- output:…
-
2
votes2
answers1120
viewsHow to keep zero left on import in Python?
Hello I have several TXT files with CPF numbers. CPF has 11 numbers, so you can have zeros left to complete this size I opened these files in Excel and gathered them in one. In the CPF column,…
-
2
votes1
answer376
viewsHow to make a "compilation" of the code in Python?
Knowing that Python is an interpreted language, is there any way to compile the program in Python? By this I mean, how to check syntax errors without having to wait for such part of the program to…
-
2
votes1
answer512
viewsHow to delete characters from a string within a Python array
I’m starting in python and decided to mess with files .txt. I did the following procedure to insert values into an array, and from it insert each value into a row of a file filename.txt. def…
-
2
votes3
answers8551
viewsGet the number of digits in a number
I was asked to make an algorithm in Python to know the number of digits in a number, there is a way to do without the manipulation of strings? def achaTamanho(x): a = str(x) if len(a) > 1: if…
-
2
votes1
answer72
viewsIt is possible to name a python module using the __import__function
I have the following code __import__('some_module') And I wanted to know if it was possible to do something like this: __import__('some_module') as some_name…
pythonasked 6 years, 10 months ago Pedro Pinto 336 -
2
votes1
answer3528
viewsTypeerror: expected string or bytes-like Object Datefield
I am having a very boring problem in Django to work with date. I am sending from my angular a date I select in a input data. In my view, i turn the date to that format: 2017-10-13 When I try to…