473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to express "if empty" concept in python

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
4 2343
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. >>> s=""
  2. >>> not s
  3. True
  4. >>> s == ""
  5. True
  6. >>>            
  7.  
Dec 19 '07 #2
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
ghostdog74
511 Expert 256MB
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
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

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

Similar topics

10
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None"...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
145
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two...
2
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage()...
1
by: Denton | last post by:
Hi all: I working in MS window environment. Now I want to use a python script to import some data from CSV file to MDB file. but I have some problems about creating MDB file in DAO. I am using...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
10
by: mcbobin | last post by:
Hi, Here's hoping someone can help... I'm using a stored procedure to return a single row of data ie a DataRow e.g. public static DataRow GetManualDailySplits(string prmLocationID, string
1
ctoz
by: ctoz | last post by:
To express "if m is greater than 1 but less than or equal to 5" is it if (m > 1 && <=5) or does it have to be two statements if (m > 1) && if (m<= 0.5)
3
by: kang jia | last post by:
hi, currently i am doing booking car online and one of the function is cancel and update booking. if the booking number users entered in is not exist. it will redirect the page stating that the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.