Python Forum
Empty variable when using print before readline
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Empty variable when using print before readline
#3
with open('readme', 'r') as file_h:
    # Read the only line to the end
    print 'file content:', file_h.readline().strip()

    # Will not nor re-read the line,so wlll try to read line 2
    content = file_h.readline().strip()
    print 'from variable:', content
So with this input:
Ek6uEmoKUAAAAAAACCTVU6bnsIAABn
123
This output:
Output:
file content: Ek6uEmoKUAAAAAAACCTVU6bnsIAABn from variable: 123
Reply


Messages In This Thread
RE: Empty variable when using print before readline - by snippsat - Oct-23-2017, 01:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyserial Readline() conversion to array bprosman 1 3,542 Apr-11-2023, 12:44 AM
Last Post: deanhystad
  Greek letters with .readline() and tkinter KinkgOfKeks 7 3,502 Mar-24-2023, 05:13 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 8,455 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Print variable without '' and spaces arnonim 1 1,208 Jan-30-2023, 05:23 PM
Last Post: deanhystad
  Problem with print variable in print.cell (fpdf) muconi 0 1,121 Dec-25-2022, 02:24 PM
Last Post: muconi
  Remove a space between a string and variable in print sie 5 2,858 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Can you print a string variable to printer hammer 2 2,780 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print variable between " paulo79 5 2,648 Mar-11-2022, 05:16 PM
Last Post: deanhystad
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 2,171 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  readline inside and outside functions paul18fr 2 2,701 May-20-2021, 01:15 PM
Last Post: csr

Forum Jump:

User Panel Messages

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