G
G
gylah-u2021-06-19 00:53:22
Python
gylah-u, 2021-06-19 00:53:22

Why are files with ._ beginning output, and how to remove their output?

Hello experts,
I have the following code:

#!/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
import os
def files(path):
    for file in os.listdir(path):
        if os.path.isfile(os.path.join(path, file)):
            yield file
            
for file in files("."):  
    print(file)

when I run it I get:
file.py
main.py
sorter.py
._sorter.py

why are ._sorter.py output and how to remove such output?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gylah-u, 2021-06-19
@gylah-u

Helped:

#!/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
import os
def files(path):
    for file in os.listdir(path):
        if os.path.isfile(os.path.join(path, file)):
            yield file
            
for file in files("."):
  if '._' in file:
    pass
  else:
    print(file)

S
Saboteur, 2021-06-19
@saboteur_kiev

So maybe there is such a file, so it is displayed?
most likely this is a temporary file that your editor / IDE creates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question