]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
* profile.py, pdb.py: added help() function
authorGuido van Rossum <guido@python.org>
Fri, 22 Oct 1993 13:56:35 +0000 (13:56 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 22 Oct 1993 13:56:35 +0000 (13:56 +0000)
* builtin.py: b/w compat for builtin -> __builtin__ name change
* string.py: added atof() and atol() and corresponding exceptions
* test_types.py: added test for list sort with  user comparison function

Lib/pdb.py
Lib/profile.py
Lib/string.py
Lib/stringold.py
Lib/test/test_types.py

index 06f5cf8c7b566ca3461b9234cc8673e8dd180bf4..f415e409f1c291e81113e261163c1562c60ba406 100755 (executable)
@@ -312,3 +312,15 @@ def test():
        import linecache
        linecache.checkcache()
        run(TESTCMD)
+
+# print help
+def help():
+       for dirname in sys.path:
+               fullname = os.path.join(dirname, 'pdb.doc')
+               if os.path.exists(fullname):
+                       sts = os.system('${PAGER-more} '+fullname)
+                       if sts: print '*** Pager exit status:', sts
+                       break
+       else:
+               print 'Sorry, can\'t find the help file "pdb.doc"',
+               print 'along the Python search path'
index 000e79a090c7f84c3b3415df9e9b49a0535e8ff1..19b0476f3959cc8de538fb938a027e0cd5b56921 100755 (executable)
@@ -377,3 +377,15 @@ def debug():
 # test command
 def test():
        run('import x; x.main()')
+
+# print help
+def help():
+       for dirname in sys.path:
+               fullname = os.path.join(dirname, 'profile.doc')
+               if os.path.exists(fullname):
+                       sts = os.system('${PAGER-more} '+fullname)
+                       if sts: print '*** Pager exit status:', sts
+                       break
+       else:
+               print 'Sorry, can\'t find the help file "profile.doc"',
+               print 'along the Python search path'
index ccc10431e4cc0d8d31bb3895badd5c564f871ec9..764c396bb07a3bab70eb26cfa09c1dbecdaa37d9 100644 (file)
@@ -116,8 +116,26 @@ def find(*args):
        except index_error:
                return -1
 
+# Convert string to float
+atof_error = 'non-float argument to string.atof'
+def atof(str):
+       import regex
+       sign = ''
+       s = str
+       if s and s[0] in '+-':
+               sign = s[0]
+               s = s[1:]
+       if not s: raise atof_error, str
+       while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
+       if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
+               raise atof_error, str
+       try:
+               return eval(sign + s)
+       except SyntaxError:
+               raise atof_error, str
+
 # Convert string to integer
-atoi_error = 'non-numeric argument to string.atoi'
+atoi_error = 'non-integer argument to string.atoi'
 def atoi(str):
        sign = ''
        s = str
@@ -130,6 +148,20 @@ def atoi(str):
                if c not in digits: raise atoi_error, str
        return eval(sign + s)
 
+# Convert string to long integer
+atol_error = 'non-integer argument to string.atol'
+def atol(str):
+       sign = ''
+       s = str
+       if s and s[0] in '+-':
+               sign = s[0]
+               s = s[1:]
+       if not s: raise atoi_error, str
+       while s[0] == '0' and len(s) > 1: s = s[1:]
+       for c in s:
+               if c not in digits: raise atoi_error, str
+       return eval(sign + s + 'L')
+
 # Left-justify a string
 def ljust(s, width):
        n = width - len(s)
index ccc10431e4cc0d8d31bb3895badd5c564f871ec9..764c396bb07a3bab70eb26cfa09c1dbecdaa37d9 100644 (file)
@@ -116,8 +116,26 @@ def find(*args):
        except index_error:
                return -1
 
+# Convert string to float
+atof_error = 'non-float argument to string.atof'
+def atof(str):
+       import regex
+       sign = ''
+       s = str
+       if s and s[0] in '+-':
+               sign = s[0]
+               s = s[1:]
+       if not s: raise atof_error, str
+       while s[0] == '0' and len(s) > 1 and s[1] in digits: s = s[1:]
+       if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
+               raise atof_error, str
+       try:
+               return eval(sign + s)
+       except SyntaxError:
+               raise atof_error, str
+
 # Convert string to integer
-atoi_error = 'non-numeric argument to string.atoi'
+atoi_error = 'non-integer argument to string.atoi'
 def atoi(str):
        sign = ''
        s = str
@@ -130,6 +148,20 @@ def atoi(str):
                if c not in digits: raise atoi_error, str
        return eval(sign + s)
 
+# Convert string to long integer
+atol_error = 'non-integer argument to string.atol'
+def atol(str):
+       sign = ''
+       s = str
+       if s and s[0] in '+-':
+               sign = s[0]
+               s = s[1:]
+       if not s: raise atoi_error, str
+       while s[0] == '0' and len(s) > 1: s = s[1:]
+       for c in s:
+               if c not in digits: raise atoi_error, str
+       return eval(sign + s + 'L')
+
 # Left-justify a string
 def ljust(s, width):
        n = width - len(s)
index ec0f84100f0715dc1fddccf26d24af71651714d9..0a43de32450a917a42b443083bdffd112e1df8d4 100644 (file)
@@ -152,6 +152,9 @@ a.reverse()
 if a <> [2,1,0,-1,-2]: raise TestFailed, 'list reverse'
 a.sort()
 if a <> [-2,-1,0,1,2]: raise TestFailed, 'list sort'
+def revcmp(a, b): return cmp(b, a)
+a.sort(revcmp)
+if a <> [2,1,0,-1,-2]: raise TestFailed, 'list sort with cmp func'
 
 print '6.6 Mappings == Dictionaries'
 d = {}