• Register
1 vote
156 views

Problem:

I am trying to print some string in my python program but for some reason, it’s not working. The compiler says python syntaxerror: EOL while scanning string literal that is totally beyond my understandings. For obvious reason, I am avoiding my original code and attaching a simple dummy code. Please check it and let me know about the problem.

def printStr():
    mystr = "This is
      a test string"
    print(mystr)
printStr()

Here is the dummy code snippet. Please pull me up from the problem. Thanks to all.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

The term “EOL” stands for End Of the Line and the error occurred due to forgot ending ( ) quotes. An EOL error means that Python hit the end of a line while going through a string. In your case, you encountered strings spanning multiple lines actionThe reason for this error is that a string enclosed in single or double quotes can't span multiple lines. You need to add triple single quotes ( ‘’’ ) or triple double quotes ( “”” ) end of the line to fix the error. 

def printStr():
    mystr = """This is
      a test string"""
    print(mystr)
printStr()

Because python's indentation rules for blocks do not apply to lines inside a multiline string. I hope you get the point.

13 9 6
94,240 points

Related questions

0 votes
1 answer 7 views
7 views
Problem: I'm playing with both learning python and trying to get github issues into a readable form. Using the advice on How can I convert JSON to CSV? I came up with this: import json import csv f=open('issues.json') data = json.load(f) f.close() f=open("issues.csv" ... item["labels"], item["state"]]) Where "issues.json" is the json file containing my github issues. When I try to run that, I get
asked Feb 15 Mashhoodch 9.1k points
1 vote
2 answers 105 views
105 views
Problem : The program supposed to take in two names, and if they are the same length it should check if they are the same word. But i am getting below error in python python typeerror: not all arguments converted during string formatting
asked Oct 21, 2019 peterlaw 6.9k points
1 vote
1 answer 589 views
589 views
Problem: I am getting the following error : error: array initializer must be an initializer list or string literal For the array; char x[80] = GetString(); Can any body explain or help?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 15 views
15 views
Program: I having trouble passing a function as a parameter to another function. This is my code: ga.py: def display_pageviews(hostname): pageviews_results = get_pageviews_query(service, hostname).execute() if pageviews_results.get('rows', []): pv = pageviews_results.get('rows') ... ='7daysAgo', end_date='today', metrics='ga:pageviews', sort='-ga:pageviews', filters='ga:hostname==%s' % hostname,)
asked Jan 11 Mashhoodch 9.1k points
0 votes
1 answer 51 views
51 views
Problem: I have this piece of code which creates a new note..WHen I try to print I get the following error even though it prints the output Error: C:\Python27\Basics\OOP\formytesting>python notebook.py Memo=This is my first memo, Tag=example Traceback (most recent call last): File "notebook.py", line 14, in <module> print(firstnote) TypeError: __str__ returned non-string (type NoneType)
asked Jan 8 Mashhoodch 9.1k points
0 votes
1 answer 29 views
1 vote
1 answer 322 views
322 views
Problem: Hello all, I am trying to play with python and completed writing a code. My codes are supposed to create a new note. Unfortunately, I messed up something in the script and it&rsquo;s not working as I expected. Find my sample script snippet below and have a look ... . So, in the end I am posting here to get responses from you guys. Thanks for your valuable time. I must recognize your help.
asked Apr 26, 2020 Gavin 15.3k points
0 votes
1 answer 3 views
3 views
Problem: I am looking to make a loop so that for each element in the list, it will get broken down into each of it's characters. For example, say the number 137 was in the list then it would be turned into [1,3,7]. Then I want to add these numbers together (I ... it). However, I keep getting the error message TypeError: 'int' object is not iterable when I try and run this. What am I doing wrong?
asked 3 days ago Mashhoodch 9.1k points
0 votes
1 answer 19 views
19 views
Problem: I am providing two values (mon_voltage and core_voltage) via the command line and I need to find a "starting point" from a two dimensional array where my iteration or loop will start from. Here is my code: myArray = [[1.02,1.13],[1.02,1.16],[1.02,1. ... : can only concatenate tuple (not "int") to tuple I can't figure out why start_point, which is an index, is a tuple. Please help.
asked Feb 13 sasha 8.7k points