[Python] python - forma ridotta
Ciao raga... Sto guardando in giro un po di codici python e spesso trovo del codici in forma ridotta: Es: val = 1 print ('prova' if vall==1 else 'aaa') Dove posso trovare le spiegazioni di tutte le forme ridotte? Questa forma ridotta l'ho capita, ma vorrei capire se ce ne sono altre ed eventualmente impararle =) =) -- Nicola Ferrari website: http://www.nicolaferrari.name skype: nick.ferro ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] python - forma ridotta
Nicola Ferrari wrote: val = 1 print ('prova' if vall==1 else 'aaa') Dove posso trovare le spiegazioni di tutte le forme ridotte? Non esistono forme ridotte o abbreviazioni come in COBOL :) In questo caso si tratta di un operatore ternario, simile al ?: presente in altri linguaggi (Java, C, Javascript, Perl) e non e' un modo alternativo di esprimere il costrutto if.. then.. elif.. else Questa forma ridotta l'ho capita, ma vorrei capire se ce ne sono altre ed eventualmente impararle =) =) Ti conviene leggere il tutorial ufficiale, e' scritto bene e abbastanza completo. Se incontri qualche caratteristica gia' presente in linguaggi che gia' conosci, stai particolarmente attento e non saltare parti del tutorial, perche' potresti avere delle sorprese. -- This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company. If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner. Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Dov'è che Python cerca i programmi da eseguire?
Non riesco a capire dove python cerchi i file da eseguire. SE provo a eseguire qualunque file della libreria mi risponde che non lo trova. ESEMPIO, stando sulla mia user-dir : se scrivopython pdb.py rispondepython: can't open file 'pdb.py': [Errno 2] No such file or directory se invece scrivo python /usr/lib/python/pdb.py (vabbe' , è da chiamare in un altro modo, ma questo non c'entra...) esso risponde usage: pdb.py scriptfile [arg] ... Se lancio l'interprete in modo interattivo e importo sys, in sys.path ci trovo anche /usr/lib/python. Se il file sorgente è nella dir corrente, oppure dò il comando dalla dir /usr/lib/python, esso viene normalmente eseguito. AMBIENTE Python 2.6.2, installato come /usr/bin/python2.6, linkato come /usr/bin/python libreria è nella directory /usr/lib/python2.6, lnkata come /usr/lib/python I link sono simbolici, tutti i file sono proprietà di root:root Tutti i .py e i .pyo della /usr/lib/python2.6 hanno permessi 644 (ho provato anche con 755, ma non cambia niente) $PATH contiene /usr/bin:/usr/sbin:/usr/X11R6/bin:/bin:/sbin:/usr/lib/python $PYTHONPATH contiene /usr/lib/python Mi dispiace fare una domanda così banale, ma forse proprio perchè è troppo banale non ho trovato risposta nè nel tutorial di Van Rossum, nella Libreria di riferimento, nè in vari altri testi che ho consultato (Cogliati, Riccio, Sciabarrà, Barisione, Martelli), e neanche nella documentazione online del sito www.python.org. Spero proprio che qualcuno mi possa aiutare. Aldes Rossi ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Dov'è che Python cerca i programmi da eseguire?
On Thu, Oct 08, 2009 at 06:34:35PM +0200, Aldes Rossi wrote: Non riesco a capire dove python cerchi i file da eseguire. Stai confondendo i path per i file da eseguire ed i path dei moduli. Il sys.path ti dice le cartelle dove python cerca i moduli quando usi 'impoort', a seguito di:: import pdb python cerca il modulo nel sys.path. Quello a cui tu invece stai pensandro è un meccanismo simile al $PATH di un sistema unix che invece non mi pare presente in python. Nota che neanche PYTHONPATH fa quello che cerchi, PYTHONPATH aggiunge solo dei path (sempre per import) al sys.path. sandro *:-) -- Sandro Dentella *:-) http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Dov'è che Python cerca i programmi da e seguire?
2009/10/8 Alessandro Dentella san...@e-den.it: On Thu, Oct 08, 2009 at 06:34:35PM +0200, Aldes Rossi wrote: Non riesco a capire dove python cerchi i file da eseguire. Stai confondendo i path per i file da eseguire ed i path dei moduli. Il sys.path ti dice le cartelle dove python cerca i moduli quando usi 'impoort', a seguito di:: import pdb python cerca il modulo nel sys.path. Quello a cui tu invece stai pensandro è un meccanismo simile al $PATH di un sistema unix che invece non mi pare presente in python. Nota che neanche PYTHONPATH fa quello che cerchi, PYTHONPATH aggiunge solo dei path (sempre per import) al sys.path. $ python -m pdb dovrebbe fare quello che chiede l'OP (ovvero, stampare usage: pdb.py scriptfile [arg] ... ;) Cheers, © -- Carlo C8E Miron Minus Emm Solution Architect™ http://pycon.it/ http://stacktrace.it/ http://chatterbox.pydinner.org/ http://www.linkedin.com/in/carlomiron ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Dov'è che Python cerca i programmi da e seguire?
2009/10/8 Aldes Rossi aldes.ro...@rossisoft.com: Carlo C8E Miron ha scritto: 2009/10/8 Alessandro Dentella san...@e-den.it: On Thu, Oct 08, 2009 at 06:34:35PM +0200, Aldes Rossi wrote: Non riesco a capire dove python cerchi i file da eseguire. Stai confondendo i path per i file da eseguire ed i path dei moduli. Il sys.path ti dice le cartelle dove python cerca i moduli quando usi 'impoort', a seguito di:: import pdb python cerca il modulo nel sys.path. Quello a cui tu invece stai pensandro è un meccanismo simile al $PATH di un sistema unix che invece non mi pare presente in python. Nota che neanche PYTHONPATH fa quello che cerchi, PYTHONPATH aggiunge solo dei path (sempre per import) al sys.path. $ python -m pdb dovrebbe fare quello che chiede l'OP (ovvero, stampare usage: pdb.py scriptfile [arg] ... ;) Cheers, © Ok, mi ero perso in un bicchiere d'acqua piccolo piccolo. Ci ho perso tanto tempo, e sarebbe bastato consultare 'man python' ! Grazie, davvero. Aldes Rossi yw © -- Carlo C8E Miron Ur Welcom' Solution Architect™ http://pycon.it/ http://stacktrace.it/ http://chatterbox.pydinner.org/ http://www.linkedin.com/in/carlomiron ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python