SkyeBoniwell :
I have this python 3 script that scans a folder for a certain file type, then gets the filename with extension and without extension.
For some reason, it is not printing out the filename without the extension.
Here is the script:
for file in os.listdir("."):
if file.endswith(".rew"):
astroFileName = file
astroFileTitle = print(os.path.splitext(file)[0])
print(astroFileName)
print(astroFileTitle)
data = dict(
Astro_Name=file,
Astro_Title=astroFileTitle,
commands = """\
max_copy cp {Astro_Name} {Astro_Title}
reginto_f /r /w {Astro_Title}
"""
for command in commands.splitlines():
command = command.format(**data)
print(command)
So for example, if the file name is 'modern_star_chart.rew', it prints out:
modern_star_chart.rew
modern_star_chart
modern_star_chart.rew None
None
As you can see, it will print out astroFileTitle once, but not the second time, it just prints None.
What could be causing this?
Thanks!
Shubham Sharma :
The print
function doesn't returns any value that is it returns None
.
Replace:
astroFileTitle = print(os.path.splitext(file)[0])
With:
astroFileTitle = os.path.splitext(file)[0]
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=368510&siteId=1