pyautogui.center, TypeError: 'NoneType' object is not subsriptable - typeerror

I'm trying to code a program to take care of some boring stuff. When I try to use pyautogui.center() I get an error. Here is an example of the code and the error:
c = pyautogui.locateOnScreen('sample.png')
d = pyautogui.center((c))
d = pyautogui.center((c))
File "C:\Users\\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyscreeze\__init__.py",
line 404, in center
return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2)) TypeError: 'NoneType' object is not subscriptable

This could be because of image is not found on screen too. But try this
sample_image = pyautogui.locateAllOnScreen('sample.png')
center_of_image = pyautogui.center(sample_image)
pyautogui.mouseDown(center[0], center[1])
pyautogui.mouseUp(center[0], center[1])

Related

Vpython Error: 'float' object has no attribute '_x'

I am writing a Vpython simulation for projectile motion and keep getting the error ('float' object has no attribute '_x') on this line(ball.vel.y = ball.vel.y + g*dt) . I have tried changing the values of ball.vel.y to an integer and changing g to an integer but the same error occurs. Here is the code
from vpython import *
import math
ball=sphere(radius=0.1, color=color.red, pos=vector(0.1,0.1,0),make_trail=True)
floor=box(pos=vector(0,0,0), length=10, height=0.01, width=0.01)
g= vector(0,-9.8 ,0)
ball.vel=vector(10*cos(43),10*sin(43),0)
dt=0.1
t=0.0
while(ball.pos.y>-0.001):
rate(100)
t=t+dt
ball.pos.x = ball.pos.x + ball.vel.x*dt
ball.vel.y = ball.vel.y + g*dt
ball.pos.y = ball.pos.y + ball.vel.y*dt
g is a vector, as is g*dt, but ball.vel.y is a scalar, and you can't add a vector to a scalar. It's unfortunate that the error message doesn't just say "You can't add a vector to a scalar". I note that if you reverse the two quantities the error message is a bit more understandable: TypeError: unsupported operand type(s) for +: 'vpython.cyvector.vector' and 'float'

ERROR TypeError: __init__() takes 2 positional arguments but 3 were given

Request help in following code
model = LinearRegression()
rfe = RFE(model, 3)
X_rfe = rfe.fit_transform(X,y)
model.fit(X_rfe,y)
print(rfe.support_)
print(rfe.support_)
Put: n_features_to_select = 3
That worked for me.

TypeError: VideoWriter() missing required argument 'frameSize' (pos 5) with opencv-python ==4.4.0.42

I want to create VideoWriter with the following code:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter('out.mp4',fourcc,fps,(frame_width,frame_height))
but i get the error:
TypeError: VideoWriter() missing required argument 'frameSize' (pos 5)
when i change my code to:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get another error:
TypeError: VideoWriter() missing required argument 'apiPreference' (pos 2)
so i change my code to :
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',apiPreference=0,fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get error:
TypeError: VideoWriter() missing required argument 'params' (pos 6)
How could i solve it? Could anyone tell me how to use the api:VideoWriter()?Thanks a lot
ok, the following code works for me :
frame_num = int(Cap.get(cv2.CAP_PROP_FRAME_COUNT))
frame_width = int(Cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(Cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(result,fourcc,fps,(frame_width,frame_height))
the type of Cap.get(cv2.*) is float, so i change it to integer
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter(path,apiPreference = 0,fourcc = fourcc, fps = 30,frameSize = (256,256) )
for i in range(len(predictions)):
out.write((img_as_ubyte(predictions[i])))
out.release()
it did worked for me
used skimage's image_as_ubyte to convert float to int.

Scrapy : TypeError: argument of type 'NoneType' is not iterable

Whit scrapy, I receive this NoneType error when I launch my spider:
if 'Jockey' in tab_arrivee_th: TypeError: argument of type 'NoneType'
is not iterable
The code works fine in the console test with a list, but not with the response.css.
I think the problem comes from the response_arrivee_th, and I don't understand why, because the 'scrapy shell' gives me a list in return, and it's the same that I use in the test.
def parse(self, response):
tab_arrivee_th = response.css('.arrivees th::text').extract()
# list obtained whit the response.css from above in scrapy shell
# tab_arrivee_th = ['Cl.', 'N°', 'Cheval', 'S/A', 'Œill.', 'Poids', 'Corde', 'Ecart', 'Jockey', 'Entraîneur', 'Tx', 'Récl.', 'Rapp. Ouv.']
if 'Jockey' in tab_arrivee_th:
col_jockey = tab_arrivee_th.index('Jockey') + 1
elif 'Driver' in tab_arrivee_th:
col_jockey = tab_arrivee_th.index('Driver') + 1
else:
col_jockey = 0
jockey = partant.css('td:nth-child(' + str(col_jockey) + ') > a::text').extract()
if 'Jockey' in tab_arrivee_th: TypeError: argument of type 'NoneType'
is not iterable
thx for the help
Solved : the 'response.css('.arrivees th::text').extract()' point to a list construct in js.
So I used scrapy-splash to have a 0.5 second delay. And it works fine.
the response for this line tab_arrivee_th = response.css('.arrivees th::text').extract() is empty , check the response again.

genfromtxt in Python-3.5

I am trying to fix a data set using genfromtxt in Python 3.5. But I keep getting the next error:
ndtype = np.dtype(dict(formats=ndtype, names=names))
TypeError: data type not understood
This is the code I'm using. Any help will be appreciated!
names = ["country", "year"]
names.extend(["col%i" % (idx+1) for idx in range(682)])
dtype = "S64,i4" + ",".join(["f18" for idx in range(682)])
dataset = np.genfromtxt(data_file, dtype=dtype, names=names, delimiter=",", skip_header=1, autostrip=2)
dtype = "S64,i4" + ",".join(["f18" for idx in range(682)])
is going to produce something like:
s64,i4f18,f18,f18,f18...
Note the lack of a comma after the i4.