Python shows error on line 15 that i cant fix

Mirko mirkok.lists at googlemail.com
Sat Sep 21 15:03:17 EDT 2019


Am 21.09.2019 um 19:57 schrieb Dave Martin:

> Can you provide an example of how to use the suite feature. Thank you. 
> 

There is no suite feature, Terry just tried to explain indented
blocks to you in simple words. Really, indented blocks are one of
the most basic aspects of Python. You *need* to read the tutorial as
it has been suggested three times now.

Anyway, given the following code:

if name == "Dave":
print("Hello Dave")
print("How are you?)

Programming languages in general cannot exactly understand what that
code means.

It could mean:
	"Say 'Hello Dave' and then 'How are you?" if the name is Dave.

But it could also mean:
	"Say 'Hello Dave' if the name is Dave and then say "How are you?"
what ever the name is.

So, we need to tell Python which command should be executed if the
name is Dave and which not. Some languages solves this with block
markers:

if name == "Dave" then
   print("Hello Dave")
   print("How are you?)
endif

Or for the other meaning:

if name == "Dave" then
   print("Hello Dave")
endif
print("How are you?)


Python uses indented blocks to make clear which commands belong
together. Indentations are runs of whitespaces (of equal length) at
the beginning of the line:

if name == "Dave":
    print("Hello Dave")
    print("How are you?")

Or for the other meaning:

if name == "Dave":
    print("Hello Dave")
print("How ar you"?)


For your code that means, that you need to indent the lines that
belong to the 'with' block

This is wrong:

with fits.open(fits_filename) as data:
df=pd.DataFrame(data[1].data)
...

What you need is this:

with fits.open(fits_filename) as data:
    df=pd.DataFrame(data[1].data)
    ...

^-- See these spaces in front of the commands. That are indentations
and all consecutive indented lines are an indented block.


Please read the tutorial at
https://docs.python.org/3/tutorial/index.html  (fourth time now ;-) )



More information about the Python-list mailing list