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
-
5
votes1
answer6374
viewsPython 3.4 and Python 2.7: How to remove the preinstalled Macbook Version?
I am currently migrating from a mac to a Windows and today I discovered, when installing all the resources I needed, that there was already a Python 2.X in it and I need to run Python 3.4.3. How can…
-
5
votes2
answers2507
viewsHow to put part of a text in bold in Tkinter?
I need to display a text in a GUI interface made with Tkinter, however, I would like only one word in the middle of this text to be in bold. I’m using it this way: texto = Label(Frame, text="Texto…
-
5
votes3
answers211
viewsHow could I improve the code?
Is there any way to improve this code? lista = [0,0,0,0,0] acuNota = 0 x = 0 arq = open("notas","w") while x <= 4: lista[x]= float(input("Insira uma nota por favor!")) acuNota = acuNota +…
-
5
votes1
answer225
viewsCannot assign "'Maria'": "Student.name_mae" must be a "Student" instance. When I try to access a student subclass field
I have a system with multiple users, I decided to make inheritance of Django’s default user, I have two users: student and teacher, which has several characteristics in common, so I created a base…
-
5
votes3
answers12860
viewsHow to fill left zeros in Python?
In php, I know we can fill a number with zeros through the printf Example: printf('%04s', 4); // Imprime: "0004" How could I do that in Python? When I try to do it the way above, the result is not…
-
5
votes2
answers1026
viewsHow to resolve "Typeerror: must be Unicode, not str" error in Python?
When backing up my database on Sqlite3, the Python interpreter returns the following message: Typeerror: must be Unicode, not str on the line f.write("%s\n" % linha), I couldn’t find a solution…
-
5
votes1
answer9671
viewsProblem declaring variables for average calculation in Python 3
n1 = input("informe sua nota do 1º Bimestre ") n2 = input("informe sua nota do 2º Bimestre ") n3 = input("informe sua nota do 3º Bimestre ") n4 = input("informe sua nota do 4º Bimestre ") media =…
-
5
votes3
answers3063
viewsCheck whether "1" list value contains "2" list
I have two lists: track_list = ['iphone 6', 'iphone 5', 'moto x2', 'galaxy s6'] tweets_data = ['Eu queria um iphone 6 sérião', 'nao gostei do moto x2', 'iphone 5 é coisa do passado'] I want to check…
pythonasked 9 years, 6 months ago Lucas Silva Simão 53 -
5
votes1
answer2420
viewsAre there any random text generators that produce correct phrases?
Is there any program, preferably in python, capable of generating random text but syntactically correct? The language I’m looking for is English.
-
5
votes2
answers1685
viewsHow to format all elements of a list in Python?
In php, when I want to generate a array formatted, I use the function array_map. Thus: $numeros = range(1, 10); array_map(function ($value) { return sprintf('%04', $value); }, $numeros); Returns:…
-
5
votes1
answer2258
viewsNFE Digital Signature(Electronic Invoice)
I am developing NFE in the Python language, I already Gero the XML, I can send it to Webservice and I get the answer, what I need now is the digital signature The signature is an xml tag with some…
-
5
votes1
answer613
viewsHow to create a symbolic link to a Python code on Linux?
I want to run a simple Python code I created from anywhere on my system. I know to do this with a shell script just turn the command ln -s /home/user/script.sh /usb/bin/script, but would like to…
-
5
votes4
answers788
viewsGenerate random values from a distribution in Python
Hello! I’m trying to generate random values of a distribution (Gamma, normal and etc) in python, but I’m having trouble importing the library. I am using the following library "import scipy.special…
-
5
votes2
answers1939
viewsHow do I convert an RGB image to Python grayscale?
I need to convert several images (in format .png) RGB colored for grayscale.
pythonasked 9 years, 4 months ago Leo Ribeiro 581 -
5
votes1
answer2733
viewsCalculating a magic square
I’m trying to make a magic square: A magic square is one divided into rows and columns, with a number in each position and in which the sum of the rows, columns and diagonals is the same. Example…
-
5
votes1
answer995
viewsAdding a comma to a string
Good personal and possible to add comma in an example string: a = '1234567890abcdefghijklmnopqrstuvwxyz_' for her to stay like this a = 1,2,3,4,5,6,7....…
-
5
votes1
answer125
viewsError importing xml.parsers.Expat in Python 2.7 only works with Python3
Good morning, a few months ago I started with python I’m using it to do tests on android applications. I have the following problem importing the xml.parsers.expat. when running straight into the…
-
5
votes3
answers5900
viewsHow do I make a program written in python open with two click’s made one executable?
An example: #!/usr/bin/python3 # coding: utf-8 # window.py from gi.repository import Gtk class App(Gtk.Window): def __init__(self): super(Gtk.Window, self).__init__(title='Hello World')…
-
5
votes2
answers380
viewsAlgorithmic complexity of map
Could you tell me the algorithmic complexity of this code, in particular, what the complexity of the function map numero = map(lambda x: x[0], lista) map(lambda x: (numero.count(x)),…
-
5
votes1
answer10433
viewsWhat is the difference between Sorted() and . Sort()?
Why the function sorted() is considered more direct than the method .sort() used in lists with tuples?
-
5
votes1
answer181
viewsPython ORM similar to Django
I studied the framework for a long time Django and I thought the ORM of the same was excellent. I had the idea, at some point, to build an application with another framework called Flask, using a…
-
5
votes1
answer139
viewsDjango generating strange code
I am using the visual studio community and created a web project with Django, but when making the homepage, is generating me this code: And the code I have is this: {% load staticfiles %}…
-
5
votes2
answers4801
viewsHow to use multiple languages in a single program?
I saw that Google Chrome is made in Python, C++ and Assembly and came to mind, like programming using multiple languages in a SINGLE program?
-
5
votes1
answer165
viewspython process
I’m trying to change an external variable within a process but it’s not working. I created a simple test class: from multiprocessing import Process class Classe(): def __init__(self, parent=None):…
-
5
votes2
answers2514
viewsUnicodedecorror: 'utf-8'
I’m having problems with Unicodedecodeerror: 'utf-8' in a python file and I’m not being able to solve it. That is the mistake: Traceback (most recent call last): File "file.py", line 448, in…
-
5
votes1
answer480
viewsPython lists and dictionaries
I’m working on Python 2.7. import collections counter_ger=collections.Counter(sub_todaas) a=counter_ger.values() b=counter_ger.keys() sub_ind_novo = [Ntodos.index(i) for i in b if i in Ntodos]…
-
5
votes1
answer479
viewssplit a string of n into n chars, split() of n n
I have the following text: "ola sou o Allan" I would like to keep this text divided by e.g., 2-on-2 chars. How can I do this?
-
5
votes1
answer620
viewsWhy does my image recognition training in Opencv generate transparent samples?
I’m using Opencv and trying to generate a file. vec to do image recognition training, but whenever I file and try to read it, I see images as if some parts of my positive are transparent! (I…
-
5
votes1
answer5711
viewsChecking and creating python directories
Hello, I am creating a code that should check if a folder exists, if it does not exist the code should create it and then proceed, otherwise it just goes with the flow. I tried with If and While but…
pythonasked 8 years, 9 months ago Cristhian Miguel 207 -
5
votes1
answer12952
viewsGenerate all combinations given a python list
I’ve searched far enough and found nowhere exactly what I want. What I want is, given a list of characters, generate all possible combinations from size x to size y. Example: 0.1.2 and order size…
pythonasked 8 years, 8 months ago Júlio César 53 -
5
votes1
answer4176
viewsAlignment with string.format and Unicode
I’m having trouble with the alignment of strings when using the .format(), for example when doing: >>> print '{:>6}'.format('agua'} agua >>> print '{:>6}'.format('água'} água…
-
5
votes1
answer190
viewsWhat is wrong with this procedure when saving a form?
I have a registration form and I’m trying to save information on it. When trying to register, it returns a form error saying the email already exists (even if registering different types of email).…
-
5
votes1
answer8320
viewsPython Hangman Game
I’m doing a Python hangman game. Every loop the program asks the letter or word: #Jogo perguntarNovamente = True game_on = True while game_on: palavra_secreta = palavra() senha_list = [l for l in…
-
5
votes1
answer3840
views'Dict' Object has no attribute 'has_key' in Python3
In Python 2, when I wanted to know if a dict had certain key, I used the method has_key. if kwargs.has_key("code"): self.code = kwargs.code However, now that I ran the same script in Python 3, I got…
-
5
votes2
answers1182
viewsUsing For in Python
Python can only work with for' (loop) using a list? It is not possible only with an integer as in other languages?
-
5
votes1
answer648
viewsHow to read Yaml with Python?
How do I read a Yaml file or code with Python? You need to install something, or you can do it natively? Example: fruits: - Apple - Orange - Strawberry - Mango…
-
5
votes1
answer3076
viewsHow to create text in a python image?
I wanted to create a text in an image, with python, to show a variable (whatever the format), e.g.: i have an image showing an A = 0, then I change a variable, refocus the image and it appears A =…
pythonasked 8 years, 4 months ago DoutorWhite 111 -
5
votes1
answer338
viewsOpen text file in Python package
I’m creating a Python package where one of my programs needs to open a text file to read some information. This file is in the same directory as my source. When I run the program in the interpreter…
-
5
votes2
answers110
viewsWhy is the output coming out like that?
I’m trying to make a program in which I use a list and this program returns 2 lists with pairs other with the odd. lista = [0,1,2,3,4,5,6,7,8,9,10] def par(numero): if numero % 2 == 0: return numero…
-
5
votes2
answers124
viewsPython: How to store the documentation(help) of a class in a String?
I’m doing a Python class explorer. I can store class methods and attributes with dir(obj) and place them in a Treeview. I would like to display the references of this when clicked. For this I would…
-
5
votes2
answers14521
viewsSort dictionary by Python value
I have a dictionary with the following format dic={759147': 54, '186398060': 8, '199846203': 42, '191725321': 10, '158947719': 4} would like to know if there is how to sort it by value and print on…
-
5
votes1
answer1868
viewsHow to randomly choose an item from a Python dictionary?
I would like to know how to randomly choose an item from a Python dictionary? For example: I have the dictionary dic = {'Pedro': 99, 'João': 19, 'Rosa': 35, 'Maria': 23} and need to choose an item…
-
5
votes2
answers836
viewsHow to set a header with a JWT token in a request made by the Requests library?
I’m using the library Requests Python to make HTTP requests. I was able to post a request quietly in order to obtain a JWT token. But now I need to send this token through a header, but I have no…
-
5
votes1
answer139
viewsHow to run a loop while waiting for input?
I want to know if you can run a repeat loop while waiting for an input type() and right after receiving the loop input for or while starts processing it immediately. something like: imputs = []…
-
5
votes3
answers2721
viewsHow to join several Python dictionaries?
In some languages, it is possible to unite objetos/array in one. For example, in PHP, I can join several arrays thus: $userInfo = ['name' => 'Wallace'] $jobInfo = ['job' => 'Developer']…
-
5
votes2
answers101
viewsHow to get an item from a list randomly?
Suppose I have the following list: frutas = ['abacate', 'mamão', 'laranja', 'uva', 'pêra'] I need to capture one of these elements from list randomly. How would I do it in Python?…
-
5
votes1
answer2888
viewsIn Python is there a debug function equivalent to "print_r" or "var_dump" in PHP?
In Python there is some function for debug equivalent to print_r or var_dump of PHP? For example, in PHP: $valor = 'Hello'; var_dump($valor); string(5)'Hello' In Python would have some similar…
-
5
votes2
answers714
viewsHow do I know if a value is eternal in Python?
How can I check in Python if a certain value is eternal? What determines that a particular type can be eternal? For example, how to find out this in the case below? a = 1 b = 'Uma string' c = [1, 2,…
-
5
votes1
answer499
viewsPython "Attributeerror: __exit__" problem
In a group, I asked them to give me tips on some program to test my knowledge. He told me to create a program that reads a file called "arquive.txt" and manages files CHAR and STAGE, with the file…
-
5
votes5
answers1463
viewsBeginner in Python, Else and Elif
idade = int(input("Insira sua idade:")) if(idade<=0): print("Sua idade nao pode ser 0 ou menos de zero") elif(idade>150): print("sua idade nao pode ser maior de 150 anos") elif(idade<18):…
pythonasked 8 years, 3 months ago Eduardo Rodrigues 51