0
I have a very simple code that clicks on an image on the screen:
from src.imagesearch.functions import clickwithwait
class Home:
def clickNEWS(self):
NEWS = r"..\NEWS.png"
clickwithwait(NEWS)
This file being the name objecthome.py
And I have a code that performs that function:
from src.objects.home.objectshome import Home
home = Home()
home.clickNEWS()
However, when rotating, the following error occurs:
OSError: Failed to read ..\NEWS.png because file is missing, has improper permissions, or is an unsupported or invalid format
He didn’t find the image, and I believe it’s because I’m running from main. How could I do this execution?
Here is a picture of the structure of the code:
Have you tried assigning the absolute path to the NEWS variable? Relative paths are always relative to the current directory.
– Lucas Maraal
i tried to do the following: NEWS = r"src Objects home NEWS.png", and it worked, but my idea is to use this function of several other py files, so it would have to have a function for each file, which would not be ideal kkk
– Gabriel Henrique
left so NEWS = r"src Objects home NEWS.png" and changed the main location, and it didn’t work
– Gabriel Henrique
Use the absolute path to the file. For example:
C:\src\objects\home\NEWS.png
, and then it will work from anywhere you run this scriptmain.py
. Just curious, why do you need to run themain.py
in different places?– Lucas Maraal
really, with the absolute path worked, I’ll have to rethink a little logic to take the kkkk path, in case I won’t use the main in several places, I will use the home.clickNEWS()
– Gabriel Henrique
I still can’t understand what you’re trying to do. The other modules that will contain
home.clickNEWS()
will be executed independently or is always from themain.py
? If it’s always frommain.py
, the relative paths will always have directory desste script as starting point, so assignsrc\objects\home\NEWS.PNG
for the variable, it shall function.– Lucas Maraal
always independently, in general, the idea is to create a bot for a game, in case, would have several routes, for example, do mission, make pvp, etc., and many of these will go through the same page, but will be in other files py, I do not know if I could pass the idea huahuaa
– Gabriel Henrique
but I managed to solve doing as you said, with the absolute path, but I had to do a function to get the start of the path + the rest of the current directory, anyway, I don’t know if it was well understood huahauhaua
– Gabriel Henrique
Take a look at this answer and her comments: https://stackoverflow.com/a/918178/8841282, I think it will help you.
– Lucas Maraal