On 03/05/10 06:16, Thomas C. Hicks wrote:
I am using Python 2.6.4 in Ubuntu. Since I use Ubuntu (with its every
6 months updates) and want to learn Python I have been working on a
post-install script that would get my Ubuntu system up and running with
my favorite packages quickly.
As an aside,
Wow, this is great! I appreciate all the pointers, lots to keep
learning here.
thomas
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
> Agreed that
>
> line = line[:line.index('%')]
>
> is slightly more readable than
>
>line = line.split('%', 1)[0]
How about:
line = line.partition('%')[0]
partition() works even if '%' isn't present.
The index() and split() techniques raise exceptions if '%' isn't
present.
Malcolm
__
On Mon, 03 May 2010 13:08:18 +0200
Stefan Behnel wrote:
> > Why aren't strings mutable, or lists immutable?
>
> What would be the use case of an immutable list, as opposed to a tuple? How
> would you use mutable strings in a dictionary?
[I'm not totally sure of the following, take it with so
On Mon, 3 May 2010 08:18:41 pm Luke Paireepinart wrote:
> On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel
wrote:
> > Luke Paireepinart, 03.05.2010 10:27:
> >> What's this bizarre syntax?
> >
> > Look it up in the docs, it's called "with statement". Its purpose
> > here is to make sure the file is c
Luke Paireepinart, 03.05.2010 12:18:
On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel wrote:
Luke Paireepinart, 03.05.2010 10:27:
I thought they changed for loop interations so that if you did
for line in open('packages.txt'):
etc...
it would automatically close the file handle after th
2010/5/3 spir ☣ :
> On Mon, 03 May 2010 10:55:11 +0200
> Stefan Behnel wrote:
>
>> Luke Paireepinart, 03.05.2010 10:27:
>> > On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
>> >> line = line.split('%', 1)[0]
>> >
>> > lines = [line[:line.index('%')] for line in ...
>>
>> Agree
On Mon, 3 May 2010 05:35:52 pm Andre Engels wrote:
> Don't change the list that you are iterating over. As you have found,
> it leads to (to most) unexpected results.
Or if you absolutely have to change the list in place, iterate over it
*backwards* (starting at the end, and moving towards the
On Mon, 03 May 2010 10:55:11 +0200
Stefan Behnel wrote:
> Luke Paireepinart, 03.05.2010 10:27:
> > On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
> >> line = line.split('%', 1)[0]
> >
> > lines = [line[:line.index('%')] for line in ...
>
> Agreed that
>
> line = line[
On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel wrote:
> Luke Paireepinart, 03.05.2010 10:27:
>> What's this bizarre syntax?
>
> Look it up in the docs, it's called "with statement". Its purpose here is to
> make sure the file is closed after the execution of the statement's body,
> regardless of an
Luke Paireepinart, 03.05.2010 10:27:
On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
line = line.split('%', 1)[0]
lines = [line[:line.index('%')] for line in ...
Agreed that
line = line[:line.index('%')]
is slightly more readable than
line = line.split('%', 1)
Luke Paireepinart, 03.05.2010 10:27:
On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
You are modifying the list during iteration, so the size changes and the
iterator gets diverted. Don't remove the line, just skip over it, e.g.
def read_package_names(open_text_file):
"""Read
On Mon, May 3, 2010 at 10:19 AM, Luke Paireepinart
wrote:
> Hmm, why not
> lines = [line for line in lines if not line.strip().startswith('%')]
I knew I missed something
--
André Engels, andreeng...@gmail.com
___
Tutor maillist - Tutor@python.
On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote:
>
> You are modifying the list during iteration, so the size changes and the
> iterator gets diverted. Don't remove the line, just skip over it, e.g.
>
> def read_package_names(open_text_file):
> """Read lines, strip any comments and r
> If that looks a bit clumsy, use a generator expression:
>
> linesToDelete = [x for x in lines if x.startswith('%')]
> for x in linesToDelete:
> lines.remove(x)
>
> which idiomatically should probably become:
>
> for x in [y for y in lines if y.startswith('%')]:
> lines.remove(x)
>
>
Hmm, why
On Mon, May 3, 2010 at 7:16 AM, Thomas C. Hicks wrote:
> I am using Python 2.6.4 in Ubuntu. Since I use Ubuntu (with its every
> 6 months updates) and want to learn Python I have been working on a
> post-install script that would get my Ubuntu system up and running with
> my favorite packages qui
Thomas C. Hicks, 03.05.2010 07:16:
%Comment introducing the next block of packages
%Below are the packages for using Chinese on the system
%Third line of comment because I am a verbose guy!
ibus-pinyin
ibus-table-wubi
language-pack-zh-hans
etc.
I read the lines of the file into a list for proce
17 matches
Mail list logo