#πŸ”’ Sudden AttributeError when troubleshooting code, the code suddenly broke without me touching it.

15 messages Β· Page 1 of 1 (latest)

copper stump
#

Hi all, was working on some code, making a function work, when suddenly my line 7 (which I have not touched for several days now)

path = os.path.dirItem(os.path.abspath(__file__))

Has risen this error

AttributeError: module 'ntpath' has no attribute 'dirItem'

And I have no idea why this error has suddenly arisen, and I have no idea where to begin fixing it, does anyone have any ideas?

high sealBOT
#

@copper stump

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.

wind flame
#

!d os.listdir

high sealBOT
#

os.listdir(path='.')```
Return a list containing the names of the entries in the directory given by *path*. The list is in arbitrary order, and does not include the special entries `'.'` and `'..'` even if they are present in the directory. If a file is removed from or added to the directory during the call of this function, whether a name for that file be included is unspecified.

*path* may be a [path-like object](https://docs.python.org/3/glossary.html#term-path-like-object). If *path* is of type `bytes` (directly or indirectly through the [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) interface), the filenames returned will also be of type `bytes`; in all other circumstances, they will be of type `str`.

This function can also support [specifying a file descriptor](https://docs.python.org/3/library/os.html#path-fd); the file descriptor must refer to a directory.

Raises an [auditing event](https://docs.python.org/3/library/sys.html#auditing) `os.listdir` with argument `path`.
wind flame
#

What do you expect dirItem to do?

copper stump
#

I'm expecting to get the path to the python file being run

wind flame
#

That's __file__

copper stump
#

right, so that list of code wasnt even necessary in the end lmfao, oops!

wind flame
#

I'm pretty sure __file__ is already absolute btw

copper stump
#

absolute?

wind flame
#

abspath

#

!e print(file)

high sealBOT
high sealBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.