- This topic is empty.
-
AuthorPosts
-
February 18, 2014 at 12:15 am #163188
nixnerd
ParticipantI have an
elif
and anelse
that are repeated in this code. However, I can’t find another way to incorporate these without breaking my very simple program.What do you guys suggest?
By the way… I’m aware this program does basically nothing at the moment. I just started it like an hour ago.
Thanks!
February 18, 2014 at 12:17 am #163189nixnerd
ParticipantI also have
raw_input()
way too many times.February 18, 2014 at 2:23 pm #163263__
ParticipantApparently,
elif
/else
is the preferred solution where other languages might use aswitch
statement. I don’t really like the way it looks, but I have to admit the reasoning is sound and it works the same way (which the exception of case fall-through, which is arguably more of a bug than a feature).As for
raw_input
, I disagree: just because you have to do it in most cases doesn’t mean it’s not dry. The alternative is to put it into a function that does the same thing, but then you have to call that function repeatedly, so what have you accomplished? un-pythonic.Another possibility would be
while running == True: status = raw_input() if clockedIn = False: # etc. ...
Obviously, the status doesn’t need to be updated when you
stop
, but would it hurt anything?February 18, 2014 at 6:11 pm #163279nixnerd
ParticipantWait… Are you saying not to use
if
? What if I need a 3-way logical fork? Hmmm. I guess I could figure out another way.February 18, 2014 at 6:56 pm #163286__
ParticipantWait… Are you saying not to use
if
?umm… no
Sorry, I think we got mixed up somewhere. Given your situation, I would normally use a
switch
statement. Given the fact that python doesn’t have aswitch
statement, I would useif
/elif
/else
(as you did). I was just pointing out that that appears to be the “correct” solution anyway.If you’re talking about the
raw_input
question, I was asking if you could just leave out thestatus
assignment in each case, since you already did it anyway (at the beginning of thewhile
loop). Is there a reason for assigning it again?February 18, 2014 at 7:05 pm #163287Alen
ParticipantI’m not a Python developer. But found this, might be helpful: http://code.activestate.com/recipes/410692/
February 18, 2014 at 8:27 pm #163291nixnerd
ParticipantI’m going to look at both of these more closely and see what I can do about this.
I just don’t like that it’s already 50 lines and barely does anything.
February 18, 2014 at 9:53 pm #163302nixnerd
ParticipantI wrote this stupidly because I’m printing all the questions/prompts. I could just use
raw_input(arg)
and put the prompt where thearg
is. Plus, I’m pretty sure I could useargv
instead ofraw_input
. There are only 3 options, raw_input isn’t really the best idea here. It’s not like I’m going to perform some wizardry on whatever garbage string they give me. It’s either option 1, 2 or 3.Poorly written. But… that’s what new git commits are for!
February 18, 2014 at 9:55 pm #163303nixnerd
ParticipantThought I’d share this with you gentlemen:
You’ve undoubtedly seen this but if you haven’t… you both know how to do math. I still find it interesting. Sometimes it’s good to spend time revamping your workflow… even if you have to write an app yourself.
February 18, 2014 at 10:02 pm #163304February 18, 2014 at 10:10 pm #163305__
ParticipantYou’ve undoubtedly seen this…
Yes, indeed.
Have you seen this? Might help you understand your place in the world as you embark on learning this fine language
February 18, 2014 at 10:10 pm #163306nixnerd
ParticipantI’m going to download this and run it a few times. There was a problem that was bothering me so much last night and now I can’t think of it. I need to run it and feed it a bunch of stuff to remember.
Thanks @traq!
February 18, 2014 at 10:14 pm #163307nixnerd
ParticipantMight help you understand your place in the world as you embark on learning this fine language.
HA HA HA HA! So true! Although… DAMN! I had no idea everyone thinks they’re superior to Java programmers. I mean, I learned Java in a CS class like everybody else in college and didn’t like it but… I have a little more respect for that language in particular.
Also… for me, C is the holy grail. When I can learn that, I’ll truly ‘feel’ like a real programmer.
February 18, 2014 at 10:15 pm #163308nixnerd
ParticipantOn a side note, I’m going to write everything for my BBB project in Python. It is literally the perfect choice for that project.
February 18, 2014 at 10:22 pm #163310nixnerd
ParticipantTo quote Zed Shaw:
“If you are reading this book and flipping out at every third sentence because you feel I’m insulting your intelligence… Go learn Lisp. I hear people who know everything really like Lisp.”
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.