I am a beginner in python. Here I have some face recognition projects from my school. In order to run my code, I use flask_ask. My code is supposed to stop after 8 minutes if the face recognition doesn't see my face. In order to do that I put a countdown function.
The problem is every time I run this known_Greeting(), it keeps saying NameError: name 'reset_Timer' is not defined. Indeed, I defined it inside the known_Greeting(). The face recognition is working, but the countdown is not working. If I replace reset_Timer=8 outside known_Greeting(), the countdown is work but it did nothing when the countdown reaches zero.
Without using the known_Greeting(), the code runs perfectly. I've been working on this code for 3 days already, and still couldn't figure it out. Below is my code. It is a bit long, so I will put the git link.
https://github.com/UMD-ENEE408I/ENEE408I_Spring_2021_Team_5/blob/main/python/face11.py
Below is the flask-ask that I am running this code.
https://github.com/UMD-ENEE408I/ENEE408I_Spring_2021_Team_5/blob/main/python/alexa4.py
This error suggests that reset_timer is not defined. As you are creating a new context with threading. Using global resources might create some issues.
Possible solution:
Try passing the reset_timer value in the parameter of the target file. Here I am trying to put the snippet for your code. Please update it on https://github.com/UMD-ENEE408I/ENEE408I_Spring_2021_Team_5/blob/main/python/face11.py#L44.
def countdown(reset_Timer):
while reset_Timer > 0:
print('T-minus', reset_Timer)
time.sleep(1)
reset_Timer -= 1
count = threading.Thread(target=countdown, args=(reset_Timer,))
Related
I am trying to render hundreds of images from maya using redshift but it's not working, I tried everything I could find online.
for i in range(10):
do_something()
prep_render_settings()
cmds.render()
this works fine but it only renders out images with Maya's internal engine, and I've tried changing the settings to redshift manually + with code but it always ends up rendering with maya software.
for i in range(10):
do_something()
prep_render_settings()
cmds.renderWindowEditor(editor,e=True, writeImage="...")
or
for i in range(10):
do_something()
prep_render_settings()
mel.eval("BatchRender;")
both successfully switch to Redshift, but the catch is that the script doesn't wait for the rendering to finish before moving on to the next round of the loop, so I end up with only 1 image render (the last one, bu named as the first one).
I'm trying to find a way to either:
1-make cmds.render() use redshift
2-call a function that will return whether or not the rendering is in progress, and only move on with the script if it's finished -in c4d there's a function called c4d.CheckIsRunning() that does exactly that-
Any help will be super appreciated, I've been stuck on this for days.
Thank you!
screenshot of my pycharm interface
Hey everyone. When I run this simple code (the tab 'youtubeyf.py
is to print 'hello world'), it produces the intended result but also another script (with the tab name "yfinance.py") result as well. In fact, the "yfinance.py" script doesn't need to be open in order for that result to appear too. It is almost as if it runs in the background, parallel without being open.
Goal: I want to run "print 'hello world'" without the dataframe from the other script appearing.
Problem: the dataframe is appearing without actually running or being open.
Troubleshoot attempts so far: I have "Alphabetted" and searched on StackOverflow, JetBrains on topics regarding reconfiguring the "run configurations", "parallels", and nothing yet.
Thank you for your time.
Edit 1: this does not solve my problem. for one, my issue isn't importing. in fact, everything is "running" smoothly, but that the results are two in one. It is analogous to two chefs preparing one meal each, say shrimp lo main and pizza, and then placing both meals onto one plate. I don't want that; I want to have shrimp lo main on Tuesday night, and then pizza Wednesday.
When importing yfinance, it could be possible that in that module, your code is structured such that when you import the module it runs a function or other code. In yfinance, you should delete any extraneous function that doesnt need to be run everytime you import yfinance somewhere else.
Edit: what you can do, if you dont want to change much of the structure yfinance.py, is wrap all the code that runs in that python file inside a main function and add the following:
if __name__=="__main__":
main()
This makes it so that python only runs main if you're actually running yfinance.py , and doesnt run main when you're importing it.
It has been a while since i have last visited stackoverflow, But i am happy to be back.
Now. Maybe some of you remember the 'Crazy PC "Virus"', (Program that constantly opens and closes your disk drive and maybe plays a song and shows a picture, But is harmless and should be made to be easy to close)
Well. For the next april fools i wanted to use this, but i cant find it.
So i decided that i needed to make it myself!
I have found some code to control the disk drive,
import time, pygame.cdrom as cdrom
#time.sleep(5)
while 1:
cdrom.init()
cd = cdrom.CD(0)
cd.init()
cd.eject()
cd.quit()
cdrom.quit()
time.sleep(5)
(Thank you shubham1810)
But i am not certain if it is python 3 and it is a while, meaning (For all i know, Still a noob at code) that it wont run any other code until the while ends.
But as stated before i also want a picture to be on the screen and a sound file to play...
Have you guys got any ideas? Because i dont :(
-Natan
EDIT 1:
Ok, i have now finally been able to install pygame, and this code works on python 3. What puzzles me is that it opens the drive one time and then doesnt close it again. Does anyone know how to do this?
EDIT 2:
I have decided that this wont work and have since found a working vbs script for the cd drive opening and closing. The script is:
Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
do
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count -1
colCDROMs.Item(i).Eject
Next
For i = 0 to colCDROMs.Count -1
colCDROMs.Item(i).Eject
Next
End If
wscript.sleep 5000
loop
I will call it within python and then the picture and the song, but that still doesnt solve my problem. I still need and a picture and a song to play in the background (So without the user finding them).
Any idears?
Firstly, there are a couple of similar questions posted on this. But they are not complete questions, and no one has really answered them all. I am using Python to send input to a game active in widow modes using "ctypes" package. The original idea is mentioned here
In particular, my codes are:
x=500
y=400
for i in range(10):
time.sleep(4)
if i > 0:
x=x+17
pos=(x,y)
#ctypes.windll.user32.SetCursorPos(x,y) # this does not work in game but
#outside the game window
ctypes.windll.user32.mouse_event(0,x,y,0,0)
print i
In order for the "mouse_event" to work, I tried inputting hexadecimal values but can't get it to move consistently. I tried setting up separate class & functions to import, then calling the function. The function works outside the game window but not inside the game window.
The separate class & functions are based on this question
Thank you for your help in advance.
While working on a simple little timer I was creating to simultaneously help me learn more about Python and to help me keep on schedule with my schoolwork; I decided to add a little tune to let me know when your time was up. However, after using the following snippet of code to program each individual note:
winsound.Beep(Freq, Dur)
I realized that whenever I actually played the little song, an odd clicking sound happened between each note. Does anyone know what's going on? Should I use a different expression? Am I just losing my mind?
Edit: Since posting this, I realized what the issue is, the program is waiting about a sixteenth of second in between playing each note. So I'd like to ask another question (any answers relating to the others would still be appreciated), namely, how can I make it not wait in between the notes.
import winsound
winsound.Beep(262,500)
winsound.Beep(277,500)
winsound.Beep(294,500)
winsound.Beep(311,500)
winsound.Beep(330,500)
winsound.Beep(349,500)
winsound.Beep(370,500)
winsound.Beep(392,500)
winsound.Beep(415,500)
winsound.Beep(440,500)
winsound.Beep(466,500)
winsound.Beep(493,500)
winsound.Beep(523,500)
All the above code does is play a simple chromatic scale from middle c to c2, but once one runs it, one would immediately see what Im talking about