[Python] super(MyClass, self).__init__(*args, **kwargs)
salve a tutti, non riesco a capire come usare *args, **kwargs in una classe. mi sono fatto uno script che riporto sotto ma, ad esempio mi perdo kwargs per strada mentre gli args proprio non li vedo da dentro la classe. lo script sotto mi ritorna bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: ({1: 'A', 2: 'B', 3: 'C'},) {} __init__ class A: ({1: 'A', 2: 'B', 3: 'C'},) {} super class B: ({1: 'A', 2: 'B', 3: 'C'},) {} class: B kwargs : {} end che non ho capito? import sys class A(object): def __init__(self,*args, **kwargs): print "__init__ class A: %s %s"%(args,kwargs) class B(A): def __init__(self,arg, *args, **kwargs): print "__init__ class B: %s %s" %(args, kwargs) super(B, self).__init__(*args, **kwargs) print "super class B: %s %s" %(args, kwargs) self.kwargs = kwargs def __str__(self): return "class: %s\nkwargs : %s" % (self.__class__.__name__, self.kwargs,) def main(): print "MRO:", [x.__name__ for x in B.__mro__] args = ('Y','Y','Z') kwargs = {1:"A", 2:"B", 3:"C"} foo = B(args, kwargs) print foo raw_input('end') if __name__ == "__main__": main() ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] super(MyClass, self).__init__(*args, **kwargs)
hai capito perfettamente, tra l' altro se seguo il consiglio di christian ottengo bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} __init__ class A: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} super class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} class: B kwargs : {} sono a dir poco confuso 2016-02-17 20:57 GMT+01:00 Francesco Pischedda : > > 2016-02-17 19:59 GMT+01:00 Giuseppe Costanzi : >> >> args = ('Y','Y','Z') >> kwargs = {1:"A", 2:"B", 3:"C"} >> >> foo = B(args, kwargs) > > > ok questo è praticamente un check della mia comprensione di questo > meccanismo di python: > > nella chiama al costruttore di B stai passando due argomenti posizionali > cioè args e kwargs che sono rispettivamente una tupla e un dict e il > __init__ di B ha un primo parametro posizionale chiamato arg (che cattura la > prima tupla) mentre mi pare di capire che tu volessi fare una cosa del tipo: > > foo = B(*args, **kwargs) > > cioè espandere la tupla args in parametri posizionali e il dict kwargs in > parametri chiave valore, ho capito male? > > > -- > "Unix IS user friendly. It's just selective about who its friend are" > > "Nevertheless I still think it’s a bad idea to make things harder for > ourselves if we can avoid it." > > "C is quirky, flawed, and an enormous success." >-- Dennis Ritchie > > "Shipping is a feature. A really important feature. Your product must have > it." > > "La gatta frettolosa ha fatto i gattini ciechi" > > > ___ > 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] super(MyClass, self).__init__(*args, **kwargs)
2016-02-17 21:20 GMT+01:00 Giuseppe Costanzi : > hai capito perfettamente, > tra l' altro se seguo il consiglio di christian ottengo > bc@hal9000:~/stimuli$ python super.py > MRO: ['B', 'A', 'object'] > __init__ class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} > __init__ class A: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} > super class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} > class: B > kwargs : {} > > sono a dir poco confuso > > 2016-02-17 20:57 GMT+01:00 Francesco Pischedda > : >> >> 2016-02-17 19:59 GMT+01:00 Giuseppe Costanzi : >>> >>> args = ('Y','Y','Z') >>> kwargs = {1:"A", 2:"B", 3:"C"} >>> >>> foo = B(args, kwargs) >> >> >> ok questo è praticamente un check della mia comprensione di questo >> meccanismo di python: >> >> nella chiama al costruttore di B stai passando due argomenti posizionali >> cioè args e kwargs che sono rispettivamente una tupla e un dict e il >> __init__ di B ha un primo parametro posizionale chiamato arg (che cattura la >> prima tupla) mentre mi pare di capire che tu volessi fare una cosa del tipo: >> >> foo = B(*args, **kwargs) >> >> cioè espandere la tupla args in parametri posizionali e il dict kwargs in >> parametri chiave valore, ho capito male? >> >> >> -- >> "Unix IS user friendly. It's just selective about who its friend are" >> >> "Nevertheless I still think it’s a bad idea to make things harder for >> ourselves if we can avoid it." >> >> "C is quirky, flawed, and an enormous success." >>-- Dennis Ritchie >> >> "Shipping is a feature. A really important feature. Your product must have >> it." >> >> "La gatta frettolosa ha fatto i gattini ciechi" >> >> >> ___ >> Python mailing list >> Python@lists.python.it >> http://lists.python.it/mailman/listinfo/python >> scusate il quoting ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] super(MyClass, self).__init__(*args, **kwargs)
2016-02-17 21:25 GMT+01:00 Christian Barra : > > > Il giorno 17 febbraio 2016 21:20, Giuseppe Costanzi > ha scritto: >> >> hai capito perfettamente, >> tra l' altro se seguo il consiglio di christian ottengo >> bc@hal9000:~/stimuli$ python super.py >> MRO: ['B', 'A', 'object'] >> __init__ class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} >> __init__ class A: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} >> super class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {} >> class: B >> kwargs : {} >> >> sono a dir poco confuso > > > Printa anche argscosi capisci dove sono finite le tue variabili :D > > *args ti gestisce tutti gli iterabiliuna lista e' iterabile cosi come un > dict. > > > > > -- > > I wish you a good day, > Christian si infatti con il tuo consiglio ho capito che va tutto in args ma non riesco a capire come mandare un dizionario in kwargs se faccio cosi' args = ('Y','Y','Z') kwargs = {1:"A", 2:"B", 3:"C"} foo = B(args, kwargs,msg="Hello") allora ottengo, quasi, quello che vorrei bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} __init__ class A: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} super class B: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} class: B kwargs : {'msg': 'Hello'} end ma mi perdo la lista ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] super(MyClass, self).__init__(*args, **kwargs)
2016-02-17 21:40 GMT+01:00 Christian Barra : > > > Il giorno 17 febbraio 2016 21:38, Giuseppe Costanzi > ha scritto: >> >> si infatti con il tuo consiglio ho capito che va tutto in args >> ma non riesco a capire come mandare un dizionario in kwargs >> se faccio cosi' >> >> args = ('Y','Y','Z') >> kwargs = {1:"A", 2:"B", 3:"C"} >> foo = B(args, kwargs,msg="Hello") >> >> allora ottengo, quasi, quello che vorrei >> >> bc@hal9000:~/stimuli$ python super.py >> MRO: ['B', 'A', 'object'] >> __init__ class B: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} >> __init__ class A: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} >> super class B: ({1: 'A', 2: 'B', 3: 'C'},) {'msg': 'Hello'} >> class: B >> kwargs : {'msg': 'Hello'} >> end >> ma mi perdo la lista > > > Mi fai vedere il resto del codice ? > -- > > I wish you a good day, > Christian come no import sys class A(object): def __init__(self,*args, **kwargs): print "__init__ class A: %s %s"%(args,kwargs) class B(A): def __init__(self,arg, *args, **kwargs): print "__init__ class B: %s %s" %(args, kwargs) super(B, self).__init__(*args, **kwargs) print "super class B: %s %s" %(args, kwargs) self.kwargs = kwargs def __str__(self): return "class: %s\nkwargs : %s" % (self.__class__.__name__, self.kwargs,) def main(): print "MRO:", [x.__name__ for x in B.__mro__] args = ('Y','Y','Z') kwargs = {1:"A", 2:"B", 3:"C"} foo = B(args, kwargs,msg="Hello") print foo raw_input('end') if __name__ == "__main__": main() > > ___ > 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] super(MyClass, self).__init__(*args, **kwargs)
2016-02-17 21:48 GMT+01:00 Christian Barra : > def __init__(self,arg, *args, **kwargs): > > args = ('Y','Y','Z') > kwargs = {1:"A", 2:"B", 3:"C"} > > foo = B(args, kwargs,msg="Hello") > > Cosa ti fa pensare che la lista (args immagino) si sia persa ? > > La domanda e' tu dove ti aspetti di trovarla :) > > args -> arg > kwargs -> *args > msg="Hello" -> **kwargs > > -- > > I wish you a good day, > Christian ok quell' args mi è scappato e levandolo ottengo bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {'msg': 'Hello'} __init__ class A: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {'msg': 'Hello'} super class B: (('Y', 'Y', 'Z'), {1: 'A', 2: 'B', 3: 'C'}) {'msg': 'Hello'} class: B kwargs : {'msg': 'Hello'} end quello che non riesco a capire e' perchè se la classe mi accetta valori arbitrari di una lista e di un dizionario ed io , mi sembra, li passo con args e kwargs l' *args si pappa lista e dizionario e per popolare **kwargs devo passargli un'altro parametro (msg': 'Hello') cioè non posso passare a *kwargs un dizionario e poi spacchettarmenlo da dentro la classe? per fare un esempio pratico args = ('Y','Y','Z') kwargs = {'server':"127.0.0.1", 'user':"guest",'passw':"12345",'database':"genbank"} foo = B(args, kwargs, server="127.0.0.1", user="guest",passw="12345",database="genbank") ritorna bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: (('Y', 'Y', 'Z'), {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'}) {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} __init__ class A: (('Y', 'Y', 'Z'), {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'}) {'passw': '12345', 'user': 'guest', 'server': '127.0.0.1', 'database': 'genbank'} super class B: (('Y', 'Y', 'Z'), {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'}) {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} class: B kwargs : {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} end mentre args = ('Y','Y','Z') foo = B(args, server="127.0.0.1", user="guest",passw="12345",database="genbank") bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: (('Y', 'Y', 'Z'),) {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} __init__ class A: (('Y', 'Y', 'Z'),) {'passw': '12345', 'user': 'guest', 'server': '127.0.0.1', 'database': 'genbank'} super class B: (('Y', 'Y', 'Z'),) {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} class: B kwargs : {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} end che e' quello che vorrei cioe' *kwargs il dizionario lo vuole spacchettato? > > ___ > 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] super(MyClass, self).__init__(*args, **kwargs)
2016-02-17 22:22 GMT+01:00 Dario Santomarco : > Il 17/02/2016 19.59, Giuseppe Costanzi ha scritto: > > salve a tutti, > non riesco a capire come usare *args, **kwargs in una classe. > mi sono fatto uno script che riporto sotto ma, ad esempio mi perdo > kwargs per strada mentre gli args proprio non li vedo da dentro la classe. > lo script sotto mi ritorna > > bc@hal9000 > :~/stimuli$ python super.py > MRO: ['B', 'A', 'object'] > __init__ class B: ({1: 'A', 2: 'B', 3: 'C'},) {} > __init__ class A: ({1: 'A', 2: 'B', 3: 'C'},) {} > super class B: ({1: 'A', 2: 'B', 3: 'C'},) {} > class: B > kwargs : {} > end > > che non ho capito? > > import sys > > class A(object): > def __init__(self,*args, **kwargs): > print "__init__ class A: %s %s"%(args,kwargs) > > class B(A): > def __init__(self,arg, *args, **kwargs): > print "__init__ class B: %s %s" %(args, kwargs) > super(B, self).__init__(*args, **kwargs) > print "super class B: %s %s" %(args, kwargs) > > self.kwargs = kwargs > > > def __str__(self): > return "class: %s\nkwargs : %s" % (self.__class__.__name__, > self.kwargs,) > > def main(): > > print "MRO:", [x.__name__ for x in B.__mro__] > > > args = ('Y','Y','Z') > kwargs = {1:"A", 2:"B", 3:"C"} > > foo = B(args, kwargs) > > print foo > > raw_input('end') > > if __name__ == "__main__": > main() > ___ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python > > Ciao, ci sono i seguenti errori: > Tua - kwargs = {1:"A", 2:"B", 3:"C"} > Corretta - kwargs = {'1':"A", '2':"B", '3':"C"} # le chiavi del > dizionario DEVONO essere stringhe > > Per le altre due ci sono due opzioni > Questa ha più senso: > Tua - def __init__(self,arg, *args, **kwargs): #quel arg sembra > un errore di battitura, non ha molto senso in quella posizione > Corretta -def __init__(self, *args, **kwargs): > > Tua - foo = B(args, kwargs) > Tua - foo = B(args, **kwargs) # se glielo passi senza i doppi > asterischi gli stai passando un oggetto dict che va a finire come lista di > argomenti catturata da *args, devi spacchettarlo con ** > > Questa ha meno senso: > Tua - def __init__(self,arg, *args, **kwargs): #supponendo ci > siano motivi particolari per cui vuoi tenere il tutto com'è > > Tua - foo = B(args, kwargs) > Corretta - foo = B(*args, **kwargs) # devi spacchettare args > altrimenti viene catturata da arg come oggetto tupla. spacchettandola accade > che la prima 'Y' va ad arg e le restanti due lettere ad *args > -- > > Dario Santomarco ho capito...grazie... args = ('Y','Y','Z') kwargs = {'server':"127.0.0.1", 'user':"guest",'passw':"12345",'database':"genbank"} foo = B(args, **kwargs) bc@hal9000:~/stimuli$ python super.py MRO: ['B', 'A', 'object'] __init__ class B: (('Y', 'Y', 'Z'),) {'passw': '12345', 'user': 'guest', 'server': '127.0.0.1', 'database': 'genbank'} __init__ class A: (('Y', 'Y', 'Z'),) {'database': 'genbank', 'passw': '12345', 'user': 'guest', 'server': '127.0.0.1'} super class B: (('Y', 'Y', 'Z'),) {'passw': '12345', 'user': 'guest', 'server': '127.0.0.1', 'database': 'genbank'} class: B kwargs : {'passw': '12345', 'user': 'guest', 'server': '127.0.0.1', 'database': 'genbank'} end che e' quello che voglio grazie a tutti per la pazienza :( > ___ > 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] super(MyClass, self).__init__(*args, **kwargs)
azz... metto l'* davanti ad args? ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] MySQLdb connect non aggiorna i dati sui client
salve a tutti, sto migrando un' applicazione da sqlite a mysql, funziona tutto tranne che per il fatto che se effettuo degli insert o update da un client queste sono visibili solo al client che esegue queste modifiche, mentre su tutti gli altri devo chiudere l'applicazione e riavviarla. Controllando sul server, le tabelle si aggiornano correttamente. E' come se gli altri client vedessero le tabelle del server solo quando si apre la connessione. Tra l' altro, usando tabelle innodb, nelle operazioni di scrittura forzo sempre il commit dell' operazione. L' applicazione ha anche una parte web, programmata con php, dove gli aggiornamenti sui dati sono coerenti. self.con.commit() cosa potrebbe essere? saluti giuseppe ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] MySQLdb connect non aggiorna i dati sui client
2016-03-02 14:29 GMT+01:00 m : > * Carlo Miron (ca...@golang.it) [160302 14:21]: >> >> >>> sto migrando un' applicazione da sqlite a mysql, funziona tutto tranne >>> che >>> per il fatto che se effettuo degli insert o update da un client queste >>> sono visibili >>> solo al client che esegue queste modifiche, mentre su tutti gli altri >>> devo chiudere l'applicazione e riavviarla. >>> Controllando sul server, le tabelle si aggiornano correttamente. >>> E' come se gli altri client vedessero le tabelle del server solo quando >>> si >>> apre la connessione. >> >> > > secondo me perché stanno all'interno di una transazione, e non la > chiudono mai, e il server sta andando con un livello di isolamento > 'repeatable read' --- quindi gli fa vedere sempre lo stesso 'snapshot' > del database > > se è quello (wild guess): > - puoi o portare il livello di isolamento a 'read committed' > (sconsigliato) > - o cambiare l'applicazione in modo che chiuda la transazione (soluzione > corretta) > > per inciso, se la diagnosi è corretta, avresti quel comportamento anche > con postgresql o altri db la diagnosi è corretta. la cura, che non è farina del mio sacco, sarebbe la seguente...non credo ti piaccia :( cur = self.con.cursor() cur.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED") cur.execute("SELECT @@session.tx_isolation") cur.execute(sql,args) if fetch == True: rs = cur.fetchall() else: rs = cur.fetchone() cur.execute("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ") cur.execute("SELECT @@session.tx_isolation") cur.close() return rs p.s. concordo anche con l'approfondita analisi di carlo ;) giuseppe > > -- > .*.finelli > /V\ > (/ \) -- > ( ) Linux: Friends dont let friends use Piccolosoffice > ^^-^^ -- > > First shalt thou take out the Holy Pin. Then, shalt thou count to three, > no more, no less. Three shalt be the number thou shalt count, and the > number of the counting shalt be three. Four shalt thou not count, nor > either count thou two, excepting that thou then proceed to three. Five > is right out. Once the number three, being the third number, be reached, > then lobbest thou thy Holy Hand Grenade of Antioch towards thou foe, who > being naughty in my sight, shall snuff it. > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
2016-03-02 15:16 GMT+01:00 m : > * Giuseppe Costanzi (giuseppecosta...@gmail.com) [160302 14:57]: >> >> >> la cura, che non è farina del mio sacco, sarebbe la seguente...non >> credo ti piaccia :( >> >> cur = self.con.cursor() >> cur.execute("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED") >> cur.execute("SELECT @@session.tx_isolation") >> > > se usi READ UNCOMMITTED, che usi un database transazionale a fare ? > cioè, stai dicendo "mi va bene leggere un dato, farci delle operazioni, > ritornare un risultato, e poi magari quel dato (a causa di un ABORT) > nel database non c'è nemmeno" > > che per carità, esistono sicuramente applicazioni che funzionano > bene anche così, però secondo me è un chiamarsi delle sfighe > > diciamo che la prima volta che ti segnalano che c'è un'inconsistenza nei > dati, sai già che cosa guardare, e puoi rispondere "lo so" ai ragione su tutta la linea ma al momento non ho le conoscenze per fare altro, mi devo studiare la cosa. tra l'altro la soluzione lo vista su stack owerflow e sembra un problema comune, ma devo approfondire la cosa. > > -- > .*.finelli > /V\ > (/ \) -- > ( ) Linux: Friends dont let friends use Piccolosoffice > ^^-^^ -- > > Se sono in due e uno è lucido, il capo è l'altro. > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
2016-03-02 15:21 GMT+01:00 Carlos Catucci : > > 2016-03-02 15:16 GMT+01:00 m : >> >> >> che per carità, esistono sicuramente applicazioni che funzionano >> bene anche così, però secondo me è un chiamarsi delle sfighe > > > Una cosa simile non e' chiamarsi sfighe, e' andarle a cercare con il > lanternino come faceva Diogene. > La cosa che non mi quaglia e' come mai le transazioni non vegano chiuse, chi > e' che non le chiude? L'applicazione Python? O l'altro bagaglio in PHP? > Ma usare un ORM non sarebbe una strada percorribile nel caso specifico? > > Carlos è python che non le chiude, o meglio mysqldb, ma anche leggendo la documentazione, non ho trovato nulla al riguardo. php viene usato solo per interrogare la database dalle pagine web. > -- > EZLN ... Para Todos Todo ... Nada para nosotros > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
2016-03-02 16:05 GMT+01:00 Giuseppe Costanzi : > 2016-03-02 15:21 GMT+01:00 Carlos Catucci : >> >> 2016-03-02 15:16 GMT+01:00 m : >>> >>> >>> che per carità, esistono sicuramente applicazioni che funzionano >>> bene anche così, però secondo me è un chiamarsi delle sfighe >> >> >> Una cosa simile non e' chiamarsi sfighe, e' andarle a cercare con il >> lanternino come faceva Diogene. >> La cosa che non mi quaglia e' come mai le transazioni non vegano chiuse, chi >> e' che non le chiude? L'applicazione Python? O l'altro bagaglio in PHP? >> Ma usare un ORM non sarebbe una strada percorribile nel caso specifico? >> >> Carlos > > è python che non le chiude, o meglio mysqldb, ma anche leggendo la > documentazione, > non ho trovato nulla al riguardo. > php viene usato solo per interrogare la database dalle pagine web. > > penso di avere trovato dove è il problema http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html >> -- >> EZLN ... Para Todos Todo ... Nada para nosotros >> >> ___ >> 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] MySQLdb connect non aggiorna i dati sui client
On Thu, Mar 3, 2016 at 6:24 PM, enrico franchi wrote: > > 2016-03-02 10:02 GMT-08:00 Giuseppe Costanzi : >> >> http://dev.mysql.com/doc/refman/5.0/en/innodb-consistent-read.html > > > Questo pero' non e' quello che hai descritto nel primo post. > > scusa enrico , ma da quello che ho capito io il problema dovrebbe essere causato proprio dal fatto che transaction isolation level = REPEATABLE READ. Come riportato "A consistent read means that InnoDB uses multi-versioning to present to a query a snapshot of the database at a point in time" ed io infatti mi ritrovo che ogni client ha :" a snapshot of the database" quando si collega. Io per connettermi uso MySQLdb e leggendo la documentazione non ho trovato niente sulla gestione dell 'isolation level. Uso MySQLdb bovinamente, mi sono fatto una classe per aprire una connessione, che certo resta aperta fino a quando non si chiude l'applicazione, eseguo i commit ad ogni update o insert ed amen. Certo non mi aspettavo questo comportamento sulle select e mi sto studiando la cosa. > . > ..: -enrico- > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
Il giorno 05/mar/2016 15:52, "Carlos Catucci" ha scritto: > > > 2016-03-04 14:22 GMT+01:00 Roberto Polli : >> >> La cosa che fa' strano però è trovare gente che si lamenta ancora >> di mysql 4 quando basterebbe un upgrade. > > > A volte non hai il controllo dell'host. Un sacco di gente ha hosting non dedicati e devi arrangiarti con la versione che passa il convento, pardon, il provider dell'host. nel caso im questione mysql è quello di un server virtualizzato con debian 5 e non è possibile aggiornarlo... > > Carlos > -- > EZLN ... Para Todos Todo ... Nada para nosotros > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
2016-03-08 1:19 GMT+01:00 enrico franchi : > > 2016-03-07 15:56 GMT-08:00 Enrico Bianchi : >>> >>> cosa potrebbe essere? >> >> Di tutto, anche se propenderei ad un problema lato codice (ok che MySQL fa >> cagare, ma non fino a questo punto) > > > +1; da cui suggerivo che invece di smacchinare con la conf di MySQL si > facesse un briciolo di root cause analysis. > > allora, questa e' ,una parte, della classe che esegue le operazioni di scrittura sul db la connessione la apro al lancio dell' applicazione ed eseguo il commit di tutti i DML (INSERT ed UPDATE) poi la chiudo, senza commit alla chiusura dell' applicazione. che mi sfugge? class DBMS(object): def __init__(self,*args, **kwargs): super(DBMS, self).__init__(*args, **kwargs) self.open_connection(kwargs) def open_connection(self, kwargs): self.con = mdb.connect(kwargs['server'], kwargs['user'], kwargs['password'], kwargs['database']) def write(self, sql, args=()): try: cur = self.con.cursor() cur.execute(sql,args) self.con.commit() cur.close() except: self.con.rollback() print sql, args print sys.exc_info()[0] print sys.exc_info()[1] print sys.exc_info()[2] finally: > . > ..: -enrico- > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
Il giorno 08/mar/2016 10:00, "Carlos Catucci" ha scritto: > > > 2016-03-08 8:52 GMT+01:00 Giuseppe Costanzi : >> >> poi la chiudo, senza commit alla chiusura dell' applicazione. >> che mi sfugge? > > > Magari dico una corbelleria ma se non fai mai commit ovvio che possano restare aperte. Tu fai affidamento sul fatto che la chiusura della applicazione chiuda la connessione e di conseguenza faccia la committ? Io non sarei cosi' sicuro. scusa carlos ma ho postato la classe che uso e sul metodo write forzo sempre il commit self.con.commit() che mi sfugge? > Carlos > -- > EZLN ... Para Todos Todo ... Nada para nosotros > > ___ > 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] MySQLdb connect non aggiorna i dati sui client
Il giorno 08/mar/2016 11:02, "Enrico Bianchi" ha scritto: > > On 03/08/2016 08:52 AM, Giuseppe Costanzi wrote: >> >> che mi sfugge? > > > Che non è detto che quel commit sia eseguito. Intanto ti conviene spostare la chiamata al commit in un context switch ed usa with per richiamare la classe, poi se continua a non funzionare si vedrà ok, ci provo anche se le modifiche sulle tabelle ci sono, ma le vede solo chi le fa. > Enrico > P.S. io la butto lì, ma se state migrando il tutto da SQLite, perché non passare direttamente a PostgreSQL? magari, sarebbe stata la mia prima scelta, è che è già um miracolo che il servizio imformatico ci abbia dato un server, di aggiornamenti non se ne parla proprio, ho provato a montare un cd per aggiornare i pacchetti ma non ci sono riiscito, che tra l altro mi sarei installato il paccheto di sqlite per php e la vita sarebbe scorsa felice, la migrazione l'ho fatta per semplificare la parte web dell'applicazione. Purtoppo, almeno qua, si fa di necessità virtute.. ___ > 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] MySQLdb connect non aggiorna i dati sui client
Il giorno 08/mar/2016 11:38, "Giovanni Porcari" < giovanni.porc...@softwell.it> ha scritto: > > > > Il giorno 08 mar 2016, alle ore 11:20, Giuseppe Costanzi < giuseppecosta...@gmail.com> ha scritto: > > > > > > Il giorno 08/mar/2016 11:02, "Enrico Bianchi" ha scritto: > > > > > > On 03/08/2016 08:52 AM, Giuseppe Costanzi wrote: > > >> > > >> che mi sfugge? > > > > > > > > > Che non è detto che quel commit sia eseguito. Intanto ti conviene spostare la chiamata al commit in un context switch ed usa with per richiamare la classe, poi se continua a non funzionare si vedrà > > > > ok, ci provo anche se le modifiche sulle tabelle ci sono, ma le vede solo chi le fa. > > > > > Enrico > > > P.S. io la butto lì, ma se state migrando il tutto da SQLite, perché non passare direttamente a PostgreSQL? > > > > magari, sarebbe stata la mia prima scelta, è che è già um miracolo che il servizio imformatico ci abbia dato un server, di aggiornamenti non se ne parla proprio, ho provato a montare un cd per aggiornare i pacchetti ma non ci sono riiscito, che tra l altro mi sarei installato il paccheto di sqlite per php e la vita sarebbe scorsa felice, la migrazione l'ho fatta per semplificare la parte web dell'applicazione. > > Purtoppo, almeno qua, si fa di necessità virtute.. > > > Provato a settare l'autocommit ? > > G si ho provato a metterlo a True anche dopo l' apertura della con ma non cambia nulla > ___ > 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] MySQLdb connect non aggiorna i dati sui client
>> > Il giorno 08 mar 2016, alle ore 11:20, Giuseppe Costanzi >> > ha scritto: >> > >> > >> > Il giorno 08/mar/2016 11:02, "Enrico Bianchi" >> > ha scritto: >> > > >> > > On 03/08/2016 08:52 AM, Giuseppe Costanzi wrote: >> > >> >> > >> che mi sfugge? >> > > >> > > >> > > Che non è detto che quel commit sia eseguito. Intanto ti conviene >> > > spostare la chiamata al commit in un context switch ed usa with per >> > > richiamare la classe, poi se continua a non funzionare si vedrà >> > >> > ok, ci provo anche se le modifiche sulle tabelle ci sono, ma le vede >> > solo chi le fa. >> > sembra comunque che non sia il solo ad avere di questi problemi http://forums.mysql.com/read.php?39,547748,547748#msg-547748 e che non sia un problema di mysqldb http://stackoverflow.com/questions/29629782/python-mysql-connector-cursor-wont-commit ma dipenda dalle tabelle innodb e dal loro lock modes >> 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] MySQLdb connect non aggiorna i dati sui client
2016-03-08 17:37 GMT+01:00 Roberto Polli : > Ciao G, > > faccio un bel thread reset: > > 1- se riesci a riprodurre il problema su github, appena ho tempo gli > do' un'occhiata; > 2- che versione di mysql stai utilizzando? > 3- che driver usi? > Pace, > R. 1 no 2 uso quella su debian 5, dovrebbe essere la 5 e qualcosa, adesso non posso controllare 3 uso MySQLdb con python a casa dove ho debian 6, sto facendo dei tests, uso direttamente uno script in python, che e' la stessa classe che usa l'applicazione, per collegarmi ed inserire alcuni dati poi uso la shell con cui mi ero collegato precedentemente allo stesso database bc@hal9000:~/stimuli$ mysql -u employee -p e l'applicazione aperta prima di fare le modifiche per "vedere l'effetto che fa" ;) Dalla shell le modifiche fatte con lo script si vedono Dall' applicazione no. Se faccio delle modifiche dall 'applicazione, dalla shell si vedono istantaneamente. Boh! > ___ > 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
[Python] Wireless barcode scanner
salve a tutti, volevo sapere se siete a conoscenza di scanner barcode progammabili in python, tipo quelli che si usano nei supermaket per fare l' inventario della merce. saluti giuseppe ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Biovarase
salve a tutti, a questo indirizzo https://github.com/1966bc/Biovarase potete trovare un mio progetto, Biovarase, in realtà il porting in tkinter dello stesso essendo il proggeto nato 3 anni fa in wxPython. L'applicativo serve a gestire il controllo di qualità in laboratorio analisi. saluti beppe ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Iterare una sequenza
salve a tutti, ho una sequenza del tipo ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT scorrendola devo trovare una sequenza target GAATTC ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT quindi dividere la sequenza da G, la prima lettera della sequenza target, e calcolarmi la lunghezza dei due frammenti risultanti ACTGATCGATTACGTATAGTAG e di questa GAATTCTATCATACATATATATCGATGCGTTCAT io avrei fatto seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" target = "GAATTCT" s = [] for i,base in enumerate(seq): s.append(base) if len(s)==8: s.pop(0) if ''.join(s) == target: print i-5 print len(seq)-(i-5) break funziona ma non e' che ne sia proprio convinto, avete suggerimenti su come iterare la sequenza? saluti beppe p.s. e' un esercizio che ho trovato su p4b, python for biologist "Let's start this exercise by solving the problem manually. If we look through the DNA sequence we can spot the EcoRI site at position 21. Here's the sequence with the base positions labelled above and the EcoRI motif in bold: in bold sarebbe questa GAATTCT 0123456789012345678901234567890123456789012345678901234 ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT Since the EcoRI enzyme cuts the DNA between the G and first A, we can figure out that the first fragment will run from position 0 to position 21, and the second fragment from position 22 to the last position, 54. Therefore the lengths of the two fragments are 22 and 33." ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Iterare una sequenza
ciao carlo, si, interessante ma vorrei iterare la sequenza mano a mano, stavo pensando a qualcosa tipo next(iterator, default) grazie comunque On Sun, Nov 26, 2017 at 10:30 AM, Carlo Miron wrote: > On Sun, Nov 26, 2017 at 10:20 AM, Giuseppe Costanzi > wrote: > >> ho una sequenza del tipo >> ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT >> scorrendola devo trovare una sequenza target GAATTC >> ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT >> quindi dividere la sequenza da G, la prima lettera della sequenza target, >> e calcolarmi la lunghezza dei due frammenti risultanti >> ACTGATCGATTACGTATAGTAG >> e di questa >> GAATTCTATCATACATATATATCGATGCGTTCAT > > qualcosa tipo > >>>> seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" >>>> target = "GAATTCT" >>>> first, second = seq.split(target, 1) >>>> first += target[1] >>>> second = target[1:] + second >>>> len(first), len(second) > (22, 33) > > ? > ㎝ > > -- > |:**THE 🍺-WARE LICENSE** *(Revision ㊷)*: > | 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 🍺 in return. —㎝ > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Iterare una sequenza
ciao federico, il secondo metodo mi piace, tra l' altro ho notato che itera solo 22 volte mentre il mio 28. in pratica vai a blocchi di lunghezza uguale al target invece di andare una base alla volta. bello, mi piace questa soluzione. grazie 2017-11-26 11:06 GMT+01:00 Federico Cerchiari : > Ciao Giuseppe, > > per trovare la posizione di un oggetto in una sequenza (lista, stringa o > altro) puoi usare il metodo '.index' delle liste: > > dna_seq = 'ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT' > target = 'GAATTCT' > target_position = dna_seq.index(target) + 1 > print('lunghezza pre-target: %d, post-target %d' % (target_position, > len(dna_seq)-target_position)) > > Se vuoi iterare sulla sequenza per farci altro fai bene a usare > 'enumerate', ma invece di costruirti la stringa di comparazione di volta in > volta puoi prelevarla dalla stringa originale ad ogni ciclo: > > for position, gene in enumerate(dna_seq): > if dna_seq[position:position+len(target)] == target: > position += 1 # Aggiungiamo 1 perchè enumerate è 0-based > print('lunghezza pre-target: %d, post-target %d' % (position, > len(dna_seq)-position)) > > Federico > > 2017-11-26 10:42 GMT+01:00 Giuseppe Costanzi : > >> ciao carlo, >> >> si, interessante ma vorrei iterare la sequenza mano a mano, >> >> stavo pensando a qualcosa tipo >> >> next(iterator, default) >> >> grazie comunque >> >> >> >> On Sun, Nov 26, 2017 at 10:30 AM, Carlo Miron wrote: >> > On Sun, Nov 26, 2017 at 10:20 AM, Giuseppe Costanzi >> > wrote: >> > >> >> ho una sequenza del tipo >> >> ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT >> >> scorrendola devo trovare una sequenza target GAATTC >> >> ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT >> >> quindi dividere la sequenza da G, la prima lettera della sequenza >> target, >> >> e calcolarmi la lunghezza dei due frammenti risultanti >> >> ACTGATCGATTACGTATAGTAG >> >> e di questa >> >> GAATTCTATCATACATATATATCGATGCGTTCAT >> > >> > qualcosa tipo >> > >> >>>> seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" >> >>>> target = "GAATTCT" >> >>>> first, second = seq.split(target, 1) >> >>>> first += target[1] >> >>>> second = target[1:] + second >> >>>> len(first), len(second) >> > (22, 33) >> > >> > ? >> > ㎝ >> > >> > -- >> > |:**THE 🍺-WARE LICENSE** *(Revision ㊷)*: >> > | 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 🍺 in return. —㎝ >> > ___ >> > Python mailing list >> > Python@lists.python.it >> > https://lists.python.it/mailman/listinfo/python >> ___ >> Python mailing list >> Python@lists.python.it >> https://lists.python.it/mailman/listinfo/python >> > > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > > ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Iterare una sequenza
ciao Christian, che dire... spettacolare; On Sun, Nov 26, 2017 at 11:25 AM, Christian Barra wrote: > In pseudo code > > seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" > ...: > ...: def finder(seq, target): > ...: len_target = len(target) > ...: i = 0 > ...: while i+len_target < len(seq): > ...: yield seq[i:i+len_target], i > ...: i += 1 > Il check per == lo puoi inserire all’interno del finder o fuori. > > —— > Christian Barra > Python Freelancer // Consultant // Trainer > Board member of the EuroPython Society > www.chrisbarra.xyz > > On 26 Nov 2017, at 10:42, Giuseppe Costanzi > wrote: > > ciao carlo, > > si, interessante ma vorrei iterare la sequenza mano a mano, > > stavo pensando a qualcosa tipo > > next(iterator, default) > > grazie comunque > > > > On Sun, Nov 26, 2017 at 10:30 AM, Carlo Miron wrote: > > On Sun, Nov 26, 2017 at 10:20 AM, Giuseppe Costanzi > wrote: > > ho una sequenza del tipo > ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT > scorrendola devo trovare una sequenza target GAATTC > ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT > quindi dividere la sequenza da G, la prima lettera della sequenza target, > e calcolarmi la lunghezza dei due frammenti risultanti > ACTGATCGATTACGTATAGTAG > e di questa > GAATTCTATCATACATATATATCGATGCGTTCAT > > > qualcosa tipo > > seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" > target = "GAATTCT" > first, second = seq.split(target, 1) > first += target[1] > second = target[1:] + second > len(first), len(second) > > (22, 33) > > ? > ㎝ > > -- > |:**THE 🍺-WARE LICENSE** *(Revision ㊷)*: > | > 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 🍺 in return. —㎝ > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > > > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > > ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Iterare una sequenza
ciao giorgio, temo che a breve dovro' studiarmelo grazie per la segnalazione On Sun, Nov 26, 2017 at 11:34 AM, Giorgio Zoppi wrote: > Io userei el automa di aho corasick. > In Bioinformatics si usa tanto. > http://carshen.github.io/data-structures/algorithms/2014/04/07/aho-corasick-implementation-in-python.html > > > 2017-11-26 10:20 GMT+01:00 Giuseppe Costanzi : >> >> salve a tutti, >> >> ho una sequenza del tipo >> >> ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT >> >> scorrendola devo trovare una sequenza target GAATTC >> >> ACTGATCGATTACGTATAGTA "GAATTC" TATCATACATATATATCGATGCGTTCAT >> >> >> quindi dividere la sequenza da G, la prima lettera della sequenza target, >> e calcolarmi la lunghezza dei due frammenti risultanti >> >> ACTGATCGATTACGTATAGTAG >> >> e di questa >> >> GAATTCTATCATACATATATATCGATGCGTTCAT >> >> io avrei fatto >> >> seq = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" >> target = "GAATTCT" >> >> s = [] >> >> for i,base in enumerate(seq): >> >> s.append(base) >> >> if len(s)==8: >> >> s.pop(0) >> >> if ''.join(s) == target: >> print i-5 >> print len(seq)-(i-5) >> break >> >> funziona ma non e' che ne sia proprio convinto, >> avete suggerimenti su come iterare la sequenza? >> >> saluti >> beppe >> >> >> p.s. >> >> e' un esercizio che ho trovato su p4b, python for biologist >> >> >> "Let's start this exercise by solving the problem manually. If we look >> through the >> DNA sequence we can spot the EcoRI site at position 21. Here's the >> sequence with >> the base positions labelled above and the EcoRI motif in bold: >> >> in bold sarebbe questa GAATTCT >> >> 0123456789012345678901234567890123456789012345678901234 >> ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT >> Since the EcoRI enzyme cuts the DNA between the G and first A, we can >> figure out >> that the first fragment will run from position 0 to position 21, and the >> second >> fragment from position 22 to the last position, 54. Therefore the >> lengths of the two >> fragments are 22 and 33." >> ___ >> Python mailing list >> Python@lists.python.it >> https://lists.python.it/mailman/listinfo/python > > > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
[Python] Esportare dati float in csv
salve a tutti, ho una routine che mi esporta dei dati estratti da un database in sqlite, tupla di liste, in csv. I dati sono principalamente float tipo rs = [(2, 0.382, 8.59, 76.4, 2.38, 0.425, 2.68, 1.09, 2.14, 18.3, 0.495), (3, 0.687, 625.0, 103.0, 1.92, 0.272, 4.75, 1.07, 2.03, 39.5, 0.115)] il problema e' che quando apro il file csv cosi' generato con xls oppure calc i numeri non interi vengono interpretati come una stringa cioe' gli viene anteposto davanti l' apostrofo '. Questa cosa mi succede, tra l' altro solo su windows, mentre con linux, io uso la debian il file viene formattato correttamente. Il problema e' di impostazione sui fogli di calcolo oppure di esportazione dei dati? C'e' un modo di forzare il tipo? Prima usavo, xlwt ma con python 3 sulla debian 9 non c'e' e comunque preferirei usare il modulo csv. Suggerimenti? beppe ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Esportare dati float in csv
2018-02-13 11:13 GMT+01:00 Carlos Catucci : > > > Il 13 feb 2018 11:03 AM, "Giuseppe Costanzi" ha > scritto: > > . > Il problema e' di impostazione sui fogli di calcolo oppure di > esportazione dei dati? > C'e' un modo di forzare il tipo? > > Esporto usando la virgola come separatore decimale sul CSV. Mettici il punto > è tutto funziona, oppure usa librerie per esportare in xlsx scusa carlos non ho capito, devo sostituire il punto con la virgola? no perche' gia' uso il punto per i decimali, mentre i campi sono separati con la virgola. ripeto preferirei farlo oin csv ma credo che come dici dovro' per forza usare qualche libreira ad hoc. p.s. il recordset e' una lista di tuple chiaramente, non come ho scritto sopra. > > > > Carlos > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Esportare dati float in csv
2018-02-13 11:42 GMT+01:00 Carlos Catucci : > > > Il 13 feb 2018 11:21 AM, "Giuseppe Costanzi" ha > scritto: > > > > > scusa carlos non ho capito, devo sostituire il punto con la virgola? > no perche' gia' uso il punto per i decimali, mentre i campi sono > separati con la virgola. > > > > Allora non dovrebbe prenderli con stringhe. Puoi postare qualche riga di > CSV? come no def exporter(self, rs, cols): file_name = "%s.xls"%(self.title,) path = tempfile.mktemp (file_name) obj = open(path,'w') print(rs) with obj: writer = csv.writer(obj,delimiter=',') writer.writerow(cols) writer.writerows(rs) self.launch(path) rs = [(2, 0.382, 8.59, 76.4, 2.38, 0.425, 2.68, 1.09, 2.14, 18.3, 0.495), (3, 0.687, 625.0, 103.0, 1.92, 0.272, 4.75, 1.07, 2.03, 39.5, 0.115)] e per rispondere a daniele, la prima cosa che ho fatto e' sostituire il punto con la virgola ma succede la stessa cosa. > > ripeto preferirei farlo oin csv ma credo che come dici dovro' per > forza usare qualche libreira ad hoc. > > > Ce ne sono di ottime che permettono di fare tutto, incluso creare altri > sheet. > > > p.s. > il recordset e' una lista di tuple chiaramente, non come ho scritto sopra > > Non > Questo non credo abbia importanza, a meno che non sia che le tuple vengono > trasformare in stringa, ma risulterebbe nel CSV > > Carlos > > > ___ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python > ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] Esportare dati float in csv
2018-02-13 12:00 GMT+01:00 Giuseppe Costanzi : > 2018-02-13 11:42 GMT+01:00 Carlos Catucci : >> >> >> Il 13 feb 2018 11:21 AM, "Giuseppe Costanzi" ha >> scritto: >> >> >> >> >> scusa carlos non ho capito, devo sostituire il punto con la virgola? >> no perche' gia' uso il punto per i decimali, mentre i campi sono >> separati con la virgola. >> >> >> >> Allora non dovrebbe prenderli con stringhe. Puoi postare qualche riga di >> CSV? > > come no > > def exporter(self, rs, cols): > > file_name = "%s.xls"%(self.title,) > path = tempfile.mktemp (file_name) > obj = open(path,'w') > print(rs) > with obj: > writer = csv.writer(obj,delimiter=',') > writer.writerow(cols) > writer.writerows(rs) > > self.launch(path) > > rs = [(2, 0.382, 8.59, 76.4, 2.38, 0.425, 2.68, 1.09, 2.14, 18.3, > 0.495), (3, 0.687, 625.0, 103.0, 1.92, 0.272, 4.75, 1.07, 2.03, 39.5, > 0.115)] > > e per rispondere a daniele, la prima cosa che ho fatto e' sostituire > il punto con la virgola > ma succede la stessa cosa. > >> >> ripeto preferirei farlo oin csv ma credo che come dici dovro' per >> forza usare qualche libreira ad hoc. >> >> >> Ce ne sono di ottime che permettono di fare tutto, incluso creare altri >> sheet. >> >> >> p.s. >> il recordset e' una lista di tuple chiaramente, non come ho scritto sopra >> >> Non >> Questo non credo abbia importanza, a meno che non sia che le tuple vengono >> trasformare in stringa, ma risulterebbe nel CSV >> >> Carlos questo uno script per simulare il problema. import csv class Tester(object): def __init__(self,*args, **kwargs): super(Tester, self).__init__( ) self.args = args self.kwargs = kwargs def exporter(self, rs, cols): obj = open("out.csv",'w') print(rs) with obj: writer = csv.writer(obj,delimiter=',') writer.writerow(cols) writer.writerows(rs) def main(): cols = ["a","b","c","d"] rs = [(1, 0.382, 8.59, 76.4), (2, 0.687, 625.0, 103),] foo = Tester() foo.exporter(rs, cols) input('end') if __name__ == "__main__": main() >> >> >> ___ >> Python mailing list >> Python@lists.python.it >> https://lists.python.it/mailman/listinfo/python >> ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python