|
251 | 251 | }, |
252 | 252 | { |
253 | 253 | "cell_type": "code", |
254 | | - "execution_count": 7, |
| 254 | + "execution_count": 4, |
255 | 255 | "metadata": {}, |
256 | 256 | "outputs": [ |
257 | 257 | { |
258 | 258 | "name": "stdout", |
259 | 259 | "output_type": "stream", |
260 | 260 | "text": [ |
261 | | - "['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'accumulate', 'acos', 'acosh', 'altzone', 'asctime', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'chain', 'comb', 'combinations', 'combinations_with_replacement', 'compress', 'copysign', 'cos', 'cosh', 'count', 'ctime', 'cycle', 'daylight', 'degrees', 'dist', 'dropwhile', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'filterfalse', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'get_clock_info', 'gmtime', 'groupby', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'islice', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'localtime', 'log', 'log10', 'log1p', 'log2', 'mktime', 'modf', 'monotonic', 'monotonic_ns', 'nan', 'perf_counter', 'perf_counter_ns', 'perm', 'permutations', 'pi', 'pow', 'prime', 'prime_gen', 'prime_square', 'process_time', 'process_time_ns', 'prod', 'product', 'radians', 'remainder', 'repeat', 'sin', 'sinh', 'sleep', 'sqrt', 'starmap', 'strftime', 'strptime', 'struct_time', 'takewhile', 'tan', 'tanh', 'tau', 'tee', 'thread_time', 'thread_time_ns', 'time', 'time_ns', 'timezone', 'trunc', 'tzname', 'zip_longest']\n", |
| 261 | + "['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__primeval__', '__spec__', 'accumulate', 'acos', 'acosh', 'altzone', 'asctime', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'chain', 'comb', 'combinations', 'combinations_with_replacement', 'compress', 'copysign', 'cos', 'cosh', 'count', 'ctime', 'cycle', 'daylight', 'degrees', 'dist', 'dropwhile', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'filterfalse', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'get_clock_info', 'gmtime', 'groupby', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'islice', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'localtime', 'log', 'log10', 'log1p', 'log2', 'mktime', 'modf', 'monotonic', 'monotonic_ns', 'nan', 'perf_counter', 'perf_counter_ns', 'perm', 'permutations', 'pi', 'pow', 'prime', 'prime_gen', 'prime_square', 'process_time', 'process_time_ns', 'prod', 'product', 'radians', 'remainder', 'repeat', 'sin', 'sinh', 'sleep', 'sqrt', 'starmap', 'strftime', 'strptime', 'struct_time', 'takewhile', 'tan', 'tanh', 'tau', 'tee', 'thread_time', 'thread_time_ns', 'time', 'time_ns', 'timezone', 'trunc', 'tzname', 'zip_longest']\n", |
| 262 | + "\n", |
| 263 | + "['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']\n", |
262 | 264 | "\n", |
263 | | - "['In', 'Out', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i2', '_i3', '_i4', '_i5', '_i6', '_i7', '_ih', '_ii', '_iii', '_oh', 'exit', 'get_ipython', 'i', 'pg', 'pgf', 'prime_gen', 'quit']\n" |
| 265 | + "['In', 'Out', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i2', '_i3', '_i4', '_ih', '_ii', '_iii', '_oh', 'exit', 'get_ipython', 'prime_generator', 'quit']\n" |
264 | 266 | ] |
265 | 267 | } |
266 | 268 | ], |
267 | 269 | "source": [ |
268 | | - "import prime_gen\n", |
| 270 | + "import prime_generator\n", |
269 | 271 | "\n", |
270 | | - "print(dir(prime_gen))\n", |
| 272 | + "print(dir(prime_generator))\n", |
| 273 | + "print()\n", |
| 274 | + "print(dir(prime_generator.prime_gen))\n", |
271 | 275 | "print()\n", |
272 | 276 | "print(dir())" |
273 | 277 | ] |
|
276 | 280 | "cell_type": "markdown", |
277 | 281 | "metadata": {}, |
278 | 282 | "source": [ |
279 | | - "## namespace:\n" |
| 283 | + "## namespace:\n", |
| 284 | + "\n", |
| 285 | + "A container that has a list of names (objects) defined in a module. It is the place where python searches for objects defined and used in a function." |
| 286 | + ] |
| 287 | + }, |
| 288 | + { |
| 289 | + "cell_type": "markdown", |
| 290 | + "metadata": {}, |
| 291 | + "source": [ |
| 292 | + "## Global, Local and Built-in Namespaces\n", |
| 293 | + "\n", |
| 294 | + "### Global:\n", |
| 295 | + "Namespace containing values defined throughout a file or module (globally)\n", |
| 296 | + "\n", |
| 297 | + "### Local:\n", |
| 298 | + "Namespace containing values defined in a part of a file or module (Locally)\n", |
| 299 | + "\n", |
| 300 | + "### Builtin:\n", |
| 301 | + "Namespace containing values common for all python file.\n", |
| 302 | + "\n", |
| 303 | + "## Order of Search:\n", |
| 304 | + "1. Local\n", |
| 305 | + "2. Global\n", |
| 306 | + "3. Builtin" |
280 | 307 | ] |
281 | 308 | }, |
282 | 309 | { |
283 | 310 | "cell_type": "markdown", |
284 | 311 | "metadata": {}, |
285 | 312 | "source": [ |
286 | | - "## Global, Local and Built-in Namespaces" |
| 313 | + "## Packages:\n", |
| 314 | + "Directory or folder containing a number of modules and subpackages.\n", |
| 315 | + "\n", |
| 316 | + "It contains '\\_\\_init\\_\\_.py' file which defines the modules that can be imported from the package.\n", |
| 317 | + "\n", |
| 318 | + "### Importing a module from package:\n", |
| 319 | + "`from package_name import module_name` \n", |
| 320 | + "`import package_name.module_name` \n", |
| 321 | + "`import package_name.module_name as custom_name`\n", |
| 322 | + "\n", |
| 323 | + "### Import a specific object from a module:\n", |
| 324 | + "`from package_name.module_name import object_name`" |
287 | 325 | ] |
288 | 326 | }, |
289 | 327 | { |
|
0 commit comments