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
votes1
answer377
viewsProblem with the Requests package
I am starting with Debian 8 and I am trying to run a code in Python, however, the error always appears: No module named request. I have checked several ways to try to fix, using Pip install ... The…
pythonasked 7 years, 6 months ago DitoLobato 21 -
2
votes0
answers785
viewsPython Pandas CSV
I started to learn Python not long ago and I’m doing a project to normalize customer data. But I don’t know how to make a comparison like: read on CSV field CP7, search for all CP7 of CSV CTT and…
-
2
votes1
answer1515
viewsPython - filtering data in text files
I’m trying to write a code to read a . txt file and extract numeric coordinates, but this file contains lines with text as well. I’m unable to filter. see a part of the file. So far I’ve managed to…
-
2
votes2
answers15185
viewsFormatting strings with ". format" and "%"
It’s been a while since I’ve been studying some python code. Some people format code using ". format": fruta = "Maça" print("Eu gosto de {0}!".format(fruta)) And others use the "%" fruta = "Maça"…
pythonasked 7 years, 4 months ago José Henrique Luckmann 1,084 -
2
votes1
answer340
viewsError using Python function input method
I have a problem with my code. I have 3 functions, one of them uses an input method called tweet but when I call the error function and does not perform, maybe I did not understand this part of…
pythonasked 7 years, 5 months ago Jhonatan Teodoro 33 -
2
votes1
answer958
viewsHow to catch the current user in the Django model?
Hello, I’m creating a Django application and I have a model with the Newdemand class in which I need that when the user creates a demand, the name of the guy is saved in a field. Here my class:…
-
2
votes1
answer152
viewsPython, ldap3 and Apache Directory Studio
I have a local LDAP server created in Apache Directory Studio, running on port 10389. When I connect using php, I can do searches normally, but when I try to connect using Python’s ldap3 module, I…
-
2
votes1
answer78
viewsVersion control of dependencies
Use python, Django on a server with CloudFoundry installed. There, I can keep my requirements.txt with all the dependencies of my application and, for security, I always keep the exact name of the…
-
2
votes3
answers7146
viewsHow to run the method inside a.py file by linux terminal
How can I call a method that is inside a.py file directly from the linux terminal, only I don’t want to enter it prompt of python For example [fedora@user ~]$ python arquivo.py metodo parametro…
-
2
votes2
answers1344
viewsHow to Create an Auto Increment in Django that is not pk
I’m creating a memo system with Django and it’s working fine, but I need to put in a self-improvement field that’s not pk. I have this field in my models. Memo = models.IntegerField() I need it…
-
2
votes2
answers61
viewsdefault values for namedtuple
When creating a class I can set some default values: class Point: def __init__(self, x, y, z=0): self.x = x self.y = y self.z = z How to proceed the same way for namedtuple? from collection import…
-
2
votes2
answers722
viewsExtract multiple values from a single variable in python
If I have a single data input, I have to remove several values assigned to my variable and give to another? representation: vrvl = int(input("Dia.mês.ano: )) dia = dia mes = mes ano = ano #entrada…
-
2
votes3
answers372
viewsSome help in function exercise (python)
The exercise speaks the following : "Write a function that takes a positive integer m and returns 1 if m is prime, 0 otherwise." My attempt : Edit: Then , performed the modifications the program is…
pythonasked 7 years, 5 months ago user158657 105 -
2
votes0
answers56
views"No module named mayavi.mlab"
I’m trying to install Pylayer on Ubuntu Xenial, but when I try to export Coverage by from pylayers.antprop.coverage import * The following error appears: no module named mayavi.mlab But I have…
-
2
votes2
answers67
viewsHow to perform an arithmetic operation by changing numerous database fields efficiently?
There is a table with 200 records and one of the fields is responsible for indicating the order that these data are shown (0, 1, 2, 3, 4, 5, ...). I need to rearrange this data, take the record from…
-
2
votes0
answers843
viewsDoubt how to mount socket in old game in Python
I have a work in the course of programming in networks and we were asked to use a game code and make a client and server using sockets, but my teacher’s explanation was very vague and he does not…
-
2
votes2
answers12373
views"perfect" square root in python and identify the rest:
It is for python 3: What I’m looking to do is show the rest of a square-root account that only accepts as many integers as possible as an answer. For example: import math x=math.sqrt(87) print(x)…
-
2
votes2
answers8846
viewsSyntaxerror: unindent does not match any Outer indentation level
What should I do when this error message appears: "Syntaxerror: unindent does not match any Outer indentation level"? I cannot declare the Else of the variable. Follow a print of the problem and the…
-
2
votes1
answer106
viewsPython Wordlist generation problem (2.7)
I’m trying to write a python script that takes n keywords and a number as input. This number will be my maximum range of string that will be written to the Wordlist. 1° Problem: As many combinations…
-
2
votes1
answer1263
viewsCreate python dictionaries using lists
I’m trying to create a translator that translates Portuguese words into binary code. I was able to do this to type only one word, but when I try to use 2 words, in the case "ab", nothing happens. I…
-
2
votes1
answer1958
viewsAssociate two lists in python
Associate two lists, a car name list and another color list and each containing n elements: listaCarros = ["gol","uno","corsa","palio","idea"] listaCores = ["branco","verde","preto","cinza","azul"]…
-
2
votes0
answers603
viewsHow to make an animation show each change in the dataset? With matplotlib
I am using matplotlib to show my 3d dataset. But I would like to show each data set change in a 3D graph. And create an animation of that or maybe save the animation. Follow the code I’m using: from…
-
2
votes1
answer493
viewsHow can I set a range for a float?
Trying to implement Newton’s method for finding roots in polynomials, using Horner’s method. n=len(a)-1 print("k\t a\t x\t px") for k in range (0, iterMax): b=a[0] c=b for i in range (n-1,1):…
-
2
votes1
answer221
viewsProblem with classifier in PLN
I’m developing a chatbot, and to get the answer I’m using the Naive Bayes classifier to sort the questions and answers. For those who want to see all the project code and more settings follow the…
-
2
votes3
answers7021
viewsHow to change the type of a column in Pandas?
I want to change the type of a column of a CSV file. I used this command: cand_doacoes['CPF_CNPJ_doador'] = cand_doacoes.CPF_CNPJ_doador.astype(int64) But the error appears: NameError Traceback…
-
2
votes0
answers251
viewsPython Web without Framework
If there are two languages that I like very much are python, which I always used for desktop and php, which I always used for web. I would like to use python for the web as well, but currently I…
-
2
votes3
answers1281
viewsPython dictionary
Next, I have a table with words in a language, I will use example to suppose, from Portuguese to English. These words are in a dictionary where the key is the Portuguese word and the value is the…
-
2
votes1
answer303
viewsHow to work with more than one python file?
I learned to import modules, but I don’t know how, for example, to create a class in a separate file and include it in the main program, how to do this?
pythonasked 7 years, 1 month ago Morais Vilson 288 -
2
votes1
answer1920
viewsRedirect to another page in the Django view
I’m learning Django now and the idea is this: I have a registration form only with the email, when this email is filled and the user click send, I need the view to direct to the other page where the…
-
2
votes2
answers81
viewsFix incorrect module return
Mathematically speaking why it happens and how to fix the following "error" in python: >>>10.53 % 1 0.5299999999999994 I’d like to understand how the python works to obtain this value, why…
-
2
votes1
answer504
viewsHow to use joblib in Python for parallelism?
I was trying to use the Thread Python to parallelize my code but I ran into a problem: when I create the Threads, the number of them exceeds 1,000 Threads easily, which, from 140, all start to give…
-
2
votes2
answers1145
viewsPython object datetime value extraction.
I need to extract only the time of a datetime object. How to proceed? The object returns the following output: "3 days, 22:01:00"
-
2
votes1
answer48
viewsWrite Dice from one list to another list
T = [0,0,0,1,0,0,0,-1,0] def acoes(T): listaAction=[] for i in T: if(T[i]==0): listaAction.append(T.index(i)) return listaAction print(acoes(T)) How do I write T-list indexes that have value 0 in…
-
2
votes1
answer126
viewsWhat is Python’s First-Class?
The first-class Java language are objects, as nothing can be created in Java without the use of classes. In Haskell, following the same previous criterion, the first-class are functions. In the case…
-
2
votes0
answers354
viewsDynamic Text Label on Tkinter
I researched a lot here in stack and google, I spent all night looking for a simple solution but I did not find, I saw some ways to solve but none worked for me until now. Situation: I am creating a…
-
2
votes1
answer706
viewsEarth distance calculation: URI - 1721
I would like to know how to calculate the distance between points of the Earth given latitude and longitude. What formulas to use to convert spherical coordinates to cartesian and vice versa. I need…
-
2
votes1
answer326
viewsSolve polynomial between two values interval
x = eval(input()) x = eval(input()) polinomio = 3*x**3- 5*x + 0.8 for x in range (x,x,0.5): print(polinomio) Traceback (Most recent call last): File…
-
2
votes2
answers1093
viewsGroup by week
I have a table like this I’m trying to separate by week, I don’t have much knowledge in which functions I can use to check how many weeks you have between these dates, to then group. The data is in…
-
2
votes1
answer2323
viewsMounting table from a csv, grouped by week, with python and pandas
I am using pandas and open the following table using the code tst = pd.read_csv('Iteracao.csv',delimiter=",") I’m trying to group as follows, where week 1 is the week of the date…
-
2
votes1
answer756
viewsHow to open pdf that is located in a folder in the project in html?
I’m trying to open a pdf file that is located in a folder within the project, but it’s not working. I followed some suggestions and tried that: <a…
-
2
votes1
answer115
viewsGraph of a Python denial of service attack
Friends, I generated the following chart: The code used was the following: import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y = []…
-
2
votes1
answer3370
viewsObject is not subscriptable error
Hello Please, I want to record a csv file from a list, but this error appears: --------------------------------------------------------------------------- TypeError Traceback (most recent call last)…
pythonasked 7 years, 3 months ago Reinaldo Chaves 333 -
2
votes2
answers597
viewsHow to put more than one parameter in Python?
Guys I’m learning Python3 and I’m having trouble making an implementation in Python. For example, in C: for (fatorial = numero; fatorial >= 1; fatorial--) I want to put this implementation up in…
-
2
votes1
answer1010
viewsUse from module import* vs use import module in python 3
The 2 do the same thing (I think at least), but have always told me that import module is better then I always used this method, but the method from module import * makes the code more concise since…
-
2
votes1
answer5877
viewsDjango - Mascara CPF, DDD and phone number
I need to put a mask on the number, ID number and phone number. I am a beginner in Python and Django and would like to know how I can present this mask at the time of typing: For CPF:…
-
2
votes1
answer311
viewsTwitter data with python
Hello. I want to mine twitter data using python. I started doing an initial example, but it’s giving error. I imported twitter_python to the python lib folder 3.6 via the setupe.py install command…
pythonasked 7 years, 3 months ago André Nascimento 1,258 -
2
votes2
answers4670
viewsHow to use Selenium Webdriver findElement(By.xpath())?
Hello, please, I am trying to get information on a public website: name of a vote, date and table with voting list This site:…
-
2
votes1
answer192
viewsHow to suspend a command without disturbing active commands
well I wanted to know if you know a command in python that suspends the operation of a command (for a few seconds)without disturbing the other commands that are active, because it was wanting to…
-
2
votes1
answer5572
viewsPandas - select lines
Hello. How do I select a specific line in a dataframe? df1=pd.read_csv('arquivo1.csv', encoding='ISO-8859-1', sep=";") I’ve tried to do df.index[2], but gives error. The 2 is the line I want.…
-
2
votes1
answer410
viewsStoring values of variables within the while function
In an exercise I answered with this code: qntd_alunos = int(input("Digite a quantidade de alunos: ")) qnt = 0 while qnt <= qntd_alunos-1: MB1 = float(input("Digite a média do primeiro bimestre:…