Python: some neat things and PHP bashing

Pythoneer

Saturday, May 21. 2005

Python: some neat things and PHP bashing

During the last weeks of my entry into the Python world I have very quickly realized that I have to change my way of thinking and programming. A very good example is this thread where I tried to act smart and learned something!

Just now I read on the python-list an ancient mail about why print is a statement and not a function, there I also found out how to avoid the new line at the end of a print which never really bothered me, but I always asked myself how to avoid it, just in case I would ever need it.

print "no new line after me",

See the comma at the end! Huhu, cool thing. Some things are just easier than I thought. And it makes perfectly sense. I am using the print statement (without parentheses) quite a lot also with comma seperated arguments, instead of concatenated strings, so that should have been something, not obvious, but one of the first options to try.

PHP bashing

Another example of why I like Python better (over PHP). In PHP I would do the following:

if (in_array("x",$array) && $value)

In Python you do the same like this

if "x" in array and value

Which one is better to read?

Another interesting Python thing was finding the common words in two strings. I would not have come up with something that simple:

>>> import sets
>>> set1 = sets.Set("Bernd das Brot".split())
>>> set2 = sets.Set("Bäcker Bernd backt Brot".split())
>>> set1 & set2
set(['Brot', 'Bernd'])

Isn't that awesome? For those new to Python the ">>>" at the beginning of the line come from the Python shell, which btw is really great, I think I mentioned that. Sets seem to be in Python since 2.3.3.
OK, in PHP you would do it using the array_intersect function. But then you go into the hell of PHP's array-functions you first need to get the order of the parameters right :-). I think PHP's array functions are the best chaos you can find, especially the different orders of parameters for functions that do alike things. I don't even want to start about the naming. Many others have done that before.

Posted by Wolfram in Programming at 01:38
Comment (1)
Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

The parameter-chaos is there so that zend can sell their IDE with code-completion :-) My two pythong flirts remained flirts, unfortunately (but I still think python is hot): http://www.jannis.to/daily/archives/354-31337133723.html http://www.jannis.to/daily/archives/326-Blok-for-Superkaramba-released.html Hehe...
#1 Jannis (Homepage) on 2005-05-22 21:45 (Reply)

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 

Calendar

Back November '08
Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Quicksearch

Categories

  • XML JavaScript
  • XML Mac stuff
  • XML Miscellaneous
  • XML Missing or not found
  • XML Music
  • XML Private
  • XML Programming


All categories

Archives

November 2008
October 2008
September 2008
Recent...
Older...

supersized.org

Owner login

supersized s9y blog hosting
Free s9y blog!

Disclaimer

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Top Referrers

www.google.com (8)
chamnapchhorn.blogspot.com (1)
search.live.com (1)
www.google.ca (1)
www.google.ch (1)
www.google.com.au (1)
www.google.de (1)

Top Exits

The owner of supersized.org is not responsible for any content on this page!