Strings for a newbie

Malcolm Wooden mwooden at dtptypes.com
Fri May 27 08:24:36 EDT 2005


Sorry John but that don't do it for me. Just get errors comming back


"John Machin" <sjmachin at lexicon.net> wrote in message 
news:42970d69 at news.eftel.com...
> Malcolm Wooden wrote:
>> I'm trying to get my head around Python but seem to be failing miserably. 
>> I use RealBasic on a Mac and find it an absolute dream! But 
>> Python....UGH!
>>
>> I want to put a sentence of words into an array, eg "This is a sentence 
>> of words"
>>
>> In RB it would be simple:
>>
>> Dim s as string
>> Dim a(-1) as string
>> Dim i as integer
>>
>> s = "This is a sentence of words"
>> For i = 1 to CountFields(s," ")
>>   a.append NthField(s," ",i)
>> next
>>
>> That's it an array a() containing the words of the sentence.
>>
>> Now can I see how this is done in Python? - nope!
>>
>> UGH!
>>
>> Malcolm
>> (a disillusioned Python newbie)
>
>
> >>> s = "This is a sentence of words"
> >>> a = s.split()
> >>> a
> ['This', 'is', 'a', 'sentence', 'of', 'words']
> >>> 





More information about the Python-list mailing list