Re: symbolic links, aliases, cls clear

2006-04-15 Thread Chris F.A. Johnson
On 2006-04-13, Barry Margolin wrote:
 In article [EMAIL PROTECTED],
  Chris F.A. Johnson [EMAIL PROTECTED] wrote:

  In fact, my scripts are portable to other terminal types by use
  of files for each terminal, generated with tput. Using a
  different terminal is as easy as . /usr/share/term-sh/$TERM or
  something similar. I generated a lot of files a few years ago,
  but I have never had any call for them, so I'd have to hunt for
  them.

 So you've essentially reinvented the whole termcap/terminfo mechanism?

   No, I've used the termcap/terminfo mechanism via tput to create a
   more efficient (and customizable) method of terminal-dependent
   control.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Floyd L. Davidson wrote:
 [EMAIL PROTECTED] wrote:
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

 Or so you would hope (however, that is *not* what you have listed!).

 Unfortunately, it is poor practice to hard code such sequences.

   I was bitten by that shortly after I started shell scripting.
   However, since all such code was isolated in functions, converting
   to a new terminal type was simple -- and quick.

   These days, the ISO-6429 standard (almost the same as the older
   ANSI x3.64) is so close to universal that I don't bother writing
   for anything else any more. If the need arises, I'll do it, but it
   will be simple to do, and much faster (both in coding and script
   execution) than trying to accommodate all terminals from the start.

 Instead the proper sequence should be obtained from the
 appropriate database (TERMINFO or TERMCAP), and the easy way to
 do that is,

tput clear

   I still have a system which does not have tput.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Floyd L. Davidson wrote:
 Keith Thompson [EMAIL PROTECTED] wrote:
tput clear

(Or clear.)

 But /clear/ merely uses tput clear.

   Not on systems without tput.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, jpd wrote:
 Begin  [EMAIL PROTECTED]
 On 2006-04-12, Chris F.A. Johnson [EMAIL PROTECTED] wrote:
These days, the ISO-6429 standard (almost the same as the older
ANSI x3.64) is so close to universal that I don't bother writing
for anything else any more.

 Oh, wonderful. ``All the world's a vax^W^WISO-6429 compatible'' all over
 again.

If the need arises, I'll do it, but it will be simple to do, and
much faster (both in coding and script execution) than trying to
accommodate all terminals from the start.

 Yes, why use a perfectly good abstraction when you can hardcode stuff.

   If it were perfectly good, there would be no question; however,
   it's not.

I still have a system which does not have tput.

 And that justifies everything else. Of course.

   If I want to write portable scripts, then yes, it does.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Christos Georgiou wrote:
 On Wed, 12 Apr 2006 15:59:05 -0400, rumours say that Chris F.A. Johnson
[EMAIL PROTECTED] might have written:

I still have a system which does not have tput.

 And that justifies everything else. Of course.

   If I want to write portable scripts, then yes, it does.

 Well, either port your system out of the window or port tput.c to your
 system and then start writing portable scripts.  tput is part of the POSIX
 1003.1 standard, and guess what the 'P' stands for in POSIX.

 It may be part of the POSIX standard, but there's nothing in the
 POSIX definition of tput that provides for cursor positioning or
 font attributes. The only defined operands are clear, init and
 reset.

 In fact, my scripts are portable to other terminal types by use
 of files for each terminal, generated with tput. Using a
 different terminal is as easy as . /usr/share/term-sh/$TERM or
 something similar. I generated a lot of files a few years ago,
 but I have never had any call for them, so I'd have to hunt for
 them.

 If you insist, I will retort to using Terry Pratchett references.

 UNCLE!

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread Chris F.A. Johnson
On 2006-03-29, mp wrote:
 i have a python program which attempts to call 'cls' but fails:

 sh: line 1: cls: command not found

 i tried creating an alias from cls to clear in .profile, .cshrc, and
 /etc/profile, but none of these options seem to work.

   Why not call 'clear', since 'cls' does not exist?

 my conclusion is that a python program that is executing does not use
 the shell (because it does not recognize shell aliases). is this
 correct?

   Even shell scripts do not normally expand aliases.

 should i use a symbolic link? if so, where should i place it?

 what is the difference between aliases and symbolic links?

   What's the difference between a raven and a writing desk?

 if i execute a command like 'clear' to clear the screen, where does the
 shell look to find the command 'clear'?

   In a directory listed in the PATH variable.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spelling mistakes!

2006-01-08 Thread Chris F.A. Johnson
On 2006-01-08, Terry Hancock wrote:

 BTW, one of the most common programming spelling errors is
 deprecate versus depreciate -- I wonder how many people
 actually realize that both words exist, but have entirely
 different meanings?

   The words overlap in meaning. Both can mean to disparage or
   belittle.

   Some dictionaries give 'depreciate' as a definition of 'deprecate'.


-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spelling mistakes!

2006-01-08 Thread Chris F.A. Johnson
On 2006-01-08, Robin Becker wrote:
 Chris F.A. Johnson wrote:
 On 2006-01-08, Terry Hancock wrote:
 
BTW, one of the most common programming spelling errors is
deprecate versus depreciate -- I wonder how many people
actually realize that both words exist, but have entirely
different meanings?
 
 
The words overlap in meaning. Both can mean to disparage or
belittle.
 
Some dictionaries give 'depreciate' as a definition of 'deprecate'.

 Well if someone told me my investments were deprecated I'd take that 
 differently to them being depreciated.

   That's why I said overlap, not that they are the same.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading files into dicts

2005-12-29 Thread Chris F.A. Johnson
On 2005-12-30, Tim Williams (gmail) wrote:
 Apologies for the top post, it was my first attempt at using gmail's
 pda-enabled web interface. There is no option to bottom post.

Can you not move the cursor?

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Chris F.A. Johnson
On 2005-12-06, Steve Holden wrote:
 Daniel Schüle wrote:
 hi,
 
 [...]
 
 
# pseudo code
i=2
lst=[i**=2 while i1000]

of course this could be easily rewritten into
i=2
lst=[]
while i1000:
i**=2
lst.append(i)



Neither of these loops would terminate until memory is exhausted. Do you 
have a use case for a 'while' in a list comprehension which would 
terminate?
 
 
 unless I am missing something obvious, I can not see why the loop should 
 not terminate

 In that case, kindly explain how the condition i1000 can become false 
 when it starts at 2 and never changes! [In other words: you *are* 
 missing something obvious].

What does i**=2 do if not change i?

 i=2
 lst=[]
 while i1000:
... i**=2
... lst.append(i)
... 
 lst
[4, 16, 256, 65536]


-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython Licence vs GPL

2005-11-26 Thread Chris F.A. Johnson
On 2005-11-26, Steven D'Aprano wrote:

 If you don't like that clause, you have two very simple options: don't
 redistribute the GPLed software. Or use some other software provided under
 a different licence.

There is a third option: persuade the owner of the copyright to
give you a different license.


-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen('alias')

2005-11-18 Thread Chris F.A. Johnson
On 2005-11-18, Belebele wrote:
From an interactive python shell, I execute the following:

 import os
 for line in os.popen('alias').readlines():
   print line


 No aliases are printed.

 I started python from an bash environment that had many aliases
 defined. I expected to see the list of aliases from within the
 interactive python shell.

Since bash does not export aliases, they cannot be seen by a child
process.

 What could I do to see those aliases defined in the shell from where
 I started python?

Store them in a file before calling python, and read that file.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.popen('alias')

2005-11-18 Thread Chris F.A. Johnson
On 2005-11-19, Chris F.A. Johnson wrote:
 On 2005-11-18, Belebele wrote:
From an interactive python shell, I execute the following:

 import os
 for line in os.popen('alias').readlines():
   print line


 No aliases are printed.

 I started python from an bash environment that had many aliases
 defined. I expected to see the list of aliases from within the
 interactive python shell.

 Since bash does not export aliases, they cannot be seen by a child
 process.

 What could I do to see those aliases defined in the shell from where
 I started python?

 Store them in a file before calling python, and read that file.

   Or redefine them as functions and use:

import os
for line in os.popen('typeset -f').readlines():
  print line

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Goto XY

2005-11-08 Thread Chris F.A. Johnson
On 2005-11-09, [EMAIL PROTECTED] wrote:
 Is there some command in python so that I can read a key's input and
 then use a gotoxy() function to move the cursor on screen?  e.g.:
 (psuedo-code)

You can use curses, but that may be more trouble than it's worth.

If you don't mind limiting your program to an ANSI-type terminals
(vt100, xterm, rxvt, linux, putty, etc), then you can just use
the codes to position the cursor:

ESC = '\033'
CSI = ESC + [

def printat(row,col,arg=):
sys.stdout.write( CSI + str(row) + ; + str(col) + 'H' + str(arg))

 When the right arrow is pushed, cursor gotoxy(x+1,y)

 To read a single keystroke, see Claudio Grondi's post in the
 thread python without OO from last January.

 Function and cursor keys return more than a single character, so
 more work is required to decode them. The principle is outlined in
 http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html;
 the code there is for the shell, but translating them to python
 should be straightforward. I'll probably do it myself when I have
 the time or the motivation.

-- 
  Chris F.A. Johnson   | Author:
  http://cfaj.freeshell.org  |  Shell Scripting Recipes:
  Any code in this post is released|  A Problem-Solution Approach,
  under the GNU General Public Licence | 2005, Apress
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Goto XY

2005-11-08 Thread Chris F.A. Johnson
On 2005-11-09, Jean-Paul Calderone wrote:
 On Tue, 8 Nov 2005 22:33:47 -0500, Chris F.A. Johnson [EMAIL PROTECTED] 
 wrote:
 [snip]

 To read a single keystroke, see Claudio Grondi's post in the
 thread python without OO from last January.

 Function and cursor keys return more than a single character, so
 more work is required to decode them. The principle is outlined in
 http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html;
 the code there is for the shell, but translating them to python
 should be straightforward. I'll probably do it myself when I have
 the time or the motivation.


 Like this?

 http://cvs.twistedmatrix.com/cvs/trunk/twisted/conch/insults/insults.py?view=markuprev=14863

More or less; probably much less.

-- 
  Chris F.A. Johnson   | Author:
  http://cfaj.freeshell.org  |  Shell Scripting Recipes:
  Any code in this post is released|  A Problem-Solution Approach,
  under the GNU General Public Licence | 2005, Apress
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Goto XY

2005-11-08 Thread Chris F.A. Johnson
On 2005-11-09, Grant Edwards wrote:
 On 2005-11-09, Chris F.A. Johnson [EMAIL PROTECTED] wrote:

 Is there some command in python so that I can read a key's input and
 then use a gotoxy() function to move the cursor on screen?  e.g.:
 (psuedo-code)

 You can use curses, but that may be more trouble than it's worth.

 In which case you could always use tput -- and it will still be
 portable.

   Not necessarily. There are differences in tput from system to
   system, not to mention how much it slows things down to call it for
   every sequence you need.

   Then there are some old systems which don't have tput.


-- 
  Chris F.A. Johnson   | Author:
  http://cfaj.freeshell.org  |  Shell Scripting Recipes:
  Any code in this post is released|  A Problem-Solution Approach,
  under the GNU General Public Licence | 2005, Apress
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python Accepted in my Organisation

2005-11-05 Thread Chris F.A. Johnson
On 2005-11-05, Steven D'Aprano wrote:
 On Fri, 04 Nov 2005 20:55:48 -0500, Chris F.A. Johnson wrote:

quoting deliberately removed to make a point

 So that people reading your reply know what you are commenting about.

 (Now, imagine that you're reading from a newsgroup where Chris' post has
 disappeared off the server, or perhaps never showed up at all.)

   Did I say something???

-- 
  Chris F.A. Johnson   | Author:
  http://cfaj.freeshell.org  |  Shell Scripting Recipes:
  Any code in this post is released|  A Problem-Solution Approach,
  under the GNU General Public Licence | 2005, Apress
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting Python Accepted in my Organisation

2005-11-04 Thread Chris F.A. Johnson
On 2005-11-04, [EMAIL PROTECTED] wrote:

 Alex Martelli wrote:
 It would still be easier to respond to your posts if you didn't
 top-post, though (i.e., if you didn't put your comments BEFORE what
 you're commenting on -- that puts the conversation in a weirdly
 distorted order, unless one give up on quoting what you're commenting
 on, or invests a lot of time and energy in editing...;-).


 oops. I developed this habit because I found I like to read it this
 way. As I usually would read just the first few lines to see if I
 want to read on. top post serve me well for this purpose. And I
 assume other may also find my stuff not worth reading and skip quick
 so why force them to scroll all the way down?

   If I want to read that way, I just tell my newsreader not to
   display the quoted material (actually it displays the first line of
   each block).

   Or I press TAB to jump to the next original material.

 I would only do in-line response type when there is a need for
 specific response in context.

If there's not, why would you quote anything?

-- 
  Chris F.A. Johnson   | Author:
  http://cfaj.freeshell.org  |  Shell Scripting Recipes:
  Any code in this post is released|  A Problem-Solution Approach,
  under the GNU General Public Licence | 2005, Apress
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows vs Linux [was: p2exe using wine/cxoffice]

2005-10-26 Thread Chris F.A. Johnson
On 2005-10-26, Tim Golden wrote:
 [Sybren Stuvel]

 Tim Golden enlightened us with:
  Well, I'm with you. I'm sure a lot of people will chime in to point
  out just how flexible and useful and productive Linux is as a
  workstation, but every time I try to use it -- and I make an honest
  effort -- I end up back in Windows

 I'm curious, what do you mean with it in the part every time I try
 to use it?

 Fair question. I have, over the years, installed and used Gentoo,
 Vector, RH, Ubuntu Breezy (my current choice) and various other 
 flavours and distros. When I use it I mean typically that I use 
 whatever desktop-type thing presents itself to me -- Gnome or XFCE 
 or Fluxbox, say -- one or more editors (I tend to try things out to
 see if they suit), and one or more command shells.

   All distros look the same to me, because I have an environment that
   I like, and I keep my home directory acros distros.

 As it happens, (and I suspect I'll have to don my flameproof suit here),
 I prefer the Windows command line to bash/readline for day-to-day use, 
 including in Python. Why? Because it does what I can't for the life of 
 me get readline to do: you can type the first few letters of a 
 previously-entered command and press F8. This brings up (going backwards
 with further presses) the last command which starts like that. And
 *then* you can just down-arrow to retrieve the commands which
 followed it. If someone can tell me how to do this with
 bash/readline I will be indebted to them and it will increase my
 chances of switching to Linux a bit! (Although not at work where I
 have no choice!)

In my ~/.inputrc:

\e[a: history-search-backward  ## shift+up-arrow
\e[b: history-search-forward   ## shift+down-arrow


-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An interesting question about print '\a'

2005-10-23 Thread Chris F.A. Johnson
On 2005-10-24, Anthony Liu wrote:
 We know that if we do

 print '\a'

 the bell will sound.

 Now, why do I hear the sound on my local machine when
 I run a python script on a remote host?

 I understand if I hear it when I do 

 print '\a'

 on my local machine.

 Does the command get sent back to the client machine?

The code is printed to stdout, which is your terminal. Your
terminal interprets ^G as a beep.

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to replace first word in string?

2005-10-22 Thread Chris F.A. Johnson
On 2005-10-22, William Park wrote:
 [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 I am looking for the best and efficient way to replace the first word
 in a str, like this:
 aa to become - /aa/ to become
 I know I can use spilt and than join them
 but I can also use regular expressions
 and I sure there is a lot ways, but I need realy efficient one

 I doubt you'll find faster than Sed.

   On the contrary; to change a string, almost anything will be faster
   than sed (except another external program).

   If you are in a POSIX shell, parameter expansion will be a lot
   faster.

   In a python program, one of the solutions already posted will be
   much faster.

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to replace first word in string?

2005-10-22 Thread Chris F.A. Johnson
On 2005-10-22, William Park wrote:
 Chris F.A. Johnson [EMAIL PROTECTED] wrote:
 On 2005-10-22, William Park wrote:
  [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  I am looking for the best and efficient way to replace the first word
  in a str, like this:
  aa to become - /aa/ to become
  I know I can use spilt and than join them
  but I can also use regular expressions
  and I sure there is a lot ways, but I need realy efficient one
 
  I doubt you'll find faster than Sed.
 
On the contrary; to change a string, almost anything will be faster
than sed (except another external program).
 
If you are in a POSIX shell, parameter expansion will be a lot
faster.
 
In a python program, one of the solutions already posted will be
much faster.

 Care to put a wager on your claim?

   In a shell, certainly.

   If one of the python solutions is not faster than sed (e.g.,
   os.system(sed .)) I'll forget all about using python.

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Set an environment variable

2005-10-21 Thread Chris F.A. Johnson
On 2005-10-21, Christian wrote:
 Erik Max Francis wrote:
 Christian wrote:
 
 Can I write a .py script that calls a .sh script that executes the 
 export command and then calls another .py script (and how would the 
 first .py script look)?
 
 No, the shell script that the Python program would invoke would be a 
 different process and so commands executed in it would have no effect on 
 the state of another.
 

 So executing an .sh script that calls a .py script works different when 
 executed from a command promt than when executed from a starter .py script?

No; it's always the same: an environment variable will only be
effective in the process in which it is set, and its children.

When you call another program, whether it's a shell script, python
script, or binary executable, you are starting a new process.
Environment variables set in that process will not affect its
parent (i.e., the process that called it).

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to improve simple python shell script (to compile list of files)

2005-10-15 Thread Chris F.A. Johnson
On 2005-10-15, Jari Aalto wrote:

 [Keep CC, thank you]

 Please suggest comments how can I make this script to work 
 from bash. Also how can I skip better the [0] argument from
 command line without hte extra variable i?

 #!/bin/bash

 function compile ()
 {
 python -c '
 import os, sys, py_compile;
 i = 0;
 for arg in sys.argv:
 file  = os.path.basename(arg);
 dir   = os.path.dirname(arg);
 i += 1;
 if i  1  and os.path.exists(dir):
 os.chdir(dir);
 print compiling %s\n % (file);
 py_compile.compile(file);
 '  $*
 }

   Don't indent:

function compile ()
{
 python -c '
import os, sys, py_compile;
i = 0;
for arg in sys.argv:
  file  = os.path.basename(arg);
  dir   = os.path.dirname(arg);
  i += 1;
  if i  1  and os.path.exists(dir):
  os.chdir(dir);
  print compiling %s\n % (file);
  py_compile.compile(file);
  '  $*
}

 compile $(find path/to -type f -name *.py)

 # End of example

 The error message reads:

   File string, line 2
 import os, sys, py_compile;
 ^
 SyntaxError: invalid syntax

 Jari



-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP: Searching File Manager written in Python

2005-10-11 Thread Chris F.A. Johnson
On 2005-10-11, anton wrote:

 I am googeling some hours now ... still without result.

 So I have a question:

 Does somebody know a filemanager:

  - which looks like Norton Commander/7-Zip Filemanager

What does Norton Commander/7-Zip look like?

  - where I can add python scripts which I can execute
on a selected file

I use gentoo (the file manager, not the Linux distro). It's not
written in Python, but you can define buttons that will run any
commands you like with the selected file[s] as arguments.

http://www.obsession.se/gentoo/

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do i read just the last line of a text file?

2005-05-29 Thread Chris F.A. Johnson
On Sun, 29 May 2005 at 05:57 GMT, John Machin wrote:
 Chris F.A. Johnson wrote:
 
 file = open(argv[1])  ## Open the file given on the command line
 all_lines = file.readlines()  ## Read all the lines
 
 I see your shadowing and raise you one obfuscation:

   ;)

 open = file(argv[1])  ## File the open given on the command line
 all_lines = open.readlines()  ## Read all the lines

   Such verbosity! (I excuse mine on the grounds that it was my first
   attempt at a Python program.)

all_lines = file(argv[1]).readlines()

   And to answer the question in the subject line:

last_line = file(argv[1]).readlines()[-1]

   Both of which assume from sys import argv.


   Now I have to get serious and forget those bad habits.

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need help of RE

2005-05-29 Thread Chris F.A. Johnson
On Sun, 29 May 2005 at 07:39 GMT, cheng wrote:
 hi all
 a string like
 
 (word1  (Word2|woRd3))
 
 how can i use the re to split it to
 
 ['word1', 'word2', 'word3']

This splits the string on one or more occurrences of any character
that is not alphanumeric: 

import re
str = (word1  (Word2|woRd3))
s = re.sub([^a-zA-Z0-9]+, ,str).split()

-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do i read just the last line of a text file?

2005-05-28 Thread Chris F.A. Johnson
On Sun, 29 May 2005 at 04:42 GMT, nephish wrote:
 Hey there.
 i want to set a variable to represent the last line of a text file
 how do i do that?
 or even better, how do i create a list of the lines of a text file?

from sys import argv  ## Import argv from sys module

file = open(argv[1])  ## Open the file given on the command line
all_lines = file.readlines()  ## Read all the lines
last_line = all_lines[-1] ## Assign the last line


-- 
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
-- 
http://mail.python.org/mailman/listinfo/python-list