Posts by nosklo • 5,801 points
236 posts
-
3
votes1
answer455
viewsA: How to install Jupyter Notebook autocomplete?
%config IPCompleter.greedy=True Just press the button TAB to complete…
-
4
votes1
answer32
viewsA: How to make the program recognize a name with spaces next to a float?
Instead of dados = input().split() use the rsplit dados = input().rsplit(maxsplit=1) This will cause the user input to be divided from right to left, dividing only once - so all words will be in…
-
3
votes1
answer244
viewsA: Parallel scripts using Threading - Python
You don’t need threads for this. Use the module subprocess and you can start multiple processes without blocking the main thread. In addition, the module subprocess allows you to run python only. If…
-
4
votes2
answers60
viewsA: ola I am having difficulty in knowing how to link a question with a response of 2 separate lists (a list of questions and one of answers):
As the question and the answer are in separate lists, when drawing a question it is difficult to find the corresponding answer. There are several ways, I’ll mention a few: Instead of using…
-
1
votes3
answers110
viewsA: Bubble Sort algorithm error in Python
Your code is correct, the problem is that you are using strings. Strings are not compared numerically but alphabetically, because they can contain letters and other characters... So '10' is actually…
-
0
votes4
answers747
viewsA: Get the most frequent and least frequent element from a list, plus the largest and smallest
Simpler than the other answers, you can use max and min for everything. These functions have a parameter key that can be passed to pick up the number with more/less occurrences. print(max(numeros))…
-
0
votes2
answers107
viewsA: Save manipulated audio files keeping the original name
The original sound file is being read while the conversion is done, so it is not possible to use the same name for the result. You have to use a different name. What you can do is generate a…
-
0
votes1
answer129
viewsA: Read files in python
The problem is related to your variable l; It is defined by for: for l in range(0,7): print(arquivo[l]) When this for executes, the variable l increasing 0 to 6 and the print will print the 7 lines…
-
2
votes1
answer637
viewsA: How to access data in json and save to a variable in python? flask-api
The method get_json() already treats the json and returns to you the converted object in python: data = request.get_json() Here data is already a python dictionary, data['title'] and data['body']…
-
0
votes1
answer41
viewsA: Typeerror in INSERT via Python in Postgresql
You can insert row by row by just using a for: with open("arquivo.json", encoding="utf-8") as arq: for linha in arq: cursor.execute("INSERT INTO tabela (coluna) VALUES (%s)", (linha,)) Notice the…
-
0
votes1
answer128
viewsA: PYTHON - How to pass a parameter?
One solution is to create a function that calls its other function; so the parameter you want to pass will be captured by the scope of the function (known as closure): snake =…
-
3
votes1
answer80
viewsA: How to draw random numbers repeatedly so that the same number is not drawn?
Check if the number typed is in the try list. If so, ask/draw another number, before increasing the number of attempts: while True: y = randint(0,10) if y in lista_tentativas: continue # ja existe,…
-
1
votes1
answer44
viewsA: Typeerror at /export_to_xls/ unorderable types: str() < int()
Please edit your question: Code indentation is wrong; The mistake is not with the traceback in addition to part of the traceback is in image form, where it should be plain text; The mistake is in…
-
5
votes1
answer273
viewsA: Python os.mkdir, file exists
Try to use the os.makedirs(), it has a parameter exist_ok that when True no error if directory already exists. os.makedirs(video_name[:3], exist_ok=True)…
-
1
votes2
answers179
viewsA: Skip line in XML with Python
Theoretically you don’t need to add these spaces. The XML format is meant to be consumed by other programs and not by humans, so you don’t need these line breaks and indentations. The program that…
-
4
votes1
answer134
viewsA: Loop to perform quantity processes in quantity
No need to use multiprocessing to start a process that will use os.system to run a shell (another process) which in turn will run another python process to start a script!! This way you are running…
-
0
votes1
answer295
viewsA: def post(request): or request.method == POST?
Short answer: neither of the two! Long answer: Each web framework has a different way of dealing with different types of requests, but in this case we are talking about the Django. Django has…
-
1
votes1
answer284
viewsA: Package code in python
It is possible, but for that, you will have to abandon the status of "a project that contains only one file . py"; you will have to include other things. Fortunately there is a tool for this…
-
2
votes2
answers95
viewsA: Remove specific set from the end of the regex array
I know the other answer has already been accepted, but I think it is worth adding to anyone reading this question in the future: Do not use regexp for this, the operation in this case is too simple…
-
6
votes2
answers335
viewsA: Remove cmd/dos window when calling Python App
Use the pythonw.exe to run the application instead of python.exe; To do this, rename your app.py to the extent app.pyw because this extension is already associated with pythonw.exe.…
-
0
votes1
answer115
viewsA: I can’t read column on pandas
I don’t know where you got these columns from, but it looks like your dataframe column is named after 'Idade ' and not 'Idade'. Try using the command: pessoas_frame['Idade ']…
-
0
votes3
answers1384
viewsA: Problem with Python matrices
The problem lies in that line: matriz = [[0] * c] * l We will divide it into two commands to facilitate the explanation: linha = [0] * c matriz = [linha] * l When creating the internal list (called…
-
1
votes2
answers1055
viewsA: Elaboration of cipher in python
Python has a perfect function for the César cipher, which is the str.translate: def cesar(texto, deslocamento): alfabeto = string.ascii_lowercase alfabeto_deslocado = alfabeto[deslocamento:] +…
-
1
votes1
answer183
viewsA: Kivy Filechooser how to select a directory
Use the property dirselect: https://kivy.org/doc/stable/api-kivy.uix.filechooser.html#kivy.uix.filechooser.FileChooserController.dirselect fc1 = FileChooserIconView(size_hint=(1, .9),…
-
1
votes2
answers171
viewsA: os.path modulo python
Like os.listdir() returns the contents of the folder name by name, without the path, the author used os.path.join() to create strings with the full path. os.path.join() joins two or more pieces of a…
-
0
votes4
answers2181
viewsA: Check file extensions in Python
Another way would be to use os.path.splitext(), is a specific function for the purpose of separating an extension from the file name. import os for nome_arquivo in os.listdir(path): nome, extensao =…
-
0
votes3
answers394
viewsA: Leave each word in a row (Text file) - Python
You can use regular expressions to split words. This makes it easy to ignore special characters such as commas and dots. The code gets simpler too: import re with open('seu_arquivo.txt') as arquivo:…
-
4
votes1
answer347
viewsA: What are dataclasses and when to use them?
An example of the use of dataclass that will be referenced throughout the explanation: from dataclasses import dataclass @dataclass class Item: nome: str preco_unitario: float quantidade: int = 0…
-
3
votes2
answers180
viewsA: Doubt about Python derived class initialization
In your example, there is no difference, it is the same thing. The difference only appears when you use diamond-shaped multiple inheritance: A / \ B C \ / D class A: def teste(self): print("teste em…
-
1
votes1
answer1068
viewsA: List and Access Python subdirectories
The command os.chdir() is changing the current python directory, however, when you will access it you are always using the variable caminhoPAI that is not being altered... A (partial) solution would…
-
0
votes1
answer42
viewsA: Help Tkinter opening a Python application
Modules are executed when they are imported, only once. See what happens, for example, in this line: import Cadcordenador This command compiles and executes the full contents of the module…
-
1
votes1
answer156
viewsA: How to find a value between two tags in an HTML text? Other than "XPATH"
The content of the page you want to extract is structured with a Markup language, HTML. Use this in your favor: Use an html parser. I recommend the excellent lxml.html, because it works with…
-
1
votes2
answers978
viewsA: How to return a json to the same Django template?
Your mistake is Object of type 'ndarray' is not JSON serializable That means the json module is working, it’s trying to convert something to json, and it doesn’t know how. This "thing" is an object…
-
2
votes2
answers253
viewsA: Extract content from "Name:" field until end of line
You can use the flag re.MULTILINE which serves precisely to search for text in multiple lines in a simplified way: >>> import re >>> texto = 'a1in1iionia\n\nDados do cliente\nNome:…
-
1
votes3
answers550
viewsA: Input jumps line, how not to jump in Python?
To avoid skipping lines, nothing needs to be done - the input() no longer jumps lines as you showed in your question. There must be some something else wrong in your code, which is causing this line…
-
2
votes1
answer360
viewsA: How to limit the number of threads running at the same time?
The most direct solution is to use a variable threading.Semaphore to count how many threads are currently running: s = threading.Semaphore(10) for i in threads: s.acquire() i.start() Hence it is…
-
0
votes1
answer86
viewsA: How to sort elements from a list using Selection Sort?
The problem is that your file has text and not numbers. In the same way that 'B' is greater than 'AA', '2' is also considered larger than '11' if they are being treated as texts. A simple way to…
-
1
votes2
answers78
views -
0
votes1
answer97
viewsA: Selenium Staleelementreferenceexception Problems with Python
This error only occurs in two situations: When the element you are referencing is removed from the page, via javascript or other method. That’s the most common situation. Something occurs on the…
-
0
votes1
answer610
viewsA: How to collect snippets of a text with the Pageobject object from the Pypdf2 library?
Take the position of lc in the text: pos = text.find('lc') Then use this variable when getting the slice you want: print(text[pos:pos+10]) Another option is to use regular expressions: import re m =…
-
0
votes1
answer118
viewsA: How to convert a text in Mathml to Latex using Pandoc?
The URL: http://pandoc.org/cgi-bin/trypandoc Place this url in url_pandoc and will be resolved. The explanation is simple. The page http://pandoc.org/try/ is dynamic and loads the elements via…
-
0
votes1
answer340
viewsA: Hello, in Tkinter how to take the value of the sum generated by numbers and compare with the user input?
Your question is not very clear. Tkinter has nothing to do with with sum of numbers, it is only a visual graphical interface for the user to interact. The part of adding up random numbers and…
-
0
votes1
answer1290
viewsA: TXT OF BANK EXTRACT (RELEASES)
It seems that the columns are fixed. Create a dictionary with the positions of each field within the row: coordenadas = { 'dt_movimento': (3, 13), 'dt_balancete': (18, 28), 'ag_origem': (36, 40),…
-
0
votes1
answer51
viewsA: The best way to make an information search program
You do not need to define a function within the loop, or it will be created every time you repeat. The function could be outside the loop, or it simply doesn’t need a function in this simple…
-
0
votes1
answer179
viewsA: Export Postgre SQL table to text (csv) via psycopg2
As you can see in documentation, copy_to is a class method cursor: cur.copy_to(f, 'wphd.empresa', sep=';', null='')…
-
2
votes1
answer321
viewsA: Tkinter Python Toplevel
Your problem is that there are two variables with the same name teste. One created in the scope of the module, and another site created within the scope of the function. You are assigning a value to…
-
0
votes2
answers50
viewsA: Error in Python method call (list)
The example below defines the variable month in a loop that runs through the 12 months (1 to 12). def year(self, execution_times): return [self.month(execution_times, month) for month in range(1,…
-
2
votes1
answer85
viewsA: What is the purpose of the "Pyobject" structure and what are the objectives of its members?
This structure is an implementation of the python language object system - each instance of any python object is stored in such a structure. There are two. A PyObject that you showed up and the…
-
1
votes1
answer515
viewsA: Mysql and python error when entering data
A tip, to read files csv use the module csv, instead of splitting the data yourself, it’s much easier. Now, by answering your question to insert data into mysql using mysql Connector, you should not…
-
3
votes1
answer89
viewsA: Tkinter Python stopping the script
The problem is that the line mainloop() is holding the execution. This function gives Tkinter control of the script, so that it responds to events such as pressing buttons, etc, until it is closed.…