Python Beginner Tutorial #9 - File Operations
Вставка
- Опубліковано 21 лип 2024
- In today's episode we will learn how to operate with files. How to write into files, how to read from files and much more.
Python Documentation: docs.python.org/3/tutorial/in...
Website: www.neuralnine.com/
Instagram: / neuralnine
Twitter: / neuralnine
GitHub: github.com/NeuralNine
Programming Books: www.neuralnine.com/books/
Outro Music From: www.bensound.com/
Subscribe and Like for more free content! - Наука та технологія
For those with issues, the .txt file must be in the same directory as your Python code/project. In other words, inside your Python project directory unless you specifically state in your code where the file is (I will give an example of it).
Neuralnine has his project (files.py) on his desktop. The "f" is just a variable name. You can use any name you want. It ends in the colon ":" because it is a statement, just like using conditional statements; they end in the colon ":"
# Inside the Python project:
with open('file.txt', 'r') as c:
content = c.read()
print(content)
# Outside the Python project/different directory:
with open("/path/to/directory/myfile.txt", 'r') as variableName:
content = variableName.read()
print(content)
dont get confused though, the "c" or "f" after 'as' is just a name, you can call it whatever you want, it doesnt have to be f or c, you can do: with open("file.txt", "r") as ThisIsAnAwesomeFile: (just make sure that the capitals match when you read the file, because it is case sensitive)
STILL DIDNT WORJK AAHHAHAHAHAH
@@imalex4543 Thank you for the accuracy, I have updated the comment.
I love your videos! They are short and concise. Kudos!
great job. my concept for open and with open is cleared now. thank you
Great content! Love your teaching style.
This video helped me understand everything I didn’t understand from school. Wish me luck on the certificate
Thanks for all your great videos.
Amazing content, greetings from brazil!
Thank you for this useful info😊
Great video helped alot🔥
You can gradually see the number of views decreasing each video. WEAKLINGS...
How many tutorial parts do you reckon someone will need to make so that the last part has 1 view? Should be a constant decrement based on the amount of views on the first chapter. On my desk by Monday.
@@patjustpat8178 Humans are irrational, it is impossible to calculate the decrease rate.
Can you copy files that way to?
Coming out of current directory?
Thanks a lot
It makes no sense that these have so little views. I would have thought that a lot of people started to code at home during the pandemic.
hey why do i have FileNotFoundError: [Errno 2] No such file or directory: 'file.txt' at 4:40 and it always says i can find any file i want to work on.
make sure the file is in the same directory as your python project. python will not find the file if it isn't.
great job sir
Thank you very much! :)
excellent explanation but the screen is very small cant see clearly, better to zoom in a little bit
Thanks
Hi bro! You are great, thanks fol all videos and for the content) I had one problem with the file operations(Error: could not find a file), could you help plz?
make sure your file is in the same directory as your python project as python can't find the file if it isn't
@@M8rix not this problem, I knew that, but the problem is still with me
alternative for IDLE?
you can use other IDEs like Pycharm, VS Code...etc. I myself use vs code because it supports other languages as well. But if only just started lerning python then IDLE is advised and afterwords you can use othes IDEs.
Hey, wanted to get in touch with you and discuss something about your channel. Can we connect on any social media platform?
I'm available at Instagram
Hi my friend!
Please Use bigger fonts when U capturing a video from your screen.
I could watch U with more passion :D
Have a nice day!
your thing is super blurry
very small, difficult to see