'Indentation and Syntax Errors in File Organizing Script in Python
I've been working on a file organizing script from a tutorial: https://www.youtube.com/watch?v=MRuq3SRXses&t=22s
However, I'm new to python, so much of its nuance is hidden to me.
I have two indentation errors, as well as two syntax errors, however after looking at several questions on here, I still can't seem to fix it. I'm confident I did not mix spaces and tabs, and the person from the tutorial I used seem to use his version of the script perfectly fine.
As for the syntax errors, I do not know what the issue could be.
Here is a copy of my code:
import os
import shutil
origin_dir = r'D:\TTITF\Game Files and Animations\Animations\Bridges\Walk ~ Alvie - V_2 R RAW'
target_dir = r'D:\TTITF\Game Files and Animations\Animations\Bridges\Walk ~ Alvie - V_2 R TRIMMED'
for f in os.listdir(origin_dir):
filename, file_ext = os.path.splitext(f)
try:
if not file_ext:
pass
elif int(filename) in range(0, 60):
shutil.move(
os.path.join(origin_dir, f'{filename}{file_ext}')
os.path.join(target_dir, 'V_O to V_4', f'{filename}{file_ext}'))
except (FileNotFoundError, PermissionError):
pass
Solution 1:[1]
You need to run the python code on IDE such as VS code,Jupyter notebook, Pycharm ( which is mentioned in tutorial that you are watching). Most developer write code in
When you are typing in the terminal you need to type keep and give space keeping in mind the indentation needed for the code
Useful commands to write in terminal
Press enter -> To enter a new line Double press enter -> To execute the code
Solution 2:[2]
In the image on the left, you're typing your code into an interactive shell, which has some limitations. In particular, if you're entering a multiline construct such as a try/except block or an if/else block, you can't use any blank lines, otherwise the interpreter thinks the block is finished.
In the image on the right, you're typing your code at a command prompt, which is just wrong.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Code run |
| Solution 2 | John Gordon |

