当您将其作为 .py 运行时,它不会加载 random 的特定模块。但如果我在 python shell 中加载它,就没有问题。
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import random
print(random.randint(0,9))
我运行它...并且:
Traceback (most recent call last):
File "random.py", line 4, in <module>
import random
File "C:\Users\root\Pythin\random.py", line 5, in <module>
print(random.randint(0,9))
AttributeError: module 'random' has no attribute 'randint'
在 python shell 中我没有问题:
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> print(random.randint(0,9))
1
我正在 Windows PowerShell (Windows10|64 位) 中运行它。使用命令python random.py
。有人帮我一把吗?非常感谢。