Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7084ec81
Commit
7084ec81
authored
Apr 02, 1992
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getattr() is now built-in; no longer need a class to simulate varargs.
parent
60279da7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
38 deletions
+30
-38
Lib/lib-old/newdir.py
Lib/lib-old/newdir.py
+15
-19
Lib/newdir.py
Lib/newdir.py
+15
-19
No files found.
Lib/lib-old/newdir.py
View file @
7084ec81
# New dir() function
and other attribute-related goodies
# New dir() function
# This should become a built-in function
#
def
getattr
(
x
,
name
):
return
eval
(
'x.'
+
name
)
# This should be the new dir(), except that it should still list
# the current local name space by default
#
def
listattrs
(
x
):
try
:
dictkeys
=
x
.
__dict__
.
keys
()
...
...
@@ -59,21 +55,21 @@ def listattrs(x):
i
=
i
+
1
return
total
# Helper to recognize functions
#
def
is_function
(
x
):
return
type
(
x
)
==
type
(
is_function
)
# Approximation of builtin dir(); this lists the user's
# Approximation of builtin dir(); but note that this lists the user's
# variables by default, not the current local name space.
# Use a class method to make a function that can be called
# with or without arguments.
#
class
_dirclass
:
def
dir
(
args
):
if
type
(
args
)
==
type
(()):
return
listattrs
(
args
[
1
])
else
:
import
__main__
return
listattrs
(
__main__
)
dir
=
_dirclass
().
dir
def
dir
(
*
args
):
if
len
(
args
)
>
0
:
if
len
(
args
)
==
1
:
args
=
args
[
0
]
return
listattrs
(
args
)
else
:
import
__main__
return
listattrs
(
__main__
)
Lib/newdir.py
View file @
7084ec81
# New dir() function
and other attribute-related goodies
# New dir() function
# This should become a built-in function
#
def
getattr
(
x
,
name
):
return
eval
(
'x.'
+
name
)
# This should be the new dir(), except that it should still list
# the current local name space by default
#
def
listattrs
(
x
):
try
:
dictkeys
=
x
.
__dict__
.
keys
()
...
...
@@ -59,21 +55,21 @@ def listattrs(x):
i
=
i
+
1
return
total
# Helper to recognize functions
#
def
is_function
(
x
):
return
type
(
x
)
==
type
(
is_function
)
# Approximation of builtin dir(); this lists the user's
# Approximation of builtin dir(); but note that this lists the user's
# variables by default, not the current local name space.
# Use a class method to make a function that can be called
# with or without arguments.
#
class
_dirclass
:
def
dir
(
args
):
if
type
(
args
)
==
type
(()):
return
listattrs
(
args
[
1
])
else
:
import
__main__
return
listattrs
(
__main__
)
dir
=
_dirclass
().
dir
def
dir
(
*
args
):
if
len
(
args
)
>
0
:
if
len
(
args
)
==
1
:
args
=
args
[
0
]
return
listattrs
(
args
)
else
:
import
__main__
return
listattrs
(
__main__
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment