Differences between revisions 5 and 6
Revision 5 as of 2002-12-05 13:08:39
Size: 1450
Editor: cs6625177-168
Comment:
Revision 6 as of 2002-12-05 13:46:26
Size: 1463
Editor: cs6625177-168
Comment:
Deletions are marked like this. Additions are marked like this.
Line 52: Line 52:
Limitations:
  killall functionality in bash was reject by guido himself (BS explantion) "talk to maintainers of posix"
== Limitations ==
  killall functionality as seen in bash was reject by guido himself (BS explantion) "talk to maintainers of posix"

Basically some of the most common code ideas are welcomed here. you probably want python as a shell. Here's some tips: TableOfContents

Hacks

general ideas

for all your code,

lack of symbol for command execution

Solution: write short method names:

   1 def S(arg):
   2   """returns string of executed command arg"""
   3   return os.popen(arg).read()
   4 
   5 def SN(arg):
   6   """returns list of executed command arg"""
   7   return os.popen(arg).read().split('\n')
   8 
   9 def SP(arg):
  10   """prints string of executed command arg"""
  11   print S(arg)
  12 
  13 def SNP(arg):
  14   """prints with lines list executed command arg"""
  15   for i in SN():
  16     print i

dirname comprables

you might not know that you have improved functionality. os.path.split replaces dirname and basename returning a tuple containing both. os.path.splitext splits on the extension returning a tuple To complete the set you might want to split the path at the root, use:

   1 import re
   2 def splitroot(s):
   3   if string.find(s,"/") == -1:
   4     return '',s
   5   if s[0] == '/':
   6     s = s[1:]
   7   m = re.match("(.*?)/(.*)$",s)
   8   return m.groups()

awk comprables

simply use re. its a fuller set of regular expressions. create a wrapper function for a utility for this if you want call it inlinegrep.

Limitations

  • killall functionality as seen in bash was reject by guido himself (BS explantion) "talk to maintainers of posix"

UsePythonAsAnInteractiveShell (last edited 2009-11-19 08:27:58 by vpn-8061f54b)

Unable to edit the page? See the FrontPage for instructions.