Python Forum
Variable from notepad problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable from notepad problem
#1
Hello dear users, let me explain you my problem with variable.

b = open("test.txt", "r").readline()

a = input("Write")

if a == b:
print("good")

I have really simple program like this. In my "test.txt" i have only two lines and in first is "a" and in second "b"

If i put in my input "a" this if statement not work and not print "good". But when only try to print out print(b) it prints "a" so i do not understand why it is not working.

My variable b is equal to "a" but my if statement says it is not equal.

I also noticed when i have only one line in my notepad then it is working. So please guys can you help me with this ? Why it is not working when i have two lines in notepad.

Thank you a lot !
Reply
#2
Please format your code according to the rules. Please read BBcode to learn how to do this.
I think your problem is in extra characters. readline() will also read the newline at the end of a line. You should strip() what you get from readline(). Perhaps this works:
b = open("test.txt", "r").readline().strip()
Reply
#3
THANK YOU A LOT !!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 717 Oct-22-2023, 10:05 PM
Last Post: deanhystad
Question Trouble installing modules/libraries and getting Notepad++ to show cyrillic letters Dragiev 6 2,179 Jul-24-2022, 12:55 PM
Last Post: Dragiev
  Reset Variable problem IcodeUser8 3 2,312 Jul-20-2020, 12:20 PM
Last Post: IcodeUser8
  Problem: Get variable JohnnyCoffee 0 1,571 Feb-22-2020, 09:26 PM
Last Post: JohnnyCoffee
  Problem defining a variable rix 6 3,135 Dec-17-2019, 11:34 AM
Last Post: rix
  Problem writing a variable value to Excel Chuck_Norwich 1 1,903 Jul-25-2019, 02:20 PM
Last Post: Chuck_Norwich
  Running python code meant for Notepad++ plugin independently greektranslator 3 2,936 Jan-28-2019, 06:03 PM
Last Post: maxtimbo
  Pass variable script return twice output problem Faruk 8 4,290 Dec-26-2018, 11:57 AM
Last Post: Faruk
  Exporting Python Output to Notepad Nirmal 4 3,518 Sep-02-2018, 02:36 PM
Last Post: Nirmal
  Problem with variable O_Pas_Sage 7 4,410 Aug-25-2018, 04:07 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020