ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello guys,
i am here to ask about the very basic hello world prog, after i create a file with .py extension and run it then on windows it opens up directly in command prompt, but wat to do if i wish to do the same in ubuntu, i.e. i want the .py file to run in terminal as a console program, which does not happen as such.
hello guys,
i am here to ask about the very basic hello world prog, after i create a file with .py extension and run it then on windows it opens up directly in command prompt, but wat to do if i wish to do the same in ubuntu, i.e. i want the .py file to run in terminal as a console program, which does not happen as such.
thank you.
I don't understand - you want a program that would open a terminal emulator/console ? How are you going to start the program under Ubuntu ?
I.e. if you are already in a terminal emulator and have entered the needed command line to run your Python progran, why do you need another terminal emulator ?
Or you want to click on something and that something should first invoke a terminal emulator and then run in it your Python program ?
I don't understand - you want a program that would open a terminal emulator/console ? How are you going to start the program under Ubuntu ?
I.e. if you are already in a terminal emulator and have entered the needed command line to run your Python progran, why do you need another terminal emulator ?
Or you want to click on something and that something should first invoke a terminal emulator and then run in it your Python program ?
no sir, i wish to just double click on my .py file and want that to run in the terminal for e.g. consider the following codes,
x = raw_input("Enter your name : ")
print x
raw_input("press <enter>")
here, i want the system to ask the 'ENter your name' in terminal, accept the answer from user in terminal and then wait for the user to press the enter key.
the current problem is : when i double click on the.py file i am asked what to do with it ? i have tried all the options, but none allows it to run on terminal, similar to that in xp.
... i wish to just double click on my .py file and want that to run in the terminal ...
Double clicking means doing so in a certain file manager, so you have to configure that file manager's file type associations to invoke a terminal and run the needed program in it.
Invoking a terminal which would executed the needed command is easy, for example, if you want '/bin/ls' to be executed in an 'xterm', try this:
Code:
xterm -C -e /bin/ls
or, if you want in the case the terminal to stay,
Code:
xterm -C -e '/bin/ls; /bin/sh'
.
So, now your task is to teach your file manager upon click on Python file to invoke
Does your Python file have executable permissions?
I didn't use GNOME for a long time, but AFAIR it asked you if you want to run it, run it in a terminal, or open it in a text editor if it's executable.
Double clicking means doing so in a certain file manager, so you have to configure that file manager's file type associations to invoke a terminal and run the needed program in it.
Invoking a terminal which would executed the needed command is easy, for example, if you want '/bin/ls' to be executed in an 'xterm', try this:
Code:
xterm -C -e /bin/ls
or, if you want in the case the terminal to stay,
Code:
xterm -C -e '/bin/ls; /bin/sh'
.
So, now your task is to teach your file manager upon click on Python file to invoke
Code:
xterm -C -e /path/to/your/file.py
.
thank you for your co-operation sir.
hello, sir, i tried the above with my filemanager and the .py file, but still i can't do it, instead to run the program now in the terminal i use the following command
python filename.py
and the program starts its execution from the next line in the terminal.
sir, i would like you to tell me that is the 'xterm' and the 'terminal' the same or different programs.
I know its a noobs questions, but i am not so experienced in linux so i expect ur co-operation.
and the program starts its execution from the next line in the terminal.
sir, i would like you to tell me that is the 'xterm' and the 'terminal' the same or different programs.
I know its a noobs questions, but i am not so experienced in linux so i expect ur co-operation.
thanking you.
Did you make your Python file executable ? I.e. did you run
chmod +x filename.py
?
What is the very first line in your 'filename.py' file ?
...
'xterm' is a terminal emulator - one of many existing under UNIXish systems. Install it if you don't have it yet. Hard to believe Ubuntu doesn't have.
I don't know how to start Gnome terminal with a command - like in my example with 'xterm'. I don't use Gnome terminal.
I suggested the OP the sure way I know. If/when he succeeds, and if Gnome terminal allows such execution (most likely it does), the OP then will switch to Gnome terminal.
Did you make your Python file executable ? I.e. did you run
chmod +x filename.py
?
What is the very first line in your 'filename.py' file ?
...
'xterm' is a terminal emulator - one of many existing under UNIXish systems. Install it if you don't have it yet. Hard to believe Ubuntu doesn't have.
yes sir, i got the xterm, ubuntu has an xterm in it.
and yes my file has executable permissions.
and it runs only in python shell when i select to display it,but not in xterm or terminal.
the codes of the file are as follows :
first line : x = raw_input("Enter your name : ")
second line : print x
third line : raw_input("press <enter>")
sir,can u please tell me wat is the unless construct, as m still a beginner in programming.
is it a constructor as in c++, if yes then wat does it do ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.