could anyone please point me to the piece of documentation
where I can find a description of .join() and all the others?
Rüdiger
The dot in dot join indicates that join resides in the thing being
dot'ted, in this case likely string. Look at
Python22\Doc\lib\module-string.html and
Python22\Doc\lib\string-methods.html
--
Emile van Sebille
em...@fenx.com
---------
Read the Python library reference, section 2.2.6.1 'String Methods' and you
will probably find much of the rest of section 2.2 of interest as well.
or (Python 2.2), at the interactive prompt type:
>>> help(str.join)
Help on method_descriptor:
join(...)
S.join(sequence) -> string
Return a string which is the concatenation of the strings in the
sequence. The separator between elements is S.
>>>
help(str) gives you a complete list of all str methods, but includes a lot
of internal stuff you probably don't care about.
--
Duncan Booth dun...@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://diveintopython.org/odbchelper_join.html
An EXCELLENT tutorial!
On Thu, 30 May 2002, Ruediger Maehl wrote:
> Date: Thu, 30 May 2002 15:05:39 +0200
> From: Ruediger Maehl <ruediger.m...@web.de>
> To: pytho...@python.org
> Subject: Where can I find .join() in the docs
_
Mutsuura Associates, Inc. /\ \
P.O. Box 1238 / \ \
Vienna, VA 22183 / /\ \ \
/ / /\ \ \
E-MAIL: con...@mutsuura.com / /_/ \ \ \
WEB: http://www.mutsuura.com / \ \ / \ \
/ /\ \ \/ /\ \ \
MAIN:(703)281-9722 / / /\ \/ / /\ \ \
CELL:(703)863-1933 / / / \ / / \ \ \
FAX :(703)281-9744 / / / \/_/ \ \_\
SBA/SDB CERTIFIED \/_/ \/_/
Specifically, I went to the Python Library Reference (which you will
find stashed under your pillow), Chapter 2 (built-in stuff), then went
to the section on sequences (which Strings are) and the page on Strings.
-- Michael Chermside
That's explaining string.join() and also some methods that might also
be available for "".xxx() usage but leaves at least me guessing about
their usage.
> --
>
> Emile van Sebille
> em...@fenx.com
Thanks,
Rüdiger
...which illustrates a difficulty for a newbie... knowing it's 'built-in
stuff' then further knowing that strings are classified under
sequences...
--
Emile van Sebille
em...@fenx.com
---------
That is the description I was looking for, but how do I guess "str"?
I also cannot find it in the Global Module Index. What else is hidden?
(Although I use Python for nearly two years, I sometimes still feel
like a beginner).
> help(str) gives you a complete list of all str methods, but includes a lot
> of internal stuff you probably don't care about.
>
> --
> Duncan Booth dun...@rcp.co.uk
> int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
> "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Thanks a lot,
Rüdiger
>> >>> help(str.join)
>> Help on method_descriptor:
>>
>> join(...)
>> S.join(sequence) -> string
>>
>> Return a string which is the concatenation of the strings in the
>> sequence. The separator between elements is S.
>
> That is the description I was looking for, but how do I guess "str"?
> I also cannot find it in the Global Module Index. What else is hidden?
> (Although I use Python for nearly two years, I sometimes still feel
> like a beginner).
str is the name of the string type. You can also do help(unicode.join) for
a similar message about the join method of the unicode type.
The library reference doesn't seem to actually mention anywhere that the
types are called str and unicode: the only mention of str that I can see
hasn't been changed from the days when it was a function.
You might find this useful as it shows you what is really in builtins, not
what is documented:
>>> def showNamespace(namespace=None):
'''Summarise namespace contents'''
if namespace is None: namespace = __builtins__.__dict__
names = {}
# Build a dictionary mapping type to list of names
for k, v in namespace.items():
names.setdefault(type(v), []).append(k)
# Extract typename and name lists into a list
items = [(t.__name__, v) for t, v in names.items()]
items.sort() # Sort by typename
# Print out the variables categorised by type
for k, v in items:
print "%s:" % k, ", ".join(v)
print
>>> showNamespace()
NoneType: None
NotImplementedType: NotImplemented
builtin_function_or_method: vars, pow, globals, divmod, apply, isinstance,
zip, hex, chr, __import__, input, oct, repr, hasattr, delattr, setattr,
raw_input, iter, compile, reload, round, dir, cmp, hash, xrange, reduce,
coerce, intern, issubclass, unichr, id, locals, slice, min, execfile,
getattr, abs, map, buffer, max, len, callable, eval, ord, filter, range
class: RuntimeError, MemoryError, StopIteration, UnicodeError, LookupError,
ReferenceError, NameError, ImportError, SystemExit, Exception,
StandardError, SystemError, IOError, IndexError, RuntimeWarning,
SyntaxWarning, Warning, ArithmeticError, KeyError, EnvironmentError,
DeprecationWarning, FloatingPointError, OverflowWarning, ValueError,
EOFError, TabError, SyntaxError, OSError, IndentationError, AssertionError,
TypeError, KeyboardInterrupt, UserWarning, ZeroDivisionError,
UnboundLocalError, NotImplementedError, AttributeError, OverflowError,
WindowsError
ellipsis: Ellipsis
instance: help, credits, copyright, license
int: __debug__
str: quit, __doc__, exit, __name__
type: float, unicode, open, super, long, complex, dict, type, tuple, list,
str, property, int, file, object, classmethod, staticmethod
Cheers,
Simon Brunning
TriSystems Ltd.
sbru...@trisystems.co.uk
-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.
Emile van Sebille:
> ...which illustrates a difficulty for a newbie... knowing it's 'built-in
> stuff' then further knowing that strings are classified under
> sequences...
Good point. How many people feel that the Python docs would be improved
by the addition of an index? And in case the response is overwhelming,
who currently manages the docs so I could volunteer to work on an index?
-- Michael Chermside
That would be Fred Drake.
But indexing isn't the full answer. Ask a newbie to wade through
http://web.pydoc.org/2.2/search.cgi?key=join
to see what I mean, although the ActivePython Documentation index gets
closer.
Isn't http://www.python.org/doc/current/lib/genindex.html good enough?
It lists these, which would probably have solved the OP's problem.
(These are links in the HTML document...)
join() (in module os.path)
join() (in module string)
join() (string method)
join() (Thread method)
-Peter
Thomas Heller's search page works *very* well ...
http://starship.python.net/crew/theller/pyhelp.cgi?keyword=join&version=curr
ent
Tim Delaney
Usually, I just in Linux, in the document root, type:
$> grep -nr "my_finding_keywords" *
to find out which documents I should read.
Now, haha, after I read this thread, I know the other ways. Thanks.
Regards,
Geiger
I would like to know how could I modify the following code so that it
can be a function in a module? I've tried. But the interpreter warns me
that no __dic__ attribute in __builtins__.
Also, how can I know how many namespaces I create in an environment and
how can I modify the code so that it can show what is in a specific
namespace.
Thanks in advance.
Regards,
Geiger
Well, you could try typing in the code you quoted, rather than misspelling
__dict__ as __dic__. Surely the error message gave you *some* idea where to
look?
To give a meaningful answer to your second question is diffcult. Each object
has its own namespace, as does each function execution, as does each module.
I'm not sure *why* you might want to to this, unless you are simply (!)
writing a debugger, or trying to improve your command of Python.
what's-in-a-namespace-ly y'rs - steve
--
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------
OK, this intrigues me. What are <type 'open'> and <type 'super'> ??
I've never seen any reference to either of these before.
--
I don't actually have a hotmail account; but I do have one on excite.com
if you really want to get in touch with me.
>> type: float, unicode, open, super, long, complex, dict, type, tuple,
> list,
>> str, property, int, file, object, classmethod, staticmethod
>>
>
> OK, this intrigues me. What are <type 'open'> and <type 'super'> ??
> I've never seen any reference to either of these before.
open is an alias for the file type. You can construct a file object by:
file(name[, mode[, buffering]]) -> file object
is the same as:
open(name[, mode[, buffering]]) -> file object
>>> print open is file
1
super is used in new style classes to call methods higher in the
inheritance search order (even if they aren't directly in base classes):
Try this example:
class A(object):
def save(self):
print "Save state of A"
class B(A):
def save(self):
print "Save state of B"
super(B, self).save()
class C(A):
def save(self):
print "Save state of C"
super(C, self).save()
class D(B, C):
def save(self):
print "Save state of D"
super(D, self).save()
b1 = B()
print "b1.save()"
b1.save()
d1 = D()
print "d1.save()"
d1.save()
The output of running this is:
b1.save()
Save state of B
Save state of A
d1.save()
Save state of D
Save state of B
Save state of C
Save state of A
Notice that calling the save method on a B object calls the save method in
its base A object, but calling the B save method when the object is really
a D the call is instead directed across to the C class.
super is quite clever really. At first sight you might think that
super(B,d1) would simply return C, but it actually returns a super object
that delays the base class search until you try to call a method on it.
This means that if C didn't have a save method the C class could be
bypassed and super(B,d1).save() would call A.save() instead.
Yeah, what I did is I read straight through the Language Reference the
first time (didn't understand much, but kind of got the lay of the
land) and eventually learned that the index of the Library Reference
was the place to look for such things. It took me a while to stop
looking in the Language Reference for things like methods of lists.
Thomas