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
-
4
votes1
answer859
viewsHow to repeat a function call every X seconds in Pyqt?
I am developing a small application in Pyqt4 where I need to upload the data to a table coming from a Webservice. This I managed to do quietly. However, now, I need that every 1 minute, these data…
-
4
votes2
answers223
viewsIs there a performance difference between Tuple and List?
In Python, I know there’s a difference between Tuple and a List. To Tuple is immutable, and the List, mutable. You even have that question here: What is the main difference between a Tuple and a…
-
4
votes3
answers756
viewsGet larger number of items in a Python list array
I have a Python array composed of arrays. But these arrays can have different sizes. For example: matriz = [[1,2,3],[4,5,6,7],[1,2,3,4,5,6]] What I want to know is if there is a medium (some python…
-
4
votes1
answer13034
viewsNameerror: name [name] is not defined
I need to do Python programming to know the CG percentage in a DNA string... maior = 0 dnaMaior = "" while True: dna = input("Digite uma sequencia de DNA: ") if dna == "Z" or dna == "z": break else:…
-
4
votes3
answers220
viewsAttributeerror: 'Qstring' Object has no attribute 'strip'
I’m making a small application in Pyqt4 to understand how it works. In a certain part, I’m using a callback function to display in a QLabel the text that is typed in QtextEdit. This text should be…
-
4
votes1
answer5659
viewsGenerate csv output of python code
I hope you can help. I’m new to python and my question is this. I created a regex extracted from a file in csv the parts of the text I want. But I want to save the output of this function in csv to…
-
4
votes2
answers3252
viewsHow to use sys.Arg for data entry
I have the function as follows: def minha_funcao(x, y ) my code . . . end of my code e a a entrada de dados eu utlizo da seginte maneira print my_func([uma lista], [outra lista]) I’d like to use the…
pythonasked 8 years, 1 month ago Guilherme Lima 3,129 -
4
votes2
answers1855
viewsIs there any way to download a Youtube video using urllib?
Is there any way to download a video on youtube using urllib in Python? I did a test, but it doesn’t work (just an example): import urllib.request youtube = "" pagina =…
-
4
votes1
answer993
viewsBroken Pipe with python sockets
I am having the following error whenever I try to send a message from the server to the client using Python sockets: server: import socket s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host =…
pythonasked 8 years, 2 months ago Nathan Aguiar Neves 51 -
4
votes1
answer339
viewsTempo datetime.datetime.now()
I’m making a script where I measure the performance of a query in a database. The code is as follows:: start = datetime.datetime.now() //CONSULTA AQUI end = datetime.datetime.now() print "Time…
-
4
votes1
answer2749
viewsTransform an array to string in python
I am trying to convert an array to a string and add "|" to it at the beginning and end of each field Below the example array ['', 'C170', '1', '14879', '', '1,00000', 'UN', '29,99', '0,00', '1',…
-
4
votes1
answer918
viewsDictionary reordering, exchanging values for keys
I have the following dictionary: tests_dict = {'test 1': ['Manuel', 'Mariana', 'Filipa'], 'test 2': ['Manuel', 'Filipa', 'Mariana'], 'test 3': ['Mariana', 'Manuel', 'Filipa']} What I need is for the…
-
4
votes2
answers58
viewsSyntax error on another machine
I have a machine on which Python 2.6.6 is installed, in a certain part of a script I do the following command: with open('saida1.txt') as saida: for line in saida: if "]L" in saida: print line In…
pythonasked 8 years, 1 month ago Maurício Salin 251 -
4
votes2
answers6889
viewshow to find and change a specific python line?
I’m learning Python and I’ve been creating txt files, adding things and rewriting them but n managed to modify a specific line, how can I do this?? and also I wanted to know how to find out on which…
pythonasked 8 years ago Jairo Bernardo 41 -
4
votes1
answer490
viewsRegex in python Find() function
I need to use a regex in the function Find() in Python for example, if I use inside a loop : arq = open("arquivo.txt","rb") var = arq.readline() a = var.find("abc.*def") He will be looking at the…
-
4
votes1
answer707
viewsAttachmate Waithostquiet Method - Extra! with python
I’m using Python to automate Attachmate - EXTRA! as many do with VBA. I’m using the package pywin32 found here. I’m following the method documentation WaitHostQuiet found here. The problem occurs…
-
4
votes1
answer127
viewsMock a raw_input
I have the following functions with raw input, which should receive a list [x,y] def input_origem(): origem = raw_input("Entre com o valor de x: ") origem = eval(origem) return origem def…
-
4
votes3
answers2432
viewsHow to speed up a script to full speed in python?
I was playing with a method to approximate the PI number and I realized that the code runs very slowly in the Python 3.6 interpreter, and the process is only using 30% of the processor. There would…
-
4
votes1
answer387
viewsHow to get a string with the name of the window that is focused in python?
Some time ago I started using pyHook to manipulate events. However, the original version has errors, so I switched it to an alternative version that corrected the errors of the original version.…
-
4
votes2
answers1073
viewsHow to run a python file as an admin?
I’m trying to run a python file, but it asks to be run as admin as q do this?
-
4
votes1
answer1035
viewsHow to move the mouse automatically, realistically, using Python?
How to make the mouse move automatically, realistically, using Python? I was able to find and change a code that produces a "V" movement on the screen. However, I would like to move the mouse using…
-
4
votes1
answer1728
viewsHow to save a video captured by webcam without showing it using Opencv in python?
I’m starting to learn Computer Vision. I’m using the Opencv module for Python 3. Reading tutorials, discover the following script: import cv2 cap = cv2.VideoCapture(0) fourcc =…
-
4
votes1
answer14432
viewsCalculation of Sine with Python
Hello, I have a problem in the sine calculus using Pyhton, I set up a function for the sine and cosene calculus, but the result is coming wrong for sine, while the cosene the result is right. I…
-
4
votes1
answer114
viewsRobo_feed routine of checking if loop giving dick in python
Robo_feed I’m new to python, I was looking to develop a robot that would take the last post of some news portals here in my region, With a survey I came to the conclusion that it would be easier to…
-
4
votes1
answer1543
viewsHow to send email with body and attached using smtplib and email in python?
When I send a simple Python email using only the smtplib library, I can write in the body of the email through the "message" argument of the following script function: def…
-
4
votes2
answers2703
viewsHow to skip the line in writing the files?
Well, basically, I need to skip a line, after certain writing. insira o código aqui print("+---------------------+") print("|DEMONSTRAÇÃO DA LINHA|") print("+---------------------+") print()…
-
4
votes1
answer283
viewsHow to get different outputs (fasta) files with Unix or python
I have a fasta file that has several sequences of genes, like: >gene1 C.irapeanum 5.8S rRNA gene CGTAACAAGGTTTCCGTAGGTGAACCTGCGGAAGGATCATTGATGAGACCGTGGAATAAACGATCGAGTG >gene2 C.irapeanum 5.8S…
-
4
votes6
answers42162
viewsRemoving duplicate elements in a python list
I have to do a function and I’m not being able to develop the logic. Here’s the thing: Write the remove_repeated function that takes as a parameter a list of integer numbers, checks whether such a…
-
4
votes1
answer195
viewsRegex for python float validation
r"[+-]? d*.? d+" This regex is accepting numbers with more than one point Ex: 12.23.43 and was not to accept...
-
4
votes1
answer1617
viewsHow to show content captured by camera in full screen in Opencv?
Would you like to know how to show the content captured via webcam (by the Pture video) in a window that occupies the entire screen? Only appears in a small window. You have to change something in…
-
4
votes2
answers2086
viewsHow to capture all exceptions in Python?
How to capture any and all Python exceptions? Are there any keywords for this? Like in Java you just make one try { } catch(Exception ex) { }
-
4
votes7
answers15010
viewsPrint "n" natural odd numbers
I’m solving an exercise that asks me to enter a value for example: 5 and print the first 5 natural odd numbers in the case: entree: Enter the value of n: 5 1 3 5 7 9 The code I wrote works but it…
-
4
votes2
answers2185
viewsHow popular select from another select using python and Django?
Good evening, everyone! I’m new to the forum and started doing a little project with python and Django, where I am trying to fill a select according to the option selected in another. However, as a…
-
4
votes2
answers94597
viewsHow to break the line?
Nome = input("Digite o nome do cliente: ") DiaVencimento = input("Digite o dia de vencimento: ") MêsVencimento = input("Digite o mês de vencimento: ") ValorFatura = input("Digite o valor da fatura:…
-
4
votes1
answer660
viewsCheck if all items in a string are different?
How can I check if all the items in a string are different ? For example: x:"abcdefga" = False y:"abcdefg" = True Since x[0] == x[7], soon would be False. But in case I would use that condition on a…
-
4
votes3
answers1815
viewsHow to start a range from 1
I wish on the part of input("Put student’s note " + str(notes) + ":" ) the computer ask "Enter student’s grade 1: " and not starting from 0, how to do this with the range function? Code below.…
-
4
votes2
answers57
viewsWhat function do I use to return or show all the equal numbers in a list of 20 numbers?
n = [] for i in range(20): n.append(int(input("Digite o número: ")))
-
4
votes2
answers2259
viewsFormat output Excel - Python
I turn a list into a Dataframe and send it to an Excel, it’s working fine. Follow the code: Df = pd.DataFrame(Lista, columns = colunas_geradas) writer = pd.ExcelWriter('Exemplo.xlsx', engine =…
-
4
votes1
answer438
viewsPython remover() list index out of range
def gera_huffman(simbolosOriginal, probabilidadesOriginal): # gera_huffman(['a', 'b','c', 'd'], [5, 2, 1, 2]) simbolos = simbolosOriginal probabilidades = probabilidadesOriginal lista = [] while…
-
4
votes1
answer896
viewsType set in Python is ordered?
When creating a variable like this: a = {1,2,5,1,3} It ends up returning a variable of type set. However, in the Python documentation, it is said that it is impossible to create a set without the…
-
4
votes2
answers471
viewsTheoretical doubt about while and indentation
count = 0 while (count < 10): # Ponto A print ("Olá...", count) count = count + 1 # Ponto B # Ponto C Why Count < 10 is always true at point B. is not true if the "Point B" belongs to the same…
-
4
votes2
answers2031
viewsFind smallest string from a python list
how do I do a function to determine the smallest string in a list by entering spaces? For example, when typing: menor_elemento(["joão", " a ", "arrozz"]) the output must return "a" (no spaces), as…
pythonasked 7 years, 7 months ago d. fritoti 85 -
4
votes4
answers5300
viewsHow to fix the number of numeric characters in a float?
I wrote a simple code where at the end of a precise mathematical operation the result would be seven numeric characters regardless of where the point is. Unfortunately I can only adjust the…
-
4
votes3
answers205
viewsHow to get mime from a file through Python?
How can I get Mimetype from a file through Python? I’m not just talking about getting through the extension, but also reading the file metadata. How can I do that? Note: I tried to use the…
-
4
votes2
answers742
viewsWhat is Python’s native support for database manipulation?
I found things about a module called mysqldb, but I couldn’t find documentation available on Docs.python.org Please disregard responding with frameworks such as Django.…
-
4
votes1
answer106
viewsPython connection Webhook problem
I have a doubt in my code. I am using an example code and tried to apply to create a json template on the local machine. Follow what is working. It is located [at this link](…
-
4
votes2
answers5956
viewsHow to run a Python command with JS?
I have a button and when clicking it I want js to execute a . py command on the server side. How do I do it?
-
4
votes3
answers4922
viewspython recursive function to compute sum of the elements of a list
I’m having difficulty in an exercise where I have to show the sum of all the elements of a list recursively. The code I arrived has only the basis of the recursion, the recursion itself did not do,…
-
4
votes1
answer7278
viewsCheck if a key exists in a dictionary
How can I check if a key exists inside a Python dictionary?
-
4
votes4
answers7713
viewsHow to detect if a variable is null?
I’m trying to validate a simple form in Python 3 and I want to make sure it doesn’t record the information if the field nome is empty, but when I make a if to check whether the variable name is…