in Education by
Here's the code: ''' file_path = (r'C:\Users\Luka\Desktop\Pyhton exercises\pi_digits.txt') with open(file_path) as file_object: contents = file_object.read() print(contents) #print(contents.rstrip()) # rstrip should remove blank space at the end ''' filename = ("prova.txt") with open(filename) as file_object: for line in file_object: print(line) Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The problem is with a file_path variable between triple quotes. C:\ starts an eight-character Unicode escape. In the code, the escape is followed by the character U, which is invalid. Double up your backslashes to escape them, e.g.: """ file_path = (r'C:\\Users\\Luka\\Desktop\\Pyhton exercises\\pi_digits.txt') with open(file_path) as file_object: contents = file_object.read() print(contents) #print(contents.rstrip()) # rstrip should remove blank space at the end """ filename = "prova.txt" Do check out Data Science with Python course which helps you understand from scratch

Related questions

0 votes
    The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is ... for unary +: 'str' Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I am new to python, I have this code: # columns are [0]title [1]year [2]rating [3]length(min) [4]genre ... make that int into a list? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    SA=1000.00 AI=0.12 MP=100.00 def remainb(x): if x==0: return 0 else: return x=(SA+(AI/12)*SA)-MP for ... . run the loop until SA==0). Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Hi, I am a relatively new programmer and my teacher gave us this problem to fix. Thing is, I have no idea ... wrong with this problem? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Do I need coding skills for Data Science using Python? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is better than R for Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me why Python is used in Data Science? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    In the python documentation, an instance of a named_tuple is created by using the below code: Point = named_tuple(' ... of doing it? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Here is my sample string: [true, {"name": "NameofItem", "amount": "1", "price": 100, "sellerName": " ... seem to make that work. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am starting to work with python again after 8 years. I am trying to do the program with BeautifulSoup and an ... '__main__': main() Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
...