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
answer664
viewsWhat is a migrate?
I am a beginner in the world of Jango and one of the first things I find in tutorials is the term migrate I’d like to know what that refers to, how to use it and what it’s for.
-
2
votes2
answers279
viewsWeb Crawler searching for specific text on the page
Well, I’m making a Crawler web to fetch the value of a coin. I wrote the following code in python: #coding: utf-8 from urllib2 import urlopen conteudo =…
-
2
votes2
answers778
viewsEmpty if declaration in function
It is possible to create a function that ends with an empty if statement and allows the code that called that function to determine if action? Example: def if(): if x>6: x = input("Valor de x")…
-
2
votes3
answers8071
viewsASCII in Python
Hi. I’m from C and I’m starting to learn Python. I have a question to move the characters of a string 3 positions and in C would look something like this: str[i] += 3; I tried to do the same thing…
-
2
votes2
answers1583
viewsPython - Assign the value of an entry to a variable
I tried to use the command mensagem = str(entry.get()) but it doesn’t work, I tried to use the entry = Entry(root, textvariable='mensagem') but also does not work, see the whole code basically want…
-
2
votes1
answer3009
viewsEquivalent of python Curl
I was learning to use API’s from websites to a project, and right at the beginning I had difficulties and had to ask. This was the example of the use of API to test credentials on the site, I…
-
2
votes1
answer259
viewsCalculate occurrences in the overlapping string
would like to know how to make how many substring combinations is possible within a string, ex: string = 'abcdcdc' sub_string = 'cdc' the returned value I want in this case, is 2, because the code…
-
2
votes1
answer42
viewsError in classifying text with a tree
I’m trying to sort, but it’s giving the error. Follow the code, then the error. #coding=UTF-8 import io import os import pandas as pd from sklearn.feature_extraction.text import CountVectorizer from…
pythonasked 7 years ago André Nascimento 1,258 -
2
votes1
answer5801
viewsHow to Create a communication between two clients via server using socket
import socket from threading import Thread def client(h, p): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # IPv4,tipo de socket s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) while…
-
2
votes2
answers68
viewsIterator should return a String
Hello, I have the following code: import csv def carregar_acessos(): X = [] Y = [] arquivo = open('acesso_pagina.csv', 'rb') leitor = csv.reader(arquivo) next(leitor) for…
-
2
votes3
answers1051
viewsIdentify a numerical sequence in a text file
I’m new to Python, and I’m having a problem that I can’t find a solution to. I have a folder with about 10k of . txt (written in many different ways). I need to extract the FIRST sequence of 17…
-
2
votes1
answer743
viewsshell_exec() PHP of a Python script
The script <?php $output = shell_exec('py core003.py'); echo $output; ?> Rotate the script => import sys print(sys.version) The output is 3.0.1 (r301:69561, Feb 13 2009, 17:50:10) [MSC…
-
2
votes0
answers165
viewsDisplay message(Qmessagebox) from a class other than the main one in Pyqt4
Friends, I ask for help from you, I imagine it is simple but I am having difficulty, because I am still learning object orientation with Pyqt4. I have a main class (Application) separate from the…
-
2
votes3
answers229
viewsImport another debris module from another using Libreoffice macros
This question refers to the use of macros in python in Libreoffice. I’ve been doing some studies on the subject and found that one of the ways to add a Python-written macro to Libreoffice would be…
-
2
votes2
answers326
viewsHow to use the Django User part in a model?
I’m blogging and the question arose, has how to use the user system of Django to make a Foreignkey in my Author variable ? from django.db import models class Category(DatastampMixin): name =…
-
2
votes1
answer120
viewsHow to avoid calling the same function several times?
I have two scripts files, one to access a CSV file, turn each row into a dictionary and return a list of dictionaries (lines). My second script is a function to create a new column in the file (C1),…
-
2
votes1
answer399
viewsHow to install PIP in Odoo’s.txt file
I want to install the Odoo on a server Ubuntu 14.04. However, to work with Brazilian legislation, it is necessary to install some dependencies Pip for the modules: Pip dependencies for modules:…
-
2
votes1
answer105
viewsAdding files to pyinstaller
When I use the option --onefile, my program cannot find the files added to .exe. I don’t know which path to specify for my program to find the files. My code is like this: import winsound…
-
2
votes1
answer428
viewsPrimes in python A-z A-Z letters
In this problem you should read a set of words, where each word is composed only of letters in the a-z and A-Z range. Each letter has a specific value, the letter a is 1, the letter b is 2, and so…
-
2
votes1
answer179
viewsPython library
Is there a place where I can make queries about Python commands and functions in English? For example: If I wish to know information about a command or module like numpy or pandas ? I noticed that…
-
2
votes2
answers1412
viewsRegex to give match on first occurrence before a word
My string is as follows: \questao{1} \begin{enumerate} todos os tipos de caracteres \end{enumerate} \begin{enumerate} -------> APENAS este deve dar match todos os tipos de caracteres…
-
2
votes3
answers3080
viewsCheck the line containing a string inside a TXT file
I need help with a program that reads a file and responds to me on which line contains a string inside it. Example I have a file . txt and inside it I have 5 lines: File.txt: arroz batata feijão…
-
2
votes1
answer239
viewsHow to get the origin of a form in cgi python?
Hello, I’m using python with cgi, for my forms. I need to get origin to make sure my website is safe, but I couldn’t find any information on it. The only thing I am doing for now is to recover the…
-
2
votes3
answers160
viewsWhat is the logic behind this function?
Why the result of L1 is: [2, 3, 4] instead of [3, 4]? def remove_dups(L1, L2): for e in L1: if e in L2: L1.remove(e) L1 = [1, 2, 3, 4] L2 = [1, 2, 5, 6] remove_dups(L1, L2) print(L1) I tested in…
-
2
votes1
answer2238
viewsWrite file in JSON
I have a number of files in JSON format, to work better organize them all in a single file using the following method: import json filename = "dados_geral.json" for mensagens in range(1,6):…
-
2
votes2
answers1322
viewsI understand a parallel run using Fork. How does Fork work?
import os def filho(): print('Ola do filho', os.getpid()) os._exit(0) def pai(): while True: newpid = os.fork()# fornece ID para um novo processo! if newpid == 0: filho() else: print('Ola do pai',…
-
2
votes2
answers64
viewsCode continues running after game’s end
In line 10, even if I choose option 2 not to continue in the game, the Game Over appears but the code continues running. On the line marked (line 10), even if I choose option 2, which should be the…
pythonasked 6 years, 11 months ago João Pedro Mossi S. Teixeira 31 -
2
votes3
answers3778
viewsCount the most popular words
I’m trying to find the number of occurrences of a list of words in a text: from collections import Counter def popularidade (texto, palavras): texto = texto.lower().split() palavras =…
-
2
votes1
answer59
viewsWhy is the class attribute not modified?
I only need to send a command from one process to the other, but I wanted to understand why when modifying the variable within a function, it does not appear in another function. from…
-
2
votes1
answer53
viewsConversion of boolean values to numbers
How do I get the answer from False be it 0 and True be it 1 equal in C? That is, I wish the answer of: u=(1>2) be it 0 and not False? Thank you…
pythonasked 6 years, 7 months ago Vitor Bento 43 -
2
votes3
answers359
viewsNumbers over 32, 64 bits
How to work with numbers above 32, 64 bits? The idea is to generate a large pseudo random numbers up to 4096, for example, by a pseudorandom number generator that generates numbers of 32. In C I…
pythonasked 6 years, 7 months ago Daniel Boso 41 -
2
votes1
answer4081
viewsHow to break a list and turn it into an array in Python?
In case, I want to turn a list of a column into a 3x3 matrix in numerical order: lista =([[1], [2], [3], [4], [5], [6], [7], [8], [9]]) With the expected result: ([[7 8 9] [4 5 6] [1 2 3]])…
-
2
votes1
answer97
viewsprint text without translineation rule
I need to print a text from a file on a single line without the line break traces. def imprime_texto(): with open("texto.txt") as arquivo: linhas = arquivo.read().split("\n") for linha in linhas:…
-
2
votes1
answer742
viewsCannot import X
I have two files inside a project of which one has the import of the other and vice versa, in this case the main_server.py has the import from Servidor.skeletons.Threads import Thread to be able to…
-
2
votes2
answers528
viewsHow to call class method in another app?
I want to create a file called config.py and put some settings inside a dictionary for whenever you need to invoke these parameters. But how I call this parameter in Python? For example, I will…
-
2
votes2
answers789
viewsReplace all characters in a string with another character
def getGuessedWord(secretWord, lettersGuessed): secretWord_copy = "" for i in secretWord: print(i) secretWord_copy = secretWord.replace(i," _ ") print(secretWord_copy) secretWord = 'apple' I’m…
-
2
votes1
answer249
viewsHow to ignore certain elements in a list that will go through a random process? (pending)
This program finds 3x3 magic squares by brute force and prints automatically when it encounters a. code: import random vetor = [1, 2, 3, 4, 5, 6, 7, 8, 9] def magicsquare(): return…
-
2
votes0
answers54
viewsTypeerror: not all Arguments converted During string formatting - Python 3.6 - Power Bill
I am a beginner in the area and during the programming studies in Python I was stuck in this exercise, the goal being to appear on the screen of the user how much he should pay per kwh used,…
-
2
votes2
answers1406
viewsRounded Tkinter button
Is there any way to round the button tips? Or even leave it as a circumference? Like this one for example:…
-
2
votes2
answers377
viewsList separated by "-"
The theme is as follows: I have a list[1,5,3,6,22,45,63,30,344,22,12,25,10] And I wanted to print the elements of that list in one line and separated by "-". I’ve tried that way…
-
2
votes2
answers343
viewsString occurrence calculation in list - Python
Staff need a help to calculate the amount of occurrences of a given string in a column of a list. Example: lista_teste=['Name','Age','Sex','Profession'],['Peter','25','Male','Physician']...] Ex:…
-
2
votes1
answer344
viewsJoin three similar codes into one
I am working with a table that shows the number of vacancies offered, candidates enrolled and enrolled in higher education courses. I want to make a program that allows the visualization of this…
-
2
votes1
answer1927
viewsExercicio calculo maior numero python
Good afternoon, I’m developing an exercise in python, I saw that there are already some similar resolutions in the forum, but I developed one of my own and I’m not understanding the reason for the…
pythonasked 6 years, 10 months ago Túlio Maia 35 -
2
votes2
answers11769
viewsProblem when calculating percentage (result is always "0")
I finished a program in Python (perfected with a response obtained right here in Stack Overflow), but I’m trying to include a percentage calculation that isn’t working. Although everything else…
-
2
votes2
answers2157
viewsCreate function hexadecimal and octal conversion function in python
Good evening, I’m trying to do two functions one to convert hexadecimal numbers into decimals and one to convert octal numbers into decimals, this is my code: def hexadecimalparadecimal(n): decimal…
-
2
votes2
answers225
viewsMake a Relationship Many for Many
I am trying to put in a view the amount of students enrolled in a course using the following Models below. NOTE: I cannot change the columns of the Models, since the database already exists and I am…
-
2
votes2
answers68
viewsPython: How to turn a method or a class into obsolete?
This time I want to learn about Python package structures, and I need your help again. How to turn a method or a class into obsolete? How to display a message in the interpreter’s Debugger, when a…
-
2
votes2
answers1328
viewsVectors names and ages - Python
I want to create two vectors, one for names and the other for ages, which can hold 10 people. I believe it would be: pessoas = [] idades = [] for c in range(10): pessoas.append(input('Digite o nome…
pythonasked 6 years, 6 months ago João Moreira 21 -
2
votes1
answer278
viewsHow do I extract the name of multiple folders within a directory?
I need to get inside a folder called /users, where inside it the various folder and copy the name of all folders, follows the example. I wish I could take the name of these folders and save to a…
-
2
votes1
answer107
viewsHow to import packages within other subpackages in Python?
I have the following structure on a project PacoteRaiz/ __init__.py Pacote1/ __init__.py Modulo1.py Pacote2/ __init__.py Modulo2.py If I want to use some function that is inside Modulo1.py in…