473,396 Members | 1,891 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,396 software developers and data experts.

Null String Variable

I have a variable that store a string (i.e. a variable name msg).I want to
say something like that: if msg is empty ...then do something.So how can i
figure that msg is empty string (no character, msg = '').Maybe a silly
question but i have no programming experiense.Thanks, Leonidas
Jul 19 '05 #1
4 16365
Rotary wrote:
I want to say something like that: if msg is empty ...then do
something. So how can i figure that msg is empty string (no
character, msg = '').


#v+

if not msg:
print 'msg is empty'

#v-

--
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/
Jul 19 '05 #2
well, somebody's already pointed out that bool(msg)==False iff msg==''.
i'm curious to know what's wrong with simply writing

if msg=='':
## do_something

Jul 19 '05 #3
Sean McIlroy wrote:
well, somebody's already pointed out that bool(msg)==False iff msg==''.
I may not have received the message yet, but if "iff" still means "if
and only if", then that statement is wrong. There are, of course, about
a dozen things for which bool(msg) is False when msg != '', not
including the possibility of objects that define their bool state
however they want.
i'm curious to know what's wrong with simply writing

if msg=='':
## do_something


I'm not sure anything is wrong with it in this case, though the idiom in
Python is generally to do just "if not msg" unless you're concerned
about the possibility that msg is not actually a string.

-Peter
Jul 19 '05 #4
Sean McIlroy wrote:
well, somebody's already pointed out that bool(msg)==False iff msg==''.
i'm curious to know what's wrong with simply writing

if msg=='':
## do_something

You would write this if there was a possibility that msg could be
something other than a string, whose value might also be interpreted as
False by the "if" (e.g. the None object, or an empty list) even though
your application wanted to handle it differently from an empty string.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: BBFrost | last post by:
I want to build a generic application that runs one of a set of class methods depending on data extracted from a database table. For example if I extract value X from the database table I also...
2
by: Mark D'Souza via .NET 247 | last post by:
In trying to create a Panel object with the FindControl methodusing a string variable as the paramater. The code is below. The variable 'testvariable' is equal to pnl_0 which is anexisting Panel on...
12
by: Bernie V | last post by:
Hi group, I'm trying to do this: String DatVandaag; DatVandaag=DateTime.Today.AddDays(-2).ToString("dd/MM/yyyy"); LiteralHeat.Text = "<center><H5>Wekelijkse vinyl TOP 10...
3
by: ad | last post by:
I have a text file in the directory of my web application. How can I read this text file into a string vaiable?
5
by: Generic Usenet Account | last post by:
I have been to recreate a problem that I am having with strings with the trivial code snippet given below. In the trivial code example, I am reading five lines from a data file, each line having...
2
by: bill | last post by:
from: http://us3.php.net/mysql_real_escape_string // Quote variable to make safe function quote_smart($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); }...
0
by: =?Utf-8?B?cm9uZSBtYXRpYXM=?= | last post by:
I have the same task to do but everytime I tried to parse my code I get a null value returned after executing "dtMaterials.WriteXml(swMaterials);". I am using the following code: Hope you can hep...
2
by: Ajak | last post by:
Hello, I'm converting a VB6 app to VB2005 which uses a third party API dll. The API function accepts structure as its parameter (byRef). Below is the struct (shortened for clarity):- ...
0
by: Jimis | last post by:
Hello. My objective is to validade a xml file against the xsd whitch is in a string variable. /* book.xml <?xml version="1.0" encoding="utf-8"?> <author xmlns='urn:bookstore-schema'...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.