* [gentoo-user-de] Mein erstes Mal in Python ;)
@ 2005-09-06 20:20 Jan Kohnert
2005-09-06 20:53 ` Emil Beinroth
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kohnert @ 2005-09-06 20:20 UTC (permalink / raw
To: gentoo-user-de
[-- Attachment #1: Type: text/plain, Size: 1791 bytes --]
Hallo Leute,
ich habe mir nun, nachdem mir bei der Einarbeitung in Python die Website nicht
sehr hilfreich erschien, ein kleines Buch mit einer Python-Einführung
gekauft. Es ließt sich so recht gut; aber soooo einfach, wie viele Leute
Python beschreiben, finde ich es noch nicht... ;)
Da ich bisher schon in C,php und bash programmiert habe, sind mir die
grundlegenden Sachen zwar schon nach ein paar Stunden weitgehend klar, aber
ich komme jetzt schon zu einem Problem, daß ich nicht wirklich lösen kann:
Ich schreibe ein kleines Testprogramm mit derzeit folgendem Inhalt:
#!/usr/bin/env python
import sys
if sys.argv[1] == "pop":
print "pop"
elif sys.argv[1] == "smtp":
print "smtp"
elif sys.argv[1] == "http":
print "http"
else:
print "Fehler"
sys.exit()
Das gibt mir auch aus, was es soll, nur bin ich gezwungen, einen Parameter
anzugeben, sonst kommt der schöne Traceback Fehlerdialog, der mir erlärt, es
gäbe kein argv[1]. Das ist ja richtig, nur hätte ich gerne, daß er in dem
FAll ebenfalls "Fehler" hinschreibt und das Programm normal endet. Der Code
würde in C so funktionieren, aber in Python ist das wohl etwas anderes... :-(
Ich kenne jedenfalls von C den Wert argc, der mir die Anzahl der Argumente
gibt, leider konnte ich bis jetzt nichts vergleichbares finden. Das einzige,
was mich entfernt an sowas erinnert, ist getopt - das habe ich noch nicht
ganz verstanden, naja das kommt noch - es erscheint mir aber etwas
Overhead... Das muß doch einfacher gehen, nur wie?
Danke!
MfG Jan
P.S.: Kennt jemand eine gute Onlinedoku über Python? So ähnlich wie die von
php, die ich einfach nur klasse finde...
--
OpenPGP Public-Key Fingerprint:
0E9B 4052 C661 5018 93C3 4E46 651A 7A28 4028 FF7A
[-- Attachment #2: Type: application/pgp-signature, Size: 190 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user-de] Mein erstes Mal in Python ;)
2005-09-06 20:20 [gentoo-user-de] Mein erstes Mal in Python ;) Jan Kohnert
@ 2005-09-06 20:53 ` Emil Beinroth
2005-09-06 21:04 ` Jan Kohnert
0 siblings, 1 reply; 3+ messages in thread
From: Emil Beinroth @ 2005-09-06 20:53 UTC (permalink / raw
To: gentoo-user-de
On Tue, Sep 06, 2005 at 10:20:21PM +0200, Jan Kohnert wrote:
> Hallo Leute,
Huhu,
> #!/usr/bin/env python
>
> import sys
>
> if sys.argv[1] == "pop":
> print "pop"
> elif sys.argv[1] == "smtp":
> print "smtp"
> elif sys.argv[1] == "http":
> print "http"
> else:
> print "Fehler"
> sys.exit()
>
> Das gibt mir auch aus, was es soll, nur bin ich gezwungen, einen Parameter
> anzugeben, sonst kommt der schöne Traceback Fehlerdialog, der mir erlärt, es
> gäbe kein argv[1]. Das ist ja richtig, nur hätte ich gerne, daß er in dem
> FAll ebenfalls "Fehler" hinschreibt und das Programm normal endet. Der Code
> würde in C so funktionieren, aber in Python ist das wohl etwas anderes... :-(
Wuerdest du in C nicht einen segfault bekommen?
> Ich kenne jedenfalls von C den Wert argc, der mir die Anzahl der Argumente
> gibt, leider konnte ich bis jetzt nichts vergleichbares finden.
len(sys.argv) sollte funktionieren.
> P.S.: Kennt jemand eine gute Onlinedoku über Python? So ähnlich wie die von
> php, die ich einfach nur klasse finde...
Gut bzw praktisch finde ich:
http://docs.python.org/lib/lib.html (python library reference)
http://rgruet.free.fr/PQR24/PQR2.4.html (quick ref)
http://diveintopython.org/toc/index.html (einfuehrendes online-buch)
MfG Emil
--
So much code, so little time.
--
gentoo-user-de@gentoo.org mailing list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [gentoo-user-de] Mein erstes Mal in Python ;)
2005-09-06 20:53 ` Emil Beinroth
@ 2005-09-06 21:04 ` Jan Kohnert
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kohnert @ 2005-09-06 21:04 UTC (permalink / raw
To: gentoo-user-de
[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]
Emil Beinroth schrieb:
> On Tue, Sep 06, 2005 at 10:20:21PM +0200, Jan Kohnert wrote:
> > Der Code würde in C so funktionieren, aber in Python ist
> > das wohl etwas anderes... :-(
>
> Wuerdest du in C nicht einen segfault bekommen?
Jupp, stimmt, ich nehms zurück, aber ich kann ja vorher mit argc prüfen. ;)
> > Ich kenne jedenfalls von C den Wert argc, der mir die Anzahl der
> > Argumente gibt, leider konnte ich bis jetzt nichts vergleichbares finden.
>
> len(sys.argv) sollte funktionieren.
Danke! Gutes kann so einfach sein. ;)
> > P.S.: Kennt jemand eine gute Onlinedoku über Python? So ähnlich wie die
> > von php, die ich einfach nur klasse finde...
>
> Gut bzw praktisch finde ich:
> http://docs.python.org/lib/lib.html (python library reference)
> http://rgruet.free.fr/PQR24/PQR2.4.html (quick ref)
> http://diveintopython.org/toc/index.html (einfuehrendes online-buch)
Werde ich mir mal reinziehen! Danke fpr die schnelle Antwort.
> MfG Emil
MfG Jan
--
OpenPGP Public-Key Fingerprint:
0E9B 4052 C661 5018 93C3 4E46 651A 7A28 4028 FF7A
[-- Attachment #2: Type: application/pgp-signature, Size: 190 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-06 21:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-06 20:20 [gentoo-user-de] Mein erstes Mal in Python ;) Jan Kohnert
2005-09-06 20:53 ` Emil Beinroth
2005-09-06 21:04 ` Jan Kohnert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox