Bitte um Erklärung if __name__ == 'main':
Verfasst: Dienstag 17. Januar 2012, 12:43
Hallo
ich habe hier folgendes Skript "codec_extractor.py"
Wenn ich das jetzt im Terminal aufrufe erhalte ich wie erwartet diesen OutputWenn ich das Skript ändere und ans Ende "if __name__ == main" schreibe
und es aufrufe erhalte ich keinen Output, aber auch keine Fehlermeldung.Vielleicht kann mir das jemand erklären, damit auch ich alter Trottel das kapiere.
Gruß....busfahrer
ich habe hier folgendes Skript "codec_extractor.py"
Code: Alles auswählen
#!/usr/bin/env python
import subprocess as sub
import sys
class FFprobe(object):
def __init__(self, path):
self.path = path
def get_codecs(self):
cmd = ["ffprobe", "-show_streams", self.path]
handle = sub.Popen(cmd, stdout=sub.PIPE, stderr=sub.PIPE)
output = handle.communicate()[0]
codecs = []
for line in output.split("\n"):
if line.startswith("codec_name="):
codec = line.strip().split("=")
codecs.append(codec[1])
print codecs
ffprobe = FFprobe(sys.argv[1])
ffprobe.get_codecs()
Code: Alles auswählen
./codec_extractor.py ed_hd.avi
['msmpeg4v2', 'ac3']
Code: Alles auswählen
#!/usr/bin/env python
import subprocess as sub
import sys
class FFprobe(object):
def __init__(self, path):
self.path = path
def get_codecs(self):
cmd = ["ffprobe", "-show_streams", self.path]
handle = sub.Popen(cmd, stdout=sub.PIPE, stderr=sub.PIPE)
output = handle.communicate()[0]
codecs = []
for line in output.split("\n"):
if line.startswith("codec_name="):
codec = line.strip().split("=")
codecs.append(codec[1])
print codecs
if __name__ == 'main':
ffprobe = FFprobe(sys.argv[1])
ffprobe.get_codecs()
Gruß....busfahrer