Re: [Python] Quasi OT
2016-09-07 18:58 GMT+10:00 Carlos Catucci : > Personalmente preferisco scrivere il JS come tale. Certo e' difficile > farlo senza usare un frmaework come jQuery, Angular, Backbone etc., ma > addirittura farlo tradurre mi spavenat un poco. > Poi magari sono solo pippe mentali mie (l'ottimo Genropy mi sembra che > alla fin fine lo faccia senza problemi > babel traduce ES6 in ES5. Anticipa solo i tempi e devo dire che ES6 e' decisamente meglio del vecchio ES5 (JS) -- Karim N. Gorjux ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Mock... non capisco la patch
Salve a tutti, ho un codice che non riesco a capire... ho un test che mi patcha una funzione: from tests.utils import mock_session_oauth @patch('app.tasks._create_session') def test_refresh_token_task(self, create_session_mocked): create_oauth_session_mocked.return_value = mock_session_oauth() # qui esegui i miei test... `mock_session_oauth` restituisce un oggetto Mock con vari settaggi che mi servono. L'ho provato da shell e funziona. Si comporta esattamente come voglio. Ora io vorrei che `create_session_mocked` diventi quell'oggetto e lo faccio all'inizio del testo. In realta' `create_session_mocked` non ha il mio MagicMock restituito dalla funzione, ma un MagicMock restituto da patch come se non avessi fatto nessun assign. Ora mi chiedo come mai succede questo. Inoltre ho capito che non e' il modo giusto per fare questa operazione, io vorrei che la patch mi usasse direttamente il mock che restituisce la mia funzione senza troppi fronzoli, puo' farlo? Puo' anche passare dei parametri alla funzione, nel caso volessi? Forse e' meglio usare il with? Grazie per gli eventuali chiarimenti. -- Karim N. Gorjux ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Quasi OT
2016-09-08 12:06 GMT+02:00 Karim : > devo dire che ES6 e' > decisamente meglio del vecchio > ES5 (JS) Su questo non ci sono dubbi Carlos -- EZLN ... Para Todos Todo ... Nada para nosotros ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Mock... non capisco la patch
2016-09-08 20:13 GMT+10:00 Karim : > Salve a tutti, ho un codice che non riesco a capire... > [...] > Mi auto rispondo. @patch(new=callable...) Al posto di callable ho messo la funzione che mi ritorna il mio mock. Tutto funziona. Grazie. -- Karim N. Gorjux ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Salvare bytecode
Salve ragazzi. Da poco, dopo C, C++ e Java mi sono avvicinato a Python, con il libro di M. Buttu. Non capisco perché, quando cerco di salvare sul disco il bytecode di un modulo eseguito come script in modo esplicito attraverso lo switch -m, non ottengo la directory __pycache__. Sapete aiutarmi? Inviato da iPhone ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
> Il giorno 08 set 2016, alle ore 15:49, Emanuele Urselli > ha scritto: > > Salve ragazzi. > Da poco, dopo C, C++ e Java mi sono avvicinato a Python, con il libro di M. > Buttu. > Non capisco perché, quando cerco di salvare sul disco il bytecode di un > modulo eseguito come script in modo esplicito attraverso lo switch -m, non > ottengo la directory __pycache__. > Sapete aiutarmi? > Sto leggendo anche io quel bel libro... :) Mi ricordo che Buttu parla del modulo dis.dis() al quale si può passare come argomento un altro modulo. Comunque dai un occhiata a pagina 279 dell'edizione 2014. Potresti scrivere l'output di quella funzione su un file con open(). Ciao -- Francesco Cargiuli ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Se non sbaglio dis.dis() serve per vedere il bytecode. Comunque ci sono riuscito. Sono cambiate un po di cose. La versione Python del libro è quella precedente a quella attuale. In pratica con lo switch -m devo passare anche il suffisso .py. E mi genera il .pyc. Con lo switch -O mi genera il bytecode ottimizzato senza assert. Ma dobbiamo inserire sempre il suffisso. Altrimenti in output abbiamo solo il risultato dello script Inviato da iPhone > Il giorno 08 set 2016, alle ore 16:27, Francesco Cargiuli > ha scritto: > > >> Il giorno 08 set 2016, alle ore 15:49, Emanuele Urselli >> ha scritto: >> >> Salve ragazzi. >> Da poco, dopo C, C++ e Java mi sono avvicinato a Python, con il libro di M. >> Buttu. >> Non capisco perché, quando cerco di salvare sul disco il bytecode di un >> modulo eseguito come script in modo esplicito attraverso lo switch -m, non >> ottengo la directory __pycache__. >> Sapete aiutarmi? > > Sto leggendo anche io quel bel libro... :) > Mi ricordo che Buttu parla del modulo dis.dis() al quale si può passare come > argomento un altro modulo. Comunque dai un occhiata a pagina 279 > dell'edizione 2014. Potresti scrivere l'output di quella funzione su un file > con open(). > > Ciao > > -- > Francesco Cargiuli > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Ah, tranquillo. Anzi, grazie per aver cercato di darmi una mano. Buono studio. Arrivederci Francesco Inviato da iPhone > Il giorno 08 set 2016, alle ore 16:38, Francesco Cargiuli > ha scritto: > > Sei più avanti di me allora. Io agli switch da linea di comando non ci avevo > ancora pensato :) > > -- > Francesco Cargiuli > francescocargi...@fastmail.com > > > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Sei più avanti di me allora. Io agli switch da linea di comando non ci avevo ancora pensato :) -- Francesco Cargiuli francescocargi...@fastmail.com ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
2016-09-08 16:33 GMT+02:00 Emanuele Urselli : > Se non sbaglio dis.dis() serve per vedere il bytecode. > Comunque ci sono riuscito. > Sono cambiate un po di cose. > La versione Python del libro è quella precedente a quella attuale. > In pratica con lo switch -m devo passare anche il suffisso .py. E mi genera > il .pyc. > Con lo switch -O mi genera il bytecode ottimizzato senza assert. > Ma dobbiamo inserire sempre il suffisso. Altrimenti in output abbiamo solo il > risultato dello script ??? Che strana versione di Python stai usando, e su che piattaforma? ㎝ -- |:**THE BEER-WARE LICENSE** *(Revision 42)*: | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a beer in return. |--Carlo Miron : ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
La 3.4 su Ubuntu Inviato da iPhone > Il giorno 08 set 2016, alle ore 17:17, Carlo Miron ha > scritto: > > 2016-09-08 16:33 GMT+02:00 Emanuele Urselli : > >> Se non sbaglio dis.dis() serve per vedere il bytecode. >> Comunque ci sono riuscito. >> Sono cambiate un po di cose. >> La versione Python del libro è quella precedente a quella attuale. >> In pratica con lo switch -m devo passare anche il suffisso .py. E mi genera >> il .pyc. >> Con lo switch -O mi genera il bytecode ottimizzato senza assert. >> Ma dobbiamo inserire sempre il suffisso. Altrimenti in output abbiamo solo >> il risultato dello script > > ??? > > Che strana versione di Python stai usando, e su che piattaforma? > > ㎝ > > -- > |:**THE BEER-WARE LICENSE** *(Revision 42)*: > | wrote this mail. As long as you retain > | this notice you can do whatever you want with this stuff. > | If we meet some day, and you think this stuff is worth it, > | you can buy me a beer in return. > |--Carlo Miron : > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
2016-09-08 17:21 GMT+02:00 Emanuele Urselli : > La 3.4 su Ubuntu Stai sbagliando qualcosa. Lo switch -m richiede il nome di un modulo, non un file. ㎝ -- |:**THE BEER-WARE LICENSE** *(Revision 42)*: | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a beer in return. |--Carlo Miron : ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Eh, è ciò che anche io ho letto sul libro. Solo che se passo il modulo mi dà un output il risultato dello script senza generare bytecode. Se invece passo il file (con suffisso .py quindi) mi genera il file .pyc. Python 3.5.2 su Ubunt 16.04 Inviato da iPhone > Il giorno 08 set 2016, alle ore 17:23, Carlo Miron ha > scritto: > > 2016-09-08 17:21 GMT+02:00 Emanuele Urselli : > >> La 3.4 su Ubuntu > > Stai sbagliando qualcosa. Lo switch -m richiede il nome di un modulo, > non un file. > > ㎝ > > -- > |:**THE BEER-WARE LICENSE** *(Revision 42)*: > | wrote this mail. As long as you retain > | this notice you can do whatever you want with this stuff. > | If we meet some day, and you think this stuff is worth it, > | you can buy me a beer in return. > |--Carlo Miron : > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
2016-09-08 17:25 GMT+02:00 Emanuele Urselli : > Eh, è ciò che anche io ho letto sul libro. > Solo che se passo il modulo mi dà un output il risultato dello script senza > generare bytecode. > Se invece passo il file (con suffisso .py quindi) mi genera il file .pyc. > > Python 3.5.2 su Ubunt 16.04 Che comando dai, esattamente? Che output ottieni? E che modulo utilizzi, e dove si trova? ㎝ -- |:**THE BEER-WARE LICENSE** *(Revision 42)*: | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a beer in return. |--Carlo Miron : ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Piattaforma: Ubuntu 16.04 Versione Python: 3.5.2 Posizione modulo: /home/Python-3.5.2 Nome file: m.py (modulo: m) Contenuto: print(__name__) Comando: $ python -m m Output: __main__ (nessun .pyc creato) Invece: Comando: $ python -m m.py Output: __main__ (generato bytecode) Lo stesso per quanto riguarda l'opzione -O (generazione bytecode ottimizzato) Inviato da iPhone > Il giorno 08 set 2016, alle ore 17:34, Carlo Miron ha > scritto: > > 2016-09-08 17:25 GMT+02:00 Emanuele Urselli : > >> Eh, è ciò che anche io ho letto sul libro. >> Solo che se passo il modulo mi dà un output il risultato dello script senza >> generare bytecode. >> Se invece passo il file (con suffisso .py quindi) mi genera il file .pyc. >> >> Python 3.5.2 su Ubunt 16.04 > > Che comando dai, esattamente? > Che output ottieni? > E che modulo utilizzi, e dove si trova? > > ㎝ > > -- > |:**THE BEER-WARE LICENSE** *(Revision 42)*: > | wrote this mail. As long as you retain > | this notice you can do whatever you want with this stuff. > | If we meet some day, and you think this stuff is worth it, > | you can buy me a beer in return. > |--Carlo Miron : > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
2016-09-08 17:39 GMT+02:00 Emanuele Urselli : > Piattaforma: Ubuntu 16.04 > Versione Python: 3.5.2 Stessa piattaforma e versione. > Posizione modulo: /home/Python-3.5.2 > Nome file: m.py (modulo: m) > Contenuto: print(__name__) > Comando: $ python -m m > Output: __main__ (nessun .pyc creato) miron@hop:/tmp/eu $ echo "print(__name__)" > m.py miron@hop:/tmp/eu $ ls m.py miron@hop:/tmp/eu $ python3 -m m __main__ miron@hop:/tmp/eu $ ls m.py __pycache__ come previsto. > Invece: > Comando: $ python -m m.py > Output: __main__ (generato bytecode) miron@hop:/tmp/eu $ python3 -m m.py m /usr/bin/python3: Error while finding spec for 'm.py' (AttributeError: module 'm' has no attribute '__path__') come previsto. > Lo stesso per quanto riguarda l'opzione -O (generazione bytecode ottimizzato) Sei sicuro di star utilizzando l'interprete giusto, e non il Python 2.7.12 di sistema? ㎝ -- |:**THE BEER-WARE LICENSE** *(Revision 42)*: | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a beer in return. |--Carlo Miron : ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Eseguo l'interprete con il comando: ./python Se eseguo semplicemente Python mi fa utilizzare quello di sistema Inviato da iPhone > Il giorno 08 set 2016, alle ore 17:47, Carlo Miron ha > scritto: > > 2016-09-08 17:39 GMT+02:00 Emanuele Urselli : > >> Piattaforma: Ubuntu 16.04 >> Versione Python: 3.5.2 > > Stessa piattaforma e versione. > >> Posizione modulo: /home/Python-3.5.2 >> Nome file: m.py (modulo: m) >> Contenuto: print(__name__) >> Comando: $ python -m m >> Output: __main__ (nessun .pyc creato) > > miron@hop:/tmp/eu > $ echo "print(__name__)" > m.py > miron@hop:/tmp/eu > $ ls > m.py > miron@hop:/tmp/eu > $ python3 -m m > __main__ > miron@hop:/tmp/eu > $ ls > m.py __pycache__ > > come previsto. > >> Invece: >> Comando: $ python -m m.py >> Output: __main__ (generato bytecode) > > miron@hop:/tmp/eu > $ python3 -m m.py > m > /usr/bin/python3: Error while finding spec for 'm.py' (AttributeError: > module 'm' has no attribute '__path__') > > come previsto. > >> Lo stesso per quanto riguarda l'opzione -O (generazione bytecode ottimizzato) > > Sei sicuro di star utilizzando l'interprete giusto, e non il Python > 2.7.12 di sistema? > > ㎝ > > -- > |:**THE BEER-WARE LICENSE** *(Revision 42)*: > | wrote this mail. As long as you retain > | this notice you can do whatever you want with this stuff. > | If we meet some day, and you think this stuff is worth it, > | you can buy me a beer in return. > |--Carlo Miron : > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
2016-09-08 17:52 GMT+02:00 Emanuele Urselli : > Eseguo l'interprete con il comando: > ./python e ./python --version ti risponde Python 3.5.2? L'hai compilato dai sorgenti? Devi aver fatto qualcosa di strano, per ottenere questo comportamento inusuale. Non saprei come aiutarti, senza una grossa quantità di informazioni in più. Sorry. ㎝ -- |:**THE BEER-WARE LICENSE** *(Revision 42)*: | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a beer in return. |--Carlo Miron : ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Salvare bytecode
Dovrei provare ad avviare con python3 (?) Inviato da iPhone > Il giorno 08 set 2016, alle ore 17:57, Carlo Miron ha > scritto: > > 2016-09-08 17:52 GMT+02:00 Emanuele Urselli : > >> Eseguo l'interprete con il comando: >> ./python > > e ./python --version ti risponde Python 3.5.2? > > L'hai compilato dai sorgenti? Devi aver fatto qualcosa di strano, per > ottenere questo comportamento inusuale. > Non saprei come aiutarti, senza una grossa quantità di informazioni in > più. Sorry. > > ㎝ > > -- > |:**THE BEER-WARE LICENSE** *(Revision 42)*: > | wrote this mail. As long as you retain > | this notice you can do whatever you want with this stuff. > | If we meet some day, and you think this stuff is worth it, > | you can buy me a beer in return. > |--Carlo Miron : > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python