Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-23 Thread localpricemaps
well actually all i want it to do is find the first thing that shows up
whether its class:food or class: drink so that works for me.  only
thing is that after it finds class:food i think it runs through the
html again and finds the following class:drink and being that there is
not class tag after that class: drink tag it fails.

Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:

  ok i found something that works.  instead of using the def i did this:
 
  for incident in row('div', {'class': 'food' or 'drink' }):
 
  and it worked!

 'food' or 'drink' doesn't do what you think it does:

  'food' or 'drink'
 'food'

  {'class': 'food' or 'drink'}
 {'class': 'food'}
 
 /F

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-20 Thread Steve Holden
Brett Hoerner wrote:
 [EMAIL PROTECTED] wrote:
[...]
 or returns the first true element, anything but False or None, I
 think... so 'food' (a string) is true, and always will return in that
 code.

Just in case newbies are reading: in Python several different values are 
considered false in the context of an if statement. These include

False   # Boolean False
0   # The integer zero
0.0 # Floating-point zero
(0+0j)  # Complex zero
None# The None object
[]  # The empty list
()  # The empty tuple
{}  # The empty dictionary

This is mainly to allow the convenience of writing

 if thing:
 ...

However, one has to be careful that code that needs to treat None 
differently from [] uses explicit testing such as

 if thing is None:
 ...

You can also construct your own classes so their instances evaluate to 
True or False according to your needs.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-19 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 i actually realized there are 3 potentials for class names.  either
 food or drink or dessert.  so my question is whether or not i can alter
 your function to look like this?

  def isFoodOrDrinkOrDesert(attr):
 return attr in ['food', 'drink', 'desert']

what happens when you try that ?

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-19 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 ok i found something that works.  instead of using the def i did this:

 for incident in row('div', {'class': 'food' or 'drink' }):

 and it worked!

'food' or 'drink' doesn't do what you think it does:

 'food' or 'drink'
'food'

 {'class': 'food' or 'drink'}
{'class': 'food'}

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-19 Thread localpricemaps
hey fredrik,

i don't understand what you are saying

Fredrik Lundh wrote:
 [EMAIL PROTECTED] wrote:

  ok i found something that works.  instead of using the def i did this:
 
  for incident in row('div', {'class': 'food' or 'drink' }):
 
  and it worked!

 'food' or 'drink' doesn't do what you think it does:

  'food' or 'drink'
 'food'

  {'class': 'food' or 'drink'}
 {'class': 'food'}
 
 /F

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to find not the next sibling but the 2nd sibling or findsibling a OR sinbling b

2006-01-19 Thread Brett Hoerner
[EMAIL PROTECTED] wrote:
 hey fredrik,

 i don't understand what you are saying

Do what he showed in the Python interactive shell,

 Fredrik Lundh wrote:
  'food' or 'drink' doesn't do what you think it does:
 
   'food' or 'drink'
  'food'
 
   {'class': 'food' or 'drink'}
  {'class': 'food'}

or returns the first true element, anything but False or None, I
think... so 'food' (a string) is true, and always will return in that
code.

http://diveintopython.org/power_of_introspection/and_or.html

Brett

-- 
http://mail.python.org/mailman/listinfo/python-list