Seite 1 von 1

Problem mit Funktionsaufruf

Verfasst: Freitag 2. September 2005, 21:34
von qweet
Hallo,

Ich habe folgenden Code:

Code: Alles auswählen

import randomclient
truerand(10, f)
Randomclient ist ein modul von random.org für echte Zufallszahlen.
Truerand ist eine definierte Funktion in diesem modul.
Jedoch erhalte ich trotzdem folgende Fehlermeldung:

Code: Alles auswählen

Traceback (most recent call last):
  File "<pyshell#22>", line 1, in -toplevel-
    truerand(num, fmt)
NameError: name 'truerand' is not defined
Warum? Und gibt es vielleicht ne Seite wo jeder zurückgegebene Fehler erklärt wird oder so was in der Art? Wär ich echt glücklich drüber :)

PS: Ich bin Anfänger!

Verfasst: Freitag 2. September 2005, 21:39
von mawe
Hi!

Das hatten wir heute schon mal :) Schau mal hier, vor allem ganz unten die Antworten von henning und jens.

Gruß, mawe

Verfasst: Samstag 3. September 2005, 10:57
von Gast
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:

Code: Alles auswählen

randomclient.truerand(10, f)
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 ;)

Verfasst: Samstag 3. September 2005, 11:01
von jens
f wird wohl von dir definiert werden müßen ;)

z.B.:

Code: Alles auswählen

f = "BlaBla"
randomclient.truerand(10, f) 

Verfasst: Samstag 3. September 2005, 16:07
von Gast
oh danke :roll:
ich hätte einfach randomclient.truerand(10, 'f') eingeben müssen... ;)