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
answer104
viewsAlways prefer xrange above range?
The range creates a list in memory of the number of elements defined by the programmer. The xrange has more performance, I do not know if in all cases, since it does not end up generating a list. I…
-
3
votes1
answer293
viewsCalling Progress bar class from another file
People come to ask for help from you, I believe very simple but that gives a bad headache for those who do not have much practice with object orientation, I have a file progressbar.py, which since…
-
3
votes2
answers327
viewsIdentify if the value being printed is float, string or int
In python it is possible to make an impression of several types of variables using the print. Take an example: print(3.4, "hello", 45); Or individually. print(3.4); print("hello"); print(45); How is…
-
3
votes1
answer2149
viewsWhat is the difference between type and dtype?
Based on a previous question, vi that it is possible to identify a variable using type. For example: print(type(3.1415).__name__) #retorno >> float Doing some research, I saw that there is…
-
3
votes1
answer1215
viewsConfigure Firefox webdriver in Selenium
I’m using Selenium (Python) to fetch some data from a site, at a given time I access a link that downloads a file. How to configure the webdriver (Firefox) to automatically accept the download,…
-
3
votes2
answers883
viewsHow to check if a method exists in a Python class?
How to check if a method exists in a Python class? Is there any function that does this? class Test(object): def method(self): pass For example, I would like to check through a condition if a…
-
3
votes1
answer564
viewspreApproval data is required
Currently, I am trying to integrate a prepayment via v2 of the api for pagseguro. For some reason I keep getting pre-approval data is required. I tried chaning the headers, I was also checking the…
-
3
votes2
answers599
viewsList of square roots
How can I make a function that takes a parameter n, return a list of the first n square roots, using higher-order functions, in Python. As shown below: [sqrt(1), sqrt(1)+sqrt(2),…
-
3
votes2
answers1109
viewsNumber divided by a divisor greater than it returns zero?
I went to do a calculation on Python 2.7 and got scared when I saw the result: val = 1 / 16 print(val); # 0 Example in IDEONE That is, when we make a division where the divided number is less than…
-
3
votes2
answers798
viewspython - Delete string end characters
Is there any way to delete characters at the end of a string in python? For example: a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" B = "ABCDEFGH" I need string "a" to be the same size as "b," so that’s possible?…
-
3
votes2
answers7052
viewsHow to count occurrences of a substring in a Python string?
How do I read two strings and check the number of occurrences of the second string in the first? Example: If the first string typed is "abracadabra" and the second "bra", then the number of…
-
3
votes2
answers10535
viewsHow to separate the digits of an integer and add them together? - Python
How to separate the digits of a number and add them up, for example: 123 -> 1 + 2 + 3 = 6 How to do this, however, do this using arithmetic operators. I saw a case where it was separated using…
-
3
votes1
answer113
viewsHow to do this regular expression in python 3.6
I need to do a regular expression to extract the links from this string : links…
-
3
votes3
answers16319
viewsConvert from string to list?
I needed to pass a string of the kind: 0.4350 0.8798 0.0099 1 for a list [0.4350, 0.8798, 0.0099, 1] with a script simple. How can I do it?…
-
3
votes1
answer1076
viewsPython type conversion
When writing some didactic examples in Python 2.7, I came across the following situation in the following program: a = 0b101 b = 0b111 c = a+b print c The result of this program is 12 (decimal). If…
-
3
votes2
answers3673
viewsLinear regression with python
I need to do the linear regression calculation, but I read that there is no possibility to use/install scipy in windows. Is there any other scipy-like library to perform this kind of calculation? Or…
-
3
votes1
answer1292
viewsWhy is a function calling itself?
def clinic(): print "Voce acabou de entrar na clinica!" print "Voce entra pela porta a esquerda (left) ou a direita (right)?" answer = raw_input("Digite left (esquerda) ou right (direita) e…
-
3
votes1
answer13093
viewsDifference between NULL, empty and Python blank
I’m making a Data Quality that receives a list with data from a Database and I have two rules: Null fields: Fields that are filled with the word NULL White/empty fields: Fields that come blank or…
-
3
votes2
answers95
viewsWhat is the numerical type builtins about?
I read in the book Python for Developers: Approaches Python 3.3 the following excerpt: In addition to the numeric type builtins of the interpreter, in the library Python standard there are several…
-
3
votes1
answer385
viewsI’m not getting loops while nested
I’m having trouble understanding this code, because I don’t understand how it behaves in loops while, follow the instructions after the code. Note 1: I am learning programming logic yet, so I am…
-
3
votes2
answers23455
viewsGet Data in the JSON structure with python
I want to access certain information in the JSON code below, with python: { "informacao1": valor_informação1, "informacao2": "{ dado=informação_dado }" print(arquivojson.get("informacao1")) The…
-
3
votes2
answers2822
viewsHow to print an integer vector by removing the last comma in Python 3?
I want to print on the screen an array of integer numbers in the same line and separated by comma, and I want to remove the comma that is after the last number. How could I do that in Python? My…
-
3
votes2
answers1210
viewsPython Shell and Django
I know that to open the interactive Python shell, we simply run on the operating system terminal: python But with Django installed, you can also open the shell using the command: python manage.py…
-
3
votes1
answer842
views__str__ and __unicode__methods
I’ve seen class codes that implement Django models overwriting both the method __str__ like the __unicode__, there is difference between them? If yes, there is some case that I should prefer one…
-
3
votes1
answer1356
viewsPython serial vs multiprocessing vs threading code
I’m using python version 3.4 How do I find out that my codes are actually working and doing what they’re supposed to? When looking at the System Monitor (linux) I noticed that codes using…
-
3
votes2
answers12290
viewspython - covery game/college project
I need to create a program that simulates a kind of "cover game" using only boolean variables, basic functions and repeaters. So far my program finds itself like this: print()…
-
3
votes1
answer697
viewsHow do I get the final URL of a JS redirect?
I was trying to make a code to get the final url of redirecting some links, I managed to do for most of the links I needed, incoming for this I could not: https://redir.lomadee.com/v2/987163d4 All…
-
3
votes2
answers441
viewsPython dot notation ( methods )
How to create point notation methods, those that are called object.show () instead of show ( objec ), or they apply only to strings, if yes why exactly ?
-
3
votes3
answers85
viewsHow does variable p work in this code?
I don’t know how the variable p of loop while is working on that code. If the variable p is the iteration variable, because the exercise also uses a variable p within the while to store the s.find(…
-
3
votes1
answer329
viewsSending emails at scheduled times
I wonder how do I get my log.txt file sent to a desired email at a set time (Ex: 15 min)? And after it is sent, the process restarts and creates a new log.txt. import pythoncom, pyHook, def…
-
3
votes2
answers296
viewsLogic operations in Python 2.7
When performing logical operations in Python 2.7, I noticed something strange. For example, when doing 5 and 6, are obtained as a result 6. Now, the correct would be 4, because, converting these…
-
3
votes1
answer393
viewsWhy does input work in Python 3.x and not 2.7?
I ran this same code with just a few minor differences in syntax to suit the right mode of script in Python version 2.7.9 and also in Python 3.4.2 Script I ran in Python 2: name=input("tell me your…
-
3
votes2
answers14794
viewsIdentify repeated elements in Python list
The list I made should read the repeated values of a list and show their positions, but it did not work correctly lista = [] listaRepetido = True for i in range(4): lista.append(int(input("Numero:…
-
3
votes2
answers876
viewsIs it possible for me to create a runtime class in Python?
I wanted to create a runtime class to do some database updates, for example, but without being dependent on DBMS but using python and I wanted to know if it is possible to create these classes at…
-
3
votes3
answers3678
viewsHow to remove unwanted words from a text?
I am trying to remove unwanted words from any text, but it takes away from other words. For example: remover_palavras = ["a", "e", "o"] The program returns: btt (potato), mns (less) What to do?…
-
3
votes2
answers1079
viewsHow to compare if the contents of two columns string of a data frame are similar
I have a data frame where I need to compare how much the contents of two columns are similar. For example: coluna a = “José Luiz da Silva” and coluna b = “José L. Silva”. How can I indicate that…
-
3
votes1
answer325
viewsHow to use Createview
I’m trying to create a simple to-do list, but I’m having some problems. I want to create a task, within it I want to create some activities. That’s the problem I can’t do. How can I create an…
-
3
votes1
answer358
viewsGraph of total connections per second during a denial of service attack
I have a network dump (PCAP file) containing slowloris attacks: The following script will show the number of connections per second to IP 192.168.1.2 at port 80: tcpdump -qns 0 -A -r 1.pcap host…
-
3
votes3
answers2001
viewsRecursive function with strings - Python
I’m having trouble solving an exercise. The statement is as follows: Implement the annoy(n) function that returns a string containing "annoy " (the word followed by a space) n times. If n is not a…
-
3
votes1
answer111
viewsDifference of parameters in Python
In Python, what’s the difference between Funcao(param='value') and Funcao(value)? Or else Funcao(u'value')? I’m starting with Python and I’ve seen codes with these three forms. I don’t know if they…
-
3
votes1
answer92
viewsPython - Qdate to datetime conversion
I need to convert an input date by a Qcalendar to datetime (from lib datetime). How can I do it?
-
3
votes1
answer282
viewsDoubts about virtualenv
I’m starting development with virtualenv and some doubts have arisen, are they: Python scripts need to be inside the virtual environment folder? In the Pycharm IDE, you need to configure something…
-
3
votes2
answers5347
viewsKnow how many years, months, days, hours, etc have passed since a certain date
I would like to know how do I make the output of the difference between two dates stay the way I want, in this case I would like it to be: Since 16 - 07 - 2014 23:00:00 passed: X years, Y months, K…
-
3
votes2
answers671
viewsErrors in the program to sort a triangle
I’m in some trouble and I don’t know how to fix it: 1) An equilateral triangle, three equal sides and angles = 60°, is read as an isosceles triangle (two equal sides). 2) In addition to printing…
-
3
votes2
answers225
viewsRegexp extract value
I have the following strings: "The.Office.US. S{SE}E{EP}.the.Dundies.720p.srt" "The Office [{SE}. {EP}] The Fight.srt" This string is a "template" of a file name, the files will be in the following…
-
3
votes1
answer397
viewsHow to make a sample space using 4.6 and 8-sided data?
I am doing a 3-data sample space probability work (one on 4 sides, one on 6 sides and the other on 8 sides) I know that the sample space, without repetition between the data, is 4*6*8 = 192. I saw…
pythonasked 7 years, 10 months ago Luis Carlos Moura 33 -
3
votes2
answers1008
viewsWhat is " x" in the Python strings?
I replied a question here on the site where there was the following string in the Python language:…
-
3
votes1
answer221
viewsScrapy cannot select a form using xpath
Hello, I am using the scrapy to make a Crawler to get to pick up questions of concuros and etc from the site gabarite.com.br, I can get the description of the question the correct alternative, but I…
-
3
votes1
answer3343
viewsLogin to site with POST request in python?
I would like to log in to this site http://www.ciee.org.br/portal/LOGIN.ASP where your form: <form name="frmLogin" method="post" action="validalogin.asp" > <span>Login:</span>…
-
3
votes3
answers760
viewsDoubt with IF and LISTS python3
I’m new to the python language, but I started to develop a script to manage linux servers etc... I have a little problem in a code snippet: def rotear(): print(" \n Disponível: \n"),…
pythonasked 7 years, 10 months ago Anderson User777 63