Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > list unpack trick?

Reply
Thread Tools

list unpack trick?

 
 
Bengt Richter
Guest
Posts: n/a
 
      01-23-2005
On Sun, 23 Jan 2005 08:22:36 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) (Bengt Richter) wrote:

>On Sun, 23 Jan 2005 15:43:43 +1000, Nick Coghlan <(E-Mail Removed)> wrote:
>
>>aurora wrote:
>>> I am think more in the line of string.ljust(). So if we have a
>>> list.ljust(length, filler), we can do something like
>>>
>>> name, value = s.split('=',1).ljust(2,'')

>>
>>Eh?
>>
>>Py> s.split('=',1).ljust(2,'')
>>Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>>AttributeError: 'list' object has no attribute 'ljust'
>>

>
> Python 2.4b1 (#56, Nov 3 2004, 01:47:27)
> [GCC 3.2.3 (mingw special 20030504-1)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> help(''.ljust)

> Help on built-in function ljust:
>
> ljust(...)
> S.ljust(width[, fillchar]) -> string
>
> Return S left justified in a string of length width. Padding is
> done using the specified fill character (default is a space).
>
>I should upgrade too
>

And learn to read instead of jumping to conclusions ;-/
No ljust for *LIST* objects, D'oh.

Regards,
Bengt Richter
 
Reply With Quote
 
 
 
 
aurora
Guest
Posts: n/a
 
      01-23-2005
On Sat, 22 Jan 2005 10:03:27 -0800, aurora <(E-Mail Removed)> wrote:

> I am think more in the line of string.ljust(). So if we have a
> list.ljust(length, filler), we can do something like
>
> name, value = s.split('=',1).ljust(2,'')
>
> I can always break it down into multiple lines. The good thing about
> list unpacking is its a really compact and obvious syntax.


Just to clarify the ljust() is a feature wish, probably should be named
something like pad().

Also there is another thread a few hours before this asking about
essentially the same thing.

"default value in a list"
http://groups-beta.google.com/group/...affefdb4272270
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Is there any nice way to unpack a list of unknown size?? Gary Herron Python 2 09-14-2008 07:16 PM
Is there any nice way to unpack a list of unknown size?? srinivasan srinivas Python 0 09-14-2008 02:57 PM
Need better way to unpack a list Nx Python 3 08-17-2005 01:27 PM
Anyone have the unpack template for utmp on HPUX? Christian Lair Perl 0 02-09-2004 05:55 PM
How can i unpack a EXE file that contains a CRC error Jackal Computer Support 1 10-08-2003 06:59 PM



Advertisments