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
answer906
viewsCustomize Django Admin
I have two classes, one is Division and the other is Group. In the group I have FK for division. I want to register a Storage in the Django Admin and in the Group select I want the group and…
-
2
votes1
answer721
viewsHow to call a class attribute in another Django class
I’m trying to create classes that will relate in a certain way. The idea is to be a game in which the player will have some options of choice and then your score is based on the score of your…
-
2
votes2
answers130
viewsDatetime without the year
I need to represent holidays and in my holiday class I need to set the start and end date of the holiday. As start date and end date I need to inform only the month, day, hour and minute. But the…
-
2
votes1
answer413
viewsHow much can I use Instagram data on a Crawler?
I’m just curious, but these days Instagram has generated me certain doubts. I have already made a simple Rawler using Beautifulsoup to extract date and receive daily information from new posts. The…
-
2
votes2
answers452
viewsLinear Regression in Various Products
I ran a simple regression to a database with a product (Product, Volume, Price). It ran perfectly. But I would like to run the same regression on a basis with more products, but I want to be able to…
-
2
votes1
answer216
viewsSingle lists with at least 2 difference elements
Considering the numbers: 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 How do I generate lists of 15 items (numbers cited above), and they need to have at least 2 items…
-
2
votes1
answer60
viewsReturn message from Else
I’m making a very simple example using Django. In my view I have the following : def index(request,idade): string = ''' {% if idoso >= 65 %} Você já é idoso {% else %} Você não é idoso {% endif…
-
2
votes2
answers9963
viewshow to compile a python script in a executable
How best to compile a python script for an executable running on a linux (Ubuntu), windows and mac operating system.
-
2
votes1
answer721
viewsError installing psycopg2 in a pypy virtualenv environment
I installed the shape sequinte pypy: wget https://bitbucket.org/pypy/pypy/downloads/pypy3-v5.10.1-linux64.tar.bz2 tar xf pypy3-v5.10.1-linux64.tar.bz2 virtualenv -p ~/pypy3-v5.10.1-linux64/bin/pypy…
-
2
votes2
answers251
viewsPython code using HMAC library
I’m doing a paper on cryptography for college using HMAC along with SHA256, and I’d like to understand what this code does on each line, I’m a little confused. #!/usr/bin/env python3 import hashlib…
-
2
votes2
answers3426
viewsImporting library in python
I am unable to import any library in python using pycharm. When I type, for example, the command import time, the words turn gray and bring nothing.
-
2
votes0
answers321
viewsInfinite loop in the on_message method
Hello, everyone. I have an infinite loop on my Discord bot, but I don’t know how to fix it. import discord import asyncio import strings_codes #minha classe de string e códigos import…
pythonasked 6 years, 9 months ago Weslley Borges 21 -
2
votes3
answers465
viewsTest sum function
Hello everybody all right? First I want to say that it is a pleasure to be part of this community. I’m studying python on my own, I found a course per application, I’m already in the functions part…
-
2
votes1
answer1977
viewsPath to a python character
I adapted a program in Python that solves labyrinths, and I’m improving it, but I had problems with the minimum path (I even studied in Graphs), I was able to understand everything. But I’m having…
-
2
votes1
answer94
viewsHow to do Mongo inserts?
I’m doing a program that will perform numerous insertions in Mongo (about 500,000). But I noticed doing some tests, that the more entries in Mongo I have, the longer is the insertion. My code: def…
-
2
votes2
answers584
viewsHow to stop a loop at a certain time?
I’m a beginner in Python and I’m trying to create an alarm clock... But it doesn’t "wake up" at the right time, someone can help me? import datetime import time print("Digite a hora para ligar…
pythonasked 6 years, 5 months ago Leonardo Massimino 23 -
2
votes1
answer163
viewsHow to remove a specific character from some specific strings within a Python list?
I have a list of examples: ['#[Header]', '#Application Name\tLCsolution', '#Version\t1.24'] I would like to know how to remove a specific character, such as the # of all elements of the list, or, if…
-
2
votes5
answers7817
viewsSum of each element of two lists
Is there any code that sums the elements of two lists, for example: A=[1,2,3,4] B=[2,4,5,6] D=[3,6,8,10] # o elemento 3 e a soma dos elementos 1 e 2 da lista A e B
-
2
votes1
answer141
viewsPython - How to keep decimal places from list item to variable?
I am using Python inside the SPSS to read some values within a dataset. These values are stored in a list. I am using 15 decimal places and in the list the values appear with 15 houses. However when…
-
2
votes1
answer130
viewsDJANGO > Render one FOR inside another
I have a situation that is as follows: I need to make a Tablea in html where I have to show the totalizers and a line and the values that make up this totalizer, as a small example below Revenue =…
-
2
votes1
answer388
viewsHow to work with more than one Python replacement using Replace?
How to work with more than one Python replacement using Replace? Note: Use of FOR or FUNCTION is not allowed and without DICTIONARY. Example: print("Bolacha".replace('a', 'e').replace('o', 'u')) How…
pythonasked 6 years, 5 months ago user110265 -
2
votes2
answers6045
viewsHow to ask questions for the user in Python, without running constantly?
I’m creating a code in Python that asks for the nick of a player and, as the user responds, he will receive a reply, check: player = (input('Digite o nick desejado:')) if player == 'Phil' :…
-
2
votes1
answer112
viewsImports within Python functions
I have seen cases where the developer does the import of a module within a function, some cases mainly in the Django documentation, why it is not very clear to me, if anyone can help me thank.…
-
2
votes2
answers807
viewsPrimitive type int() in Python
I am beginner(1 semester of TADS), the maximum programming I saw was programming logic and now I’ve started to study Python. In the course of Python Video Course he taught that the primitive type…
-
2
votes1
answer125
viewsDjango View class keeps values
A curiosity that has accompanied me for a long time in Django and I never managed to heal: Next. Let’s say I have something like: from django.shortcuts import render from django.views import View…
-
2
votes2
answers2493
viewsError using Selenium Webdriver in Python
I’m trying to develop a script in Python that simply open the browser as shown on that site Selenium with Chrome, but every time I try to run the program I come across the following error: browser =…
-
2
votes0
answers166
views(Socket) Client and Server Connection - how to get Cmd-> Client (Python) return
I want to execute a command in the client’s Cmd and return the values to the server. I Already Managed to Execute the command in the client’s Cmd... Now how do I return the values to the server? The…
-
2
votes1
answer1399
viewsCreating a bar graph to compare data
I’m taking the Science Data Course from Udacity. It’s my first contact with programming, so don’t judge the silly mistakes haha. I’m comparing two data frames with information from cars of the year…
-
2
votes1
answer509
viewsCalculate the Cartesian product with functional programming
I’m writing a Python function that takes two lists and returns a list of tuples with the Cartesian product of the input function. I cannot use any ready-made Python library function. Ex:…
-
2
votes2
answers426
viewsLists in PYTHON
I’m using lists to do a little programming. Initially I wanted to make a program that created as many variables as the person wanted, but I found an easier way. I thought I’d create a list and add…
-
2
votes2
answers2568
viewsChange the value of a number in a matrix without knowing the position (index) in Python
Hello, How do I change the value of a number in a matrix when I don’t know what its index is and there might be more than one value to change? For example, if I have the matrix: [[4,5,3,15,4],…
-
2
votes1
answer340
viewsPython : 'int' Object is not iterable Random function
I’m having this mistake when I run the code. If I define pos=(algum numero qualquer) code runs normally ,but if I use this error function. 'int' Object is not iterable in line 20 at first. Where am…
-
2
votes5
answers6866
viewsIndicate whether a character is a vowel or a consonant
Write the function vogal which takes a single character as parameter and returns True if it is a vowel and False if it is a consonant. Note that: vogal("a") must return True vogal("b") must return…
pythonasked 6 years, 4 months ago Uilson Pasafam 31 -
2
votes1
answer65
viewsHow do edits count during debug?
When I am debugging a code in Pycharm (Shift+F9) and make some changes, it is not recognized during the same debug session. I am obliged to restart the debug again for the changes to be recognized.…
-
2
votes2
answers218
viewsSee how native functions were written - Python
There is a practical way to check, how is written the code of any Python function, example max()?
-
2
votes1
answer83
viewsGet String Type Data from a CSV Document
I have a CSV (Excel) document with valid and invalid emails. And I wanted to take the values of the fields in the form of string, but the following code gives the return shown below: import csv…
-
2
votes2
answers1256
viewsClient and server programming: How to achieve numerous data exchanges per client and multiple clients simultaneously?
The client: from socket import * serverHost = 'localhost' serverPort = 50007 # Menssagem a ser mandada codificada em bytes menssagem = [b'Ola mundo da internet!'] # Criamos o socket e o conectamos…
-
2
votes1
answer83
viewsPython dunders __copy__ e __deepcopy__
I’ve seen it in some codes, especially Django dunders __copy__ and __deepcopy__, the idea by traś them I understand that provide copies of the object, but usually the dunders can be called…
-
2
votes1
answer812
viewsComparison of values in python Tuples list 3.x
My doubt is how I can interact on this list to make comparisons between values. def trocar(vals, posX, posY): temp = vals[posX] vals[posX] = vals[posY] vals[posY] = temp return None def…
-
2
votes3
answers1348
viewsHow to calculate the median of a large amount of values?
I have a list of approximately 1.5 million values and I need to define what is the median of this set. The values are stored in a file such as string, between single quotes (ex.: '155'). How do I…
pythonasked 6 years, 3 months ago Daniel Augusto 23 -
2
votes2
answers445
viewsHow to concatenate value to a column of a table in csv?
I’m having a hard time creating an algorithm that adds an element to the third row in the CSV file in the Python language. The file has following data: Serial; Imei; Número; Icc; Stock…
-
2
votes3
answers2206
viewsHow to not return a None value in Python?
I have the following example code: lista = [100,200,1000,3000,2,3,4,5,6,7,8] def regras(x): if x < 100: if x % 2 == 0: return x if x >= 100: return (x+x) v1 = list(map(regras,lista)) print(v1)…
-
2
votes1
answer174
viewsString search with character "|"
I need to perform a query in a txt file in Python, but I have 2 problems due to interpretation of special characters. When I insert | or \ the result is replaced: the | is addressed as white space…
-
2
votes2
answers396
viewsConvert date string to ISO 8601 format (with "T" and "Z")
With a string date in the format 01/01/2018 13:00:40, how I could convert it to ISO 8601 format using the "T" and "Z"? Example: 2018-01-01T13:00:40Z I got it this way: datetime.strftime(…
-
2
votes2
answers1143
viewsExtract and print specific xml values using Python
Hello :) I am trying to capture data from an xml to use in a search using python, but my algorithm is only returned the data from the last tags, example: The xml is found in…
-
2
votes2
answers908
viewsPython - Transforming lists into a single list
How can I turn a list into a single list? I need to turn this: lista = [["Danilo","Gilson"],["Eduarda",["Costa","Otávio"]]] therein: lista = ["Danilo","Gilson","Eduarda","Costa","Otávio"]…
-
2
votes5
answers691
viewsMethod Reverse returns None
I’m applying the method reverse in a list and the same returns None. Ex. teste = ['audi', 'subaru', 'fiat', 'ford'] print(teste.reverse()) None…
-
2
votes1
answer331
viewsSave entire CSV file to mysql
Goal: Create a program in python that when taking the file data CSV, save to Mysql and generate a chart. What has been done so far: A python program, where it reads the file and prints the data in…
pythonasked 6 years, 7 months ago Marcielli Oliveira 1,597 -
2
votes1
answer239
viewsIs it possible to inherit a python class without writing all attributes in the definition?
I have the following example code: from Testes import POO class Fisica(POO.Cliente): def __init__(self,sexo,nome,idade): super().__init__(nome,idade) self.sexo = sexo Note that the name and age…
-
2
votes1
answer51
viewsTime leaving with unexpected result
I’m running a code that prints the hours on the terminal but when I use the code below it brings me a totally wrong value on time: Code: from time import gmtime, strftime print(strftime("%a, %d %b…