Seite 1 von 1
Verständnisproblem
Verfasst: Freitag 9. Februar 2007, 17:07
von bennym
Hallo!
Ich habe Folgendes Problem:
Code: Alles auswählen
x = raw_input("Gib was ein: "):
if x == "1":
if os.path.exists("/xy"):
...
Warum geht das nicht? Gibt es irgendeine Konstruktion in der Richtung
if x == "1" and os.path.exists.("xy"):
...
Vielen Dank im Vorraus
mfg benny
Verfasst: Freitag 9. Februar 2007, 17:14
von Leonidas
Das funktioniert doch:
Code: Alles auswählen
In [43]: x = raw_input("Gib 'x' ein:")
Gib 'x' ein:x
In [44]: if x == 'x' and os.path.exists('/'):
....: print 'Ok!'
....:
Ok!
Verfasst: Freitag 9. Februar 2007, 17:51
von nkoehring
Allerdings sollte seine erste Konstruktion auch funktionieren...
Wahlweise kann man es natuerlich auch anders machen:
Code: Alles auswählen
import os
import sys
the_path = "/"
x = raw_input("Eingabe? ")
(x == "x" and os.path.exists("/")) and sys.stdout.write(":)\n")
...das ist allerdings in diesem fall sicherlich unleserlicher als eine if-abfrage.
Verfasst: Samstag 10. Februar 2007, 17:04
von bennym
Das funktioniert doch:

Da ist mir aber ein dicker Bock unterlaufen...
Danke für die Hilfe!
mfg benny