Most voted "python-3.x" questions
Python 3 is the latest version of the Python programming language and was formally released on December 3, 2008.
Learn more…3,274 questions
Sort by count of
-
0
votes1
answer94
viewsa bug in the range() function?
I’ve been writing a function for a class that takes a dictionary and converts it into a string to represent a matrix. def __str__(self): grid_str = ['' for _ in range(self.heigth)] for y in…
-
0
votes1
answer503
viewsImport attributes from models classes from another app
Good afternoon guys, I’m good a doubt! I am using 2 Apps in Django admin App1 = Registrations App2 = Controlling Fellows I imported into "Stock Changers" (App2) the app1 model, the "Person" class in…
-
0
votes1
answer726
viewsHow to insert accented characters in Text Entries in Pyqt5?
My text entries in Pyqt5 (Qlineedit, Qplaintextedit, Dialogs,...) do not accept accented characters typed on the keyboard. I can only insert them if I type them in another editor and appeal to…
-
0
votes2
answers136
viewsError whenever using max python function 3.6.1
am starting me in python and in this code I send below whenever the syntax error execution invalidates. Can you give me a help? lst=[6,10, 2, 1, 9, 35] lstord= sorted(lst) lstord.reverse() print max…
-
0
votes1
answer220
viewsHow to make the program write all information?
print('Bem-vindo!') print() numero_contas = int(input('Deseja registrar quantas contas: ')) x = 0 while x < numero_contas: x = x + 1 conta = str(input('A conta é de qual site:')) print() usuário…
python-3.xasked 7 years, 8 months ago BRKappa 41 -
0
votes1
answer104
viewsQueryset model Category, Product and Productimage
Hello, help me assemble this queryset. Briefly the model model.py class Category(models.Model): name = models.CharField('Nome', max_length=100) slug = models.SlugField(max_length=100, unique=True)…
-
0
votes1
answer4423
viewsCSV file reading and data storage in a vector
I have the following difficulty: I need to read the data that is inside a CSV file and store it in an array to perform calculations with such data, but I don’t know how to do it. I’m using Python…
-
0
votes1
answer3155
viewsHow to clear Windows Python interpreter screen?
I’m starting to study Python (version 3), doing several syntax tests using the interpreter for Windows. However, I would like to clear the commands I have already executed from the screen as the…
-
0
votes2
answers16445
viewsHow do I delete a file from a python folder
the code below lists the files of a particular directory, wanted to know how I do to delete only 1 file from this directory def etc(): path ="diretorio"` dir = os.listdir(path) for file in dirs:…
-
0
votes1
answer5061
viewsHow to make the link clickable, to be accessed?
print('-----') print('SITES') print('-----') print() print() print('Duolingo Brasileiro') print('Duolingo Inglês') print('Duolingo Alemão') escolha_site = str(input('Escolha qual versão do site do…
python-3.xasked 7 years, 8 months ago BRKappa 41 -
0
votes2
answers941
viewsHow to turn a String list into a Float list?
If I run this code, it will give a string list: So that I can not make the average number correctly (since it is in string). What can I do to have the number printed in float/int? Does this "bug"…
-
0
votes2
answers783
viewsSet the User logged in to the model as default | Django + Python3
I am trying to learn Django, and with this I am trying to create a simple system of tickets. I have made a lot of progress in my studies, but now I’ve tackled the following problem. How to do by…
-
0
votes2
answers328
viewshow to make the time appear in the window(label)?
I have the following "timer" code, but it does not appear in the window, only in the Python 3.6 console. How to make it be printed in the window? (Obs.: the window only opens when the preset time is…
-
0
votes1
answer697
viewsRender items with Django Forms. Three Models involved, unico Forms
Hello, I’m having doubts to render my model’s items. The system works as follows: User taking an exam Exame. Within each exam has the types of exam ItemExame User generates a report Laudo that pulls…
-
0
votes1
answer4307
viewsHow to make a program differentiate even and odd numbers in python
hello good night I would like to learn how to make a program differentiate odd pairs numbers I have to learn about what ?
python-3.xasked 7 years, 5 months ago 9 98u 27 -
0
votes1
answer96
viewsAverage True Range Calculation
I have the following problem: I performed the calculation of ATR (Average True Range) using numpy library, there was no code problem (exception, etc...) however, the result shows a small decimal…
-
0
votes1
answer311
viewsRecursion - I want to count how many times digits 3 and 4 appear
I want to count how many times the numbers 3 and 4 appear. What is going wrong? def count(x): y=0 if x[0]=='': print(y) return if x[0]=='3': y=y+1 return count(x[1:]) count('23334')…
python-3.xasked 7 years, 5 months ago Yonack 3 -
0
votes1
answer132
viewsStyle of a program’s widgets using Pyqt5
I have been creating a kind of text editing software using python3.5 and pyqt5, and at the stage of creating the packages I ended up noticing that the development version, which used a Pyqt5 package…
-
0
votes3
answers331
viewsAvoiding code duplication without the use of switch/case in the Python language
Friends, I have the following code in Python: data_hoje = time.strftime("%d %b %Y", time.gmtime() ) #data de hoje data_desejada = time.strftime("%d %b %Y", time.gmtime(time.time() + (3600 * 24 *…
-
0
votes0
answers35
viewsHow to insert Weather Underground forecast icons
Good afternoon I’m trying to insert the Weather Underground icons but no Python 3 icons. Below I leave a part of the code. url =…
-
0
votes1
answer187
viewsWriting IP addresses to file, each IP on a different line using Python
from scapy.all import * pkts = rdpcap("lalalao.pcap") for p in pkts: ## print p.time if IP in p: #if packet has IP layer src_ip = p[IP].src dest_ip = p[IP].dst print src_ip f = open('IP_src.txt',…
-
0
votes1
answer106
viewsTraversing a file and splitting its contents into other separate files using Python
from scapy.all import * pkts = rdpcap("lalalao2.pcap") #time slice de t em segundos : 10 minutos t = 600 somaMin = pkts[0].time + t valores=[] for p in pkts: if p<=somaMin: valores.append(p)…
-
0
votes1
answer253
viewsWhy can’t Tkinter execute a 'simple command'?
I would like to understand why in the code below the tikinter (I think this is the problem) can not execute something simple like 'c = c + 1' ? Code: from tkinter import * import pygame.mixer sounds…
-
0
votes1
answer183
viewsHow to search within Python code
Hello, I would like to make a code that when I typed for example, "product name", it checked if there is any word with the name I typed and returned a value, example "200 real". But I have no idea…
-
0
votes1
answer244
viewsHow to keep a fixed value within a recursive function?
I would like to create a variable with the first value passed as parameter in a function, but every time a recursive call is made the variable receives the value of the new parameter passed. For…
-
0
votes0
answers380
viewsReplace matrix elements with an "X"
I have code that should print a matrix according to the input. You should print the matrix so that the "X" forms a right spiral starting from the middle, someone has some idea? ps.:Code comments are…
-
0
votes1
answer576
viewsFiller
Good morning, I have a data frame with air temperature, global radiation and CO2, but my CO2 data are with NaN and I need to find data in other "lines" with similarity to fill Nan by CO2 data.…
-
0
votes2
answers4433
viewsTypeerror: 'str' Object does not support item assignment
I made my "version" of a game I saw in a book. def hangman(a): stages = ["", "________ ", "| ", "| | ", "| 0 ", "| /|\ ", "| / \ ", "| " ] wrong = 0 board = "__" * len(a) letters = list(a) win =…
-
0
votes0
answers108
viewsExtracting source and destination IP to check if the server has become inoperative after attack
from scapy.all import * from collections import deque def print_attack_measure(pcap_file): plist = rdpcap(pcap_file) server_ip = "192.168.1.5" n = 300 d = deque(maxlen=n) # If you want…
-
0
votes1
answer140
viewsReportlab in Heroku - Word error with accent
I’m generating reports with reportlab But when there are words accentuated, I’m taking 500 Internal Server Error in the Heroku. Localhost works just fine. I tried the next one didn’t work out…
-
0
votes1
answer118
viewsMultiprocessing or Multithreading
Good people, recommend what to optimize code? multiprocessing or multithreading? the script is running in series, but has several for in series. Complete code: https://pastebin.com/WtD6XbVT…
-
0
votes1
answer2683
viewsHow to factor n! or ! n?
How to factor a number? n! or ! n Example: Let’s take x = 5 x = input('Digite um número inteiro: ') i = 1 while i <= x: for i in range(x): i = i + 1 a = [] a.append(i) print(a) break Since the…
-
0
votes1
answer318
viewsTypeerror: Len() of unsized Object how to resolve
def invert_map(x): y = _np.empty_like(x) y[x] = _np.arange(len(x)) return y Result gives this in this function : File "E: Anaconda3 lib site-Packages arlpy comms.py", line 74, in invert_map y[x] =…
python-3.xasked 7 years, 3 months ago Sergio Nunes 351 -
0
votes1
answer167
viewsSocket-python syntax error
except socket.error, (errno, msg): if errno == 1: # Operation not permitted msg = msg + ( " - Note that ICMP messages can only be sent from processes" " running as root." ) raise socket.error(msg)…
-
0
votes1
answer248
viewsList empty after python loop
Hello, I have the following code that does this: It will traverse a vector that has a certain set of elements (residuo) with the same ID ([1][1][1][2][2] for example) and then store all elements of…
-
0
votes2
answers8348
viewsSum of elements in lists
[[3, 2, 7], [8, -2, 5], [-1, 4, 3], [2, 2, -9]] Then it stores in three distinct variables, ignoring the negative values, the sum of the elements separately. That is, the sum of the first element of…
-
0
votes2
answers1885
viewsHow to create a board of user-determined size and present it as text using python?
I am trying to create a program in Python 3.6.1 that creates a board according to the size typed by the end user and prints the result in the shell. It needs to be presented as text, and cannot use…
-
0
votes0
answers227
viewsbyte indices must be integers or Slices, not str
itens = [] lugares = [] lugar = None from pickle import dumps # Definição das funções: def adlugar(nome, lookmsg, passagens, objs = None): global lugares global dic dic = dumps(nome) dic = {"nome":…
python-3.xasked 7 years, 6 months ago Pedro Henrique 1 -
0
votes1
answer741
viewsCreate dataframe tuples generated by Pandas
Is it possible to generate a tuple that stores the values of the lines of a dataframe generated by pandas? I uploaded the values of a CSV file to a dataframe, now I need to perform some calculations…
-
0
votes1
answer138
viewsSqlite inoperative in Python executable program created by cx_Freeze
I made a simple application in Python 3.6 and Sqlite3. When I run the main program by cx_Freeze and install it on the machine I developed the application on (where Python and Sqlite are installed),…
-
0
votes0
answers218
viewsCompile py code for exe
I need to compile the script in python to make it . exe, but only with the pure Python kernel, which does not have most of the libraries I used to develop. The kernel I use for development, is…
-
0
votes0
answers69
viewsCustomize . read() and . write() in Python
I’m starting to learn Python and I came up with a question using with to open files, it is possible to pass arguments to the methods arquivo.read() to read a line and jump to the bottom line when a…
python-3.xasked 7 years, 3 months ago Bruno Santos 13 -
0
votes1
answer78
viewsSame code producing distinct results in Codeenvy and Windows 8.1
I had made the following code in codevy.io and Python installed in codenvy is 3.5.1. I took this code and put to run in windows 8 with python 3.6.1. The purpose of the code is to clean some CSV…
-
0
votes1
answer213
viewsHow to make the elements of a tuple to be the arguments of a python function?
I will first remove the problem and then explain what I am trying to do. If you know how to answer the short problem, you don’t need to see the rest. Is there a way to pass the elements of a tuple…
-
0
votes2
answers439
viewsPython graph does not display values correctly
I’m trying to learn how to make graphics in Python. I made one now and it didn’t get very good: All dates are on April 10, 2017, coming only the time from 07h50:00 until 08h40:00 (GMT -3h) In the…
-
0
votes1
answer1866
viewsDecompose the value of a Python banknote
I need to read an integer value and calculate the fewest possible banknotes (ballots) in which the value can be decomposed. Banknotes considered are 100, 50, 20, 10, 5, 2 and 1. And dps print the…
-
0
votes2
answers469
viewsSum recursive sequence
I am implementing a recursive code that adds the following sequence: x + x 2 / 2 + x 3 / 3... x n / n, for this sum, I thought of a definition, combining two recursive functions, as follows below,…
-
0
votes1
answer3354
viewsImport in Python
How do I import in Python being this class created by me? Example: in java I create a connection class and I can import it in the stock class to be able to persist in the bank, but I don’t know how…
-
0
votes1
answer40
viewsError trying to reinstall Python
My Python was installed on partition "D:" (on a normal HD) and my OS on "C:" (on an SSD). I moved the SDD (Partition "C:") from my old computer to a new one and tried to reinstall python in it, but…
python-3.xasked 7 years, 2 months ago Diego Moura 118 -
0
votes6
answers7088
viewsIntersection between two sets (element that is in set A and B at the same time)
I’m trying to make a function that returns the intersection between two sets: def intersecao(conjuntoA, conjuntoB): inter = [x for x in range(1,12) if x in conjuntoA and conjuntoB] return inter a =…