[Trac] Re: Python question

2009-06-08 Thread Ariel Balter
errors contains a list of tuppes, each with two elements.  The first 
element in each tupple is a string, the field_name, and a second is 
the string that gets manufactured with %s is required' % field_name 
based on the value of field_name.

I'm guessing that the next thing is that the list errors will get 
zipped into a dictionary.  There is actually a way to make 
dictionaries with those kinds of expressions, but I don't remember the 
syntax off the top of my head.

Dan Winslow wrote:

 Can someone explain this construct to me?

  

 errors = [(field_name, '%s is required' % field_name)

for field_name in required_fields

if self._is_empty(ticket[field_name])]

  

 What does 'errors' contain? I can see that it's a list of some 
 sort...but the parenthetical grouping in the first line looks like it 
 is some kind of initializer for field_name...so what does it return? 
 The contents of field_name? and how does the for loop work...what's 
 the difference between the if returning false or true?

  

 Dan Winslow
 Director of Information Technology, AIM INSTITUTE
 1905 Harney Street, Suite 700
 Omaha, NE 68102
 402-345-5025 x156
 dwins...@aiminstitute.org mailto:dwins...@aiminstitute.org
 www.aiminstitute.org http://www.aiminstitute.org

  


 

-- 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Ariel I Balter, Ph.D.
Postdoc
Biological Monitoring/Modeling
Fundamental and Computational Sciences Directorate

Pacific Northwest National Laboratory 
Mail:
PO Box 999, MS P7-58,Richland, WA 99352
Shipping:
790 6th Street, MS P7-58, Richland, WA 99354

Tel:  509-376-7605 
Cell:  509-713-0087
ariel.bal...@pnl.gov
www.arielbalter.com
www.pnl.gov 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---

begin:vcard
fn:Ariel Balter, PhD
n:Balter;Ariel
email;internet:abal...@indiana.edu
tel;home:812-332-2721
tel;cell:812-219-4558
x-mozilla-html:TRUE
url:http://arielbalter.com
version:2.1
end:vcard



[Trac] Re: Python question

2009-06-08 Thread Emmanuel Blot

 Can someone explain this construct to me?
You'd want to look for list comprehension documentation in Python

The code snipped can be rewritten as:

errors = []
for field_name in required_fields:
   if self._is_empty(ticket[field_name]):
  errors.append((field_name, '%s is required' % field_name))


     errors = [(field_name, '%s is required' % field_name)
        for field_name in required_fields
        if self._is_empty(ticket[field_name])]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---



[Trac] Re: Python question

2009-06-08 Thread Dan Winslow

Thanks, very much, I was having trouble finding it in Python docs. I didn't 
know what to call it!

-Original Message-
From: trac-users@googlegroups.com [mailto:trac-us...@googlegroups.com] On 
Behalf Of Emmanuel Blot
Sent: Monday, June 08, 2009 12:04 PM
To: trac-users@googlegroups.com
Subject: [Trac] Re: Python question


 Can someone explain this construct to me?
You'd want to look for list comprehension documentation in Python

The code snipped can be rewritten as:

errors = []
for field_name in required_fields:
   if self._is_empty(ticket[field_name]):
  errors.append((field_name, '%s is required' % field_name))


     errors = [(field_name, '%s is required' % field_name)
        for field_name in required_fields
        if self._is_empty(ticket[field_name])]



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---



[Trac] Re: Python question

2009-06-08 Thread Dan Winslow

Although...this 

errors=[]
errors.append(name,message)

gives

TypeError: append() takes exactly one argument (2 given

-Original Message-
From: trac-users@googlegroups.com [mailto:trac-us...@googlegroups.com] On 
Behalf Of Emmanuel Blot
Sent: Monday, June 08, 2009 12:04 PM
To: trac-users@googlegroups.com
Subject: [Trac] Re: Python question


 Can someone explain this construct to me?
You'd want to look for list comprehension documentation in Python

The code snipped can be rewritten as:

errors = []
for field_name in required_fields:
   if self._is_empty(ticket[field_name]):
  errors.append((field_name, '%s is required' % field_name))


     errors = [(field_name, '%s is required' % field_name)
        for field_name in required_fields
        if self._is_empty(ticket[field_name])]



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---



[Trac] Re: Python question

2009-06-08 Thread Ariel Balter
Consider:
{{{#!python
field_names = [
   'first',
   'second',
   'third',
   ]

stuff = [(field_name, 'the field name is \%s\' % field_name) for 
field_name in field_names]

print(stuff)

print('\n\n')

more_stuff = dict(stuff)

for key, value in more_stuff.items():
   print(key + ':\t' + value)
}}}

Dan Winslow wrote:

 Can someone explain this construct to me?

  

 errors = [(field_name, '%s is required' % field_name)

for field_name in required_fields

if self._is_empty(ticket[field_name])]

  

 What does 'errors' contain? I can see that it's a list of some 
 sort...but the parenthetical grouping in the first line looks like it 
 is some kind of initializer for field_name...so what does it return? 
 The contents of field_name? and how does the for loop work...what's 
 the difference between the if returning false or true?

  

 Dan Winslow
 Director of Information Technology, AIM INSTITUTE
 1905 Harney Street, Suite 700
 Omaha, NE 68102
 402-345-5025 x156
 dwins...@aiminstitute.org mailto:dwins...@aiminstitute.org
 www.aiminstitute.org http://www.aiminstitute.org

  


 

-- 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Ariel I Balter, Ph.D.
Postdoc
Biological Monitoring/Modeling
Fundamental and Computational Sciences Directorate

Pacific Northwest National Laboratory 
Mail:
PO Box 999, MS P7-58,Richland, WA 99352
Shipping:
790 6th Street, MS P7-58, Richland, WA 99354

Tel:  509-376-7605 
Cell:  509-713-0087
ariel.bal...@pnl.gov
www.arielbalter.com
www.pnl.gov 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---

begin:vcard
fn:Ariel Balter, PhD
n:Balter;Ariel
email;internet:abal...@indiana.edu
tel;home:812-332-2721
tel;cell:812-219-4558
x-mozilla-html:TRUE
url:http://arielbalter.com
version:2.1
end:vcard



[Trac] Re: Python question

2009-06-08 Thread Dan Winslow

Never mind, looks like I needed an internal paren, I guess to produce a 'tuple'

errors=[]
errors.append((name,message))

-Original Message-
From: trac-users@googlegroups.com [mailto:trac-us...@googlegroups.com] On 
Behalf Of Dan Winslow
Sent: Monday, June 08, 2009 12:10 PM
To: trac-users@googlegroups.com
Subject: [Trac] Re: Python question


Although...this 

errors=[]
errors.append(name,message)

gives

TypeError: append() takes exactly one argument (2 given

-Original Message-
From: trac-users@googlegroups.com [mailto:trac-us...@googlegroups.com] On 
Behalf Of Emmanuel Blot
Sent: Monday, June 08, 2009 12:04 PM
To: trac-users@googlegroups.com
Subject: [Trac] Re: Python question


 Can someone explain this construct to me?
You'd want to look for list comprehension documentation in Python

The code snipped can be rewritten as:

errors = []
for field_name in required_fields:
   if self._is_empty(ticket[field_name]):
  errors.append((field_name, '%s is required' % field_name))


     errors = [(field_name, '%s is required' % field_name)
        for field_name in required_fields
        if self._is_empty(ticket[field_name])]





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---



[Trac] Re: Python question

2009-06-08 Thread Emmanuel Blot

 Never mind, looks like I needed an internal paren, I guess to produce a 
 'tuple'
Yeah ;-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Trac 
Users group.
To post to this group, send email to trac-users@googlegroups.com
To unsubscribe from this group, send email to 
trac-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~--~~~~--~~--~--~---