Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

mileaga

  • 2 years ago

Please forgive me if this is too basic...I'm running Python in Linux. It's already installed and I open it through a terminal and not a separate IDLE. I've written my first program, but I don't know how to test it. I don't know how to get Python to look for it in the right place. Does that make sense?

  • This Question is Open
  1. s3a
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Does cd /the/dir/it/is/in and then python3 filename.py work?

  2. Alchemista
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah, as s3a said you can run it with "python filename.py"

  3. s3a
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Also, on Debian, I'm pretty sure "python" uses whatever is default but if you use the "python2" or "python3" command, you get to explicitly choose which version you use.

  4. slotema
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    If I assume you've got a textfile with your python program, you can run it from the python console by calling `execfile( "program.py" )` (or e.g. `execfile( "../test/program.py" )` ). You can also simply call `python program.py` from your terminal. Another way, which is the way I usuallt prefer, is by putting a line in front of your script that tells the terminal how to execute it. You can then simply run your program from the terminal (e.g. ./program.py) if you make it executable. The line will be something like `#!/usr/bin/python` (and it should be the first line in your file). This will also work for perl/ruby/bash scripts.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.