Question:
How do I Run a File from Gedit Using Command Prompt through Python?
Emmett
2012-12-08 12:49:56 UTC
I am currently reading "Learn Python the Hard Way" as a means to learn the programming language python. However, once I reached exercise 1 and followed the instructions, the outcome was not satisfactory.
The exercise asks for me to create a text document using the text editor "Gedit." It tells me then, to name the file "ex1.py" From there it tells me to run the file using the terminal (command prompt) by simply typing in "python ex1.py"
Nothing happens but an error. So I tried something else I type in "start ex1.py" and python pops up for like five seconds before closing out again. I feel like I'm on the right track, however my spirits are starting to get down. Please help me!
I use Windows 7 (which I understand is not the best for learning python, but I am determined to do so)
Four answers:
t
2012-12-08 13:45:40 UTC
Try running Python using its full path (C:\Python27\python.exe or wherever you installed it), and post the full error message.



Edit #1:



The prompt "C:\Users\Name>" belongs to the Windows command prompt. That's where you can type commands and run programs (like python.exe). The prompt ">>>" belongs to the Python interpreter. That's where you can type Python. To exit the Python interpreter and go back to the command prompt use Control-Z or type "quit()" followed by Enter.



The first command ("C:\Python27\python.exe") executed perfectly - the Python interpreter started, printed some information, and displayed its prompt (">>>"). This is a very good sign. The second command ("python ex1.py") was given to the Python interpreter, not the command prompt, which is why you got an error message.



Please try running "python ex1.py" again, this time at the command prompt (it should look like "C:\Users\Name>python ex1.py").

- If you get a message like "'python' is not recognized as an internal or external command, operable program or batch file" you need to add C:\Python27 to the path variable (see http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx ).

- If you get a message like "python: can't open file 'ex1.py': [Errno 2] No such file or directory", you are not in the same folder as ex1.py and need to navigate to that folder using the cd command.

- If you get a longish message with the filename, a line number, and a line of your code, there is a bug in 'ex1.py' but everything else is working.

- If it's not one of those, post the message.



Edit #2:



There is a problem with the code in ex1.py. Please post its contents.



Edit #3:



You are missing the word print at the start of each line in ex1.py.

The author's gedit / powershell comment doesn't make sense to me either (could be a broken telephone -- exact wording would help). Use PowerShell or the command prompt to start python ("python ex1.py") and use Gedit, Notepad or Notepad++ to type your Python code.
bandemer
2016-10-19 14:00:50 UTC
Gedit Python
kenton
2016-10-14 02:27:13 UTC
ning a Java application from Command instantaneous Create a non everlasting folder C:mywork. utilising Notepad or yet another textual content editor, create a small Java document HelloWorld.java with proper right here textual content: public classification HelloWorld { public static void important(String[] args) { gadget.out.println("hi, international!"); } } keep your document as HelloWorld.java in C:mywork. to be particular your document call is HeloWorld.java, (not HelloWorld.java.txt), first opt for "keep as document form:" All archives, then form interior the document call HelloWorld.java. Run Command instantaneous (got here upon lower than All classes/upload-ons interior the starting up menu). form C:> cd mywork This makes C:mywork the present listing. C:mywork> dir This reflects the listing contents. you need to work out HelloWorld.java between the archives. C:mywork> set course=%course%;C:application FilesJavajdk1.5.0_09bin This tells the gadget the position to discover JDK classes. C:mywork> javac HelloWorld.java This runs javac.exe, the compiler. you need to work out not some thing in spite of the indisputable fact that the subsequent gadget instantaneous... C:mywork> dir javac has created the HelloWorld.classification document. you need to work out HelloWorld.java and HelloWorld.classification between the archives. C:mywork> java HelloWorld This runs the Java interpreter. you need to work out this methodology output: hi, international! If the gadget can not discover javac, examine the set course command. If javac runs yet you get mistakes, examine your Java textual content. If this methodology compiles yet you get an exception, examine the spelling and capitalization interior the document call and the classification call and the java HelloWorld command. Java is case-comfortable! it truly is a probability to make the path putting everlasting yet you need to be very careful because your gadget might want to crash if you're making a mistake. proceed with extreme caution! In abode windows XP, pass to regulate Panel, opt for "gadget," click on the "progressed" tab, click on the "surroundings variables" button. interior the decrease record, "gadget variables," click on course: click "Edit" and on the suitable append ;C:application FilesJavajdk1.5.0_09bin (or the path to the acceptable folder the position the present version of JDK is put in). do not positioned areas earlier the appended course string. click ok on the path edit container and ok on the Ennvironment Variables container. the recent putting will pass into result next time you run Command instantaneous. -------------- attempt this java -jar .jar --------------
anonymous
2012-12-08 12:50:24 UTC
too hard


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...