Die Website hat mir ein kleines bischen weitergeholfen.
Bin mittlerweile so weit:
Code: Alles auswählen
import randomclient
randomclient.truerand
<function truerand at 0x00B45A70>
Denke mal das funktioniert fehlerfrei.
Truerand hat aber Parameter. Und wenn ichs so aufrufe:
kommt Fehlermeldung:
Code: Alles auswählen
Traceback (most recent call last):
File "<pyshell#7>", line 1, in -toplevel-
randomclient.truerand(10, f)
NameError: name 'f' is not defined
Aber es ist doch definiert
Jedenfalls laut dem Code des Moduls:
Code: Alles auswählen
# num is number of random numbers to fetch.
# format is b, o, d, or h for strings in that base
# format is n to return integers, or f for raw bytes.
# for all formats, except f, the data is returned as
# a list. bytes are returned as an unmolested string.
def truerand(num, fmt):
if fmt == 'n':
f = 'd'
else:
f = fmt
s = '/cgi-bin/randbyte?nbytes=%d?format=%s' % (num, f)
cxn = httplib.HTTPConnection('www.random.org')
cxn.request('GET', s)
ans = cxn.getresponse()
if ans.status != 200:
cxn.close()
return []
s = ans.read()
cxn.close()
if fmt == 'f':
return s
l = split(s)
if fmt == 'n':
return map(int, l)
return l
Also bin dankbar für jede weitere Antwort