Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem creating an archive
#1
Hi everyone, first of all, sorry if my english is quite poor.

I'm new into programming and python, and today, I found my first newbie problem that I can't solve, even after I googled it a lot.


I'm trying to create a text file that doesn´t exist in the working directory, with this:

file = open('file.txt', 'w')
Or with this one:

file = open('file.txt', 'w+')
In every case I get the same error:
FileNotFoundError: [Errno 2] No such file or directory: 'file.txt'


I understood that, if I use that code, the program will open the file, and if it doesn't exists, it will create it.
I've tried a lot of things, like reinstalling VS Code, Python, checked the paths, checked the directory permissions, but nothing works, and I can't find the solution.

Thank you in advance!
Reply
#2
Is that the only line in your program, or is there more?

Can you try creating a program with just that one single line and reproduce it? What OS are you running this on? Windows?
Reply
#3
You should post your full code. Is the directory valid? Try using an absolute link? Is this a .py file or a py2exe file?
Reply
#4
(May-10-2020, 01:16 AM)mwd1993 Wrote: You should post your full code. Is the directory valid? Try using an absolute link? Is this a .py file or a py2exe file?

I'm using VS Code on Windows.
The proyect is in .py
I've created a folder named "Proyects" in my documents.
I'm working inside that folder, and when I check the current directory, it is the same one.

The tutorial I am watching, use this:

def app():

    file = open('file.txt', 'w')

app()
After that, the guy explains that "file.txt" was created because it didn't exists, and it is now on the activity bar together with the .py files. I tried some things about absolute path I read in other forums, but I really don't know if that's the problem, or how to do it correctly
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting specific file from an archive tester_V 4 501 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Installing Pillow from remote archive in Linux Flatpak ChrisOfBristol 6 1,450 Sep-23-2022, 07:48 PM
Last Post: ChrisOfBristol
  Creating a TG crypto Bot_ problem when trying to with bot.polling p1ner0 1 1,427 Apr-27-2022, 03:43 AM
Last Post: p1ner0
  Find specific file in an archive tester_V 8 3,454 Feb-13-2021, 06:13 PM
Last Post: tester_V
  Problem in creating a vector termo 11 3,900 Oct-10-2019, 03:09 PM
Last Post: stullis
  Invalid archive error when attempting to install dash bootstrap components meaydemi 0 4,772 Jul-11-2019, 05:49 PM
Last Post: meaydemi
  Create file archive that contains crypto hash ED209 1 2,048 May-29-2019, 03:05 AM
Last Post: heiner55
  Archive (.7z, .zip, .rar, .tar, etc) Password Extractor btforensics 1 5,709 Jul-08-2018, 08:29 PM
Last Post: Larz60+
  Problem while creating an Excel File using python Math_Enthusiast 3 3,172 Dec-09-2017, 08:49 PM
Last Post: buran

Forum Jump:

User Panel Messages

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