• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

"Automate boring stuff using Python": Why Python ?

 
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Albert,

Why python has gained popularity in automating things compared to other scripting languages like ant,maven,shell script (sorry for giving lame examples).

Thanks
Ayub
 
Rancher
Posts: 276
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While the OP has explicitly directed this to the author, I wonder if I can put in my 2 cents. NB: My opinion would come from the decidedly wrong side of the spectrum (read "giant ignoramus" when it comes to Python)!

  • Indentaion implies block: This was in old Fortran and in some ways in Makefiles! (I loathe Makefiles just for that reason, FWIW). However, it makes code easier to read when the lines in a block (e.g., an if condition or a loop) are required to be indented by the language rules.
  • Terse and yet almost English like syntax: Unlike Java's or C++'s weird syntax for ternary operator, Python's ternary operator is simply beautiful.
  • Community following: Again, this isn't unique to Python, and yet for some reason, this seems to have worked in Python's favor significantly.


  • In addition to answering the OP's question, I'd be interested in hearing Albert's opinions of my views above.
     
    Ayub ali khan
    Ranch Hand
    Posts: 399
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the inputs Anand !!
     
    Bartender
    Posts: 9612
    16
    Mac OS X Linux Windows
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Ayub ali khan wrote:ant,maven,



    These are build tools (though you can also automate tasks with them), so the comparison isn't really fair. I would not look to Python to automate builds.

    Ayub ali khan wrote:
    shell script (sorry for giving lame examples).



    As a professional Java programmer, this is where I use Python the most. I find shell scripting syntax positively cryptic. Python fits the bill as most *nix systems have it already installed and I find it easier to write, debug and maintain. Also, we use Oracle Weblogic, which exposes the entire server configuration and runtime as MBeans and makes them accessible through a Python shell called WLST. this makes it possible to use Python to automate tasks like setting up a new server, migrating an existing server configuration or checking on the state of a running application.
    I recommend it to beginners and people who aren't programmers because, compared to Java, there isn't as much theory to get started (what's an object?), there isn't as much syntax to explain (what's "public static void main(String args[])"?) and there isn't as much work to run a program (you can use the interactive console to try things out or just run a script, no compiling necessary).
     
    Ayub ali khan
    Ranch Hand
    Posts: 399
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the inputs Joe!!
     
    Author
    Posts: 31
    5
    Python
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Python was originally based on a language called ABC, which was developed as a teaching language with easy to learn syntax. I think a large part of Python's readability and simple syntax stems from this. And the standard library has such incredibly useful features (such that GvR is reputed to have a time machine to let him implement features as soon as you need them), Python really filled in the space that before I had used Perl for.

    Shell scripting is something that I hope would have gone extinct by now. It's nice when you just want to clump together several shell commands, but once you need to start adding any sort of flow control, string manipulation, or any kind of complexity, a scripting language like Python would be a much better substitute.
     
    Ayub ali khan
    Ranch Hand
    Posts: 399
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Al Sweigart for your valuable inputs!!
     
    Al Sweigart
    Author
    Posts: 31
    5
    Python
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Anand's comments cover a lot of it.

    Anand Hariharan wrote:

  • Indentaion implies block: This was in old Fortran and in some ways in Makefiles! (I loathe Makefiles just for that reason, FWIW). However, it makes code easier to read when the lines in a block (e.g., an if condition or a loop) are required to be indented by the language rules.




  • At first I hated Pythons significant indentation, but now I wish every language used this. Aside from the spaces-and-tabs issue (I use 4-space indents), it makes the grouping obvious and cuts out those lines of single curly braces. It also neatly side steps the "opening brace on the same line or next line" religious arguments.

    Anand Hariharan wrote:

  • Terse and yet almost English like syntax: Unlike Java's or C++'s weird syntax for ternary operator, Python's ternary operator is simply beautiful.




  • This is key. In Java, I always have to look up how to open a text file! (BufferedInput or BufferedReader passed to an InputStream, or whatever) "Hello world is one line" goes a long way to making a language easy to learn, and thus popular. A sophisticated IDE like Eclipse is needed for Java, but not for Python.

    Though I wish the ternary operator was more like Java or C++.

    Anand Hariharan wrote:

  • Community following: Again, this isn't unique to Python, and yet for some reason, this seems to have worked in Python's favor significantly.




  • Python's community is awesome. I highly recommend people of all skill levels go to PyCon (the main one or any of the smaller ones). The Python community actually takes diversity seriously, and it shows in their results. The number of women giving presentations at has steadily increased from 1% in 2011 to 33% in 2015. The IRC channel is beginner-friendly as well.
     
    Anand Hariharan
    Rancher
    Posts: 276
    VI Editor C++ Debian
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Al Sweigart wrote:Anand's comments cover a lot of it.


    Thank you Al. Appreciate it.

    Al Sweigart wrote:Though I wish the ternary operator was more like Java or C++.


    Could you elaborate, please? I suppose opinions vary, but in this case, I know very, very little of Python, and you are ... well you! So opinion matters.

    In C++, one could write

    - whereas in Python one would write


    To me, the latter reads much better. I suppose there are operator precedence issues that come in play but I do not know the language well enough (read 'at all'!).

    thank you,
    - Anand
     
    Al Sweigart
    Author
    Posts: 31
    5
    Python
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    My preference for C++ ternary operators is probably just an old habit. But I do like how it reads "this-condition, this-value-if-true, this-value-if-false" instead of Python's "this-value, if-this-condition-is-true, or-else-this-value-if-the-previous-condition-was-false"
     
    Anand Hariharan
    Rancher
    Posts: 276
    VI Editor C++ Debian
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Al Sweigart wrote:My preference for C++ ternary operators is probably just an old habit. But I do like how it reads "this-condition, this-value-if-true, this-value-if-false" instead of Python's "this-value, if-this-condition-is-true, or-else-this-value-if-the-previous-condition-was-false"



    Would you apply the same reasoning on list comprehensions? They sure read unusually when compared to the explicit for-loop counterparts.
     
    Al Sweigart
    Author
    Posts: 31
    5
    Python
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's not a strong preference of mine either way.
     
    Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic