[FAQTS] Python Knowledge Base Update -- May 12th, 2000
Fiona Czuczman
fiona at sitegnome.com
Fri May 12 11:15:22 EDT 2000
Hi,
Below are the entries that I've entered into http://python.faqts.com for
today.
cheers, Fiona
## New Entries #################################################
-------------------------------------------------------------
What are the keys for auto-completion? ie. selecting one item in the scrollbox with a keystroke?
http://www.faqts.com/knowledge-base/view.phtml/aid/2769
-------------------------------------------------------------
Fiona Czuczman
Neil Hodgson, Mark Hammond
You choose the selected item with the tab key. You can move up and down
with the cursor keys: up, down, page up, page down, home, end. Typing
characters moves the selection to the first item that starts with the
string typed since the auto-completion appeared.
Alt+/ or Ctrl+Space do auto-expand (no list - just looks for similar
words in the same buffer)
-------------------------------------------------------------
What's the best way to obtain seeds for random number generators?
http://www.faqts.com/knowledge-base/view.phtml/aid/2770
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh, Mike Steed, Ivan Van Laningham, Will Ware, Paul Jackson
RFC 1750 provides a whole lot of information on this topic:
http://www.faqs.org/rfcs/rfc1750.html
"Computer clocks, or similar operating system or hardware values,
provide significantly fewer real bits of unpredictability than might
appear from their specifications."
Depending on how serious you are about randomness, you may want to use a
hardware source (e.g., an audio input device). See 8.7 in the following
document:
http://www.faqs.org/faqs/cryptography-faq/part08/
Also, under linux, see /dev/random. random.c claims:
* This routine gathers environmental noise from device drivers, etc.,
* and returns good random numbers, suitable for cryptographic use.
Will Ware wrote:
If you really need a lot of randomness, and you don't mind spending
an evening or two with a soldering iron, I once made up a pretty
good random bit generator circuit, described at:
http://world.std.com/~wware/hw-rng.html
You can bring the bits in one of the pins of your printer port. I
have some information about a Linux device driver for the thing, if
you're interested in pursuing it, that was developed by some students
who recently used the circuit for a course project.
-----------------
A Random Number web site from SGI is:
http://lavarand.sgi.com/
-------------------------------------------------------------
How can I extract just the links in a web-page or html-document?
http://www.faqts.com/knowledge-base/view.phtml/aid/2771
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh
In addition to the question:
It would be nice if relative links like'<a
href="/source/test_pyt.tgz">Logo</a> in a page at
http://www.test.site.org became
"http://www.test.site.org/source/test_pyt.tgz" in the end too ...
Solution:
from the eff-bot archives:
#
# extract anchors from an HTML document
#
# fredrik lundh, may 1999
#
# fredrik at pythonware.com
# http://www.pythonware.com
#
import htmllib
import formatter
import string
import urllib, urlparse
class myParser(htmllib.HTMLParser):
def __init__(self, base):
htmllib.HTMLParser.__init__(self, formatter.NullFormatter())
self.anchors = []
self.base = base
def anchor_bgn(self, href, name, type):
self.save_bgn()
if self.base:
self.anchor = urlparse.urljoin(self.base, href)
else:
self.anchor = href
def anchor_end(self):
text = string.strip(self.save_end())
if self.anchor and text:
self.anchors.append((self.anchor, text))
if __name__ == '__main__':
URL = "http://www.pythonware.com"
f = urllib.urlopen(URL)
p = myParser(URL)
p.feed(f.read())
p.close()
print "anchors =", p.anchors
print "title =", p.title
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
-------------------------------------------------------------
How do I copy one object into another without having them refer to each other?
http://www.faqts.com/knowledge-base/view.phtml/aid/2772
-------------------------------------------------------------
Fiona Czuczman
Emile van Sebille, Thomas Thiele
You could create a separate instance, or provide a copy
function as part of the class.
>>> a = A('bragi')
>>> b = A('')
>>> b.name = a.name
>>> b.name
'bragi'
>>> a.name = 'stini'
>>> b.name
'bragi'
>>>
>>> class A:
def __init__(self,name):
self.name = name
def copy(self):
retval = A(self.name)
# other copy functions
return retval
>>> a = A('bragi')
>>> b = a.copy()
>>> b.name
'bragi'
>>> a.name = 'stini'
>>> b.name
'bragi'
>>>
Or, you could use copy.copy and copy.deepcopy.
>>> class X:
... def __init__(self):
... self.a = 5
...
>>> x = X()
>>> list = [x]
>>> cl1 = copy.copy(list)
>>> cl2 = copy.deepcopy(list)
>>> list[0].a = 6
>>> list[0].a
6
>>> cl1[0].a
6
>>> cl2[0].a
5
-------------------------------------------------------------
How do I change the mouse pointer to the default 'wait' icon during a short operation in tkinter?
http://www.faqts.com/knowledge-base/view.phtml/aid/2773
-------------------------------------------------------------
Fiona Czuczman
Fredrik Lundh, John Grayson
Use:
root.config(cursor="wait")
root.config(cursor="")
Or:
Look at page 369 of John Grayson's book.
You might want to look at Pmw's BLT busy cursor
for a full busy cursor implementation.
More information about the Python-list
mailing list