1.

Solve : Do you know Python? You Should.?

Answer»

Look around for the most in demand programming jobs and Python will be in the top.
Some boys turn away because Python is just a script and not a compiler. That is not a good resown to ignore it. It can be incorporated into other THINGS that are compiled.

Anyway, I want to share this tutorial:

The 11 Beginner Tips for Learning Python Programming


It has a related video. So watch it if you don't like to read much. INTERPRETED versus compiled hasn't realistically been a consideration for ages. Mostly because the lines have blurred but also because languages like Javascript have become so CENTRAL to thinks like client WEB development and even Application development.

The way I see it there are 11 types of programmers: Those who are good with more than one programming language,those who will be, and those who won't be programming for very long.

Python is great for a lot of things, particularly for "answering QUESTIONS". Here is a fun one I made a while back that finds the total length of a ffmpeg supported file type in a specific directory (using hard-coded paths is a giveaway that I never really intended it to be portable!):

Code: [Select]#! /usr/bin/env python
import os
import sys
import re
import fnmatch
import tempfile
import datetime
import codecs
def searchfolder(folder,filemask):
filelist=[]
for root,subFolders,files in os.walk(folder):
for file in files:
buildpath=os.path.join(root,file)
if os.path.isfile(buildpath):
if fnmatch.fnmatch(buildpath,filemask):
filelist.append(buildpath)
return filelist

def getVideoLength(filepath):
tmpf = tempfile.NamedTemporaryFile()
fname = tmpf.name
print(filepath)
tmpf.close()
sSystem = "D:\\programs\\ffmpeg\\static\\bin\\ffmpeg -i \"%s\" 2> %s" % (filepath, tmpf.name);
os.system(sSystem)
tmpf = open(fname)
try:
lines = tmpf.readlines()
tmpf.close()
os.remove(tmpf.name)
getduration=''
for l in lines:
l = l.strip()
if l.startswith('Duration'):
getduration = re.search('Duration: (.*?),', l).group(0).split(':',1)[1].strip(' ,')
if getduration!='':
timeparts = getduration.split(':') #hour,minute,second
phour=int(timeparts[0])
pminute=int(timeparts[1])
pseconds=float(timeparts[2])
return datetime.timedelta(hours=phour,minutes=pminute,seconds=pseconds)
except:
return datetime.timedelta(hours=0,minutes=0,seconds=0)

if __name__ == '__main__':

sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
searchfor = sys.argv[1]
searchin = sys.argv[2]
print("examining files matching " + searchfor + " in directory " + searchin)
totalcount=datetime.timedelta(seconds=0)
for countthese in searchfolder(searchin,searchfor):
#print Countlines(countthese)
grablength = getVideoLength(countthese)
if grablength is not None:
totalcount = totalcount + getVideoLength(countthese)

print("total length:" + str(totalcount))







Discussion

No Comment Found