[Tutor] append, list and variables

Emile van Sebille emile at fenx.com
Fri Jul 16 19:54:01 CEST 2010


On 7/16/2010 8:37 AM Mary Morris said...
> Thanks-that helps a lot.
> The only question I have about your pseudocode is what the 'initialize
> result container' does.  I'm pretty new to python and scripting in general
> so I'm still trying to figure everything out.

It creates an empty data storage container for use within the processing 
loop -- if it wasn't defined before use, you'd get an error the first 
time you tried to append to it.  There's some good info in the tutorial 
-- see http://docs.python.org/tutorial/datastructures.html for details.

Emile



>
> On Thu, Jul 15, 2010 at 12:58 PM, Emile van Sebille<emile at fenx.com>  wrote:
>
>> On 7/15/2010 11:32 AM Mary Morris said...
>>
>>   Hi,
>>> I'm working on a program that parses through all of our source code at my
>>> office and i need to get my code to print a list of the decorators.  I
>>> used
>>> a find(@) to locate all the decorators, but I need to assign them to a
>>> variable somehow to get it to print a list. How do I do this? How do I
>>> assign a variable to all the indexed strings after the @ symbol?
>>>
>>>
>> So, decorator lines start with an '@'.  Source files end in '.py'.
>>
>> Pseudo code could be:
>> ----
>> initialize result container
>>
>> with each sourcefilename in globbed list:
>>   for eachline in opened(sourcefilename):
>>     if line.startswith('@'):
>>       append [sourcefilename, line] to result
>>
>> # print it
>>
>> for eachline in result:
>>   print eachline
>> ----
>>
>> Hope this gets you going,
>>
>> Emile
>>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list