File traversing

Nibin V M nibinvm at gmail.com
Tue Apr 17 10:31:32 EDT 2012


# python test.py
  File "test.py", line 1
    with open('/etc/trueuserowners') as res_own_file:
    ^
IndentationError: unexpected indent
 [~]# cat test.py
 with open('/etc/trueuserowners') as res_own_file:
    all_res = set(line.strip().replace(' ', '').split(':')[1] for line in
res_own_file if ':' in line)

 print all_res

am I missing something? :)

On Tue, Apr 17, 2012 at 4:44 PM, Nibin V M <nibinvm at gmail.com> wrote:

> wow...thanks Karl :)
>
> On Tue, Apr 17, 2012 at 2:20 AM, Karl Knechtel <zahlman at gmail.com> wrote:
>
>>
>>
>> On Sun, Apr 15, 2012 at 5:51 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>>>
>>> (You may also want to consider using the 'with' statement to guarantee
>>> a timely closing of the file. Outside the scope of this mail though.)
>>>
>>> I think this list is just to collect unique entries, yes? If so, a set
>>> may be more to your liking. Check out:
>>> http://docs.python.org/py3k/library/stdtypes.html#set
>>>
>>>  <http://mail.python.org/mailman/listinfo/python-list>
>>>
>>
>> In cases like this I like to just show the final code after making all
>> the changes, and let the student ask questions :)
>>
>> with open('/bah') as res_own_file:
>>     all_res = set(line.strip().replace(' ', '').split(':')[1] for line in
>> res_own_file if ':' in line)
>>
>> --
>> ~Zahlman {:>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
>
> --
> Regards....
>
> Nibin.
>
> http://TechsWare.in
>
>


-- 
Regards....

Nibin.

http://TechsWare.in
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120417/0b205aad/attachment-0001.html>


More information about the Python-list mailing list