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
-
6
votes1
answer183
viewsCollect shared URL statistics on Facebook using Python
To collect statistics from a shared Facebook URL in PHP, I am using Curl to query the following URI: // URL para submeter $pageUrl = 'http://www.example.com/my-new-article-is-neat'; // URI a…
-
6
votes3
answers3015
views -
6
votes1
answer2529
viewsDoubts about using Stratified K-Fold in Scikit Learn
I want to perform a cross-validation using 10 folds stratified, using the language Python and the library Scikit Learn (Sklearn). Looking for some tutorials on the internet, I did some testing and…
-
6
votes3
answers14381
viewsAre there interfaces in python?
In languages like PHP and Java, there are interfaces, which, when implemented in a class, requires it to contain the methods of this interface in the same way as they were declared. Example in PHP:…
-
6
votes0
answers53
viewsWhat is a Python metaclass?
What is a Python metaclass? On what occasions should they be used?
-
6
votes3
answers450
viewsAnnotate: Returning the cheapest product and supplier name (Django)
Given the table below product;company;price AAAAA;forn1;395.69 BBBBB;forn1;939.45 CCCCC;forn1;480.33 DDDDD;forn1;590.59 EEEEE;forn1;847.69 AAAAA;forn2;227.31 BBBBB;forn2;375.90 CCCCC;forn2;602.18…
-
6
votes1
answer900
viewsMore elegant ways to invert integers, arrays and strings in Python
Hail! I’ve been looking for elegant ways to do string inversion, arrays and integers in Python. What do you think of my codes below and what suggest to improve them? They work... Thank you! frase =…
-
6
votes1
answer190
viewsDifference between "list(range(1, 10))" and "range(1, 10)"?
I asked that question here How to format all elements of a list in Python?. In one of the answers, @Ciganomorrisonmendez, put the following excerpt: list(range(1, 10)) But every time I used the…
-
6
votes2
answers40971
viewsProblem using Switch Case in Python 3
print ("ESCOLHA A CERVEJA PELO NUMERO") print ("1-ANTARTICA R$6.00;2-SKOL R$6.50;3-BRAHMA R$8.20;4-SOL R$8.25;") cerveja = input ("5-NORTENHA R$16.80;6-PROIBIDA R$4.80;7-DEVASSA R$5.90;8-HEINEKEN…
-
6
votes1
answer120
viewsnumpy.diagonal returning read-only copy even in version 1.10
I’m doing a program in Python where I need to change the values diagonally from an array. The following chunk of code should be sufficient to understand the general idea (it changes to 2 the value…
-
6
votes1
answer323
viewsDeveloping in Python with Visual Studio 2013
I want to develop in Python using Visual Studio 2013 or 2015 because I’m already used to the IDE, but I have no experience with the language. In the English OS there is a question that lists Visual…
-
6
votes1
answer187
viewsWhat are the PEP’s in Python?
I was researching about the Type Hints in Python and came across this page. PEP 0484 - Type Hints What would this PEP be? This is some kind of proposal for the next versions of languages?…
pythonasked 9 years ago Wallace Maxters 102,340 -
6
votes1
answer3041
viewsWhat is the __new__ in python method for?
class Fabrica(object): """ pra quê serve o metodo __new__ in python? """ def __new__(cls[, ...]): # seu codigo aqui #EOF What she makes, and how to make use of it?…
pythonasked 9 years ago user37612 -
6
votes1
answer2595
viewsHow to use the arguments passed to a python script?
In scripts php, we can, when running from the command line, capture its values from the arguments passed through the variable $argv and its number through the variable $argc. For example (Script):…
pythonasked 8 years, 11 months ago Wallace Maxters 102,340 -
6
votes3
answers1779
viewsHow not to repeat values in a Python list?
If I create two lists, and then add the two, I create a third that owns all the items of the previous two: >>>a = [1, 2, 3] >>>b = [3, 4, 5] >>>c = a + b >>>print…
-
6
votes6
answers37862
viewsHow to remove characters from a string?
The program must read two strings and remove from the first string all the letters that occur in the second string. Example: Be the strings "chocolate" and "hollow", then the program should print…
-
6
votes2
answers9159
viewsRead multiple numbers on the same line with raw_input
I need to write a program that reads values and then use them to calculate areas of different geometric figures. My problem is: how to enter the data on the same line? Example: 3.0 4.0 2.0 followed…
pythonasked 8 years, 11 months ago Guilherme Santana De Souza 743 -
6
votes3
answers37709
viewsRemove element from a list by key (key) and by value (value)
I have the following list my_list = [1,2,3,4,5,6,7,8,9] Let’s say I want to remove num 7 by value and/or key and keep: my_list = [1,2,3,4,5,6,8,9] How do I do?…
pythonasked 8 years, 7 months ago Alberto Pimenta 169 -
6
votes2
answers675
viewsRun Python command with Selenium called by PHP through Apache
I want to run the following script in Python by a web site on the server: #!/Python34/python from selenium import webdriver driver = webdriver.Firefox()…
-
6
votes2
answers48
viewsNew instance overwrites old values
Take a look at this class: class Signal: point = None view = { "x": None, "y": None, } def __init__(self, point): self.point = point self.set_position() print(self.point + " -> " +…
-
6
votes2
answers2294
viewsScraping in Python - read pdf
I made a Scrapping in Python that takes a URL of any PDF, reads and returns, but in some Pdfs I’m having the problem of coming with some characters like this: ".\nO xc3 xb3rg xc3 xa3o tamb xc3 xa9m…
-
6
votes2
answers298
viewsHow to run audio with Pyqt?
Is there any way to run an audio file with Pyqt? You can do this only with Pyqt or you need to install another library?
-
6
votes1
answer2127
viewsHow to clone objects in Python?
In some languages, besides being able to instantiate a class to construct a given object, we can also clone an existing instance, if we want an object with the same characteristics of the current…
-
6
votes1
answer278
viewsImporting specific modules is faster/performative than importing everything (with the asterisk)?
In Python, since I realized that it is possible to import specific functions or classes from a module, I chose to always do so. One of the reasons is legibility. The other reason I’m not sure, so I…
-
6
votes1
answer380
viewsWhy use two server-side languages on the same system?
Why I see many systems with two, up to three programming languages? When I see a system that migrates from one language to another, I even understand, but why do many maintain two or three…
-
6
votes1
answer3403
viewsHow does any and all work in Python?
How the functions work any and all in Python and what are the differences between them? They happen to be functions equivalent to Array.prototype.some and Array.prototype.every javascript?…
-
6
votes1
answer584
viewsWhat does this "." point in Python mean?
What does that mean dot between the variable var and index? Example: var = ['João','Pedro','André','Alice'] var.index('André') Has any name?…
-
6
votes2
answers190
viewsClass properties difference vs Instance
What is the purpose of creating attributes in the class if I can create in the instance itself?
-
6
votes3
answers6745
viewsHow to validate whether it is a vowel without writing all the letters of the alphabet
Write the vowel function that takes a single character as a parameter and return True if it is a vowel and False if it is a consonant. Note that vowel("a") must return True vowel("b") must return…
-
6
votes3
answers6054
viewsDraw a rectangle using Python repeating structures
I have to solve the following activity in Python: I need to write a program that prints a rectangle with the full edges and the middle open: >>> digite a largura: 10 >>> digite a…
pythonasked 7 years, 9 months ago Marcos Vinicius 63 -
6
votes1
answer4852
viewsWrite to a CSV file
I need my script write to a CSV file. It will open a CSV file that has the column created_at (date and time), after that, the variable will be "broken" and will be written in a new CSV file the day…
-
6
votes5
answers21141
viewsWhat is the functionality of n?
I’m learning to program in Python and some basic things still confuse me, for example this question I asked. What is the use of n?
-
6
votes1
answer489
viewsPrediction with Tensorflow Neural Networks
Hello, I’m having trouble implementing a neural network. My problem is that I can only implement it with an attribute 'X' I need help with this code for example, how do I put two input attributes?…
-
6
votes1
answer705
viewsHow to extract information from an HTTP header with Python?
We know that in the HTTP protocol, the end of the header is indicated by "\r\n\r\n". Example: It may be that, for some reason, the customer does not send the "\r\n\r\n" to the server (could be an…
-
6
votes1
answer1909
views -
6
votes1
answer4113
viewsCount of a specific character in a word in Python 3
I recently asked a similar question, but I received answers where my input was supposed to be a number. Is it possible to count how many specific characters you have in a word? As in "example" you…
-
6
votes3
answers1943
viewsRun Python and C# together
How can I in C# import, ie, execute some script in another language (Python)? Example: If you write "R" in a C#program, it executes a file if called ApertouR.py.
-
6
votes4
answers162
viewsWhat is the difference between the operator IN and ==?
I would like to know the difference between the operator IN and the == in Python?
-
6
votes1
answer76
viewsDynamic typing and team development
Is there any good practice, standardization, recommendation, etc. aimed at preventing invalid types from being passed to methods and functions? If I am working alone is more quiet, I even wrote the…
python python-3.x software-engineering encoding-styleasked 6 years, 7 months ago Matheus Saraiva 2,157 -
6
votes4
answers320
viewsFlatten lists. Is a more concise solution possible?
I solved the following Python exercise: Implement a function that receives a list of length lists any and return a list of a dimension. The solution I was able to make was this:: #!/usr/bin/env…
-
6
votes1
answer238
viewsWhat does the asterisk represent in the definition of a function in Python?
For example, in the module documentation pickle it is common to see such a notation: pickle.dump(obj, file, protocol=None, *, fix_imports=True) pickle.dumps(obj, protocol=None, *, fix_imports=True)…
-
6
votes2
answers3155
viewsHow does Python overload polymorphism work?
I recently learned POO in Java and am now learning in Python. There is overload polymorphism (implement methods with equal names in the same class, which depending on the parameters you deliver to…
-
6
votes1
answer2565
viewsExtract information from lattes
Introducing Since 1999, Brazilian researchers have had a website where they can post information about their academic career. This information is known as Currículos Lattes. I wish to download a few…
-
6
votes1
answer295
viewsWhy does Fractions.Fraction(1/3) not return "1/3"?
import fractions a = int(input()) b = 1 / a b = fractions.Fraction(b) print(b) This is a piece of code I’m developing. This part had the function of taking the decimal resulting from the division "1…
-
6
votes1
answer591
viewsAdd list values with different sizes
I have two lists with varying numbers and sizes. For example: array 1 ['1', '142', '33', '33', '9', '2'] array 2 ['1', '12', '7', '-2', '39', '11', '31', '49', '50', '1'] How do I make a loop to add…
-
6
votes4
answers461
viewsHow can a group of parameters be required if at least one of them is informed?
In Python we have the default values, which are optional when we call a function. I was wondering if there’s any way to make a group of values optional, like if you pass all those values or none.…
pythonasked 5 years, 10 months ago Matheus Cezario 69 -
6
votes2
answers1136
viewsWhat is the purpose of using "Else" together with Try/except in Python?
In Python, what’s the advantage of using else in a block try/catch? If in this example below: try: f = open('texto.txt', 'r') except IOError: print('O arquivo não existe!') else: print(f.read())…
pythonasked 5 years, 10 months ago Thiago Krempser 1,878 -
6
votes2
answers2537
viewsWhen should I use a Property instead of a Python attribute?
If I set the class Person down below: class Person: def __init__(self, name): self.__name = name In this other way: class Person: def __init__(self, name): self.name = name self.kind = kind…
-
6
votes2
answers1649
viewsWhat is the underscore (or underline _ ) for in the repeating structure?
What this _ ago? Why it is being used in the code snippet below? print('3 numeros') data = [] for _ in range(3): data.append(input()) numbers = list(map(int, data)) print(numbers)…
-
6
votes1
answer1867
viewsPython integer split operator
Can anyone explain why this function returns -2 and not -1? print(-3//2) The operator // does not return the entire part of the division?…