Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread SherjilOzair
Well, if not modify python itself, I was thinking of making another shell, 
which borrows a lot from python, something like merging bash and python. such 
that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at 
the some shell. This I think would be VERY useful.

IPyhton is very good, but after all, it is just an advanced interpreter, not a 
default shell. I don't want this to run on top of bash or sh. But it should run 
on its own, at shell level.

Bash and sh, according to me, have very ugly syntaxes and the general user does 
not even use those. Python put on the shell would be adhering to python's 
vision, i.e. bringing programming to the masses.
The general user, who earlier could not do batch operations, and had to buy 
software and such for all that, could now write his open simple python script 
and run it in his shell that would do as he wants.

Python on the shell could effectively remove learning grep, awk, sed, bash and 
the various unix utilities.
Don't take me wrong. Those are awesome tools, and I use them. But the 
awesomeness is not experienced by the general UNIX user on mac or linux. Python 
could do that.

We all know how great a programming language python is. Imagine being able to 
control your computer with such an elegant language. Imagine that I import some 
speech recognition utility on the terminal shell, and voila, I'm speaking to 
the computer and it is doing stuff on the terminal for me.

Shell would give python raw power! And Python would manage it well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread SherjilOzair
Well, if not modify python itself, I was thinking of making another shell, 
which borrows a lot from python, something like merging bash and python. such 
that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at 
the some shell. This I think would be VERY useful.

IPyhton is very good, but after all, it is just an advanced interpreter, not a 
default shell. I don't want this to run on top of bash or sh. But it should run 
on its own, at shell level.

Bash and sh, according to me, have very ugly syntaxes and the general user does 
not even use those. Python put on the shell would be adhering to python's 
vision, i.e. bringing programming to the masses.
The general user, who earlier could not do batch operations, and had to buy 
software and such for all that, could now write his open simple python script 
and run it in his shell that would do as he wants.

Python on the shell could effectively remove learning grep, awk, sed, bash and 
the various unix utilities.
Don't take me wrong. Those are awesome tools, and I use them. But the 
awesomeness is not experienced by the general UNIX user on mac or linux. Python 
could do that.

We all know how great a programming language python is. Imagine being able to 
control your computer with such an elegant language. Imagine that I import some 
speech recognition utility on the terminal shell, and voila, I'm speaking to 
the computer and it is doing stuff on the terminal for me.

Shell would give python raw power! And Python would manage it well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread Steven D'Aprano
On Sun, 19 Feb 2012 00:16:43 -0800, SherjilOzair wrote:

> Well, if not modify python itself, I was thinking of making another
> shell, which borrows a lot from python, something like merging bash and
> python. such that I can do `cd ~/Desktop/dev` and `for i in
> open('file.txt'): print i` at the some shell. This I think would be VERY
> useful.
> 
> IPyhton is very good, but after all, it is just an advanced interpreter,
> not a default shell. I don't want this to run on top of bash or sh. But
> it should run on its own, at shell level.

That's up to your operating system. If your OS lets you choose a shell, 
tell it to use IPython. IPython already supports being used as the system 
shell:

http://ipython.org/ipython-doc/dev/interactive/shell.html
http://transneptune.net/2009/06/16/ipython-as-your-default-shell/

If your OS doesn't support choosing a shell, you can't use anything but 
the built-in shell regardless of what Python does.

Either way, this is not a Python problem to solve. It is an OS issue.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: entering unicode (was Python usage numbers)

2012-02-19 Thread rusi
On Feb 19, 8:44 am, Steven D'Aprano  wrote:
> On Sun, 12 Feb 2012 19:09:32 -0800, rusi wrote:
> > I have some bunch of sanskrit (devanagari) to type.  It would be easiest
> > for me if I could have the English (roman) as well as the sanskrit
> > (devanagari).
>
> > For example using the devanagari-itrans input method I can write the
> > gayatri mantra using
>
> > OM bhUrbhuvaH suvaH
> > tatsaviturvarenyam
> > bhargo devasya dhImahi
> > dhiyo yonaH prachodayAt
>
> > and emacs produces *on the fly* (ie I cant see/edit the above)
>
> > ॐ भूर्भुवः सुवः तत्सवितुर्वरेण्यम् भर्गो
>
> देवस्य धीमहि धियो योनः
>
> > प्रचोदयात्
>
> > Can I do it in batch mode? ie write the first in a file and run some
> > command on it to produce the second?
>
> What is the devanagari-itrans input method? Do you actually type the
> characters into a terminal?

Its one of the dozens (hundreds actually) of input methods that emacs
has.
In emacs M-x set-input-method
and then give devanagari-itrans.
Its details are described (somewhat poorly) here 
http://en.wikipedia.org/wiki/ITRANS
>
> If so, you should be able to type the first into a file, copy it, then
> paste it into the input buffer to be processed.

For now Ive got it working in emacs with some glitches but it  will do
for now:

http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/bfa6b05ce565d96d#
>
> --
> Steven

Thanks
[Actually thanks-squared
one for looking
two for backing up this thread to something more useful than ... :-)
]

Coincidentally, along this, your response, Ive got another mail to
another unicode related interest of mine: apl under linux.

So far I was the sole (known) user of this: 
http://www.emacswiki.org/emacs/AplInDebian
I hear the number of users has just doubled :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread Terry Reedy

On 2/19/2012 3:18 AM, SherjilOzair wrote:

Well, if not modify python itself, I was thinking of making another
shell, which borrows a lot from python, something like merging bash
and python. such that I can do `cd ~/Desktop/dev` and `for i in


'cd xxx' cannot work because that is not python syntax. "cd('xxx')" 
could. Right now, one can import os and do shell stuff, but not so 
convinient for interactive use. 'os.chdir' is not so convenient as 'cd'. 
Two possible options, either of which might exist on PyPI:


1. a shell module used as 'from bashshell import *' which would have 
functions closely mimicking, in this example, bash


2. a shell module used as 'from bashshell import bash; bash()' which 
would invoke an sub-interactive mode like help() that would allow 'cd 
xxx' and similar syntax, which still affecting the global environment.
The latter would trade the inconvenience of '()'s for the inconvenience 
of entering and exiting a special submode.


I have not used IPYthon so I have no idea how close it gets to either of 
these.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


logging with logging.config.fileConfig

2012-02-19 Thread Herman
I tried to use file to config my logger and I got a weird situation
that each message is outputted twice...
Here is my scenario:
python: 2.6

file abc_logging.conf:

[loggers]
keys=root,abc

[handlers]
keys=consoleHandler

[formatters]
keys=detailFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_abc]
level=DEBUG
handlers=consoleHandler
qualname=abc

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=detailFormatter
args=(sys.stdout,)

[formatter_detailFormatter]
format=%(asctime)-15s %(levelname)s: %(filename)s:%(lineno)s: %(message)s
datefmt=%Y-%m-%d %H:%M:%S


Then in my program, i config the file with this:

SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
logging.config.fileConfig(SCRIPT_DIR + os.path.sep + 'abc_logging.conf')
LOG = logging.getLogger('abc')


I tried to print out the logger handlers with this:
 print("*"*10)
 print("number of handlers: %s" % len(LOG.handlers))
 print(LOG.handlers)
 LOG.debug(sql)

But there is no suspicious behavior:

**
number of handlers: 1
[]
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging with logging.config.fileConfig

2012-02-19 Thread MRAB

On 19/02/2012 20:23, Herman wrote:

I tried to use file to config my logger and I got a weird situation
that each message is outputted twice...
Here is my scenario:
python: 2.6

file abc_logging.conf:


[snip]

[logger_abc]
level=DEBUG
handlers=consoleHandler
qualname=abc


Add this line to stop the logging message from being propagated to
higher level (ancestor) loggers:

propagate=0

[snip]



Then in my program, i config the file with this:

SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
logging.config.fileConfig(SCRIPT_DIR + os.path.sep + 'abc_logging.conf')
LOG = logging.getLogger('abc')


I tried to print out the logger handlers with this:
  print("*"*10)
  print("number of handlers: %s" % len(LOG.handlers))
  print(LOG.handlers)
  LOG.debug(sql)

But there is no suspicious behavior:

**
number of handlers: 1
[]
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...


--
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread Michael Torrie
On 02/18/2012 11:58 AM, SherjilOzair wrote:
> Has it been considered to add shell features to python, such that it
> can be used as a default shell, as a replacement for bash, etc.
> 
> I'm sure everyone would agree that doing this would make the terminal
> very powerful.
> 
> What are your views on this?

I use python for system programming all the time, in place of bash.
However Python is not designed as shell language, just as Bash is not
really designed for the type of application development that Python is.

Bash works by giving you a view of the file system as your primary way
of interacting with it as a shell.  This is ideal because usually you
want to manipulate files and processes (that's just what you do on a
command line shell normally). Python doesn't work on that level.  Like
other langueages like php, you can manipulate files and processes
through standard library calls.  Frankly doing:

cd ~/blah

is much faster and more convenient in an interactive shell than:

import os
os.chdir(os.getenv("HOME") + "/blah")

Also bash is designed to start and control processes:

ls *.txt | wc -l
or
someprocess | grep something 2>&1 > /tmp/somefile.txt

In python there is no direct correlation to these things, and in fact
Python has different ways of doing that kind of thing (better for some
things) if you want to write scripts (for example,
http://www.dabeaz.com/generators/)

My own experience has shown me that Python is a very capable
systems-programming language, but that traditional shells are there for
a reason.  And if I need to script something, I usually go to Bash first
because it's simpler and easier, at least for very small tasks.  Once
the bash script gets to be 100 lines or more, I switch to python.  Then
I use some modules I wrote myself to make subprocess.Popen a little
simpler.  Another library that I heard about on this list, called
extproc, also seems to be similarly great for doing this.

There have been attempts over the years to bring access to files and
processes into python and still be pythonic, but they are all awkward.
For example, this sort of syntax using dynamic attributes:

shell.wc(shell.ls('/tmp/*.txt'), "-l")
or
shell.ls('/tmp/*.txt').pipe(shell.wc())

But it turns out that coming up with a python-compatible syntax is
pretty hard, especially when it comes to pipes (don't forget standard
err!)  Besides all this, it's just plain awkward and unnecessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread 88888 Dihedral
在 2012年2月20日星期一UTC+8上午8时23分33秒,Michael Torrie写道:
> On 02/18/2012 11:58 AM, SherjilOzair wrote:
> > Has it been considered to add shell features to python, such that it
> > can be used as a default shell, as a replacement for bash, etc.
> > 
> > I'm sure everyone would agree that doing this would make the terminal
> > very powerful.
> > 
> > What are your views on this?
> 
> I use python for system programming all the time, in place of bash.
> However Python is not designed as shell language, just as Bash is not
> really designed for the type of application development that Python is.
> 
To use Python as a shell with customized scripts  is feasiable for those hose 
have to work on different OS enviroments from  time to time. This is a handy 
approach to ease the user the burden  to memorize
different commands of different OS environments. 

Of course, this might add some overheads in executing some operations.

Nowadays attracting more people especially noices to use linux is the way to 
keep unix programming alive in the future.  

-- 
http://mail.python.org/mailman/listinfo/python-list