Anfänger Frage

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
kosmonaut
User
Beiträge: 3
Registriert: Dienstag 9. September 2008, 19:14

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?
Benutzeravatar
cofi
Python-Forum Veteran
Beiträge: 4432
Registriert: Sonntag 30. März 2008, 04:16
Wohnort: RGFybXN0YWR0

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
kosmonaut
User
Beiträge: 3
Registriert: Dienstag 9. September 2008, 19:14

Vielen vielen Dank :)
kosmonaut
User
Beiträge: 3
Registriert: Dienstag 9. September 2008, 19:14

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?
Benutzeravatar
veers
User
Beiträge: 1219
Registriert: Mittwoch 28. Februar 2007, 20:01
Wohnort: Zürich (CH)
Kontaktdaten:

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 ;)
[url=http://29a.ch/]My Website - 29a.ch[/url]
"If privacy is outlawed, only outlaws will have privacy." - Phil Zimmermann
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".
Antworten