D
D
Denis99992015-12-24 00:47:19
Python
Denis9999, 2015-12-24 00:47:19

Error in Python 3 when reading from a file?

I read lines from a file and output to the command line. At the same time, when I output what I read from the file, everything works, but when I perform small manipulations with this line, an error occurs. Why, after all, in both cases strings are displayed, the variable and is not displayed?
Mistake:

IndentationError: unindent does not match any outer indentation level

f = open('stroki.txt')
for line in f:
  print (line)
  a = "https://site.com/desc?target="+line+"&platform=message"
        print (a)

in the print (a) program at the same level, here I couldn’t get there, after posting the question it goes to the right

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis9999, 2015-12-24
@Denis9999

The reason was that opposite one line was indented with Tab, and the other with 4 spaces

S
Saboteur, 2015-12-24
@saboteur_kiev

because in python you need to indent strictly according to the nesting of blocks.
put
print (a)
on the same level as
a = " https://site.com/desc?target= "+line+"&platform=message"
and everything will be ok

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question