By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,173 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,173 IT Pros & Developers. It's quick & easy.

how to express "if empty" concept in python

P: 88
hi

currently i am getting an array from database,the code is in the following, if id do not exist variable b will render an empty array. at this time, i would like to check if this array is empty means the id is not exist in my Booking1 table. How should i express this " if empty " concept in python?

Expand|Select|Wrap|Line Numbers
  1.  
  2. def confirmUp(request):
  3.     q=request.session['BK_id']
  4.     b=Booking1.objects.filter(id__exact=q) 
  5.              if b=empty
  6.                     return HttpResponseRedirect("/Notexist.html/")
  7.              else:
  8.                return render_to_response('proceed.html',{'b': b})
  9.  
Dec 19 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 511
Expand|Select|Wrap|Line Numbers
  1. >>> s=""
  2. >>> not s
  3. True
  4. >>> s == ""
  5. True
  6. >>>            
  7.  
Dec 19 '07 #2

P: 88
Expand|Select|Wrap|Line Numbers
  1. >>> s=""
  2. >>> not s
  3. True
  4. >>> s == ""
  5. True
  6. >>>            
  7.  
thanks for your kind reply. but it seems did not work, as it never go through my if statement and in fact b is an empty Array from my print and the session['BK_id] never exist in my Booking1 table. the following is my code and "print" part is my testing of code.

Expand|Select|Wrap|Line Numbers
  1. def confirmUp(request):
  2.     q=request.session['BK_id']
  3.     b=Booking1.objects.filter(id__exact=q) 
  4.     print b
  5.     print "LLLLLLLLLLLLLLLLLLL"
  6.     if b==" ":    
  7.         print "KKKKKKKKKKKKKK"
  8.         return HttpResponseRedirect("/Notexist.html/")    
  9.     else:    
  10.         return render_to_response('proceed.html',{'b': b})    
  11.  
  12.  
can hep me with this function, thanks so much :)
Dec 20 '07 #3

Expert 100+
P: 511
thanks for your kind reply. but it seems did not work, as it never go through my if statement and in fact b is an empty Array from my print and the session['BK_id] never exist in my Booking1 table. the following is my code and "print" part is my testing of code.

Expand|Select|Wrap|Line Numbers
  1. def confirmUp(request):
  2.     q=request.session['BK_id']
  3.     b=Booking1.objects.filter(id__exact=q) 
  4.     print b , type(b)      ### <<----- print type 
  5.     print "LLLLLLLLLLLLLLLLLLL"
  6.     if b==" ":    
  7.         print "KKKKKKKKKKKKKK"
  8.         return HttpResponseRedirect("/Notexist.html/")    
  9.     else:    
  10.         return render_to_response('proceed.html',{'b': b})    
  11.  
  12.  
can hep me with this function, thanks so much :)
print the type and post your result.
Dec 20 '07 #4

P: 88
print the type and post your result.
before i can print out, it already got error at if b==" " and the error message is:

Request Method: GET
Request URL: http://localhost:8000/homepage/
Exception Type: ImproperlyConfigured
Exception Value: Error while importing URLconf 'fyp2.urls': invalid syntax (views.py, line 521)
Exception Location: C:\Python25\lib\site-packages\django\core\urlresolvers.py in _get_urlconf_module, line 255
Python Executable: C:\Python25\python.exe
Python Version: 2.5.1

thus i think this syntax is not invalid. can help me with this. thanks in advance ;)
Dec 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.