Re: python along or bash combined with python (for manipulating files)
On Tue, Oct 13, 2009 at 11:18 PM, TerryP wrote: > On Oct 14, 2:13 am, Peng Yu wrote: >> Bash is easy to use on manipulating files and directories (like change >> name or create links, etc) and on calling external programs. For >> simple functions, bash along is enough. However, bash does not support >> the complex functions. Python has a richer library that could provide >> support for complex functions (such compute the relative path between >> two paths). >> >> I'm wondering for a task that can not be done with bash along whether >> it would be better to do in pure python or with a mix of both python >> and bash. What I care is mostly coding speed and a little bit >> maintainability (but not much). Can somebody provide some experience >> on when to combine python and bash and when to use pure python? > > bash can **not** manipulate files and directories beyond things like > the '>' and '>>' I/O redirections, and some minor loading/saving of > state data from/to files (command history, directory stack, etc). Most > of what you refer to are **separate operating system specific > programs** and have absolutely nothing to do with the shell. > > Very sophisticated scripts are possible using bash and ksh, there is > even a form of ksh that has tk capabilities! (tksh). The Python and > Bourne-derived languages are however fundamentally different > creatures, and use very different data models. You should **not** > write Python (or Perl) scripts as if they were shell scripts -- doing > so is very bad practice. When you want a shell script, write a shell > script. When you write a Python script, write a Python script. It > really is that simple. > > > As a rule of thumb, when you have need of data structures beyond what > scalar strings and very simple word lists can provide -- you should > use Python. bash and ksh provide support for arrays, and ksh even has > dictionaries! (Hashes in Perl speak.) That makes programming in bash/ > ksh more robust then pure sh, but also less portable. The best time to > use bash is when you require bash specific features, other wise don't > use bash. The same can be said for ksh. Do you know what are bash and ksh specific features? Is there a thing that bash/ksh can do but python can not do? > When the words array, dictionary, class, object, and/or using multiple > source files comes to mind when implementing a program - you probably > want to use Python, Perl, Ruby, or some other general programming > language, not a shell scripting language like bash. > > You should be cautious to avoid mixing bash and Python code in one > file. > > > > If maintainability is not a factor in what you are writing, then you > should probably not be writing code in any language unless it is the > language of Mathematics (and even then, maintainability is a wise > consideration). > > -- > TerryP. > Just Another Programmer. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
In article <38890afc-c542-478a-bbe7-9a63dc6c9...@j9g2000vbp.googlegroups.com>, TerryP wrote: > >Very sophisticated scripts are possible using bash and ksh, there is >even a form of ksh that has tk capabilities! (tksh). The Python and >Bourne-derived languages are however fundamentally different >creatures, and use very different data models. You should **not** >write Python (or Perl) scripts as if they were shell scripts -- doing >so is very bad practice. When you want a shell script, write a shell >script. When you write a Python script, write a Python script. It >really is that simple. Oh, well, I guess I follow bad practice a lot. Shame on me. (That is, I disagree that it's bad practice to use Python as if it were a straight scripting language, os.system() and all. I prefer using Python because it makes it easy to upgrade scripts as needed.) -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --re...@lion.austin.ibm.com -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
On Oct 13, 10:18 pm, TerryP wrote: > On Oct 14, 2:13 am, Peng Yu wrote: > > > Bash is easy to use on manipulating files and directories (like change > > name or create links, etc) and on calling external programs. For > > simple functions, bash along is enough. However, bash does not support > > the complex functions. Python has a richer library that could provide > > support for complex functions (such compute the relative path between > > two paths). > > > I'm wondering for a task that can not be done with bash along whether > > it would be better to do in pure python or with a mix of both python > > and bash. What I care is mostly coding speed and a little bit > > maintainability (but not much). Can somebody provide some experience > > on when to combine python and bash and when to use pure python? > > bash can **not** manipulate files and directories beyond things like > the '>' and '>>' I/O redirections, and some minor loading/saving of > state data from/to files (command history, directory stack, etc). Most > of what you refer to are **separate operating system specific > programs** and have absolutely nothing to do with the shell. > > Very sophisticated scripts are possible using bash and ksh, there is > even a form of ksh that has tk capabilities! (tksh). The Python and > Bourne-derived languages are however fundamentally different > creatures, and use very different data models. You should **not** > write Python (or Perl) scripts as if they were shell scripts -- doing > so is very bad practice. When you want a shell script, write a shell > script. When you write a Python script, write a Python script. It > really is that simple. > > As a rule of thumb, when you have need of data structures beyond what > scalar strings and very simple word lists can provide -- you should > use Python. bash and ksh provide support for arrays, and ksh even has > dictionaries! (Hashes in Perl speak.) That makes programming in bash/ > ksh more robust then pure sh, but also less portable. The best time to > use bash is when you require bash specific features, other wise don't > use bash. The same can be said for ksh. > > When the words array, dictionary, class, object, and/or using multiple > source files comes to mind when implementing a program - you probably > want to use Python, Perl, Ruby, or some other general programming > language, not a shell scripting language like bash. > > You should be cautious to avoid mixing bash and Python code in one > file. > > If maintainability is not a factor in what you are writing, then you > should probably not be writing code in any language unless it is the > language of Mathematics (and even then, maintainability is a wise > consideration). > > -- > TerryP. > Just Another Programmer. With all of Terry's admonitions in mind, Python scripts do integrate very well as a individual tool within a shell toolchain. With the multiple command line parsers and the ease of reading stdin and writing to stdout, it's fairly trivial to make a script which integrates cleanly into a bash script (or oneliner). It's trivial to implement a script which will either work with files, or work with stdin/stdout. Garrick -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
On Oct 14, 3:42 am, Jean-Michel Pichavant wrote: > Peng Yu wrote: > > Bash is easy to use > > +JOTW > > :) > > JM why choose.. http://shython.sourceforge.net/ I don't think this is the most recent I would also try the package index -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
Peng Yu wrote: Bash is easy to use +JOTW :) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
En Tue, 13 Oct 2009 23:13:24 -0300, Peng Yu escribió: Bash is easy to use on manipulating files and directories (like change name or create links, etc) and on calling external programs. For simple functions, bash along is enough. However, bash does not support the complex functions. Python has a richer library that could provide support for complex functions (such compute the relative path between two paths). I'm wondering for a task that can not be done with bash along whether it would be better to do in pure python or with a mix of both python and bash. What I care is mostly coding speed and a little bit maintainability (but not much). Can somebody provide some experience on when to combine python and bash and when to use pure python? You may be interested in this article: http://www.ibm.com/developerworks/aix/library/au-python/ and these from David M. Beazley (more advanced): http://www.dabeaz.com/generators/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
On Oct 14, 2:13 am, Peng Yu wrote: > Bash is easy to use on manipulating files and directories (like change > name or create links, etc) and on calling external programs. For > simple functions, bash along is enough. However, bash does not support > the complex functions. Python has a richer library that could provide > support for complex functions (such compute the relative path between > two paths). > > I'm wondering for a task that can not be done with bash along whether > it would be better to do in pure python or with a mix of both python > and bash. What I care is mostly coding speed and a little bit > maintainability (but not much). Can somebody provide some experience > on when to combine python and bash and when to use pure python? bash can **not** manipulate files and directories beyond things like the '>' and '>>' I/O redirections, and some minor loading/saving of state data from/to files (command history, directory stack, etc). Most of what you refer to are **separate operating system specific programs** and have absolutely nothing to do with the shell. Very sophisticated scripts are possible using bash and ksh, there is even a form of ksh that has tk capabilities! (tksh). The Python and Bourne-derived languages are however fundamentally different creatures, and use very different data models. You should **not** write Python (or Perl) scripts as if they were shell scripts -- doing so is very bad practice. When you want a shell script, write a shell script. When you write a Python script, write a Python script. It really is that simple. As a rule of thumb, when you have need of data structures beyond what scalar strings and very simple word lists can provide -- you should use Python. bash and ksh provide support for arrays, and ksh even has dictionaries! (Hashes in Perl speak.) That makes programming in bash/ ksh more robust then pure sh, but also less portable. The best time to use bash is when you require bash specific features, other wise don't use bash. The same can be said for ksh. When the words array, dictionary, class, object, and/or using multiple source files comes to mind when implementing a program - you probably want to use Python, Perl, Ruby, or some other general programming language, not a shell scripting language like bash. You should be cautious to avoid mixing bash and Python code in one file. If maintainability is not a factor in what you are writing, then you should probably not be writing code in any language unless it is the language of Mathematics (and even then, maintainability is a wise consideration). -- TerryP. Just Another Programmer. -- http://mail.python.org/mailman/listinfo/python-list
Re: python along or bash combined with python (for manipulating files)
On Oct 13, 9:13 pm, Peng Yu wrote: > Bash is easy to use on manipulating files and directories (like change > name or create links, etc) and on calling external programs. For > simple functions, bash along is enough. However, bash does not support > the complex functions. Python has a richer library that could provide > support for complex functions (such compute the relative path between > two paths). > > I'm wondering for a task that can not be done with bash along whether > it would be better to do in pure python or with a mix of both python > and bash. What I care is mostly coding speed and a little bit > maintainability (but not much). Can somebody provide some experience > on when to combine python and bash and when to use pure python? Scripting languages try to optimize gluing disparate programs together to accomplish a task; bash excels at this. Programing languages try to optimize finding the solution to a problem; Python excels at this. Generally, I try to stick to one language per problem, be it bash, C+ +, Java, Perl or Python. Bash scripts translate easily into the others, so you don't lose much time if you decide you started with the wrong language. Countering that, I also maintain a "toolbox" of programs that I can call upon when needed. In those cases, I don't hesitate to call a program that I've written in any language from a bash script. BTW, I actually prefer ksh to bash, but YMMV. -- http://mail.python.org/mailman/listinfo/python-list
python along or bash combined with python (for manipulating files)
Bash is easy to use on manipulating files and directories (like change name or create links, etc) and on calling external programs. For simple functions, bash along is enough. However, bash does not support the complex functions. Python has a richer library that could provide support for complex functions (such compute the relative path between two paths). I'm wondering for a task that can not be done with bash along whether it would be better to do in pure python or with a mix of both python and bash. What I care is mostly coding speed and a little bit maintainability (but not much). Can somebody provide some experience on when to combine python and bash and when to use pure python? -- http://mail.python.org/mailman/listinfo/python-list