Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
'NoneType' object is unsubscriptable
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
BlackLion  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 11:01 am
From: BlackLion <omar.fari...@gmail.com>
Date: Mon, 30 Apr 2012 08:01:56 -0700 (PDT)
Local: Mon, Apr 30 2012 11:01 am
Subject: 'NoneType' object is unsubscriptable

tengo un problema serio en la aplicación que estoy haciendo deseo mostrar
un reporte mensual de producción y lo hago de la siguiente manera: le
pregunto al usuario el rango de fechas (desde-hasta) y las guardo en 2
variables 'finicio' y 'ffin', y tambien le pregunto el turno
de producción 'turno', una vez hecho esto hago algo así:
date = finicio
while date <= ffin:
   t_l10_co = db((lf == date) & (lt == turno)).select(db.logo.c10clipon)
   aj = t_l10_co.last()
   l10co = aj['c10clipon']
   suma=suma+l10co
   date = datetime.timedelta(1)
Pensé que así funcionaria pero me da error cuando pasa por las fechas donde
se carga información por ser día no laboral, el error es este:

 Traceback (most recent call last):

  File "gluon/restricted.py", line 205, in restricted
  File "C:/Omar/web2py/applications/gestpro/controllers/default.py" <http://127.0.0.1:8000/admin/default/edit/gestpro/controllers/default.py>, line 682, in <module>
  File "gluon/globals.py", line 173, in <lambda>
  File "C:/Omar/web2py/applications/gestpro/controllers/default.py" <http://127.0.0.1:8000/admin/default/edit/gestpro/controllers/default.py>, line 650, in reportemensual
TypeError: 'NoneType' object is unsubscriptable

entiendo el error, lo que deseo es un forma de resolverlo ya que no se de que otra forma podré hacer el reporte mensual sin tener que estar llenando las tablas con ceros automáticamente


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Etkin  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 11:49 am
From: Alan Etkin <spame...@gmail.com>
Date: Mon, 30 Apr 2012 08:49:06 -0700 (PDT)
Local: Mon, Apr 30 2012 11:49 am
Subject: Re: 'NoneType' object is unsubscriptable

No sé cómo es el flujo del reporte (qué va, cuándo y cómo), pero por el
código que mostrás, la falla parece ser que cuando la consulta que hace el
bucle devuelve una secuencia de registros vacía, al pedir el valor del
campo de un registro inexistente genera la excepción. Lo más sencillo sería
omitir el error y continuar (con un bloque try-except o comprobando que el
resultado de la consulta no sea vacío), pero no sé si el reporte lo permite.

Por ejemplo, para omitir el registro nulo es algo así:

Declaración del bucle:
    Si t_l10_co no es None:
        ...
        date = <dato>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 12:05 pm
From: BlackLion <omar.fari...@gmail.com>
Date: Mon, 30 Apr 2012 09:05:08 -0700 (PDT)
Local: Mon, Apr 30 2012 12:05 pm
Subject: Re: 'NoneType' object is unsubscriptable

ok pero que valor compruebo que no sea None, "aj = t_l10co.last()"? Porque
una vez que trato de asignarle ese contenido a una variable me da
la excepción

El lunes, 30 de abril de 2012 11:01:56 UTC-4, BlackLion escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luis Díaz  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 12:15 pm
From: Luis Díaz <diazluis2...@gmail.com>
Date: Mon, 30 Apr 2012 11:45:47 -0430
Local: Mon, Apr 30 2012 12:15 pm
Subject: Re: 'NoneType' object is unsubscriptable
puedes hacer un len(aj) > 0
de esta forma sabes si extrajo registros.

la otra cosa que te recomendaría es colocar nombres de variables mas
descriptivos..
lo único que me quedo claro fue "suma"... y en realidad suma de?
debería tener un nombre descriptivo del valor que contiene.. no de lo
que se hace con ella..

Díaz Luis
Analista Programador Facultad de Odontología UC
http://www.about.me/diazluis
User Linux 532223

El día 30 de abril de 2012 11:35, BlackLion <omar.fari...@gmail.com> escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jose  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 12:53 pm
From: Jose <jjac...@gmail.com>
Date: Mon, 30 Apr 2012 09:53:37 -0700 (PDT)
Local: Mon, Apr 30 2012 12:53 pm
Subject: Re: 'NoneType' object is unsubscriptable

El lunes, 30 de abril de 2012 12:01:56 UTC-3, BlackLion escribió:

Lo que creo que deberías hacer es una consulta que sume y agrupe por fecha.
Algo similar a.

suma = db.mi_tabla.mi_campo_a_sumar.sum().with_alias("suma")
qry_fecha_inicio = (db.mi_tabla.fecha >= fecha_inicio)
qry_fecha_fin = (db.mi_tabla.fecha <= fecha_fin)
qry_turno = (db.mi_tabla.turno==turno)

registros = db(qry_fecha_inicio & qry_fecha_fin &
qry_turno).select(db.mi_tabla.fecha, otros_campos, suma,
groupby=db.mi_tabla.fecha, orderby=db.mi_tabla.fecha)

No lo probé, pero debería funcionar

Saludos
Jose

mas info:

http://www.web2py.com/books/default/chapter/29/6#sum,-min,-max-and-len
http://www.web2py.com/books/default/chapter/29/6#orderby,-groupby,-li...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 1:54 pm
From: BlackLion <omar.fari...@gmail.com>
Date: Mon, 30 Apr 2012 10:54:40 -0700 (PDT)
Local: Mon, Apr 30 2012 1:54 pm
Subject: Re: 'NoneType' object is unsubscriptable

trate de hacer lo que me indicaste y me dijo object of type 'NoneType' has
no len()
El lunes, 30 de abril de 2012 12:15:47 UTC-4, Luis Díaz escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 2:04 pm
From: BlackLion <omar.fari...@gmail.com>
Date: Mon, 30 Apr 2012 11:04:55 -0700 (PDT)
Local: Mon, Apr 30 2012 2:04 pm
Subject: Re: 'NoneType' object is unsubscriptable

El lunes, 30 de abril de 2012 12:53:37 UTC-4, Jose escribió:

Y luego de hacer esto como obtengo lo que contiene el query, así:
a = registros.last()
contenido = a['mi_campo_a_sumar']

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Etkin  
View profile   Translate to Translated (View Original)
 More options Apr 30 2012, 8:53 pm
From: Alan Etkin <spame...@gmail.com>
Date: Mon, 30 Apr 2012 17:53:01 -0700 (PDT)
Local: Mon, Apr 30 2012 8:53 pm
Subject: Re: 'NoneType' object is unsubscriptable

El tema es este: si  t_l10_co no devolvió resultados (instancia de Rows sin
registros), al hacer .last() devuelve None. Luego, para este caso tendrías
que continuar el bucle sin procesar datos, evitando el error, o reemplazar
la propiedad del registro inexistente con un dato válido por defecto (o
cualquier otra cosa que evite la excepción). Para la primera opción sería
algo así:

while date <= ffin:
   t_l10_co = db((lf == date) & (lt == turno)).select(db.logo.c10clipon)
   aj = t_l10_co.last()
   # procesar datos sólo si la consulta no es vacía.
   if aj is not None:
     l10co = aj['c10clipon']
     suma=suma+l10co
     date = datetime.timedelta(1)

El lunes, 30 de abril de 2012 15:04:55 UTC-3, BlackLion escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options May 2 2012, 10:53 am
From: BlackLion <omar.fari...@gmail.com>
Date: Wed, 2 May 2012 07:53:51 -0700 (PDT)
Local: Wed, May 2 2012 10:53 am
Subject: Re: 'NoneType' object is unsubscriptable

Solucione el problema utilizando try-except, el codigo quedo más largo pero
no hay rollo muchas gracias


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options May 2 2012, 12:10 pm
From: BlackLion <omar.fari...@gmail.com>
Date: Wed, 2 May 2012 09:10:46 -0700 (PDT)
Local: Wed, May 2 2012 12:10 pm
Subject: Re: 'NoneType' object is unsubscriptable

Surgio una falla inesperada y es que cuando el programa esta ejecutando
esto:
ex20 = db((sbf == date) & (sbt == turno)).select(db.soldadura_b.extintor20)
c = ex20.last()
try:
e20 = c['extintor20']
except:
e20 = 0
s50 = s50+e20
me da este error:
unsupported operand type(s) for +: 'int' and 'NoneType'
no entiendo por qué, porque si la variable es NoneType le estoy asignando
un valor entero = 0, si alguien me puede ayudar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sebastian Bassi  
View profile   Translate to Translated (View Original)
 More options May 2 2012, 12:35 pm
From: Sebastian Bassi <sba...@gmail.com>
Date: Wed, 2 May 2012 12:35:31 -0400
Local: Wed, May 2 2012 12:35 pm
Subject: Re: 'NoneType' object is unsubscriptable
2012/5/2 BlackLion <omar.fari...@gmail.com>:

> s50 = s50+e20
> me da este error:

> unsupported operand type(s) for +: 'int' and 'NoneType'

> no entiendo por qué, porque si la variable es NoneType le estoy asignando un
> valor entero = 0, si alguien me puede ayudar

Por empezar no uses "try" asi solo, pone try tipo_de_error. Si no
sabes cual es el tipo de error, correlo una vez sin try y miralo,
luego ponelo en el try, asi te aseguras que se active solo por eso y
no por otra cosa.
Ahora en donde asignas s50?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
BlackLion  
View profile   Translate to Translated (View Original)
 More options May 2 2012, 1:50 pm
From: BlackLion <omar.fari...@gmail.com>
Date: Wed, 2 May 2012 10:50:21 -0700 (PDT)
Local: Wed, May 2 2012 1:50 pm
Subject: Re: 'NoneType' object is unsubscriptable

Al comienzo de esa funcion digo que s50 = 0, y el tipo de error que da sin
el try es que dice que 'NoneType is unsuscriptable', sera que debo colocar
algo así:
except NoneType:
                          e20 = 0
A ver si así hace lo que yo quiero, lo que me intriga es que hace unos 30
minutos sin especificar ni el try ni el except, funcionaba bien, pero ahora
no.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alan Etkin  
View profile   Translate to Translated (View Original)
 More options May 3 2012, 9:15 am
From: Alan Etkin <spame...@gmail.com>
Date: Thu, 3 May 2012 06:15:48 -0700 (PDT)
Local: Thurs, May 3 2012 9:15 am
Subject: Re: 'NoneType' object is unsubscriptable

> sera que debo colocar
> algo así ...

Esta es una forma:

try:
    ...
except TypeError:
    e20 = 0

> unsupported operand type(s) for +: 'int' and 'NoneType'

El error que te da actualmente es porque uno de los dos objetos de la
suma
es de tipo None. Necesitarías depurar el código para saber cuándo se
cambia a None (probablemente cuando
llamás a una función de la DAL como .select() o .last() o
registro["campo"])
y establecer el valor numérico por defecto que necesites antes de que
se haga la operación.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Omar Fariñez  
View profile   Translate to Translated (View Original)
 More options May 3 2012, 3:13 pm
From: Omar Fariñez <omar.fari...@gmail.com>
Date: Thu, 3 May 2012 14:43:57 -0430
Local: Thurs, May 3 2012 3:13 pm
Subject: Re: 'NoneType' object is unsubscriptable

si ya vi que hay una diferencia cuando dice que es unsuscriptable es porque
no hay nada, por ejemplo si pido un reporte en una fecha donde no se haya
guardado nada, es decir, fines de semana feriados, etc. Pero si lo que esta
guardado es un 'None' el query si lo trae y por eso no hace la suma.
Gracias por la ayuda


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »