Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47941 > unrolled thread

Re: A certainl part of an if() structure never gets executed.

Started byZero Piraeus <schesis@gmail.com>
First post2013-06-12 11:20 -0400
Last post2013-06-19 01:05 +0300
Articles 6 — 6 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: A certainl part of an if() structure never gets executed. Zero Piraeus <schesis@gmail.com> - 2013-06-12 11:20 -0400
    Re: A certainl part of an if() structure never gets executed. rusi <rustompmody@gmail.com> - 2013-06-13 05:30 -0700
      Re: A certainl part of an if() structure never gets executed. Roy Smith <roy@panix.com> - 2013-06-13 09:01 -0400
    Re: A certainl part of an if() structure never gets executed. Neil Cerutti <neilc@norwich.edu> - 2013-06-13 12:34 +0000
      Re: A certainl part of an if() structure never gets executed. Νικόλαος Κούρας <support@superhost.gr> - 2013-06-13 20:00 +0300
        Re: A certainl part of an if() structure never gets executed. Jan Riechers <janpeterr@freenet.de> - 2013-06-19 01:05 +0300

#47941 — Re: A certainl part of an if() structure never gets executed.

FromZero Piraeus <schesis@gmail.com>
Date2013-06-12 11:20 -0400
SubjectRe: A certainl part of an if() structure never gets executed.
Message-ID<mailman.3181.1371124494.3114.python-list@python.org>
:

On 12 June 2013 10:55, Neil Cerutti <neilc@norwich.edu> wrote:
>
> He's definitely trolling. I can't think of any other reason to
> make it so hard to kill-file himself.

He's not a troll, he's a help vampire:

  http://slash7.com/2006/12/22/vampires/

... a particularly extreme example, I'll admit: his lack of
consideration for others apparently knows no bounds. The email thing
is just another aspect of that.

 -[]z.

[toc] | [next] | [standalone]


#47946

Fromrusi <rustompmody@gmail.com>
Date2013-06-13 05:30 -0700
Message-ID<8a75b1e4-41e8-45b5-ac9e-6611a469830a@g9g2000pbd.googlegroups.com>
In reply to#47941
On Jun 12, 8:20 pm, Zero Piraeus <sche...@gmail.com> wrote:
> :
>
> On 12 June 2013 10:55, Neil Cerutti <ne...@norwich.edu> wrote:
>
>
>
> > He's definitely trolling. I can't think of any other reason to
> > make it so hard to kill-file himself.
>
> He's not a troll, he's a help vampire:
>
>  http://slash7.com/2006/12/22/vampires/
>
> ... a particularly extreme example, I'll admit

Thanks for that term.

[toc] | [prev] | [next] | [standalone]


#47953

FromRoy Smith <roy@panix.com>
Date2013-06-13 09:01 -0400
Message-ID<roy-33547B.09013613062013@news.panix.com>
In reply to#47946
In article 
<8a75b1e4-41e8-45b5-ac9e-6611a469830a@g9g2000pbd.googlegroups.com>,
 rusi <rustompmody@gmail.com> wrote:

> On Jun 12, 8:20 pm, Zero Piraeus <sche...@gmail.com> wrote:
> > :
> >
> > On 12 June 2013 10:55, Neil Cerutti <ne...@norwich.edu> wrote:
> >
> >
> >
> > > He's definitely trolling. I can't think of any other reason to
> > > make it so hard to kill-file himself.
> >
> > He's not a troll, he's a help vampire:
> >
> >  http://slash7.com/2006/12/22/vampires/
> >
> > ... a particularly extreme example, I'll admit
> 
> Thanks for that term.

Yeah.  I've never heard that before, but it's perfect.

[toc] | [prev] | [next] | [standalone]


#47948

FromNeil Cerutti <neilc@norwich.edu>
Date2013-06-13 12:34 +0000
Message-ID<b1tshpF9297U1@mid.individual.net>
In reply to#47941
On 2013-06-12, Zero Piraeus <schesis@gmail.com> wrote:
> On 12 June 2013 10:55, Neil Cerutti <neilc@norwich.edu> wrote:
>>
>> He's definitely trolling. I can't think of any other reason to
>> make it so hard to kill-file himself.
>
> He's not a troll, he's a help vampire:
>
>   http://slash7.com/2006/12/22/vampires/
>
> ... a particularly extreme example, I'll admit: his lack of
> consideration for others apparently knows no bounds. The email thing
> is just another aspect of that.

He's also changed his NNTP-Posting-Host, just yesterday, along
with at least three changes in From address, and one change in
Reply-To.

And to start with he came here with an obvious troll name.

-- 
Neil Cerutti

[toc] | [prev] | [next] | [standalone]


#47989

FromΝικόλαος Κούρας <support@superhost.gr>
Date2013-06-13 20:00 +0300
Message-ID<kpcts5$21co$6@news.ntua.gr>
In reply to#47948
		if '-' not in name + month + year:
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = 
%s ORDER BY lastvisit ASC''', (name, month, year) )
		elif '-' not in name + year:
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM 
clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit 
ASC''', (name, year) )
		elif '-' not in month + year:
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and 
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
		elif '-' not in year:
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER 
BY lastvisit ASC''', year )


This finally worked!

[toc] | [prev] | [next] | [standalone]


#48672

FromJan Riechers <janpeterr@freenet.de>
Date2013-06-19 01:05 +0300
Message-ID<mailman.3561.1371594689.3114.python-list@python.org>
In reply to#47989
On 13.06.2013 20:00, Νικόλαος Κούρας wrote:
>          if '-' not in name + month + year:
>              cur.execute( '''SELECT * FROM works WHERE clientsID =
> (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and
> YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
>          elif '-' not in name + year:
>              cur.execute( '''SELECT * FROM works WHERE clientsID =
> (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER
> BY lastvisit ASC''', (name, year) )
>          elif '-' not in month + year:
>              cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit)
> = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
>          elif '-' not in year:
>              cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) =
> %s ORDER BY lastvisit ASC''', year )
>
>
> This finally worked!


I spared myself to read the whole thread cause its super long and I find 
it admirable that some people took time to troubleshoot the issue and 
(even) added optimizations of what can be done differently/better.. even 
so it seems there was only a wrong char used in the ifs?..

And as a short note - you should add code which handles the worst-case 
scenario (everthing fails, nothing valid, avoid into code which might 
require variables/data which is not present and so forth..)


But generally speaking:
As a best practice in any language not just Python.
If you have the option to print out evaluations and values, use it!


As rule of thumb for debugging code:
1. Print out what values you get in (from user, in(to) a function)
2a. Test statements and logic either by setting a print (in your case 
inside each if) with something like "if1", "if2", ... "else fired" or 
what you prefer OR do a direct comparison if the evaluation statements 
are not super long (someone mentioned that..)
2b. In case of longer statements/calculations, break them into chunks, 
simplify the problem to smaller ones and try to verify the results as 
possible (being "far apart" and "getting closer" after each time is 
already a good hint in calculations..)
3. If you catch data from a database and you see now results -> print 
out if your search/query even can return anything at all or if your 
query itself has a flaw or similar.

Optional but also useful:
4. On the end of a function, print if the output of the function is as 
expected

This small technique costs minimal time, but brings a brilliant ability:
1. Understand the code flow
2. Understand mistakes
3. Save yourself a big time by searching targeted for code parts which 
are executed..

..and ignore not directly connected code - for example when looking at 
other peoples code without documentation, comments or introduction.
This can spare loads of headaches.

And all this can be done in a couple of minutes..

Jan

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web