28.01.2015 Views

Tutorial Python - Starship

Tutorial Python - Starship

Tutorial Python - Starship

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

# La interpretorul interactiv <strong>Python</strong> se adauga functia de autocompletare<br />

# si un fisier de tip jurnal pentru comenzi. Se cere <strong>Python</strong> 2.0+,<br />

# readline. Autocompletarea este executata implicit prin tasta Esc (dar,<br />

# tasta poate fi inlocuita - vezi documentatia readline).<br />

#<br />

# Puneti fisierul in ~/.pystartup, iar variabila de mediu sa-l<br />

# indice, cum ar fi in bash "export PYTHONSTARTUP=/max/home/itamar/.pystartup".<br />

#<br />

# Retineti ca PYTHONSTARTUP nu expandeaza "~", deci va trebui<br />

# indicata intraga cale a directorului home .<br />

import atexit<br />

import os<br />

import readline<br />

import rlcompleter<br />

historyPath = os.path.expanduser("~/.pyhistory")<br />

def save_history(historyPath=historyPath):<br />

import readline<br />

readline.write_history_file(historyPath)<br />

if os.path.exists(historyPath):<br />

readline.read_history_file(historyPath)<br />

atexit.register(save_history)<br />

del os, atexit, readline, rlcompleter, save_history, historyPath<br />

A.4 Comentarii<br />

Aceste facilităţi reprezintă un pas enorm comparativ cu versiunile anterioare ale interpretorului; oricum au rămas<br />

câteva deziderate neâmplinite : ar fi frumos ca să fie sugerat un alineat corect la continuarea unei linii (analizorul<br />

sintactic ştie dacâ se va cere un alineat). Acest nou mecanism ar putea utiliza tabela de simboluri a interpretorului.<br />

Util ar fi şi un mecanism care să verifice (sau să sugereze) potrivirea parantezelor, ghilimelelor, etc.<br />

A.4. Comentarii 87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!