Python Forum
reset on inactivity (building a morse decoder)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reset on inactivity (building a morse decoder)
#5
(Apr-15-2020, 12:40 PM)deanhystad Wrote: Indentation is how Python blocks code. Other languages use start and end markers, but in python you indicate which code is inside an if statement by indentation. The code below is a valid if/else.
while True:
    key.wait_for_press(120)
    if not key.is_pressed():
        os.system("clear") # Linux - OSX
        print("Welkom bij de morse emulator van maritiem centrum Ameland")
    else:
        key_down_time = time.time() #record the time when the key went down
        tone_obj.play(-1) #the -1 means to loop the sound
        key.wait_for_release()
This code complains about the "else:" because then indentation of the "print" command is an end marker for the "if" statement
while True:
    key.wait_for_press(120)
    if not key.is_pressed():
        os.system("clear") # Linux - OSX
    print("Welkom bij de morse emulator van maritiem centrum Ameland")
    else:
        key_down_time = time.time() #record the time when the key went down
        tone_obj.play(-1) #the -1 means to loop the sound
        key.wait_for_release()
The equivalent C code is:
while (1)
{
    wait_for_press(key, 120)
    if (!is_pressed(key))
    {
        os_system_clear()
    }
    print("Welkom bij de morse emulator van maritiem centrum Ameland");
    else
    {
        key_down_time = time()
        tone_obj_play(-1)
        wait_for_release(key)
    }


Thank you very much for the explanation.

Now i have the next problem i can't solve or understand.

Quote:Traceback (most recent call last):
File "./morse-code2.py", line 69, in <module>
if not key.is_pressed():
TypeError: 'bool' object is not callable
Angry maybe i'm stupid but it`s all new for my.
Reply


Messages In This Thread
RE: reset on inactivity (building a morse decoder) - by gerrit1985 - Apr-15-2020, 01:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 8 3,508 Dec-03-2024, 10:21 AM
Last Post: skylartyler
  How can i fix json.decoder.JSONDecodeError ? JgKSuperstar 9 7,425 Oct-30-2021, 11:23 PM
Last Post: JgKSuperstar
  How to fix bugs in Morse alphabet code? dokipo 10 5,072 Oct-26-2021, 06:43 PM
Last Post: deanhystad
  How to reset row value in pandas Mekala 0 2,075 Sep-19-2020, 09:36 AM
Last Post: Mekala
  coding a decoder... Popkhorn 2 2,907 May-28-2020, 07:26 AM
Last Post: Popkhorn
  Reset a variable mln4python 4 10,744 Aug-19-2019, 08:28 AM
Last Post: mln4python
  UTF-8 decoder reports bad byte that is not there Skaperen 0 3,020 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 7,166 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 10,779 Sep-13-2017, 09:23 AM
Last Post: Cronax3

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020