#πŸ”’ path being repeated

14 messages Β· Page 1 of 1 (latest)

silver heron
#

I am coding a journal where the user can open and create journals. However, when the user enters their desired path, the program is unable to find the path because the entire path is being added to the start of the filename. How do i fix this?

 # loading an already existing journal (command o)
def open_journal(args):
    global current_profile

    if not args:
        print("ERROR: No file path provided.")
        return

    try:
        # convert input into path object 
        file_path = Path(args[0]).resolve()

        if not file_path.exists() or file_path.suffix.lower() != ".dsu":
            print(f"ERROR: Invalid or missing DSU file at {file_path}.")
            return

        current_profile = Profile()
        try:
            current_profile.load_profile(str(file_path))
            print(f"Loaded journal: {current_profile.username}")
        except Exception as e:
            print(f"ERROR: Could not load journal. {e}")

    except Exception as e:
        print(f"ERROR: Could not process file path. {e}") ```

here is the output: Entering admin mode. Type commands directly.
O C:\Users\user\OneDrive\Desktop\testing1\journal.dsu
ERROR: Invalid or missing DSU file at C:\Users\user\OneDrive\Desktop\testing1\UsersuserOneDriveDesktoptesting1journal.dsu.
atomic shoreBOT
#

@silver heron

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

robust heron
#

What do you see if you do print(repr(args[0]))?

silver heron
#

under this line like this?: ```py
try:
# convert input into path object
file_path = Path(args[0]).resolve()
print(repr(args[0]))

robust heron
#

sure, there will do

silver heron
#

O C:\Users\user\OneDrive\Desktop\testing1\journal.dsu
'C:UsersuserOneDriveDesktopproject2journal.dsu'
ERROR: Invalid or missing DSU file at C:\Users\user\OneDrive\Desktop\testing1\UsersuserOneDriveDesktoptesting1journal.dsu.

#

to be honest, I'm not too sure if this part of the code is the issue, but that's where it's raising errors, but I could be parsing it wrong?

robust heron
silver heron
#

im not familiar with shlex, but I was told that that might be the issue, is there a better way to parse the command, the path, and the filename together?

robust heron
atomic shoreBOT
silver heron
atomic shoreBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.