Python_input txt file by the cmd - python

I had this error when I trying to use example from CS50 introduction in AI course
I use win 10 in my end , they using MAC its worked in their end but didn't work in my end
what is the issue or what I need to do to run this txt file with my code using the windows terminal

You are running maze.py from "C:>"
Open file explorer.
Navigate to your Desktop
In the top type cmd
Pess Enter
In cmd run
maze.py maze3.txt

Make sure the maze3.txt file is in you Desktop, from where you're running the script. From the error, it seems like that file is not there.

Related

Using VSCode with WSL, run button does not run with mnt. Hence, my code is not found to run

I am using WSL ubuntu on a windows computer while using VSCode as my code editor.
I'm trying to run python files on WSL but when pressing on the run button (https://i.stack.imgur.com/J5DfM.png) (ctrl + alt + n) the code gets executed with the default windows explorer pathway (c:\users...) so that makes my file not readable for WSL to run.
Here is a screenshot on what it seems like:
Screenshot of the shell
As you can see, when I press on the run button it comes with the error:
python: can't open file 'c:\Users\name\Desktop\firstone\newfolder\base.py': [Errno 2] No such file or directory
Because it is coming in the format of c:\Users...
Meanwhile when I run a command that I typed on my own of the correct format:
python -u /mnt/c/Users/name/Desktop/firstone/newfolder/base.py
It works correctly.
Do you know how I can automatically map the run button to run for a wsl environment?
I would really appreciate your help, thank you.
I have found the answer for anyone what is wondering later.
Follow the instructions on this article.
https://learn.microsoft.com/en-us/windows/python/web-frameworks
The most important part is to initiate the "Run Python File in Terminal" first before pressing the run button.

Trying to run Python program from command prompt

Path must be messed up and I can't fix it.
In the command prompt I am trying to open and run a python program that I made in IDLE. I am running Python 3.8.5. According to Automate the Boring Stuff, I should just be able to do:
py birthdays.py
But when I do that I get:
C:\Users\name\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'birtdays.py': [Errno 2] No such file or directory
All of my scripts are located in: C:\Users\henri\AppData\Local\Programs\Python\Python38-32.
The only thing that I could think of is that it is going one step too far and searching in python.exe instead of just Python38-32. But Ii'm not even sure it works like that.
I tried to add the exact path using:
set PATH=%PATH%;C:\Users\name\AppData\Local\Programs\Python\Python38-32
But when I do this and press enter nothing happens.
when I want to use CMD to run python scripts, I just use
cd\
to back the main root of drive C. then use
cd folderAddress
for several time until to reach the exact scrip containing folder. Finally, I type
python scriptName.py
In your command prompt type python.The output should be python 3.** (depending on your python version).
If you see the python version it's working fine. In command prompt navigate to the folder that you have your python file using cmd command. then type
python birtdays.py
Don't forget the space after python.

How to make Windows execute my Python script files when I click them

I have made a Python program that uses output.to_csv('results.csv'). When I run it in Spyder it creates that CSV file. But when I double click on it nothing happens. Cmd appears and closes but nothing on the folder, no results.csv.
What am I missing? What more do I have to do?
Run the program from the command line itself instead of double-clicking the .py file.
I assume you are on Windows since you mention CMD. First, cd into the directory containing your program. Then, run python <program>.py or python3 <program>.py depending on your installation.
This time, you will see any output or error messages that appear in CMD without it immediately closing.
If the .csv file really exists, you should be able to go to your File Explorer and find the file at the top of the "Quick Access" section. Right-click the file and hover over "Open With >". Then select Notepad and a notepad will open up showing your results.
If you do not see the file, then try running your program on the command prompt (for Windows):
Press the windows key and type "cmd" in the search bar.
Choose "Command Prompt"
Go to the dir of your program using the cd command
Type python <program name>.py
If there are no errors, follow the steps in the first paragraph.
Ok i guess windows is not recommended at all for this type of tasks. I mean running something simple as create such file is like trying to kill the Lernaean Hydra.
What i did is i just runned it with anaconda prompt and it worked sweet! Thanks for help. Thanks to all!
PS: I'm seriously considering changing to Linux after this
For anyone having the same problem, but have anaconda installed. 1) Open Anaconda Prompt, 2) use cd (1 space) then adress of the folder which contains your py program (eg. cd C:\Users\Bernie\Desktop\tasos) and hit enter, 3) on the next line that appears type: python program_name.py, 4)Hit enter, 5)success!

python 2.7: run from cmd vs directly from python

I wrote the next program:
with open('h.txt','a') as f:
f.write('asd')
when i run it from the cmd (e.g typed C:\Users\USER\PycharmProjects\2016_project\test.py in the cmd)
- no new file was created
but when I double clicked the icon in the windows explorer (I'm with windows (10)) a new text file was created
can someone explain to me what's happening??
and how to bypass this problem?
(p.s. I'm most of the time in school so it may take me a little time to responce)
thanks
Choose the folder and use Python to run. Use like:
cd C:\Users\USER\PycharmProjects\2016_project
python test.py

Launching a file from within Atom, when that file type is already associated in the OS

I generally code in Python, under Windows 7. Just double clicking a .py file in any file manager launches that file in the command prompt, due to the .py file association with c:\Python27\python.exe
So my question is: Can I somehow launch the current file that I'm working on in Atom in the Windows's command prompt?
Without alt-tabing to the file manager and clicking the file I mean.
I tried quite a lot of packages, most recommended being script. But all packages that I've tried execute the file in the Atom's console, which currently does not support stdin(can't input data through commands like raw_input()). And that is really what I require the most at the moment.
Is there an easy workaround? I've been at it for a few hours and can't seem to be able to find a solution, literally anywhere.
Well...eventually found an answer myself. If anyone needs this feature under windows, just install run-in-terminal. In the plug-in's settings go to line Terminal with arguments box and enter start /D {working_directory} D:\Python27\python.exe {file_path}. And simply press F5 to run the code from the main editor's window. PERFECT!!!!
PS. Might want to change D: to C: depending where your python file is.
Good Luck!!
<3 Atom

Categories