summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-10-22 13:56:35 (GMT)
committerGuido van Rossum <guido@python.org>1993-10-22 13:56:35 (GMT)
commite61fa0a1e4c6598f286f54772c7e065c49dc17ba (patch)
treef21820dcbed2fd21bc6089eadac6b55ff8817ae9 /Lib
parent3bb8a05947fb67ed827dd1e8d7c0a982a1ff989e (diff)
downloadcpython-e61fa0a1e4c6598f286f54772c7e065c49dc17ba.zip
cpython-e61fa0a1e4c6598f286f54772c7e065c49dc17ba.tar.gz
cpython-e61fa0a1e4c6598f286f54772c7e065c49dc17ba.tar.bz2
* profile.py, pdb.py: added help() function
* 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
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/pdb.py12
-rwxr-xr-xLib/profile.py12
-rw-r--r--Lib/string.py34
-rw-r--r--Lib/stringold.py34
-rw-r--r--Lib/test/test_types.py3
5 files changed, 93 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 06f5cf8..f415e40 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -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'
diff --git a/Lib/profile.py b/Lib/profile.py
index 000e79a..19b0476 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -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'
diff --git a/Lib/string.py b/Lib/string.py
index ccc1043..764c396 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -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)
diff --git a/Lib/stringold.py b/Lib/stringold.py
index ccc1043..764c396 100644
--- a/Lib/stringold.py
+++ b/Lib/stringold.py
@@ -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)
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index ec0f841..0a43de3 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -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 = {}