Posts by nosklo • 5,801 points
236 posts
-
4
votes2
answers114
viewsA: Replace numbers that are within a word
I prefer to do this with a replacement function: >>> def f(m): ... text = m.group() ... if text.isdigit(): # se for tudo digito ... return text ... else: ... return re.sub(r'\d', '', text)…
-
2
votes1
answer394
viewsA: Web Scraping with python
Unfortunately, the elements you are looking for are not in the HTML code of the site, but are generated dynamically via Javascript after the page is loaded in a browser. Since Beautifulsoup does not…
-
0
votes3
answers733
viewsA: Display only words that have an even number of vowels within a sentence
Hello! Welcome to Python. Initially your code creates a list with a string only inside, I suggest creating only the string, because the list is confusing here: frase = "Foi magnifica a festa ontem."…
-
0
votes2
answers124
viewsA: Httpresponse not returning anything
The image does not show the whole code, but it looks like your view is returning None. You have marked a line of code, but this is not the only line that returns something in this method. In fact…
-
1
votes1
answer194
viewsA: I cannot render html in python 3
The problem is that the syntax {{ variavel }} exists to include common text in your HTML, not to include more HTML code. This syntax causes Bottle to automatically "escape" the entire contents of…
-
1
votes1
answer2376
viewsA: Selenium.common.exceptions.Nosuchelementexception: Message: Unable to locate element: {"method":"id","selector":"//input[contains(@id,
This error means that at the moment that this line of code is running, the page does not contain any element that matches the criteria (element <input> attribute-ridden id availing 'seq'). A…
-
0
votes2
answers2434
viewsA: Check each file size in a Python folder with 'os'
This code takes the sum of all the sizes of all the files in a folder and all its subfolders (in bytes, if you want kb is only divided by 1024 later). The cool thing is that it’s super compact and…
-
2
votes2
answers1213
viewsA: Is there any way to connect Python to a Websocket as a client?
I suggest using the aiohttp because it is asynchronous and so does not need threads: async with session.ws_connect('ws://echo.websocket.org') as ws: await ws.send_str('Olá Websocket!') async for msg…
-
1
votes1
answer112
viewsA: Is there a list of objects when sending requests in html?
As the documentation says here, the request.form is a ImmutableMultiDict who behaves like a dictionary. You can use dictionary methods in it normally, such as request.form.keys(),…
-
0
votes1
answer1226
viewsA: Python Indexerror: list index out of range
Reading at a glance, it seems that the code tries to read from a text file './_inc/filtered.txt' a list of proxies with their ports, separated by : kind of: proxy1.com:1234…
-
1
votes1
answer782
viewsA: Python asyncio and threading
The problem is you’re calling loop.close() before he has the opportunity to run the routine blah. The routine blah is scheduled to run in the loop, but the main thread (which has the loop) is stuck…
-
1
votes3
answers639
viewsA: How to compress python code 3?
You can use the "one line converter", converts any python code into a single line automatically: https://onelinepy.herokuapp.com/ Your code stays like this: (lambda __y, __print, __g: [(lambda…
-
3
votes1
answer78
viewsA: Use await with object that implements the __await__method
the magic function __await__ is for you to create an object "suitable" in the same way as the new reserved word async def... That is, if you use __await__ you don’t need to use async def: class…
-
1
votes1
answer50
viewsA: Problem with pyinstaller+ os.getcwd() on MAC OS
As you can see in the documentation here, during the implementation of a programme frozen with pyinstaller the path of the executable is in sys.executable - the problem is that it does not happen…
-
2
votes3
answers1564
viewsA: Python variable reference return
When we define a variable, basically we are naming a memory address This is incorrect, for other languages, but not for python. In python, there are no variables. What exists are names; The best…
-
1
votes1
answer1902
viewsA: Progress Bar - Tkinter
To update the progress bar, associate a Tkinter variable in it: import tkinter as t from tkinter import ttk root = t.Tk() .... # codigo definindo o resto da interface ... var_barra = t.DoubleVar()…
-
1
votes1
answer1024
viewsA: how do I put a Scrollbar in a python window as if it were a web page, the more content could go down Scrollbar
In Tkinter, frames cannot be rolled. The solution is to create a Canvas and put another frame inside it. That class JanelaRolavel is a Frame containing a Canvas with another Frame inside. Just place…
-
1
votes1
answer733
viewsA: Scrapy for login
The problem is that the user input and password form is not on the page you are loading - the page you are loading only has javascript code, and the form is mounted by this code dynamically. Like…
-
0
votes1
answer122
viewsA: Dúvidas Array Python
The problem is on this line: ws = str(list(filter(lambda w: w.startswith('MSSQL'), v))) The str() ali is converting the result into a string! So when you access ws[1] is taking the second character…
-
2
votes1
answer1358
viewsA: Access Denied when trying to delete directory with PYTHON
First let’s optimize this code: instead of using os.listdir() use os.walk() because it is already automatically recursive. In addition we can treat the folder name as direct date using strptime.…
-
0
votes2
answers228
viewsA: How to use this script for a server list? - Python
Use a repeat structure like the for: meus_servidores = [ ('ip_do_servidor1', 'Administrator', 'senha_servidor1'), ('ip_do_servidor2', 'Administrator', 'senha_servidor2'), ('ip_do_servidor3',…
-
2
votes2
answers406
viewsA: Python calling super() in class that does not implement inheritance
Every class has a base class. When you do not specify the base class, automatically the class inherits from object which is the class "father of all": >>> class Foo: ... pass ...…
-
3
votes1
answer1721
viewsA: Screen Transition - Tkinter
Just put your components in separate frames, then you can change them: import functools import tkinter as t class Tela(t.Frame): def __init__(self, parent, nome): t.Frame.__init__(self, parent)…
-
0
votes2
answers1021
viewsA: How to run a python script that is located on another machine
python does not have remote execution functionality. You need to "mount" the remote folder and provide a local path to python: mkdir /pasta_local sudo mount -t cifs //192.168.0.8/compartilhamento/…
-
2
votes2
answers925
viewsA: How to generate break condition of a repeat loop in Python during its execution?
Your problem is that the function raw_input() "locks" (Blocks) - that is - it waits for user input and does not return until that input comes. The program stops there! time.sleep() also only returns…
-
0
votes2
answers534
viewsA: Python - Select clickable
The code below uses sqlalchemy to create a table in the database and insert random names, then use tkinter to display a list of these names, and clicking displays the selected name. BANCO_DE_DADOS =…
-
1
votes1
answer68
viewsA: Error in Fortran
FORTRAN only accepts unary operators alongside other arithmetic operations if they are within parentheses: G = 6.67408*(10**-11) should be G = 6.67408 * (10 ** (-11)) This should solve the error you…
-
0
votes1
answer250
viewsA: Get multiple Entry Python values
For this you have to create several StringVar, one for each entry: self.entry_vars = [] # lista com todas as StringVars for y1 in lista: sv = StringVar() # cria uma StringVar e armazena…
-
0
votes1
answer2244
viewsA: Convert Python to exe
pyinstaller generates executables for windows if run on windows. Running pyinstaller on linux will generate an executable for linux. One way around that is to use the Wine. Create a new prefix and…
-
16
votes2
answers21590
viewsA: What is the function of "Try" and "except"
The try/except is used for handling exceptions. Exception is when a thing does not occur as planned. It can be said that the programs have a normal flow, and an exceptional flow which are the…
-
2
votes1
answer2279
viewsA: How to install packages on Pip without internet access?
To install a file .whl locally, use pip install normally: pip install arquivo.whl pip install C:\Pasta\arquivo.whl If you have dependencies, you can specify a folder to search for dependencies: pip…
-
0
votes1
answer31
viewsA: How to create a class instantiation using variables from a function return in Python 3?
What you want to do is: a = Sala(*choose_sala()) The * causes each returned element to be passed separately as a separate parameter for the class Sala. See more about this in the official basic…
-
0
votes1
answer30
viewsA: Python - Replace x lines above and below the searched text
The tricky thing is to try to do this using Tkinter functions that are horrible. If possible, extract the text and use python functions - for example regex: result =…
-
0
votes2
answers470
viewsA: Match Checking Python Hangman game
One way is to test if there are still risks in riscos: while erros < 7 : if ' _ ' not in riscos: print('Voce ganhou') Testing: DICA: Animal Pré Histórico... [' _ ', ' _ ', ' _ ', ' _ ', ' _ ', '…
-
2
votes2
answers1183
views -
1
votes1
answer181
viewsA: In Python, how to assign stdout, stdin, and stderr to variables , using the "subprocess" module with the hidden console?
First of all, you can’t use shell=True - if you use the shell, it will not work. Then just create an instance of the secret and hidden class subprocess.STARTUPINFO: info = subprocess.STARTUPINFO()…