[Courses] [python] No lesson -- open discussion
Ehud Kaldor
ehud.kaldor at gmail.com
Mon Sep 12 23:30:27 UTC 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
i know some time went by, but this seems like a good forum to ask:
is there a good library for 'reading' images? OCR is what comes to
mind, but I am not sure if this is the right technical term for taking
an image of text and reading the text off it.
Thank you, Ehud
On 08/26/2011 08:38 PM, Akkana Peck wrote:
> Leslie writes:
>> I am trying to get good at manipulating files in python. My next
>> objective: to delete one line of a file. From my researches on the
web,
>> it looks like you have to do it indirectly, by writing the lines you
>> want to keep to a "good" file. Here is an example:
> [ ... ]
>> Is this in fact the best way to get rid of a line?
>
> Yes. I don't know of any way to insert or delete lines inside files
> under Linux (whether in Python or any other language).
>
> Your example is exactly how I'd do it, with two exceptions. First,
> there's no need to write the bad line to a second file unless you
> need to save that as well. You can just say
> ... if not "goofy" in l:
> ... goodf.write(l)
> Of course, if the goal is to keep a record of the bad lines, then I'd
> create a third file just as you did.
>
> Second, instead of
>>>> lines = inp.readlines()
>>>> for l in lines:
>
> I'd do
>>>> for l in inp :
>
> The difference is that the second version reads one line from the
> file at a time, while the first reads the whole file in to a list,
> so Python has to keep the contents of the whole file in memory.
> Of course that's not a big deal for your small example file, but
> if you wanted to use it on a really large file, it might make a
> difference.
>
> ...Akkana
> _______________________________________________
> Courses mailing list
> [1]Courses at linuxchix.org
> [2]http://mailman.linuxchix.org/mailman/listinfo/courses
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - [3]http://enigmail.mozdev.org/
iQIcBAEBAgAGBQJObpYTAAoJEAYu2FhJ51YkZ5sP/A7ynZCErW0PvxnedsKxIHx7
Wy9v7fSJWfFwHjpgibmJUuEb3hx6AewzRVshujoWRnPhML9Dcv5fXySUF1b2rRra
7+w4AFSGju7KeATZHQColFpkDsAv/RhzE+GH+2SIXu3myzUtyv3WsFx1VK/nTt0+
aMMV5OllyDx9xOWPlTnYFmhk0g2g7gu4npY4anm4jw+h/9GYPpWXdCukA5cxLHak
dy6j2FnCSILs6aDnuoEMqIOve986SEnywLGHIektwOjFBZFyPv+Eb/mz51W0HuEE
xfvcDSogx3IKO3H0AiPF1wd4CK/88HGVxwd23yI93YdIjWdYI1A9D9s282zr/w0P
55JzpPAObi7f+KE8zgkFCuv3wCLcksBGRIvACr1Ocvs7IaIeRJFyMSDF6GzKZSPC
1FA56LQI6Mf4bphUxH+pLyy1HTF9VplKL9BknIvvOX5mEMWeaWrtItkaK48ua+5S
F0Y86AprDdbGeWjvfwgUMiAFh1XjWKagMJS8+hYyqyGpuCvrF3yFE8ieVLiIuiiF
gBLDGI+vh6RzZSOB2wF2oXD/WekjPsElg9XehYd0FT5+biNkgebXRAGwzTFh4wsq
5yy8Q2gikGQ6AUJXZ+Y7mQrh9oPJGuYAFPUjXsxqUgEtBK9DwleiXUl8wybMDrxK
NkszIP6dDsgXAe+XmQw/
=9yoe
-----END PGP SIGNATURE-----
References
1. mailto:Courses at linuxchix.org
2. http://mailman.linuxchix.org/mailman/listinfo/courses
3. http://enigmail.mozdev.org/
More information about the Courses
mailing list