Fredrik Lundh wrote:
I usually mention "import" in the first hour (before methods), and nobody has ever had any problem with that...
Well, same here, but that might change, since the string module is nearly obsolete. You can show reasonably powerful stuff(*) without a single import.
(*) and that's what you need to get people interested.
I usually start out with something web-oriented (which means urllib). how about adding a "get" method to strings? or an "L" prefix character that causes Python to wrap it up in a simple URL container:
but in practice, if you really want people to get interested, make sure you have a domain-specific library installed on the training machines. why care about string fiddling when your second python program (after print "hello world") can be:
Yes, I know. I didn't want to make a point, just to point out that it is possible to show neat stuff without import. Sure, the next thing I show is COM stuff or formatted stock market reports, using urllib, xml... -- no point.
--- the rest below is not to Fredrik but the whole thread ---
I'd like to express my opinion at this place (which is as good as any other place in such a much-too-fast growing thread):
The following statements are ordered by increasing hate. 1 - I do hate the idea of introducing a "$" sign at all. 2 - giving "$" special meaning in strings via a module 3 - doing it as a builtin function 4 - allowing it to address local/global variables
Version 4 as worst comes visually quite close to languages like Perl. In another post, Guido answered such objection with "grow up". While my emotional reaction would be to reply with "wake up!", I have some rationale reasons why I don't like this:
I have to read and sometimes write lots of Perl code. The massive use of "$" gives me true headache. I don't want Python to remind me of headaches.
One argument was that "$" and the unembraced usage in "$name" is so common and therefore easy to sell to Python newbies. Fine, but no reason to adopt this overly abused character. Instead, I'm happy that exactly "$" is nowhere used in formatting. I don't want to make Python similar to something, but to keep it different in this aspect. Like the triple quotes, the percent formatting exists rather seldom in other languages, and I love to use templates for makefiles, scripts and whatsoever, where I don't have to care too much about escaping the escapes. With an upcoming "$" feature, I fear that "%" might get abandoned in some future, and I loose this benefit.
I agree with any sensible extension/refinement of the "%" sign. I disagree on using "$" for anything frequent in Python. I don't want to see variable names as placeholder inside of strings. Placeholders should be dictionary string keys, but this dictionary must be obtained explicitly. I do like the allvars() proposal.
crap-py -ly - chris