Strings for a newbie

Steve Holden steve at holdenweb.com
Fri May 27 13:38:32 EDT 2005


Malcolm Wooden wrote:
> Yes Sergei, as 3 of the lines are Dim statements, the real code is just 4 
> lines, a totally logical. It's not the amout of code thats a probelm, it's 
> following the logic and structure thats important. As I said Python.. UGH!
> 
> Malcolm
> 
Yes, the weirdest thing about the whole language is the way it jumps off 
the Internet and forces you to use it ... :-) (Which is my way of saying 
  that if you are happy with RealBasic then there's no need to pick 
Python up in the first place).

I can quite see why you would prefer

s = "This is a sentence of words"
For i = 1 to CountFields(s," ")
   a.append NthField(s," ",i)
next

to

s = "This is a sentence of words"
a = s.split()

How dare Python be shorter than RealBasic and easier to understand? 
(although you should check the validity of the Python code against a 
RealBasic interpreter. You might be surprised.) You also said

> my actual code is:
> 
>   for x in range(len(l)):
>     h = string.split(l[x])
> 
> where the sentence string is in an array of one element 'l'
> Error is:
> 
> Traceback (most recent call last):
>   File "<string>", line 34, in ?
>   File "<string>", line 27, in SentenceText
>   File "C:\PYTHON22\lib\string.py", line 122, in split
>     return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'
> 
> 

and then wondered why you got error messages trying to apply "split()" 
to some list. This is equivalent to saying "somebody told me to hammer 
this nail in, but my screwdriver won't hammer things".

Those who don't *want* to understand will find ways not to. Those who 
*do* want to understand will engage on a dialog until their problems are 
solved.

The fact that you don't even use the split() method that RealBasic makes 
available means you are overlooking the fact that the two languages are 
actually identical (modulo a few declarations) for your problem!

python-ugh-indeed-ly y'rs  - steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list