Posts by Guilherme Carvalho Lithg • 646 points
39 posts
-
0
votes1
answer45
viewsQ: Replace multiple substrings of a dictionary
I’m trying to make a replace, but I’m not getting it. My code: dicionario = { "uva":"R$ 5,00", "abacaxi": "15%", "abacate": "preço: N/A" } for key, value in dicionario.items(): if 'R$ ' in value or…
-
1
votes1
answer329
viewsA: How to redesign a window with Pyqt5?
I was able to update the widget and decided to respond here to help anyone with the same problem. Whenever a new item is added, simply call the function refresh after the action. On the model: def…
-
1
votes2
answers3755
viewsA: Open new tab using Selenium and python
You can try it: # Abre uma nova aba e vai para o site do SO driver.execute_script("window.open('http://stackoverflow.com/', '_blank')") # Muda de aba…
pythonanswered Guilherme Carvalho Lithg 646 -
0
votes2
answers563
viewsA: Selenium (list of elements of a class)
You can access the attribute href of each element of the class and open this url in a new tab. So: lista_elementos = driver.find_elements_by_class_name('card-action') for i in lista_elementos: if i…
-
1
votes2
answers1462
viewsA: How to clear Python’s Idle screen?
There is no native IDLE command, but it is possible to do this with external libraries. You can do using the os, for example: import os os.system('clear') # se estiver utilizando linux…
-
0
votes1
answer301
viewsA: Recover link when using click() from Python
You can take the attribute of the tag that contains the link, as in the example: links = driver.find_elements_by_partial_link_text('Excel') for link in links: print(link.get_attribute('href'))…
-
2
votes1
answer356
viewsA: Object movement
The Rect does not have the attributes up and down, but has top and bottom. Change your code to: if evento.key == K_DOWN: jogador.rect.bottom += jogador.velocidade that will work.…
-
1
votes1
answer65
viewsQ: How to avoid too many Try/except?
I have the code below that plays values inside keys in a dictionary. However, I need several try / except so that the code works perfectly, since, in the absence of one of the fields, the code will…
-
0
votes1
answer186
viewsA: Automation in HTML [Python]
Answering the questions: 1- In this case, the script stops running, just when I ask user interaction, and in Python there is no window (as in other languages) showing the inputs/outputs ? R- There…
-
1
votes1
answer55
viewsA: Doubt Python URL
The function find_all() returns a list of elements, so it is possible to take the attributes of the elements as follows: # Retorna o valor do atributo 'alt' do primeiro elemento da lista…
pythonanswered Guilherme Carvalho Lithg 646 -
1
votes2
answers838
viewsA: How to check if server is available before request.urlopen in Python?
You can just use one try and except, thus: import urllib.request import json try: url= urllib.request.urlopen('http://ENDERECOIP/pasta/arquivo.php') x= url.read() y = json.loads(x.decode('utf-8'))…
-
1
votes1
answer465
viewsA: Python script error for copying . txt files
The problem is that you are not specifying the file path when copying. The shutil is trying to access the file fil.txt in the current directory, which does not exist. You can resolve this by…
-
1
votes1
answer45
viewsA: My Tkinter library buttons/buttons are not showing
Is missing using the pack() for objects to appear. For example: jlabel = Label(janela2, text="Não está aparecendo") jlabel.pack() In addition, you can choose the position, passing it as a parameter,…
-
0
votes1
answer49
viewsA: I can’t get xpath from comment box on Youtube
I did some tests and I was able to comment as follows: First, for the comment field to appear, you need to scroll down the page a little. So I used: driver.execute_script("window.scrollTo(0, 350)")…
-
0
votes3
answers243
viewsA: How to save file without overwriting the previous python?
You are passing the same name to the files in the variables nome1 and nome2, so it’s overwriting. Try to change that way: #ARMAZENAMENTO nome1=("Video_camera1.avi") nome2=("Video_camera2.avi")…
-
1
votes1
answer2337
viewsA: How to access an iframe using Selenium Python
You can do it this way: # Pega o XPath do iframe e atribui a uma variável iframe = driver.find_element_by_xpath("//*[@id="editor"]/div[3]/div[3]/iframe") # Muda o foco para o iframe…
-
1
votes1
answer2254
viewsA: How to click on links with Selenium Python
You can click through the Xpath of the element. For this, just follow the template: Taking the xpath of an element: To catch the xpath, using the Google Chorme, just click with the right click on…
-
0
votes3
answers463
viewsA: How to list files in a folder with size
You can generate a dictionary of all files and sizes with the following code: import os path = "C:\\seu\\path\\" lista = [f for f in os.listdir(path)] tamanhos = [] dict_arquivos = {} for item in…
pythonanswered Guilherme Carvalho Lithg 646 -
2
votes2
answers46
viewsA: Calling 3-column CSV file in Python
If you set a separator, sure. Do it like this: df = pd.read_csv('file.csv', sep=';', encoding="ISO-8859-1", header=None) Since apparently the columns are separated by ';'…
-
0
votes4
answers1706
viewsA: Functions of PYAUTOGUI not working
Hello, Nathan! Sorry to reply a little late, but I’ve been through a similar problem now. The solution was to simply open the application I wanted to click as Administrator and magically the mouse…
-
1
votes1
answer329
viewsQ: How to redesign a window with Pyqt5?
I have a CRUD made with Pyqt5 that adds a user to a database Postgresql and does a search to show registered users in a QT Listwidget. However, when adding a new user, the screen does not "reload"…
-
7
votes1
answer2738
viewsA: How to make a python file execute commands in cmd?
Just use the library os As in the example below: import os os.system('netsh wlan show profile')
-
0
votes1
answer418
viewsA: Loop in Selenium (python)
You can make use of the try and the except in form: import time from selenium import webdriver user = "usuario" pwd = "senha" driverpath = "/caminho/do/driver/chromedriver.exe" driver =…
-
0
votes2
answers72
viewsA: Accountant who does not count
As commented, the counters are being initialized at each loop with zero value, as they are "participating" in the loop. To solve, it is enough that they are initialized only once, being outside the…
pythonanswered Guilherme Carvalho Lithg 646 -
0
votes3
answers7958
viewsA: Ban to bot command on Discord.js
Apparently, the error is in the user’s role. The group name should be exactly as in the code ["Administrator"] It is possible that in your Discord the role is as "Manageaching" and this is causing…
javascriptanswered Guilherme Carvalho Lithg 646 -
0
votes2
answers4733
viewsA: Open and close multiple tabs in Python browser
You can use keyboard shortcuts to create tabs and close. For example: Control+T to open a new tab and Control+W to close. To do this in Lenium, simply: from selenium import webdriver from…
-
1
votes1
answer873
viewsA: Unzip file . gz with Python
You can do this using libraries gzip and shutil, as in the example: import gzip import shutil with gzip.open('file.gz', 'rb') as entrada: with open('file', 'wb') as saida:…
-
2
votes1
answer397
viewsA: cv2.error: Opencv(4.1.0)
This error means that you are loading an empty image. As specified in the error, the image must have a width > 0 and a height > 0. Here, I was able to open an image with exactly the same code.…
-
0
votes1
answer208
viewsA: Qpushbuttos with more robust designs
It is possible yes! For styles, there is the function .setStyleSheet() For a style on the button, you can write the code this way: btn.setStyleSheet("font: 15pt Arial;margin: 1px; border-color:…
-
0
votes2
answers437
viewsA: Is there a way to center the screen created in python ( pyqt ) for any resolution?
You can add this code to your Mainwindow: self.move(QtGui.QApplication.desktop().screen().rect().center()- self.rect().center()) You can also try the code below:…
-
0
votes3
answers5733
viewsA: How to save the output result of a Python script to a txt file?
To write to a file, just the following code: file = open('file.txt', 'w') file.write('Seu texto aqui') file.close() Remembering that in the code above, the argument 'w' overwritten everything in .…
-
0
votes2
answers725
viewsA: Inserting images into a Tkinter frame
I was able to insert an image into a frame with the code below: from PIL import Image, ImageTk root = Tk() frame = Frame(root) frame.pack() bottomframe = Frame(root) bottomframe.pack() img =…
-
0
votes1
answer41
viewsA: Beautifulsoup - href search by text
For some reason, the HTML structure in Pycharm needs to follow some criteria. I tested your code here and managed to make it work by adding one to every line skipped in HTML. This backslash tells…
-
0
votes2
answers38
viewsA: Error SQL syntax when exporting CREATE TABLE (Myphpadmin)
Your problem, as the error itself says, is in the syntax. The condition is missing for the WHERE. You must specify the column where the WHERE = 1 Example: SELECT * FROM 'wphk_rconvert-subscriptions'…
-
1
votes3
answers503
viewsA: Combination of values for sample selection
I changed your code a little bit and it worked right here. What I did: I took the column NAME and played all the items on a list; I took the column WORTH and played all the items on a list; I made a…
pythonanswered Guilherme Carvalho Lithg 646 -
0
votes1
answer76
viewsA: Guessing minigame telling wrong
There are two causes for problems in your code: The total hits are being printed before being incremented; Variables are not being initialized with 0, to be incremented when needed. Solving these…
-
2
votes1
answer1968
viewsA: Chatterbot installation error
Apparently, your setuptools are outdated. The code below should solve the problem. pip install --upgrade setuptools
-
0
votes1
answer94
viewsA: Problem aligning buttons with image, in a widget, using pyqt5 graphical library
Events are being activated twice as there are two calls to the same. To correct, simply remove the lines self.pressed.connect(self.update) self.released.connect(self.update) When centering the…
-
0
votes1
answer347
viewsA: How to remove the edge of a Pyqt5 window on Raspberry Pi?
I did the tests here on a Raspberry Pi and it worked by passing the following parameters: self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowCloseButtonHint)…