Seite 1 von 1

Anfänger Frage

Verfasst: Dienstag 9. September 2008, 19:32
von kosmonaut
Hallo!

Ich leg mal gleich los...
Habe Kate als Editor und gab das hier ein: #!/usr/bin/python print 'Hallo Welt'

Und speichere es auf mein Desktop unter: hallowelt.py

Nun öffne ich ein Terminal und gebe das hier ein: python hallowelt.py...(zum öffnen der datei)......


Doch leider kommt das dabei raus: python: can't open file 'hallowelt.py': [Errno 2] No such file or directory


Tut mir leid wegen solche Kindergarten Fragen aber könnt ihr mir bitte weiter helfen?

Verfasst: Dienstag 9. September 2008, 19:34
von cofi
Nun wenn du das auf dem Desktop speicherst, dann musst du das auch dort abrufen .. dh wohl ~/Desktop wenn du KDE benutzt - was ich annehme ;).

python Desktop/hallowelt.py wirds dann wohl sein ;)

Wenn du deine Datei ausführbar machst - chmod +x Desktop/hallowelt.py - , dann langt auch ein Desktop/hallowelt.py

Verfasst: Dienstag 9. September 2008, 19:42
von kosmonaut
Vielen vielen Dank :)

Verfasst: Dienstag 9. September 2008, 19:55
von kosmonaut
Wohin sollte ich die Text-Dateien speichern um sie ohne eingabe des ortes öffnen zu können?

Also nur mit python hallowelt.py ist das überhaupt möglich?

Verfasst: Dienstag 9. September 2008, 19:59
von veers
kosmonaut hat geschrieben:Wohin sollte ich die Text-Dateien speichern um sie ohne eingabe des ortes öffnen zu können?

Also nur mit python hallowelt.py ist das überhaupt möglich?
In ein Verzeichnis welches sich in $PATH (/usr/bin zum bsp.) befindet. Dann kannst du das Script sogar direkt starten: $ hellowelt.py ;)

Verfasst: Dienstag 9. September 2008, 20:00
von abgdf
Ich hab' mal geschrieben:
2. How to execute a Python-script

Executing a Python-script isn't difficult: Copy and paste its code into a text-editor ...
On Linux, I suggest learning how to use one of the editors "vim" or "emacs", but "kate", "gedit" or "kwrite" will do, too ...
Make sure, that all characters are copied and pasted correctly and that all code-indentation is kept.
Then save the script as for example "script.py" ...
On Linux, you have to make your script executable first. You can do that by executing

chmod +x script.py

After that you can run it by doing

./script.py

in its directory.
HTH

P.S.: Ein guter Platz für eigene Skripte, die von überall ausgeführt werden sollen, ist oft auch "/usr/local/bin".