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
-
1
votes1
answer584
viewsCreating Table/BD with Django?
I use python 3.4 and the latest version of Django, I am using the command "python Manage.py sqall" but does not recognize the sqall command. (I’m trying to create a table in Bd, and already insert…
-
1
votes2
answers54
viewsDoubt with Lists
When I type this command in the console, it returns me an empty list. But if I create a file and have it executed, nothing appears, what happens? How should I do? lista = [] x = 1 while x > 0: x…
-
1
votes2
answers52286
viewsWhich operator is equivalent to different in Python?
I know some other operators: Greater than: > Less than: < Equality: == But the "different" operator, as it is in Python?…
-
1
votes2
answers180
viewsProblem with importing files into different directories
I’m having a problem using different files in different directories, this is the directory tree of my project: DeatHash ├── deathash │ ├── deathash.py │ ├── dictionaries │ │ ├── dictionary_test.txt…
-
1
votes1
answer266
viewsSelenium + Python error when using time.Sleep()
I am automating a task on a website using python + Selenium. Every time I use the time.sleep() will run the time of Sleep returns this error. ConnectionAbortedError: [WinError 10053] Uma conexão…
-
1
votes0
answers46
viewsGet the Start Address from a process thread and finish it individually
What I want to do is open up to check if a process is open, see the thread list, identify it by Start Address, and finish a process-specific thread. I can do it manually by the processhacker, but I…
-
1
votes1
answer279
viewsEncodings do not work in an Opencv file in Python 3
I followed the face detection tutorial using Opencv and wrote in Python 3. This file is not used print. I already know that Python 3 is international, is compatible with UTF-8 and does not need…
-
1
votes1
answer127
viewsProblem presenting date in Qtablewidget in python with Pyqt5
I have a program that shows product information and I wanted to present the date, only when the date comes up, this is what it shows: PyQt5.QtCore.QDate(2018, 7, 7). For those who need the code…
-
1
votes3
answers1041
viewsSort sequence of numbers from a TXT file
I have a TXT file with numbers separated by spaces and I want to sequence from the smallest number to the largest, just the numbers from the first line of that file. The logic of sequencing I…
-
1
votes1
answer632
viewsTraining of images in tensorflow
Good night! I’m trying to build a neural network in python using tensorflow and its other libraries, my doubt and, I have 4 classes and I need to do a training of them I have many images for each…
-
1
votes1
answer34
viewsBytearray disk size
Suppose I convert some image to bytearray. with open("img.png", "rb") as imageFile: f = imageFile.read() b = bytearray(f) print b[0] How do I know how much disk space this bytearray will take over…
-
1
votes1
answer507
viewsCalculation of the maximum value for an expression of natural numbers using Python
Natural data m and n determine, among all pairs of natural numbers (x,y) such that x < m and y < n, a pair for which the value of the expression x*y - x**2 + y is maximum and also calculates…
-
1
votes1
answer1889
viewsPrint in ascending order the natural first n which are multiples of i or j or both
Data n and two positive integers i and j different from 0, print in ascending order the first natural n s which are multiples of i or of j and or both. Example: For n = 6 , i = 2 and j = 3 the…
-
1
votes1
answer4911
viewsEoferror type exception treatment
while True: try: x = input().split() l.append(x) except EOFError: break I’m having a problem with this code where I’m not getting an EOF from x, because if I don’t type anything and just hit enter,…
-
1
votes3
answers2181
viewsPython functions-Global and local variables
Is there a way to let the variable from within a (local) function go global? If not, what way can we declare a global variable?
pythonasked 6 years, 4 months ago Antônio Gally 39 -
1
votes1
answer98
viewspython - strange loop
I’m almost done with my application. In the final moments of the code I’m locking into a loop that I can’t resolve. # O programa pede para o usúario inserir uma data no formato dd/mm/aa, # e efetua…
-
1
votes1
answer213
viewsGood practice of python tests
I am a week studying tests in python, I started with unittest and some doubts arose... I must use a test class for each method of a class, or use a test class for each class...and yet, how to…
-
1
votes1
answer416
viewsHow to define in the parameters the type of arguments that should be sent?
Crude example of what I want (that doesn’t work): # -*- coding: utf-8 -*- def a(int(b), str(c)): # Isso não funciona, mas quero algo assim. print('Isso é um Numero: %i' %b) print('Isso eh uma…
-
1
votes2
answers355
viewsGet CSV list with Python
I have a CSV file with more than 9000 lines. I need to get a list with only one data of each line. An example is the following: 01/02/19,carlos,casa,rio 03/05/18,luis,carro,maceio…
-
1
votes1
answer55
viewsIs it valid for two objects to have reciprocal references?
Is this an acceptable practice or is it a gambit and shouldn’t you ever do it? Is there any solution to avoid this? It turns out that the player object needs to know what the state of the game is in…
-
1
votes3
answers268
viewsError when calculating a loop value
#O usuário informa o número de alunos totais na sala, em seguida são declaradas as variáveis que complementarão os loops alunos = int(input("Qual o número de alunos na sala?\n")) notasAlunos = []…
-
1
votes2
answers50
viewsGet list names that are 4 in size
I am trying to solve the following problem: from a list of names, I need to return only the names with len 4. I wrote the code below but apparently the loop is not working since, in a list with 4…
-
1
votes1
answer245
viewsWhat are the impacts of excessive use of Try/Except (Exception Treatment)?
I create a lot of programs with a graphical interface and a lot of user interaction. I always exaggerate on try/except. What are the impacts of excessive use?
-
1
votes1
answer584
viewsWhat can’t be done with f-string that you can do when using . format?
Hello I would like to know in which cases I need to use the format method instead of f-string because with f-string it is not possible to do. For example I think it is not possible with f-string to…
pythonasked 6 years, 4 months ago Mateus Cardoso Silva 69 -
1
votes1
answer226
viewsHow to Communicate Between Threads and Pyside Qt?
The graphical user interface window created in Pyside is normally executed following the normal program flow. The actual python script of the program runs in a Thread in parallel. But this thread…
-
1
votes2
answers1183
viewsHow to create a Python directory inside a server?
Using the function mkdir it is possible to create a file in any directory inside the folders of the computer: Import os diretorio = "C:\\Users\\CRIACAO 2\\Desktop\\teste" os.mkdir(diretorio) But…
-
1
votes1
answer112
viewsHow to avoid repeating commands through a function?
I am creating a program to do some math math with some commands and has 1 line of code that repeats in all conditions, with only a small change in each of the conditions. My question is how to…
-
1
votes1
answer471
viewsAlgorithm Graphs to solve Sudoku
I’m having a doubt, my code when it runs in one of the examples of Sudoku, it prints at the end the expected result, the other example of sudoku it does not print correctly the expected result. I’d…
-
1
votes1
answer108
viewsDjango tests are not recognized
When executing the test commands of Django, no test is recognized. My file structure is as follows: Eagle/ eagle/ __init__.py settings.py urls.py wsgi.py dashboard/ __init__.py admin.py apps.py…
-
1
votes1
answer84
viewsHow to get Windows Primary and Secondary DNS using Python?
My Python program needs the following machine information to work: DNS Primario. DNS Secundário. How can I get this information using Python?
pythonasked 6 years, 4 months ago user110265 -
1
votes1
answer357
viewsraw_input and python print do not work in functions
Good people I’m starting now in python and I have to create this project of a quiz that completes the spaces of the sentences. But my difficulty is in understanding why the raw_inputs and print are…
pythonasked 6 years, 8 months ago KelvinLopes 11 -
1
votes4
answers365
viewsRepetition for calling variables
I have four variables [t1, t2, T3, T4], and each of them was defined as a string previously. t1 = 'A vida vai ficando cada vez mais dura perto do topo.' t2 = 'A moralidade é a melhor de todas as…
-
1
votes1
answer512
viewsAbstract classes in Python
The method __subclasscheck__ should be defined at metaclass level, whereas the method __subclasshook__ can be defined as a class method provided that the class has as a metaclass ABC (or one of its…
-
1
votes1
answer611
viewsAttributeerror: 'tuple' Object has no attribute 'reshape'
Error: AttributeError: 'tuple' object has no attribute 'reshape' Code: xx, yy = np.meshgrid(np.arange(x_min, x_max, h),np.arange(y_min, y_max, h)) y_pred = y_pred.reshape(xx.shape) plt.figure() In…
pythonasked 6 years, 3 months ago Lucas Castro 25 -
1
votes1
answer1333
viewsCalculating the execution time of a program
How do I add a "timer" at the beginning of the program and during the execution I can read the time since the beginning of the program in seconds?
-
1
votes1
answer2323
viewsWhat is the difference between Python versions 3.4, 3.5, 3.6, 3.7?
I thought Python only updated versions 2.7 to maintain compatibility but 3.x abandoned earlier versions. But he insists on updating versions 3.4, 3.5, 3.6, 3.7 constantly. What these various…
-
1
votes2
answers3158
viewsWrite a python script that reads an 8-digit integer
Write a program that reads an 8-digit integer number. The output of your program must be the sum of all digits of the given integer. If the number typed does not have 8 digits, the program must…
pythonasked 6 years, 7 months ago user108684 11 -
1
votes1
answer1024
viewshow do I put a Scrollbar in a python window as if it were a web page, the more content could go down Scrollbar
I wanted that when entering the program window using Tkinter, it would be possible to use a Scrollbar to search for more items in the window so that it does not get its limited height, being able to…
-
1
votes2
answers4781
viewsSum of column totals
I own this dataset: I would like to create command to sum up the values of each year, and put in a list. lista=[] for i in range(2008, 2041): area[i].sum() lista.append(i) But it didn’t work out the…
pythonasked 6 years, 3 months ago user9080886 21 -
1
votes1
answer68
viewsCode review: Threaded server to handle multiple clients
The server with Threading: import socket from threading import Thread def Servidor(): servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ip = "0.0.0.0" porta = 8884 servidor.bind((ip,…
-
1
votes1
answer168
viewsProgram to convert mp3 using multiprocessing module is looping
import subprocess from multiprocessing import Process, Lock def ConverteMusica(a,lock): input_file_fmt = '{}.mp3' output_file_fmt = a for x in range(1, 5): subprocess.call(['ffmpeg', '-i',…
-
1
votes2
answers558
viewsImports into __init__.py file
I’m studying the documentation of Django and noticed that in some files __init__.py there are imports, I know the archive __init__.py defines a module but do not understand why imports in it.…
-
1
votes1
answer3264
viewsChange Column Data using Pandas
I’m trying to learn panda but I’m having a question here I have the following data: PSG CLASS AAA 1 BBB 2 CCC 3 DDD 1 I wanted to create a new column, using Pandas, with the name Class and with the…
-
1
votes1
answer2705
viewsI can’t close the Tkinter Window
Well I am making a python application using Tkinter, I made a login window after checking user and password I would like to open a system window and close the login window. I’m breaking my head and…
-
1
votes0
answers118
viewsHow to reduce the instruction block inserted within a conditional if structure in python?
Hi, I’m developing a program that calculates and sizes wall beams. It works basically with security checks (request less or equal to resistance), when one of these checks is not met, the program…
-
1
votes1
answer3104
viewsPython string corrupted with character
I have a program that creates for your running another program on the user’s computer. In a snippet, I define the directory to which the new program will be intended as diret = "C:\\Users\\" +…
-
1
votes1
answer75
viewsGhost repetition structure
maze = """\ ############## # # # # # ########## # # X# # ## #### # # # #### # # ############## """ EMPTY, BLOCK, STEP, END ,WALL=" ", "*", ".", "X", "#" UP, DOWN, LEFT, RIGHT = "˄", "˅", "<",…
pythonasked 6 years, 7 months ago Marcos Vinícius 124 -
1
votes1
answer172
viewsOn big scrapings how to avoid Connectionerror?
In Python 3, I have a program to make web-scraping tables on websites. There are 5,299 pages, on each page there is a table With XHR I found the generated JSON on each page. But there is always a…
-
1
votes2
answers2434
viewsCheck each file size in a Python folder with 'os'
I’m having a hard time figuring out the size of each file (in KB) in a certain folder. Initially I listed all the files with 'os.listdir' and I believe it has something to do with 'os.stat' to find…
pythonasked 6 years, 3 months ago Thiago Cruz 49 -
1
votes2
answers174
viewsPrint reverse order
Given a number x, where 1000 x<10000, prints the number x with its digits in reverse order. For example: x = 2736, the answer will be 6372. x=float(input()) x=float(x) if (x >= 1000 and x <…