LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to execute the python script using the cmd line in linux...? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-execute-the-python-script-using-the-cmd-line-in-linux-908542/)

archanadubbaka 10-17-2011 04:19 AM

How to execute the python script using the cmd line in linux...?
 
Hi LQ Members,

I am completely new to python and executing the scripts using the cmd line is creating a prob to me. Could please any 1 help me out.

I write the code and save it as prog1.py using gedit of ubuntu.

Now i try to execute it as:
$ chmod +x prog1.py
$python prog1.py

but all the time it throws me a syntax invalid error.

Please help me regarding this.

Thanks & Regards,
Archana

grail 10-17-2011 04:41 AM

Showing us the actual error would be of help.

archanadubbaka 10-17-2011 06:06 AM

Hi Grail,

The following is the error it displays when I try to execute the code:-

# /usr/bin/python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> chmod +x apple.py
File "<stdin>", line 1
chmod +x apple.py
^
SyntaxError: invalid syntax

Please help me sort this problem.

Thanks & Regards,
Archana.

TobiSGD 10-17-2011 06:09 AM

YOu have to launch those commands in Bash, not the Python interpreter. Try them again, without launching Python before.

archanadubbaka 10-17-2011 06:28 AM

Thanks for your guidance and solution TobiSGD!

Regards,
Archana

grail 10-17-2011 07:09 AM

Remember to mark as SOLVED once you have a solution.


All times are GMT -5. The time now is 03:29 AM.