Anyone into Python? I have a few questions relating to nested loops
Anyone into Python? I have a few questions relating to nested loops
Re: Python
By: Mortifis to All on Sun Dec 09 2018 01:40 pm
Anyone into Python? I have a few questions relating to nested loops
I've done a bit of Python for work.
Re: Python
By: Mortifis to All on Sun Dec 09 2018 01:40 pm
Anyone into Python? I have a few questions relating to nested loops
Ask away. I'm curious what your question is.
What is need is a counter so that the GPIO pins blink only for the length of an mp3 then automagically shutdown when the song is over
In the code I pasted to Nightfox the lights blink until ^C is hit
Re: Python
By: Mortifis to All on Sun Dec 09 2018 01:40 pm
Anyone into Python? I have a few questions relating to nested loops
I've done a bit of Python for work.
Re: Re: Python
By: Mortifis to Minex on Mon Dec 10 2018 11:37:55
What is need is a counter so that the GPIO pins blink only for the length of an mp3 then automagically shutdown when the song is over
What value does audio.info.length represent? Duration of the song in seconds / milliseconds / something else? File size?
I doubt if a counter is the right way to go. Seems like you could store the start time prior to entering the loop, and then make your While condition something like 'current_time - start_time < song_duration', so that the loop breaks once that amount of time has passed.
isn't that just a counter of sorts as well?
I appreciate you looking in this for me, I think I figured out the correct loop usage I need, python is soooo F$%&'n finicky -;P:
Re: Re: Pythonthe passage of
By: Mortifis to echicken on Mon Dec 10 2018 15:13:06
isn't that just a counter of sorts as well?
Sure, as much as any clock is a counter incrementing with
time. I don't mean that "using a counter" is inherentlybad, just that
there's a more straightforward approach that also lets youditch a magic
number.
Doesn't matter, you'll achieve the same result in the end.
Re: Re: Pythonfigured out the
By: Mortifis to Nightfox on Mon Dec 10 2018 12:16 pm
I appreciate you looking in this for me, I think I
finicky -;P:correct loop usage I need, python is soooo F$%&'n
Good to hear you may have figured it out.of using curly
Yeah, Python has strict rules about indentation. Instead
braces to mark blocks of code like other languages, all thelines in a block
of code in Python must be indented the same way (samenumber of spaces or
tabs).
Yeah, Python has strict rules about indentation. Instead of using curly braces to mark blocks of code like other languages, all the lines in a block of code in Python must be indented the same way (same number of spaces or tabs).
This is something I love about Python, personally.
Make sure you don't mix spaces and tabs for indentation in your code, or Python will likely complain.
Re: Re: Python
By: Kirkman to Nightfox on Tue Dec 11 2018 09:26 pm
This is something I love about Python, personally.
Make sure you don't mix spaces and tabs for indentation in your code, or Python will likely complain.
I like that it helps keep code consistent, but one downside that bugs me is that text editors often assume you want to continue your indented code block in Python, and Python doesn't use curly braces, which text editors often use with other languages to know when you're done with a code block. In other languages, text editors can even know you're done with a one-line block of code without curly braces since that's how other programming languages work.
I keep running into unexpected indent or unexpected unindent when using nested loops and such, which is obviously my lack of understanding of Python. Another problem I keep running into is, for example, x = x + 1 or x += 1 ... syntax error. I won't paste my troubled code but Python is definitely a finicky language
Sysop: | Kurt Hamm |
---|---|
Location: | Columbia, SC |
Users: | 8 |
Nodes: | 20 (0 / 20) |
Uptime: | 135:15:19 |
Calls: | 2,804 |
Calls today: | 1 |
Files: | 64 |
Messages: | 854,509 |