# 18.py import os, sys, time print os.path.split('/alfa/beta/gamma') # ('/alfa/beta', 'gamma') print os.path.split('/alfa/beta/gamma/') # ('/alfa/beta/gamma', '') print os.path.split('/') # ('/', '') print os.path.split('//') # ('//', '') - benche' '//' non sia correttamente formato. print os.path.split('/stelle') # ('/', 'stelle') print os.path.split('stelle/sirio') # ('stelle', 'sirio') ####################################### def leggifile (nome): f=open(nome,'r') # Oppure f=file(nome,'r'). testo=f.read() f.close(); return testo ####################################### a=leggifile('diffus.f') righe=a.split('\n') ####################################### def scrivifile (nome,testo): f=open(nome,'w') f.write(testo); f.close() ####################################### def scrivifilev (nome,testi,sep='\n'): f=open(nome,'w') for x in testi: f.write(x+sep) f.close() ####################################### f=open('prova','w') f.write('Maria Tebaldi\n') f.write('Roberto Magari\n') f.write('Erica Rossi\n') f.close() ####################################### def aggiungifile (nome,testo): f=open(nome,'a') f.write(testo); f.close() ####################################### t=time.localtime(); print t # (2006, 2, 8, 19, 48, 23, 2, 39, 0) # anno, mese, giorno, ora, minuti, secondi, # giorno della settimana (0 = lunedi'), # giorno nell'anno, 1 se tempo estivo. print time.strftime('%d %b %Y, %H:%M',t) # 08 Feb 2006, 19:54 print time.ctime() # Wed Feb 8 19:50:20 2006 print time.time() # Meglio time.clock(). # 1139424643.05 for i in range(1000000): pass print time.time() # Meglio time.clock(). # 139424643.23