Posts by nosklo • 5,801 points
236 posts
-
3
votes2
answers2695
viewsA: How to select a Python file using Tkinter
To display file manipulation dialog boxes, use the sub-module functions tkinter.filedialog: from tkinter import filedialog as dlg path = dlg.askopenfilename() Below is a list of the functions of…
-
4
votes1
answer926
viewsA: What would be WSGI?
What is WSGI? "Web Server Gateway Interface"... is a layer that lies between the web server and your application. What relationship does it have with my web application? You have to develop your…
-
6
votes1
answer239
viewsA: Where are the objects created in Python stored?
Yes, all created objects only exist in RAM memory, and the same is out of place when the program is closed. If you want to persist data, you need to store it in a persistent storage type, such as…
-
3
votes1
answer79
views -
0
votes1
answer225
viewsA: Python - Button depending on box
First of all, you need to fix that line: Box = Entry().pack() The problem here is that the method pack() does not return anything, so its variable Box will be empty (with None). To store the object…
-
1
votes1
answer1934
viewsA: Pygame does not run a.mp3 file and returns pygame-error
It is likely that the IDE you are using does not use as the current directory the directory where the script is, so when trying to open the file without specifying the path, as you are doing, it…
-
3
votes1
answer1121
viewsA: How to read txt file separated by "|" using Python with the Pandas library?
You can use the module csv to parse automatically: import csv with open('seu_arquivo.txt', newline='') as f: # pular as linhas divisorias: f = (linha.strip('|') for linha in f if '---' not in linha)…
-
1
votes1
answer562
viewsA: Error in subprocess.run( ) in Python 3.7.2
The subprocess.run() serves to execute subprocesses. This means it should be used when you want your script to run another executable program available on your computer. In case you are running the…
-
2
votes3
answers212
viewsA: Problem with number guessing game
It is not necessary to repeat all the code twice just to start over. Instead use a loop like the while to repeat a part of the code using a condition: import random opcao = "s" while opcao == "s":…
-
4
votes2
answers2094
viewsA: Open Python file only works with Windows folders in English
The problem is that the correct, true names of the folders you mentioned are the same English names, Users and Documents. What happens is that there is a viewing hook set in the hidden files…
-
1
votes1
answer42
viewsA: Read XML file with Argparse and convert it to JSON
You are in luck! There is a module called xmltodict that does just that: import xmltodict, json with open('arquivo.xml') as f: d = xmltodict.parse(f.read()) with open('arquivo.json', 'w') as f:…
-
1
votes1
answer78
viewsA: Webscrapping Soup + python export to txt and check with shell script
First to get the first ping only of Virtual RS, just do an if for tr in doc.xpath('//tr'): nome = tr[0].text_content().strip() if nome == 'SEFAZ Virtual RS': valor_ping =…
-
2
votes2
answers323
viewsA: Python-based web Scrapping does not provide complete html page information
The code below uses lxml to parse the page directly from the URL: import requests, lxml.html resp = requests.get('http://www.nfce.se.gov.br/portal/ConStatusAuto?Origem=1') doc =…
-
1
votes1
answer125
viewsA: Is there any way to limit the number of characters in a crypt?
If you want a fixed message size, you have to reverse the logic: just set the size to the largest possible response, and then complete the ones that are smaller with any character. In the case of…
-
1
votes2
answers216
viewsA: Filter objects in DJANGO - published_date__lte
lte in Django you mean "Less than or Equal" that is, less than or equal <=. In case you are filtering the posts whose publication date published_date are less than or equal to the current date…
-
1
votes1
answer95
viewsA: Help with Json and Python
To change the JSON file, the best way is to change in memory and then rewrite the changed file: OS() newip = input("Please enter your new default ip address: ")…
-
3
votes1
answer960
viewsA: How to run a function after a certain time in Pygame?
You can’t use the time.sleep() because it will stop the entire execution of the program. Instead, always let the controller return to your event loop, and do everything you can through events. You…
-
0
votes1
answer501
views -
2
votes1
answer846
viewsA: Take print screen when error occurs on Selenium Webdriver
After the .get() open browser, start an error handling block of type try/except to handle any error that occurs in the script from then on. firefox.get(...) try: ... TODO SEU CODIGO AQUI ... except…
-
1
votes1
answer56
viewsA: Intellisense python
Python is a dynamic language, so it is not possible to know beforehand which methods can be invoked on an object without executing the code. What most Ides do is a static analysis of objects,…
-
4
votes5
answers4459
viewsA: Access dictionary within a Python list
The solutions of the other answers always use a for to search the data sequentially, going through all the records. I will offer here two alternative solutions: The first can only be used if the…
-
2
votes1
answer771
viewsA: How do you put a local file to download in flask or python?
Simply create a folder called static and put the file there; flask creates the route to that folder automatically. Then just direct the download to the link; You can use the function url_for flask…
-
3
votes1
answer459
viewsA: Error while using urllib library
It seems that the certificates are no longer installed automatically on Mac, you need to install them. Run the following command to install certificates: /Applications/Python\ 3.7/Install\…
-
1
votes1
answer207
viewsA: How to use scrapy on Asp.net pages
Scrapy is a module that combines the twisted.web to download the pages and the BeautifulSoup or the lxml to parse them. Your problem is that the button you want to click probably doesn’t actually…
-
0
votes2
answers2447
viewsA: How to automatically download PDF to Selenium? With Python
The problem is that it depends on the site, not always the servers are configured to return the mimetype application/pdf for Pdfs. Just check, through your browser’s developer tools, which exact…
-
1
votes1
answer661
viewsA: How to reduce the runtime of a python script?
I sent your code as python 3 and it was accepted without any modification... See below screenshot of the result: I made a version that got a little faster than yours; To save time I did not convert…
-
2
votes2
answers127
viewsA: Difficulties with the FOR command in Python
Analyzing this part: azmt0 = ang[0] azmt1 = azmt0 + ang[1] azmt2 = azmt1 + ang[2] ... azmt11 = azmt10 + ang[11] Each azmtXX is actually the value of ang accumulated, then we can do the for in ang…
-
1
votes1
answer213
viewsA: python Count of different words with only one counter?
Using that phrase: frase = "olá mundo olá mundo adeus" palavras = frase.split() Now we can use the defaultdict to make a counter dictionary that stores an integer number for each word - we already…
-
1
votes1
answer151
viewsA: Problems with python utf8 encoding
Looks like you’re using the python 2; This python version automatically does the implicit conversion between bytes (that in python 2 is str) and unicode; This can be a serious problem for you as the…
-
1
votes1
answer51
viewsA: I can’t figure out what’s causing this mistake
Your mistake: return grelha[linha][coluna] TypeError: 'int' object is not subscriptable Indicates that this line is trying to access an element contained within an object int, as if it were a list.…
-
3
votes1
answer347
viewsA: Scraping data using Robobrowser
Robobrowser is a module that combines the requests to download the pages and the BeautifulSoup to parse them. Your problem is that the button you want to click probably doesn’t actually exist even…
-
2
votes1
answer4550
viewsA: How to make a Console menu in Python
The function input() asks the user to type something, and then returns a string containing what was typed by the user. In case, you are calling the function here: str(input('Escolha uma opção: '))…
-
1
votes1
answer99
viewsA: How to schedule a schedule with kivy
When defining class methods, the first parameter is always the class instance being used to call the method, and is passed automatically by python. By convention, the name self: def…
-
0
votes1
answer234
viewsA: Error creating function in Python 3.7.0
When defining a function, we place in parentheses the name of variables that will receive the parameters passed for its execution. For example, a function that takes the name of a file and opens it…
-
1
votes2
answers1097
viewsA: How to search for a word in a file and pull the phrase where it is together with the result?
You need to divide the text into sentences. The example below uses the endpoint . as a phrase delimiter: with open('Vidas Secas.txt') as arquivo: texto = arquivo.read() frases = [frase.strip() for…
-
1
votes1
answer169
views -
0
votes1
answer469
viewsA: Application with login and access control (Error: Typeerror: 'Nonetype' Object is not subscriptable)
TypeError: 'NoneType' object is not subscriptable Let’s analyze the error message. You’re saying an object of the type NoneType is not subscriptable. Well, the only object NoneType that exists is…
-
1
votes1
answer1852
viewsA: Define matrix in python
The problem is that you are mixing two techniques. One way to do it is by using the forstructured one on each line: matriz = [] for n_lin in range(5): linha = [] # cria uma linha para a matriz for…
-
0
votes1
answer122
viewsA: Learning to Program - PYTHON IDE
This error is common, missed to put the line # coding: utf-8 This should be the first line, you should put it in all the files .py that you create with this editor. The reason is that your editor…
-
1
votes1
answer33
viewsA: A (CTRL + A) in telnet client
Ctrl + To is byte 1. You can test as follows: import sys print(sys.stdin.readline()) Spin and type Ctrl + To and Enter, the result: '\x01\n' so to send it just send this character: mess = "\x01XXXX"…
-
1
votes1
answer651
viewsA: Python - Dismembering text file
A more direct way would be to create a list of open files, where you have a file for each fruit. So you can have a single code that writes to all files directly without having to split into lists in…
-
1
votes1
answer86
viewsA: Find a value in a given column in a.txt file
Have you said what happens when you run, if you make a mistake, or if you have some other problem in the result. Since we don’t have the file, just you, there’s no way to guess what’s going on. One…
-
2
votes1
answer42
viewsA: Create a function that reads a list correctly
Since your file seems to be separated by semicolons, I suggest you use the module csv to read it instead of splitting lines manually. To solve your problem, one of the most elegant ways is to use…
-
1
votes1
answer242
viewsA: Omdb API sorting python dictionary items
Use the sort function sorted(), it allows you to pass a parameter key= containing a function that serves to define the sorting key. In case we can use operator.itemgetter to create a function that…
-
1
votes2
answers1013
viewsA: How to initialize this Tkinter Photoimage function?
The class PhotoImage of tkinter is used to display images in Labels, Buttons, Canvas and Text. The method _show() is an internal method of the object Image; It should not be called directly. A tip…
-
1
votes1
answer1142
viewsA: How to fix this Json error
This error occurs when the first letter of the string is not valid in JSON. It’s very common when you think the site will return JSON, but it returns HTML for some reason, because Htmls usually…
-
1
votes1
answer1193
viewsA: How to send images via socket in Python?
EDIT: Now with the code and the error is much easier to help. UnicodeDecodeError occurs when trying to turn into a string a byte sequence that does not match the encoding used. From the error text,…
-
2
votes1
answer673
viewsA: How to save binary files in python?
Every file is a sequence of bytes, so, every file is "binary". To only thing that you can store in a healthy file bytes. Whatever you’re thinking of saving to a file, go had which convert into bytes…
-
4
votes1
answer559
viewsA: Read file information. txt using Python
You can use regular expressions to parse these lines. import re with open('seu_arquivo.txt') as f: for linha in f: indice, restante = linha.split(':', 1) registro = {k: (float(v1), float(v2)) for k,…
-
2
votes3
answers78
viewsA: Difficulty with first code
You should test using the operator in to know if an object is part of a sequence. If you want to know if the object is not in the sequence, use not in. For example: if elemento in alcalinos:…