1) Build a program that will import and either:
a) Natively understand the files or
b) Import, then convert the files
2) Allow me to search the files by any of the fields.
3) Upon finding records that match #2; return the entire row, and just
that row.
1) IT Dept doesn't object to Python being installed on my PC (big one!)
2) According to everything I've read, it's really easy to learn (big two!) 3) It's a simple program for helping me parse and search LARGE text files.
Essentially the deal is this: Every month (EVERY MONTH) I get a text
file that has been processed by our mainframe billing system that contains...information, that is uniquely identified by several different fields - some can be duplicates, but there is ALWAYS one unique identifier.
Almost every month I have to go searching in these files to locate information - either by one of those aforementioned identifiers, or by date/time information, etc.
1) Build a program that will import and either:
a) Natively understand the files or
b) Import, then convert the files
2) Allow me to search the files by any of the fields.
3) Upon finding records that match #2; return the entire row, and just
that row.
Now my question: Is Python even a good choice for this?
I know that Perl has been used to do things like this before, but Perl
is not acceptable to the IT department.
Well if you have a huge millstone tied around your neck, you'll find it
much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
Re: Python
By: Digital Noise to DOVE-Net.Programming on Thu Sep 07 2006 20:37:00
1) IT Dept doesn't object to Python being installed on my PC (big one!)
2) According to everything I've read, it's really easy to learn (big two!) 3) It's a simple program for helping me parse and search LARGE text files.
Perl was built specifically for this exact type of task.
Essentially the deal is this: Every month (EVERY MONTH) I get a text
file that has been processed by our mainframe billing system that contains...information, that is uniquely identified by several different fields - some can be duplicates, but there is ALWAYS one unique identifier.
I suppose you have to keep the data confidential, so we can't look at an example of the data. Does the format also have to be confidential? Or could you produce a ficticious dataset in the same format?
Almost every month I have to go searching in these files to locate information - either by one of those aforementioned identifiers, or by date/time information, etc.
Sounds like a Perl coders dream. Except you never actually said what you *DO* with the data once you've located it....
I know that Perl has been used to do things like this before, but Perl
is not acceptable to the IT department.
Well if you have a huge millstone tied around your neck, you'll find it
much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
Re: Python
By: Angus McLeod to Digital Noise on Thu Sep 07 2006 23:52:00
Well if you have a huge millstone tied around your neck, you'll find it much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
If I had to guess, I'd guess that it's so that the "real programming
tasks" can be given to a programming dept to make more expensive and
take longer.
If I had to guess, I'd guess that it's so that the "real programming
tasks" can be given to a programming dept to make more expensive and
take longer.
Re: PythonBy: Hawke to Angus McLeod on Fri Sep 08 2006 01:28 am
If I had to guess, I'd guess that it's so that the "real programming tasks" can be given to a programming dept to make more expensive and take longer.
Still looks like you just want awk... or maybe even just grep.
Still looks like you just want awk... or maybe even just grep.
Is AWK available for Windows (since that's the defacto platform here), and easily usable for someone other than me later down the road?
I'm trying to build more than a one-time use application, and one that can be utilized by others than myself without them having to learn a
programming language.
Re: Re: Python
By: Digital Noise to Deuce on Fri Sep 08 2006 09:35 am
Still looks like you just want awk... or maybe even just grep.
Is AWK available for Windows (since that's the defacto platform here), and easily usable for someone other than me later down the road?
I assume it is... it was available for DOS at one point.
I'm trying to build more than a one-time use application, and one that can be utilized by others than myself without them having to learn a programming language.
awk and grep are pretty much as much application as they're ever going to get already... it's all command-line driven.
Re: Python
By: Angus McLeod to Digital Noise on Thu Sep 07 2006 23:52:00
Well if you have a huge millstone tied around your neck, you'll find it much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
If I had to guess, I'd guess that it's so that the "real programming
tasks" can be given to a programming dept to make more expensive and
take longer.
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 :
089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
Re: Re: Python
By: Digital Noise to Angus McLeod on Fri Sep 08 2006 09:24 am
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 : 089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
I'll give you this: At least your sample data is entertaining. :)
I'll give you this: At least your sample data is entertaining. :)
Belly wrote:
Re: Re: Python
By: Digital Noise to Angus McLeod on Fri Sep 08 2006 09:24 am
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 :
089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
I'll give you this: At least your sample data is entertaining. :)
What do you mean sample? :o
1) Build a program that will import and either:
a) Natively understand the files or
b) Import, then convert the files
2) Allow me to search the files by any of the fields.
3) Upon finding records that match #2; return the entire row, and just that row.
Sounds like you want awk.
It's PPV data - I've copied and pasted a section from the PAL (PPV Auto Loader) file below - hopefully it'll keep the format:
============================================================================ TITLEID:SHOWID:BASEID:LONG DESCRIPTION : SH DESC:START DATE/TIME: LEN :
CHNL# : RTG : SUBJ : PRICE : CNTRLR # :ORDER:INTSTI: -------:------:------:-----------------:--------:---------------:-----:-----
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 :
089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
As you can see, it's colon seperated, and does include headers on every
page (this is the result of the PAL file being processed by the system; however, the system provides no function to search these files, hence my problem).
I just need to locate the data because occasionally I have to change
things manually, and I need to locate like the Title ID; or Search by
the Date/Time, etc.
If I had to guess, I'd guess that it's so that the "real programming tasks" can be given to a programming dept to make more expensive and
take longer.
Still looks like you just want awk... or maybe even just grep.
Still looks like you just want awk... or maybe even just grep.
Is AWK available for Windows (since that's the defacto platform here), and easily usable for someone other than me later down the road?
I really would prefer something with a GUI that I could build, but this would definitely work for my personal needs.
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 : 089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
I'll give you this: At least your sample data is entertaining. :)
Re: Re: Python
By: Digital Noise to Angus McLeod on Fri Sep 08 2006 08:24:00
It's PPV data - I've copied and pasted a section from the PAL (PPV Auto Loader) file below - hopefully it'll keep the format:
============================================================================
TITLEID:SHOWID:BASEID:LONG DESCRIPTION : SH DESC:START DATE/TIME: LEN :
CHNL# : RTG : SUBJ : PRICE : CNTRLR # :ORDER:INTSTI: -------:------:------:-----------------:--------:---------------:-----:-----
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 :
089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 :
059:01= 501 : : 6=6 : 0009.95: : 30: 1:
As you can see, it's colon seperated, and does include headers on every page (this is the result of the PAL file being processed by the system; however, the system provides no function to search these files, hence my problem).
Is it safe to assume that each line of data is in the same format?
I just need to locate the data because occasionally I have to change things manually, and I need to locate like the Title ID; or Search by
the Date/Time, etc.
So you want to find (say) all lines where TITLEID = 53988? Or maybe where START DATE = 09/01/06? And then what, manually edit them? Or have some change applied programatically?
Re: Re: Python
By: Belly to Digital Noise on Sat Sep 09 2006 12:55:00
53987 :36869 :31059 :DORM ROOM GRL UNC:DORM ROO:09/01/06 06:00 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
53988 :36870 :31067 :WMN EROTC WRSTL13:WMN EROT:09/01/06 10:00 : 089:01= 501 : : 6=6 : 0014.95: : 30: 181:
53989 :36871 :31058 :WILD GRLS BARTNDR:WILD GRL:09/01/06 11:30 : 059:01= 501 : : 6=6 : 0009.95: : 30: 1:
I'll give you this: At least your sample data is entertaining. :)
Yeh! :-) I assumed it was not production data, but a test set selected
for our benefit.
Re: Python
By: Deuce to Hawke on Fri Sep 08 2006 09:25:00
If I had to guess, I'd guess that it's so that the "real programming tasks" can be given to a programming dept to make more expensive and take longer.
Still looks like you just want awk... or maybe even just grep.
Yes. It would be nice to do do something like
doit --titleid=53988
but grep might do it.
What I want to do is this:
1) Build a program that will import and either:
a) Natively understand the files or
b) Import, then convert the files
2) Allow me to search the files by any of the fields.
3) Upon finding records that match #2; return the entire row, and just
that row.
Now my question: Is Python even a good choice for this?
I know that Perl has been used to do things like this before, but Perl
is not acceptable to the IT department. I'm sure I could ask our
Database Programmer to build this in Access, but I'd rather not burden
him (he's already like 6mths behind), plus I'd like to learn this myself.
Any thoughts?
Dunno what the uniquely identifying fields look like, but you could
probably combine #2 and #3 into a Perl one-liner, or very close to it. --snip--
My question is why anyone would use Python for *anything*, INCLUDING a "Hello, world!" program.
I know that Perl has been used to do things like this before, but Perl
is not acceptable to the IT department.
Well if you have a huge millstone tied around your neck, you'll find it
much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
You have no idea - 99.9% of our PPV buys are adult related.
That one file has 8 channels in in, enough data for 30/31 days worth of even 24 hrs a day. There are another 4/5 files for the Adult-only channels as we
Angus McLeod wrote:
Dunno what the uniquely identifying fields look like, but you could probably combine #2 and #3 into a Perl one-liner, or very close to it. --snip--
My question is why anyone would use Python for *anything*, INCLUDING a "Hello, world!" program.
See above, I don't care much for what I've seen of python, but it seems
like a good newbie choice especially if a GUI front end is desired.
I know that Perl has been used to do things like this before, but Perl
is not acceptable to the IT department.
Well if you have a huge millstone tied around your neck, you'll find it much harder to swim. I'd be really interested to hear *why* your IT department has decided to ban Perl.
Probably ignorance... just a guess..
It would be nice to do do something like
doit --titleid=53988
but grep might do it.
See, I have no problems with using tools like 'gawk' or 'grep' (assuming there was a Windows version of 'grep') to complete this task.
The holy was between Perl and Python is mostly unfounded.
See, I have no problems with using tools like 'gawk' or 'grep' (assuming there was a Windows version of 'grep') to complete this task.
It's just that I'm not the only one that does it (I do 95.9856% of the time), and it's a need that extends beyond me.
See above, I don't care much for what I've seen of python, but it seems
like a good newbie choice especially if a GUI front end is desired.
The holy was between Perl and Python is mostly unfounded.
Let me address this "holy war" briefly: I have no time for a language
that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of
Computer Science.
Let me address this "holy war" briefly: I have no time for a language that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of Computer Science.
I've seen a lot worse than that. It might be dumb, but it sure makes
it less likely that you are going to write crappy code that is hard to
read by the next poor sap that comes along.
See above, I don't care much for what I've seen of python, but it seems
like a good newbie choice especially if a GUI front end is desired.
Hard to beat MS-Access for this... you can crank out a GUI for simple stuff like this in minutes. It's RAD stuff is the main reason it's used so often.
Hard to beat MS-Access for this... you can crank out a GUI for simple stuff like this in minutes. It's RAD stuff is the main reason it's used so often.
very much agreed.. was in reference to being able to do other stuff as well... Access is a great tool for quick-n-dirty data work... even when connecting to an rdbms via odbc it works well...
Re: Re: Python
By: Coriolanus to Tracker1 on Sun Sep 10 2006 21:27:00
The holy was between Perl and Python is mostly unfounded.
Let me address this "holy war" briefly: I have no time for a language
that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of
Computer Science.
Let me address this "holy war" briefly: I have no time for a language that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of Computer Science.
I've seen a lot worse than that. It might be dumb, but it sure makes
it less likely that you are going to write crappy code that is hard to read by the next poor sap that comes along.
So the language designers are trying to make *style* a part of the
language definition. I will never support that. Some people like
fn() { if () {
} } else {
}
and other people prefer
fn() if ()
{ {
} } else
{
}
while some like
fn(){} if () {}
else {}
for small values of f() and simple if, and any attempt to force one
or the other on the programmer is a BAD thing.
Angus McLeod wrote:
Re: Re: Python
By: Coriolanus to Tracker1 on Sun Sep 10 2006 21:27:00
The holy was between Perl and Python is mostly unfounded.
Let me address this "holy war" briefly: I have no time for a language that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of Computer Science.
You must LOVE RPG-II. It is a great language if you like crossword
puzzles. RPG-II code looked so much like a crossword puzzle. I did just enough to pass the class. And those 3270(whatever) data entry stations.
8 inch floppies. ewww, I'm getting chills just remembering the
antiquated stuff.
Ok rant is over.
So what do you think of RPG?
After the class I wanted to take a real RPG and aim it at the IBM
System-3 it ran on.
Artiken
For what it's worth, this is an interesting discussion of what you can
and can't do with Python indentation:
http://www.secnetix.de/~olli/Python/block_indentation.hawk
You must LOVE RPG-II. It is a great language if you like crossword
puzzles. RPG-II code looked so much like a crossword puzzle. I did just enough to pass the class. And those 3270(whatever) data entry stations.
8 inch floppies. ewww, I'm getting chills just remembering the
antiquated stuff.
Ok rant is over.
So what do you think of RPG?
After the class I wanted to take a real RPG and aim it at the IBM
System-3 it ran on.
Re: Re: Python
By: Angus McLeod to Coriolanus on Mon Sep 11 2006 22:48:00
Let me address this "holy war" briefly: I have no time for a languag that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of Computer Science.
I've seen a lot worse than that. It might be dumb, but it sure makes it less likely that you are going to write crappy code that is hard to read by the next poor sap that comes along.
So the language designers are trying to make *style* a part of the language definition. I will never support that. Some people like
fn() { if () {
} } else {
}
and other people prefer
fn() if ()
{ {
} } else
{
}
while some like
fn(){} if () {}
else {}
And I tend to prefer:
def fn(): if ():
stuff stuff
else
more stuff
for small values of f() and simple if, and any attempt to force one
or the other on the programmer is a BAD thing.
For what it's worth, this is an interesting discussion of what you can
and can't do with Python indentation:
http://www.secnetix.de/~olli/Python/block_indentation.hawk
I do think Python is cleaner looking code without the extra curly
braces, but that is my personal preference. I'm not so sure it's a
travesty against computer science to use indent/outdent to define
blocks of code. That is almost as arbitrary as using curly-braces to
define the block. It is a means to an end, not something evil :-)
Let me address this "holy war" briefly: I have no time for a language that deliberately uses WHITESPACE as a significant syntactic element. That's the *DUMBEST* idea I've ever heard in in the entire world of Computer Science.
You must LOVE RPG-II. It is a great language if you like crossword
puzzles. RPG-II code looked so much like a crossword puzzle.
Ok rant is over.
So what do you think of RPG?
And I tend to prefer:
def fn(): if ():
stuff stuff
else
more stuff
For what it's worth, this is an interesting discussion of what you can
and can't do with Python indentation:
http://www.secnetix.de/~olli/Python/block_indentation.hawk
I do think Python is cleaner looking code without the extra curly
braces, but that is my personal preference.
I'm not so sure it's a travesty against computer science to use indent/outdent to define blocks of code. That is almost as arbitrary as using curly-braces to define the block. It is a means to an end, not something evil :-)
and can't do with Python indentation:
http://www.secnetix.de/~olli/Python/block_indentation.hawk
The only reason I hate the significant leading whitespace issue with
Python is due exclusively to the tab/space war. In python you can,
of course, use either one, but MIXING the two shall not be done.
As everyone knows, tabs are for formatting. As everyone who has
ever used proportional font s for anything knows, leading tabs are
the ONLY way to line up text vertically.
So, tabs should be used for lining up text.
HOWEVER about 25% of the different ways that text is presented in a fixed-width font, when copied, will expand the tabs to spaces. For
example, say I have PuTTY running with a connection to my home where
I did some prototyping so I want to just copy/paste a couple choice
code bits from there into my code at work. when using Python, I am *required* to reformat it to match the surrounding code... even if
it already visually matches.
In that last paragraph however, I purposely withheld vital
information... I use four-char tabstops (thanks DM). If I used
8-char ones, it would still "work".
Regarding the oft-quoted "It will look better" thing, the C
construct:
if (thing) {
...
}
else if (other_thing) {
...
}
else if (something_else) {
...
}
else {
...
}
Is quite a bit more readable than the correctly indented version:
if (thing) {
...
}
else
if(other_thing) {
...
}
else
if (something_else) {
...
}
else {
...
}
Which I presume is what is REQUIRED by Python... unless Python
includes perls hacktastic elsif thing and makes an if following an
else illegal (as it is in perl)
Re: Re: Python
By: Coriolanus to Angus McLeod on Tue Sep 12 2006 01:41 pm
For what it's worth, this is an interesting discussion of what you can and can't do with Python indentation:
http://www.secnetix.de/~olli/Python/block_indentation.hawk
The only reason I hate the significant leading whitespace issue with Python due exclusively to the tab/space war. In python you can, of course, use eit one, but MIXING the two shall not be done.
As everyone knows, tabs are for formatting.
As everyone who has ever used proportional font s for anything knows, leadin tabs are the ONLY way to line up text vertically.
So, tabs should be used for lining up text.
HOWEVER about 25% of the different ways that text is presented in a fixed-wi font, when copied, will expand the tabs to spaces. For example, say I have PuTTY running with a connection to my home where I did some prototyping so I want to just copy/paste a couple choice code bits from there into my code at work. when using Python, I am *required* to reformat it to match the surrounding code... even if it already visually matches.
In that last paragraph however, I purposely withheld vital information... I four-char tabstops (thanks DM). If I used 8-char ones, it would still "work
Regarding the oft-quoted "It will look better" thing, the C construct:
if (thing) {
...
}
else if (other_thing) {
...
}
else if (something_else) {
...
}
else {
...
}
Is quite a bit more readable than the correctly indented version:
if (thing) {
...
}
else
if(other_thing) {
...
}
else
if (something_else) {
...
}
else {
...
}
Which I presume is what is REQUIRED by Python... unless Python includes perl hacktastic elsif thing and makes an if following an else illegal (as it is i perl)
Which I presume is what is REQUIRED by Python... unless Python
includes perls hacktastic elsif thing and makes an if following an
else illegal (as it is in perl)
if (thing):
...
elif (other_thing):
...
elif (something_else):
...
else:
...
Well the whole spaces vs. tabs things just makes it impractical. Source file modified by different authors, editors, or computers, makes it impossible to sure that no tabs are going to creep into the source files and confuse the parser/compiler. Just stupid design, imho.
Ok, so you don't like the use off braces for block-scoping the source.
Fair enough. There are a host of other options, such as:
if (foo) if (foo)
(block) begin
else (block)
(block) end
end_if; /* or 'fi' */ else
begin
(block)
end;
But to tell you the truth, sometimes I like
while (condition) do block done ;
and sometimes I like
while (condition) { block } ;
and sometimes I like
while (condition) block end_while ;
but indentation don't work for me. Look at this code:
if foo:
if bar:
do_red();
else:
do_blue();
that else: clause is a single TAB character away from disaster.
I once used an Algol-68 compiler that required the keywords be underlined! The keywords had to be typed as follows:
IF = I, Backspace, Underscore, F, Backspace, Underscore.
or IF = I, F, Backspace, Backspace, Underscore, Underscore.
I did some work on the parser for that compiler and let me tell you, the lexical scanner was an absolute trip!
if (foo) if (foo)
(block) begin
else (block)
(block) end
end_if; /* or 'fi' */ else
begin
(block)
end;
Ok, now that's just silly. I would rather have {} than use begin/end.
That is a lot of extraneous typing with no good purpose.
I was just pointing out the minimal typing to generate readable code.
but indentation don't work for me. Look at this code:
if foo:
if bar:
do_red();
else:
do_blue();
that else: clause is a single TAB character away from disaster.
Fair enough, but at least it will be a _readable_ bug ;-)
I once used an Algol-68 compiler that required the keywords be underlined! The keywords had to be typed as follows:
IF = I, Backspace, Underscore, F, Backspace, Underscore.
or IF = I, F, Backspace, Backspace, Underscore, Underscore.
I did some work on the parser for that compiler and let me tell you, the lexical scanner was an absolute trip!
I don't even know what to say to that. Ugh!
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: | MCMLXXIX |
---|---|
Location: | Prospect, CT |
Users: | 325 |
Nodes: | 10 (0 / 10) |
Uptime: | 235:17:11 |
Calls: | 508 |
Messages: | 219888 |