This works in idle, but not as python script?

This little listing works line for line in Idle3, but not as python script ?
Why this ? Apparently this script can only continue after input ? :

m = [list(map(int,input().split())) for i in range(16)]
print(m)
bool ('m')

This little listing works line for line in Idle3, but not as python
script ?
Why this ? Apparently this script can only continue after input ? :

m = [list(map(int,input().split())) for i in range(16)]

So, reads 16 lines of text containing integers, and converts each into a
list of ints.

print(m)

This should work.

bool (‘m’)

This will also work, but (a) IDLE probably prints the result, like the
python interactive prompt does - a script doesn’t print unless you tell
it to, so silence and (b) this doesn’t do what you might have intended.

You’re computeing bool(‘m’) i.e. the string ‘m’. Unrelated to your
list in the variable m. So it will always compute True, because the
string ‘m’ is not empty (strings are like other Python collections: true
if not empty, false if empty).

You probably meant “bool(m)” which computes bool() for your variable
named m. However, since that is inherently a list if 16 sublists, that
will also always be true (a 16 element list is not empty), so this is
not a very useful thing to compute.

Cheers,
Cameron Simpson cs@cskk.id.au

thx - to avoid misunderstanding - variable ‘m’ was thought for ‘mainboard’ and mainboard
for example - just a number - has 16 chips or little ssds.
:wink:

How would I have to write above snippet for a script (not for idle) ?

That depends on what you wanted the snippet to do. You had this:

m = [list(map(int,input().split())) for i in range(16)]
print(m)
bool ('m')

I had the impression that you expected to see the value of “bool(‘m’)”
(or, more likely, “bool(m)”). So:

m = [list(map(int,input().split())) for i in range(16)]
print(m)
print(bool('m'))

Cheers,
Cameron Simpson cs@cskk.id.au