I was using
nltk to parse english on Python 3.4 with PyCharm. When I ran my file, I received the following error:
Error processing line 1 of /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zope.interface-4.1.3-py3.4-nspkg.pth: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 167, in addpackage exec(line) File "<string>", line 1, in <module> AttributeError: 'module' object has no attribute 'ModuleType' Remainder of file ignored Traceback (most recent call last): File "/Users/james/naturallang/grammar.py", line 3, in <module> import nltk.book File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/__init__.py", line 89, in <module> from nltk.internals import config_java File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/nltk/internals.py", line 11, in <module> import subprocess File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 424, in <module> _PopenSelector = selectors.SelectSelector AttributeError: 'module' object has no attribute 'SelectSelector'
After a little tinkering, I found that running an empty file gave me the following error:
Error processing line 1 of /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/zope.interface-4.1.3-py3.4-nspkg.pth: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site.py", line 167, in addpackage exec(line) File "<string>", line 1, in <module> AttributeError: 'module' object has no attribute 'ModuleType' Remainder of file ignored
A Python script can find out about the type, class, attributes and methods of an object. This is referred to as reflection or introspection. See also Metaclasses. ,Another great feature of Python is its availability for all platforms. Python can run on Microsoft Windows, Macintosh and all Linux distributions with ease. This makes the programs very portable, as any program written for one platform can easily be used on another. ,Microsoft Windows users can use MinGW to compile the extension module from the command line. Assuming gcc is in the path, you can build the extension as follows: ,It is possible to call the method on an arbitrary object, by using it as an attribute of the defining class instead of an instance of that class, like so:
>>> print("Hello World!") Hello World!
python - V
pacman - S python
pacman - S python2
if 1: print("True") print("Done")
if 1: print("True") print("Done")
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL), help? What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum About Us , featuresstuff Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys CodeProject Stuff ,If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
module 'random' has no attribute 'choice'
module 'random' has no attribute 'sample'
import random t = [1, 2, 3, 4, 5] choose = random.choice(t) print(choose)
from random import choice
A Python ‘module’ refers to a single .py file that contains function definitions and variable-assignment statements. Importing a module will execute these statements, rendering the resulting objects available via the imported module.,As with a module, importing this package will execute the contents of __init__.py and make available sum_func and divide_func as attributes of the resulting module object:,Note that the module is still being executed in full, however instead of producing the module-instance my_module, this imort statement instead only returns the specified objects that were defined in the module.,A module is simply a text file named with a .py suffix, whose contents consist of Python code. A module can be imported into an interactive console environment (e.g. a Jupyter notebook) or into another module. Importing a module executes that module’s code and produces a module-type object instance. Any variables that were assigned during the import are bound as attributes to that object.
# accessing `defaultdict` from the standard library 's `collections` package from collections import defaultdict # import the entire numpy package, giving it the alias 'np' import numpy as np
% load_ext autoreload % autoreload 2
"" " Our first Python module.This initial string is a module - level documentation string. It is not a necessary component of the module.It is a useful way to describe the purpose of your module. "" " print("I am being executed!") some_list = ["a", 1, None] def square(x): return x ** 2 def cube(x): return x ** 3
# importing my_module in our interactive session >>> import my_module I am being executed! # produced is a object that is an instance of the module-type >>> my_module <module 'my_module' from 'usr/my_dir/my_module.py'> >>> type(my_module) module
# all of the variables assigned in the module are made # available as attributes of the module object >>> my_module.some_list ['a', 1, None] >>> my_module.square <function my_module.square(x)> >>> my_module.square(2) 4 >>> my_module.cube(2) 8
>>> help(my_module) Help on module my_module: NAME my_module DESCRIPTION Our first Python module.This initial string is a module - level documentation string. It is not a necessary component of the module. FUNCTIONS cube(x) square(x) DATA some_list = ['a', 1, None] FILE c: \users\ ryan soklaski\ desktop\ learning_python\ python\ module5_oddsandends\ my_module.py