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
-
3
votes1
answer2087
viewsWhat is the difference between "string" and "Character" in Python?
What is the difference between the string and Character? For example: print 'Olá, mundo!' print "Olá, mundo!" Since the two in theory are the same thing, right? PS.: I opened XML to do my color…
-
3
votes1
answer1258
viewsRead a list of lists in txt python 3
I have a pretty giant list of lists and it keeps getting in the way of my code. So I wanted to save this list in a txt file and ask the algorithm to save this list in a new variable. Suppose my list…
-
3
votes2
answers10609
viewsHow to get the lowest value in a list?
I’m stuck in this program, I can’t create a function in Python. The exercise is as follows: Write a function called buscarMenor() that takes a list of integers and returns the smallest of the…
-
3
votes1
answer649
viewsOpen multiple files with "with open"
It is possible to open more than one file in a program with with open("meutexto.txt", "r") as f: I didn’t find anything about it (or didn’t look hard enough). I know it’s possible to do otherwise:…
-
3
votes1
answer1093
viewsRemove repeated words using python
I have a text file with many repeated words. I need every word in the file to appear only once. import codecs wordList = codecs.open('Arquivo.txt' , 'r') wordList2 = codecs.open('Arquivo2.txt', 'w')…
-
3
votes1
answer595
viewscheck if two keys in a dictionary have equal values
hello, I have a dictionary {'A': ['B', 'C'], 'B': ['A', 'C'], 'C': ['A', 'B']}, I would like to know if there is any way to check if for example the key 'A' and the key 'C' have equal elements and…
-
3
votes5
answers7921
viewsHow to properly format CPF in Python?
I have the following code: test = input ("CPF: ") When the typed CPF gets: 12345678900 But when I return this input he comes back: 123.456.789-00 How do I do it in Python?…
-
3
votes2
answers447
viewsPython assignment and OO
Studying about object orientation in Python I was told that a difference of such language in the instance and assignment of a class is, when we do Darth = Pessoa ( 'Darth Vader' ) The name / surname…
-
3
votes1
answer254
viewsWhat is the real use of the pass in this case?
I am working on the adaptation of a Jango project already created. During the analysis of the code I came across the following excerpt: def objects_delete_action(modeladmin, request, queryset): for…
-
3
votes2
answers1591
viewsShow the runtime of an algorithm in milliseconds in python?
So far only found questions that show seconds. I would like to find in Milliseconds. Follow the code I tried: import time start = time.time() def firstDuplicate(a): dic={} for x in a: if(x in dic):…
-
3
votes2
answers5942
viewsHow to allow special characters in Python?
In my program I want to include characters like these in the print: , and a few more of these. I’m trying to take an array with numbers and turn them into these characters, so it looks like a…
-
3
votes2
answers2331
viewsCompare Latitude and Longitude in Python
I have an application where an Android client sends the coordinates to a Python server, which should put such information in a Mysql Database if the client is within an area (an 8-vertex polygon, to…
-
3
votes2
answers407
viewsHow to correlate files from two txt files in Python
I would like to know a way to correlate equal words in different txt files. It will read the words of a txt file and look for those words in the other txt file.
-
3
votes2
answers95
viewsDoubt about importing libraries
Let’s say, there’s folder A. In this folder A there is the lib folder. In this lib folder, there is a library called example.py. How do I stop importing the.py example? I see it’s possible to import…
-
3
votes3
answers4130
viewsGet X and Y from the screen using PYTHON
I want to create a bot(macro) that performs some click tasks, for this I am using the autopygui in python! But I don’t have much experience in X and Y, and testing it manually and boring. I would…
-
3
votes1
answer1722
viewsIs it possible to create 3d games with pygame?
Is it possible? And if possible I need to know how to draw my own 3d images or is there a website that provides free 3d images?
-
3
votes2
answers423
viewsIdentify string between two known snippets in a string
I would like you to help me on the following: Given this CGC UUC GCU UUG GAA AAU UUG UGU GUU UUU UGU GGC UGC UCG CUG CUC AAA UUG UUC GCU GCU UUU UGU GUC CUG GCU GCU UUU AUU AUU UUA CGC UGC UUG GCG…
-
3
votes1
answer7534
viewsCount elements of a column
How to count the number of occurrences in columns? Filing cabinet: luz NC luz mas ADV más blanquita ADJ blanco que CQUE que las ART el que CQUE que traía VLfin traer de PREP de serie NC serie mi PPO…
-
3
votes3
answers942
viewsNumber greater than 7 in a Python list
I want to know how many numbers is more than 7 on the 'a list'. Note: I’m using slicing because in the case I’m putting in practice, do not know the amount of items you have in the list. a=[5, 10,…
-
3
votes4
answers94
viewsPutting elements in lists
I would like to have two lists: one with the name of the fruit and the other with the colors. lista = ['banana [amarela]\n', 'uva [vinho]\n', 'laranja [laranjado]\n', 'kiwi [verde]\n', 'framboesa…
-
3
votes1
answer91
viewsHow to call the id of the previous select
I have two selects, one for division and the other for groups. When the division is selected it has to bring in the second only the groups that are part of that division. In the url variable that…
-
3
votes0
answers75
viewsWhat is the difference of declaring these strings in Python?
Is there any difference between a string declared with single quotes ' a = 'Special cases aren\'t special enough to break the rules.' and one with double quotes " b = "Special cases aren't special…
-
3
votes2
answers1193
viewsIs there any way to overwrite a specific line of a text file using Python?
I would like to edit a specific line from a file, but the file write.() does not allow such manipulation. Being the Text: 1 "Ola" 2 "Como vai?" 3 "Tudo bem?" I’d like to edit only line 2: 1 "Ola" 2…
pythonasked 7 years, 4 months ago Eviner Rayzeck Santos 33 -
3
votes1
answer428
viewsError processing large images with openCV
I’m trying to process an orthomosaic, the problem is that the image is too big, with other smaller maps I can process normally, but when I go to process a bigger map it from the error in converting…
-
3
votes1
answer1631
viewsHow to delete components from an image using python?
I’m a beginner in python and would like to know how to eliminate components (red, blue or green) of an image using python, I downloaded some image processing libraries (like opencv). I wonder if…
-
3
votes1
answer474
viewsProbabilistic Considerations on the Calculation of Shannon Entropy in a Network Traffic
Probabilistic Considerations on the Calculation of Shannon Entropy in a Network Traffic I have a dump file (CAP format) of a network traffic capture made with Debian tcpdump. Until a certain time,…
-
3
votes1
answer243
viewsHow to validate a script in PEP8?
I noticed some questions that asked about PEP8, something like "in this way is correct?", recent example: Problems with PEP8 indentation rules Then I wondered, is there any way to know if the code…
-
3
votes2
answers244
viewsTerminology - What is the difference between statement and statement?
What would be the difference between them? Instruction would be a line of code representing certain commands/actions passed to the computer to execute. Statement, following logic, would be a kind of…
-
3
votes2
answers1295
viewsCount certain characters in a word in python
I’m making a command to help read a globe. entrada = int(input("Quantos centimetros no globo: ")) km = entrada * 425 m = km * 1000 cm = m * 100 print(entrada, "centimetros no globo equivalem a:",…
-
3
votes1
answer1886
viewsRemove whitespace from the Python list
I’m reading a file, stopwords.txt, and in this file each stopword is on a line, example: a o para Each stopword I am saving on a list as follows: with open(sys.argv[1],"r") as file_entrada:…
-
3
votes2
answers893
viewsHow to remove part of a JSON file
I need to remove parts of a JSON, but I don’t know how to do it I’m converting the same to CSV, and when I convert the structure gets all weird Follow print explaining better, what is marked in…
-
3
votes1
answer999
viewsPython, Django with multiple databases
To work with multiple databases in the Laravel framework, once configured all the connections in the configuration files, just define in the model which connection to the database that model will…
-
3
votes3
answers8207
viewsSeparate each phrase word in an index from the python list
This code snippet generates me the following output. tamanho = len(lista_nome_base_docs) print (tamanho) lista_geral_de_lista_arquivos = [] for i in range(tamanho): with…
-
3
votes1
answer1392
viewsPython indentation error
I am new in Python and I am doing a project... however I was running this and gave an error in line 44, whose message is: Indentationerror: expected an indented block import blockchain, threading,…
pythonasked 7 years, 6 months ago Matheus Grossi 321 -
3
votes2
answers3545
viewsHow to print the percentage sign in Python 2/3?
How do I use % after a markup? Ex: print("%d texto texto 10% texto"%var_a)
-
3
votes2
answers3836
viewsHow to access variables defined in another function?
I’m writing a show about the NIM game. He asks me to call functions within another function, but when I try to compute variables belonging to this function in another function (the function that…
pythonasked 7 years, 6 months ago Guilherme Matos Passarini 99 -
3
votes1
answer358
viewsSort lists with multiple parameters using lambda expression
Given the class Ponto, the function ordenar sort the list elements by the following criteria: first value in x, afterward y and finally value in z. Okay, the code works. But I’d like to understand…
-
3
votes1
answer2152
viewsPython - Open multiple files in one For
Could someone please help me explain why I can’t add the texts of each file to each position on my list? ''' Funções para o processamento dos textos (cartas) para base de aprendizagem'''…
-
3
votes2
answers1882
viewsHow to create a. trusted desktop file on Linux?
I have the following file . desktop to open a file in Python, it is working, but every time before running opens a dialog box saying that the application launcher is unreliable as per the image…
-
3
votes3
answers1153
viewsNext() in CSV Reader with Python 3
Hello, I am taking a course of Machine Learning/Classification and well it uses a CSV file in which one should ignore the first line of the file. So I made the following code: import csv def…
-
3
votes2
answers1301
viewsCalling a Python function by the text present in a variable
I am new in Python and I would like to know if it is possible to call a function by the text present in a variable, example: I ask the user to enter the name of a function, and save what was typed…
pythonasked 7 years, 5 months ago Mateus Vieira 41 -
3
votes1
answer1155
viewsImport python C++ modules
I’m trying to import into one script python a module C++: import hector_path_follower The archive c++ defines a namespace for the class: namespace pose_follower { class HectorPathFollower { ... } }…
-
3
votes2
answers3658
viewsHow to modify the font size of the axis in Python matplotlib.pyplot
Good afternoon. I would like to know how I can increase the font on the axes when I plot a graph using matplotlib.pyplot.…
pythonasked 7 years, 1 month ago Fernan David Martinez 41 -
3
votes1
answer84
viewsEliminate code redundancy in a while loop
In this example: . Request today’s date via a form. . Check if typed in dd/mm/yyyy format. . Compare to current system date from datetime import date def verificacaoData(): dataForm = input('Digite…
-
3
votes1
answer229
viewsWhat’s if __name__ == '__main__': if the kivy can run the application without this line of code?
In the kivy documentation shows that pro app working is required if __name__ == '__main__': MyApp().run() But I try to remove the if condition; and the app ran anyway; someone explains why, please!…
-
3
votes1
answer2858
viewsOptional parameter in function
I was trying to create a square root function: def root(n, ind): if ind == None: ind = 2 ind2 = 1 / ind print(n ** ind2) I want the ind not be mandatory. I thought if I didn’t, the value would turn…
-
3
votes1
answer155
viewsCode to generate continuous beep
The code below does the following, it reads a log file in real time and every time in the line of the code has the letter N a beep is issued from windows. At first this code is working. To…
pythonasked 7 years, 4 months ago Lucas Oliveira 33 -
3
votes1
answer379
viewsChained exceptions in Python
I am in doubt in a situation not so common but that I have seen some developers use that is the case of the string of exceptions. I read the Python documentation about them but it was not as clear…
-
3
votes1
answer581
viewsFlash text on Tkinter / Side effect
Hello, I’m starting my studies in Python, with the use of Tkinter. Take it easy on the answers / critics (rs!). I need to "blink" a text (Blink), with a value, when this is the fastest (lap record).…
-
3
votes1
answer187
viewsLibrary sys - maxsize
What is this function for sys.maxsize? import sys Menor: int = sys.maxsize What does this expression mean?
pythonasked 7 years ago Marcos Vinícius 124