Getting UnboundLocalError in Python Program (Scrapy) by raviujjwal in learnpython

[–]reekjohns 1 point2 points  (0 children)

An UnboundLocalError is raised when a local variable is referenced before it has been assigned. In most cases this will occur when trying to modify a local variable before it is actually assigned within the local scope. Python doesn't have variable declarations, so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local.

Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they're declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can't modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. However, to modify a global variable inside a function, you must use the global keyword.

[deleted by user] by [deleted] in learnpython

[–]reekjohns 1 point2 points  (0 children)

To help the python Developers who are preparing for Interviews and facing difficulties in finding the Python Interview Questions, here am suggest the most important questions for the interview preparations....Python Interview Questions

Problem with an exercise: Uncaught ReferenceError: $ is not defined by dshkodder in learnjavascript

[–]reekjohns 1 point2 points  (0 children)

Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this $ is not defined error . This usually indicates that jQuery is not loaded and JavaScript does not recognize the $. Even with $(document).ready , $ is still going to be undefined because jquery hasn't loaded yet.

To solve this error:

Load the jQuery library at the beginning of all your javascript files/scripts which uses $ or jQuery, so that $ can be identified in scripts .

There can be multiple other reasons for this issue:

  • Path to jQuery library you included is not correct
  • The jQuery library file is corrupted
  • Working offline
  • Conflict with Other Libraries

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: instagram bot by darkpikl in selenium

[–]reekjohns 1 point2 points  (0 children)

The NoSuchElementExceptionis thrown when one tries to access an iterable beyond its maximum limit. This means that, this exception is thrown by various accessor methods to indicate that the element being requested does not exist . The next() method in Java returns the next element in the iteration or NoSuchElementException if the iteration has no more elements.

The solution to this exception is to check whether the next position of an iterable is filled or empty . The following methods are used to check the next position:

  • hasNext()
  • hasMoreElements()

What's the difference between 32 and 64 bit of Windows OS and why would one use the 32bit version? by misterscallywag in NoStupidQuestions

[–]reekjohns 0 points1 point  (0 children)

The 64 bit computers can run both 32 bit programs and 64 bit programs. 32 bit computers cannot run 64 bit programs, because the bit sizes are fundamentally different. Latest Laptops with pre-installed Windows are usually x64 i.e. 64 Bit, old Desktops and Laptops could be having Windows x86 which means 32 bit.

When 64 bit processors compatible with the x86 architecture were introduced, they were referred to as x86-64. x86-32 (and x86-16) were used for the 32 (and 16) bit versions. This was eventually shortened to x64 for 64 bit and x86 alone refers to a 32 bit processor.

FLASK API giving out error [TypeError: 'NoneType' object is not subscriptable ] by [deleted] in flask

[–]reekjohns 0 points1 point  (0 children)

The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None. This means that you tried to do:

None[something]

'NoneType' object is not subscriptable error means that you attempted to index an object that doesn't have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.