Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » unsupported operand type(s) for -: 'unicode' and 'int' [RSS Feed]

#1 Dec. 23, 2010 18:23:08

prasad i.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

unsupported operand type(s) for -: 'unicode' and 'int'


Hi Everyone,
I am getting type error on integer. I have tried converting all the
possible variables to int but still the problem persist. Can anyone
help me out with this type error
following is the stack tracehttp://dpaste.com/289886/following are the 2 functions which are giving me the problem

def list_movies(request,page_no=1, orderby=None):
try:

page=int(page_no)
except ValueError:
page=1
if orderby is None:
orderby='-date_pub'
latest_movies=Movies.objects.all().order_by(orderby)
pagination=TubePagination(latest_movies, 20)
try:
page=int(page)
assert (type(page) is IntType)
movies=pagination.get_page(page)
except InvalidPage:
errorcontent=''
return HttpResponse(content=errorcontent,mimetype='application/
json')
json_serializer=serializers.get_serializer('json')()
jsonobj=json_serializer.serialize(movies, ensure_ascii=False)
return HttpResponse(content=jsonobj, mimetype="application/json")




class TubePagination:
def __init__(self, arg0, arg1=1):
self.objs=arg0
self.pagesize=arg1
def get_page(self, arg0):
upperbound=self.pagesize * int(arg0)
if upperbound > len(self.objs):
k=upperbound - len(self.objs)

if k > self.pagesize :
raise InvalidPage(arg0)
else:
lowerbound=len(self.objs) - (len(self.objs) %
self.pagesize)
else:
lowerbound=upperbound-self.pagesize
if lowerbound < 0:
lowerbound = 0
return self.objs

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 24, 2010 02:54:28

Sam L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

unsupported operand type(s) for -: 'unicode' and 'int'


I'd say you should check if the pagesize variable is a string or not
on this line -

upperbound=self.pagesize * int(arg0)

Remember in Python, 'hello' * 2 == 'hellohello'.

On 24 December 2010 05:04, prasad iyer <p.c.i...@gmail.com> wrote:
> Hi Everyone,
> I am getting type error on integer. I have tried converting all the
> possible variables to int but still the problem persist. Can anyone
> help me out with this type error
> following is the stack trace
>http://dpaste.com/289886/>
> following are the 2 functions which are giving me the problem
>
> def list_movies(request,page_no=1, orderby=None):
>        try:
>
>                page=int(page_no)
>        except ValueError:
>                page=1
>        if orderby is None:
>                orderby='-date_pub'
>        latest_movies=Movies.objects.all().order_by(orderby)
>        pagination=TubePagination(latest_movies, 20)
>        try:
>                page=int(page)
>                assert (type(page) is IntType)
>                movies=pagination.get_page(page)
>        except InvalidPage:
>                errorcontent=''
>                return HttpResponse(content=errorcontent,mimetype='application/
> json')
>        json_serializer=serializers.get_serializer('json')()
>        jsonobj=json_serializer.serialize(movies, ensure_ascii=False)
>        return HttpResponse(content=jsonobj, mimetype="application/json")
>
>
>
>
> class TubePagination:
>        def __init__(self, arg0, arg1=1):
>                self.objs=arg0
>                self.pagesize=arg1
>        def get_page(self, arg0):
>                upperbound=self.pagesize * int(arg0)
>                if upperbound > len(self.objs):
>                        k=upperbound - len(self.objs)
>
>                        if  k > self.pagesize :
>                                raise InvalidPage(arg0)
>                        else:
>                                lowerbound=len(self.objs) - (len(self.objs) %
> self.pagesize)
>                else:
>                        lowerbound=upperbound-self.pagesize
>                if lowerbound < 0:
>                        lowerbound = 0
>                return self.objs
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » unsupported operand type(s) for -: 'unicode' and 'int' [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support