-3

I know this is a similar post to How to check if text is "empty" (spaces, tabs, newlines) in Python? , however I'm still having troubles.

I don't understand how to use it, I'm trying to check if a variable, which contains a string, consists of only spaces, tabs and newlines. How would I use issppace() as I'm confused with it always being False?.

Help would be much appreciated.

ProTechXS
  • 57
  • 1
  • 7
  • 4
    Show some actual code, what you expect, and what you get, otherwise we can only guess – Chris_Rands Mar 16 '18 at 16:21
  • have you tried using string.strip and seeing if that's empty – L_Church Mar 16 '18 at 16:21
  • My guess: " I'm trying to check if a variable, which contains a string" you have something like a list of strings and you want to check if any/all of them are empty/whitespace – Chris_Rands Mar 16 '18 at 16:21
  • 1
    Are you sure that the string "only consists of space, tab and newline"? There might be other non-printable characters in the string, like `\x00`, that are not spaces. What does `repr(your_string)` or `[ord(c) for c in your_string]` print? You could also use `[(c, c.isspace()) for c in your_string]` to find the culprit. – tobias_k Mar 16 '18 at 16:27
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [On topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. StackOverflow is not a design, coding, research, or tutorial service. – Prune Mar 16 '18 at 16:35
  • @Chris_Rands yeah you are correct – ProTechXS Mar 16 '18 at 18:02
  • For now, since we can't tell what your actually problem is until add an [mcve] to your question, I'm closing it as a duplicate @ProTechXS. – Christian Dean Mar 16 '18 at 22:56

1 Answers1

0

You can use:

if string_to_check.strip():
    print("Contains characters")
else:
    print("Contains no characters")