Django.fun

Python - Invalid Syntax - Why is this error being thrown?

I already know that this is going to be a trashy question, as per the SO question guidelines, but I have to keep details down to a minimum. I have a traceback, but I don't know why its throwing an error.

Traceback:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "...USER...\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "...USER...\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "...USER...\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "...USER...\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "...USER...\site-packages\django\core\management\base.py", line 419, in check
    all_issues = checks.run_checks(
  File "...USER...\site-packages\django\core\checks\registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "...USER...\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "...USER...\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "...USER...\site-packages\django\urls\resolvers.py", line 412, in check
    for pattern in self.url_patterns:
  File "...USER...\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "...USER...\site-packages\django\urls\resolvers.py", line 598, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "...USER...\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "...USER...\site-packages\django\urls\resolvers.py", line 591, in urlconf_module
    return import_module(self.urlconf_name)
  File "...USER...\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "...USER...\urls.py", line 20, in <module>
    path('django_app/', include('django_app.urls')),
  File "...USER...\site-packages\django\urls\conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "...USER...\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "...USER...\urls.py", line 2, in <module>
    from . import views
  File "...USER...\views.py", line 185
    if t > 0:
            ^
SyntaxError: invalid syntax

The "syntax error" is being thrown inside of a class that I made inside of my views.py file...

A general, crude idea of the code is:

import os
import sys
import numpy
some other imports

class constructor():
 __init()__:
   some stuff
 def func():
   some logic

        (t, b, l, r) = self.removed_space
        (w, h, th) = self.dimensions
        if l > 0 or r > 0:
            ppi_w = 0
        if t > 0 or b > 0:
            ppi_h = 0

        if t > 0:
            t = round(t * ppi_h)
            if len(array) > 2:
                t_a = 0
            else:
                t_a = 0
            ar = 0
            m = 0
        if b > 0:
            b = 0
            if len(array.shape) > 2:
                b_a = 0
            else:
                b_a = 0
            ar = 0
            m = 0

I know a true answer for this likely isn't a reasonable request, but I am desperate and just asking for general ideas as to why this error might actually be occuring. I am using notepad++, so spacing is consistent. I know the syntax for the if statement is right... and apart from that, its got me beat.

Answers: 1

Answered by John Gordon, Sept. 17, 2021, 3:15 a.m.
if t > 0:

There's nothing wrong with that line. Check the previous line of code for imbalanced parentheses.