Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resolve a "NameError: name 'null' is not defined" error while trying to import any module in Python 2.7

I installed python today and used pip install successfully to get some modules. But I am unable to import any .py modules.

I created mod.py (it has a simple print command) in the same directory as the code I am trying to run. I uninstalled and reinstalled anaconda as well. But the error persists. Anyone with any ideas on how to fix this? Thanks!

import mod

NameErrorTraceback (most recent call last)
<ipython-input-1-18de99490651> in <module>()
----> 1 import mod

C:\Users\Mayank\mod.py in <module>()
      3   {
      4    "cell_type": "code",
----> 5    "execution_count": null,
      6    "metadata": {},
      7    "outputs": [],

NameError: name 'null' is not defined

This is a sample of what the .py code looks like in the editor (same problem):

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fib(n):    # write Fibonacci series up to n\n",
    "    a, b = 0, 1\n",
    "    while b < n:\n",
    "        print b,\n",
    "        a, b = b, a+b\n",
    "\n",
    "def fib2(n):   # return Fibonacci series up to n\n",
    "    result = []\n",
    "    a, b = 0, 1\n",
    "    while b < n:\n",
    "        result.append(b)\n",
    "        a, b = b, a+b\n",
    "    return result"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
like image 748
Mayank Seksaria Avatar asked Mar 29 '19 23:03

Mayank Seksaria


1 Answers

null isn't a reserved word like it is in JavaScript. None is used.

like image 184
Nathan Hamm Avatar answered Sep 19 '22 22:09

Nathan Hamm