Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running Brackets code
#1
Photo 
I am new to python, just installed today and have been playing around with brackets and Python. I am confused on how to get my code from brackets to run in python. My code in brackets was saved as print("happy to be here") and I saved it as happy.py. any help is greatly appreciated! Thank you!

Attached Files

Thumbnail(s)
   
Reply
#2
Well, get started right!

First look up: Setting up a Python Virtual Environment. Lots of info out there. Profis will set up a Virtual Environment for each new project, I believe.

snippsat, a moderator and very experienced programmer here recommends a tool called uv for this task.

The uv docs. Read this, then you will know how to set up your Virtual Environment.

I don't know if you use Windows or Linux. In Linux we have a terminal called bash, you can do things from the command line.

To run a Python programme in bash, not in an IDE, you must have the shebang as the first line, like this: #! /usr/bin/python3 Not sure what that looks like in Windows, I almost never use Win.

#! /usr/bin/python3
print("Hello cruel world!")
If I save this as happy.py in my Virtual Environment, I can run it in a bash terminal like this:

(This is what I see in my bash terminal. GPE is my Python Virtual Environment)

Output:
(GPE) peterr@peterr-Modern-15-B7M:~/PVE$ python happy.py Hello cruel world! (GPE) peterr@peterr-Modern-15-B7M:~/PVE$
Once you have your Virtual Environment, you can start it like this in a bash terminal:

Quote:peterr@peterr-Modern-15-B7M:~/PVE$ cd PVE && source GPE/bin/activate && python3 -m idlelib.idle

My Virtual Environment is in a folder called PVE and is called GPE. You need to put your own Virtual Environment path and name in this.

This will start Idle, which is a free IDE that comes with Python. At least for beginners, Idle is OK. The profis here prefer other IDEs I think!

If you run into problems getting set up, ask here, I'm sure people will be glad to help. don't forget to read the docs!
Reply
#3
A couple of things:
1. Don't post images, copy/paste as text and format using proper BBCode tags
2. Learn about different ways to execute python code.
Basically:
Output:
>>>
means you are in Python interactive shell, i.e. execute python code line by line as you enter it.
You cannot execute shell/OS commands. They are executed in cmd/shell (that is when you have something lile C:\>
to exit from python interactive mode use exit()
e.g.
Output:
C:\Users\JohnDoe>python <--here you are in cmd shell and start python in interactive mode Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 12:49:59) [MSC v.1935 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> name = input("what is your name? ") what is your name? John >>> print(f'hello {name}') hello John >>> exit() <--exit from python back to cmd shell C:\Users\JohnDoe>cd C:\Users <-- execute OS command C:\Users>python happy.py <--run your happy.py, assuming it is located in c:\Users folder
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code not running even without errors Azdaghost 2 1,079 Apr-25-2025, 07:35 PM
Last Post: Azdaghost
  python code not running Azdaghost 1 828 Apr-22-2025, 08:44 PM
Last Post: deanhystad
  writing and running code in vscode without saving it akbarza 5 4,894 Mar-03-2025, 08:14 PM
Last Post: Gribouillis
  problem in running a code akbarza 7 3,347 Feb-14-2024, 02:57 PM
Last Post: snippsat
  the order of running code in a decorator function akbarza 2 1,969 Nov-10-2023, 08:09 AM
Last Post: akbarza
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into &lt;/&gt;? Winfried 0 3,341 Sep-03-2022, 11:21 PM
Last Post: Winfried
  Code running many times nad not just one? korenron 4 2,841 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 8,279 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 3,052 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 8,424 Feb-02-2022, 10:21 AM
Last Post: mcva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020