The solution requires three things - a thing called a ‘shbang’, Permissions, and what the line end format is.
I’ve been pretending to learn to program Python for several years now, on a Windows 7 machine. One of my grandsons exhibited a desire to learn ‘to code’ . . . So I set up a Linux computer and installed python. Then I copied ALL of my python files to the Linux box, and when I double clicked them most of them would not run.
Something as simple as this, for example.
print()
print (" : Hello You Dirty Dog You")
print()
#
quit = input(" : Press enter to quit.")
So, to make this run when double clicked under Linux I had to :
Add the shebang. #!/usr/bin/env python3.8 This goes in line 1.
Because I am using Spyder, I can easily fix the line ends here. Go to the ‘Source’ menu, select ‘Convert end-of-line characters’ and check the ‘line feed (Unix)’ radio button. (It was the Windows cr/lf when I started.)
Save.
Go to the folder containing the program. Right click the script and select ‘properties’. Click the ‘Permissions’ tab and check on ‘Allow executing file as program’.
When double clicked, because this script needs a ‘terminal window’ select ‘Run in Terminal’ and away we go.
Oddly enough, Turtle Graphics programs and Tkinter programs do not need the shebang and if I click that ‘Allow executing file as program. it stops working.
#!/usr/bin/env python3.8
#
#Sample program to display text, enter a variable, and display it.
#
print (" ")
print (" ")
print ("Hello You Dirty Dog You")
print (" ")
dog = input(" What is your name, dog? ")
print (" ")
print (" Your Name Is : ", dog)
print (" ")
quit = input(": press enter to quit.")
you may use this: \n new line character to introduce a line break versus adding this: print(“ “) multiple times making your script unnecessarily verbose.
For example, implementing the new line character to your script above may now become (a little over 50% savings - for this particular example at least):
print ("\n\nHello You Dirty Dog You")
dog = input("\nWhat is your name, dog? ")
print (f"\nYour Name Is : {dog}\n")
quit = input(": press enter to quit.")
Many Thanks. I did learn about the \n later in my studies . . . the {dog} in a print statement is new to me though.
I’ve gone through all this mostly because I think my Grandson(s) might want to ‘learn to code’. The oldest one seems to be a clown working on a career either in begging or extortion . . . Either way he gets a hard time from me.