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
votes2
answers2151
viewsHow to avoid "Missing 1 required positional argument" error when one of the parameters is omitted
I have this function in Python: def v(m1,m2): print(m1) print(m2) It gives an error when I do not enter one of the parameters, for example inserted m1 = [1,2,3] and omitting m2: v([1,2,3]) Missing 1…
-
2
votes1
answer273
viewsCancel button on a timer
Hello, I was doing a timer that went up to 100 and then to, and then I had the brilliant idea to put a cancel button on the count. I did some things only that when he says "To cancel type "c"" the…
-
2
votes1
answer2625
viewsCopy and paste using Python commands
I need to know how to make a copy of any text on the screen, simulating the mouse action. For the mouse, I’m using Pyautogui, running the actions. I need to save the copied content and store that…
pythonasked 5 years, 1 month ago Felipe Alencar 31 -
2
votes1
answer72
viewsSelect desired value with REGEX for two different standards
I have the following data entry: INSTANCE-hostname:Sys INSTANCE-hostname-INSTANCE_00:Ins You will always follow this case, where only what interests me is the value hostname, that is, my OUTPUT…
-
2
votes1
answer2321
viewsWhat is None in Python?
I am using the online IDE repl.it. A part of the code has this user input opcao = input(print('Digite:\n1- Acertei\n0-Errei\n\n=')) what gives the exit: Digite: 1- Acertei 0-Errei = None It doesn’t…
-
2
votes1
answer127
viewsDoubt with loop for counter
I want to run this very simple loop: for i in range (1, 5): num = int(input("Digite um numero positivo: ")) if (num < 0): print("Você digitou um número negativo, tente de novo.") If the user…
-
2
votes1
answer87
viewsConsistency in Python results
Hello, I’m studying python code and I came across this line: np.random.seed(0) where it says consistency of results. I searched, but I still can’t understand the function of this command. Could…
-
2
votes0
answers705
viewsHow to replace single quotes with double quotes in python?
I used the function replace to replace single quotes from a field in csv with double quotes, but in output the value comes out with escape character , it is this character remains when clicking to…
-
2
votes1
answer104
viewsFunction . split() buging the output of the string in python2, how to solve?
Hello, I’m new to Python and my question may be obvious, but I would like to better understand the workings of the string; I am facing an error of execution of a function that I created and do not…
-
2
votes2
answers199
viewsHow to reduce formula . replace in Python
I’m with a dataframe where you would like to replace the 0.1 encoding by yes and no. Some columns of the df have this encoding and so I wrote the following command: dados_trabalho =…
-
2
votes1
answer2222
views -
2
votes1
answer42
viewsSearch in Index on Mongodb returning non-existent words, 'Bed' do you think 'Camera'?
Hello I am new in this database and I have made the following index for my documents: produtos.create_index([('Tags', pymongo.TEXT)], unique=False, sparse=True,name='tags',…
-
2
votes1
answer227
viewshow to return an integer in python? - Python
I’m new to python and I have a question about how to return 0 or 1 instead of True and False. Even putting int the output is being "[False, True, False, True, False, False, True, False]" a="101001"…
pythonasked 5 years ago Yan Andrey 75 -
2
votes1
answer4515
viewsPython data output formatting
My question is about formatting output data from the program. I’m solving one of the exercises wiki.python.org, whose data entry is as follows:: alexandre 456123789 anderson 1245698456 antonio…
-
2
votes1
answer276
viewsEnsure that the unit test is validated in an IF. Unit Test
I need to create a unit test that validates the following code. But how can I guarantee that the test validates the downloaded and downloaded content? if not (os.path.exists(filename)):…
-
2
votes1
answer105
viewsString comparison gone wrong - Python
I have this function that checks if the code I typed is in the code list, but even though the code is in the list it does not enter if and returns false. I can’t understand why it doesn’t work.…
-
2
votes1
answer834
viewsPython - Count values within another count of values in a dataframe?
I have a df as follows and I need to make a top 10 of the most repeated words in problem and within these selected words do the same within the solution. Obs: the dataframe has more than 20,000…
-
2
votes0
answers206
viewsError with Python Nmap
I’m trying to make a script on python using the Python nmap, but I keep getting an error on the console when I try to run the script! My code: import nmap import os nmScan = nmap.PortScanner() def…
-
2
votes0
answers51
viewsIs it possible to call a python function via a DLL in C?
I have a commercial program that makes a calculations and allows me to calculate something to feedback the simulation every time step through a DLL code in C. I need to do mathematical optimizations…
-
2
votes0
answers128
viewsError permission denied in python
I was writing a code to try to connect to my wi-fi network using python. I used the following code: from wi - fi import Cell, Scheme try: cell = Cell.all('wlan0') except: print(Exception) passkey =…
-
2
votes1
answer410
viewsWhy can’t I make an "append()" on a list formed from a "Join()"?
I started creating a list in Python leaving each element below the other through the join(). Then I tried to add an element to the list through append(): abc = '\n'.join(['a','b', 'c'])…
-
2
votes2
answers426
viewsunion of lists
I am doing this algorithm where I have to do the union of two lists and the repeated numbers can only appear once. But it’s gone wrong, someone to save me? def uniao(l1,l2,r=[]): if len(l1) == 0:…
pythonasked 4 years, 12 months ago Gabriel Borges 41 -
2
votes1
answer1508
viewsSQL Server Connection - Python
Good afternoon guys I’m having trouble making a connection with sql, whenever I try to make the connection the following error occurs: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL…
-
2
votes2
answers98
viewsWhat is the difference between a string defined within a text file and another defined as a variable?
Imagine the following: texto = "They fly quickly over the snow in their sledges; the motion is pleasant, and, in my opinion, far more agreeable than that of an English stagecoach" texto1 =…
-
2
votes1
answer42
viewsHow can I timeout an attempt to connect to SQL Server using sqlalchemy?
I have a list of 200 hosts to connect. The problem is that when I try to connect to a host that is not available, it takes about 10 seconds for me to receive an exception telling me that I have not…
-
2
votes1
answer232
viewsError: Collections.defaultdict' Object has in Python iteritems attribute
When executing the code below the compiler returns the following message: collections.defaultdict' object has no attribute 'iteritems' I’m using version 3.6.5 of Python. Follows the code: import…
-
2
votes1
answer269
viewshow to use Vue.js interpolation in a Jango template?
Django uses a template syntax tool, called jinja2, which allows interpolation in the html document using double keys. Unfortunately, Vue.js uses interpolation in the same way. <p id="exemplo">…
-
2
votes1
answer1491
viewsBrowse and count records from a JSON
I have a Python code that I can display on the screen all JSON records, only I need to bring only the field 'Nome' and the count of each. First he brings with [] (list format) and I need the…
-
2
votes1
answer1934
viewsPygame does not run a.mp3 file and returns pygame-error
I was touching the Pygame and when performing a program that plays music: from pygame import mixer mixer.init() mixer.music.load('ex021.mp3') # Dark Souls III Soundtrack OST - Main Theme.mp3…
-
2
votes2
answers689
viewsUsing self-free method in Python
I saw in other topics some discussions about passing the self as argument. But it was not very clear to me. Even though my function has no argument to be started I still need to pass the self as a…
-
2
votes1
answer1847
viewsError reshaping an image | Valueerror: cannot reshape array of size 72000 into Shape (1.24000)
I’m trying to use Python with Opencv to then make a classification. However, at the time I will make popular the object, I have the following error: Valueerror: cannot reshape array of size 72000…
-
2
votes1
answer146
viewsHow to use Conv2dtranspose from Keras?
Does anyone know how to use the Conv2DTranspose Keras found in this link : https://keras.io/layers/convolutional/#conv2dtranspose ? Could you explain to me what each parameter of this function does…
-
2
votes1
answer91
viewspop-up with python progress bar
I am currently migrating a system to python and it has a window that opens making the progress bar. In my migration I used the tqdm to generate a progress bar on the system, but in another part of…
-
2
votes1
answer448
viewsPass variable javascript to Django Form
I have a Django form with this "Linked Exam" field that works as follows: The user clicks on Select Exam, goes to another window in which selects an existing exam, and with it returns to the…
-
2
votes0
answers250
viewsPick values between two dates and display in the Django template
I have two models, flow and report, in the stream there is a date field, and in the report there are two fields, start date and end date, I want to make the report show the records in the flow…
-
2
votes2
answers2695
viewsHow to select a Python file using Tkinter
I have the following Python code using the library tkinter: from tkinter import * class Application: def __init__(self, master=None): self.widget1 = Frame(master) self.widget1.pack() self.msg =…
-
2
votes3
answers1958
viewsHow to print list elements in reverse order?
I created a program that takes integers from the user and prints them back in the reverse order that received them, however my program is not returning all integers it receives. When I enter 9…
-
2
votes1
answer704
viewsHow does Python handle common functions and internal Python functions?
I’m looking at Python’s dual functions compared to the common functions that use def to create them. See an example of a common function that converts a number to binary: def…
python function characteristic-language lambda-expressions python-internalsasked 5 years, 8 months ago gato 22,329 -
2
votes1
answer83
viewsPython recursive function
I need to build a recursive function in Python that takes an integer n and print to zero and then go back to n. Example: n = 5; > 5 4 3 2 1 2 3 4 5 Until then I built a function, but it only…
-
2
votes1
answer674
viewszip argument #1 must support iteration (did not understand this error)
I have the following code. v1 = [1,2] v2 = [2,1] def vector_add(v, w): '''Soma entre dois vetores''' return [v_i + w_i for v_i, w_i in zip(v,w)] def vector_subtract(v, w): '''Subtrai elementos…
pythonasked 5 years, 8 months ago Gabriel Menezes 113 -
2
votes4
answers1133
viewsAdd negative elements from a list
I want to add up only the negative elements of a Python list. The code I initially thought was: lista = [12, -2, 4, 8, 29, 45, 78, 36, -17, 2, 12, 8, 3, 3, -52] for n in lista: if n < 0:…
-
2
votes1
answer46
viewsUpside down widgets in Kivy
I have a problem running any Kivy screen, because it always appears upside down. This problem is only with this specific library, the other ones I use work normally. A simple code like: from…
-
2
votes2
answers172
viewsI would like to know how to write >>> print("Size = %4.2f cm" % Size) and what does %4.2f mean
I’m doing a college assignment and I’d like to know what the %4.2f in >>> print("Tamanho = %4.2f cm" % Tamanho) and how a value (8.47826) is represented by following this parameter after…
-
2
votes4
answers333
viewsBring only the values of the Python keys
I need to bring one dict only the values of chave['nota'], but it only brings once. Follow the code: def AlunoeNota(disciplinas, nome): print('Aluno da FHO '+nome + '- SI' ) for nota in…
-
2
votes2
answers61
viewsPass X function as parameter to Y function, but only define X parameter within Y
Does anyone know how to make the code below work? Or some alternative that works, but follows the principle. def f_numbers(number='no'): if number == 'no': return 'Você não definiu um número' else:…
-
2
votes0
answers38
viewsHow to display the content slowly when using the print function without breaking line?
PYTHON 3 import time for i in range (1, 11): time.sleep(1) print (i) RESULT: Screen output every second. Based on the above instructions, every time the condition is true a result will be printed on…
-
2
votes1
answer4368
viewsRun Selenium in Chrome invisibly (headless)
I’m doing a program in Python 3.8 using Selenium and Chromedrive, to access a website through Google Chrome. When it is time to run, the program opens two windows, one of Google Chrome and another…
-
2
votes1
answer194
viewsHow many times has the highest number been read?
I have the following problem: the user enters with the amount of numbers to be read, later I want the largest among this quantity 'X' of numbers to be displayed and also how many times this higher…
-
2
votes1
answer82
viewsWhat is the bincount method of numpy for/what?
I read the documentation but I don’t understand what it does: print(np.bincount(np.array([0, 1, 1, 1, 2, 3, 7]))) The exit is: [1 3 1 1 0 0 0 1]…
-
2
votes2
answers739
viewsreturn python function variable
I have a function that returns several values, and I wanted to pass two of them out of the function, but when I try it returns that the variable outside the function has not been declared. To…