python3 运行行报错 AttributeError: module ‘random‘ has no attribute ‘randint‘
2021/9/20 14:07:04
本文主要是介绍python3 运行行报错 AttributeError: module ‘random‘ has no attribute ‘randint‘,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
今天在运行文件 random.py文件时报错了 AttributeError: module ‘random’ has no attribute ‘randint’。
random.py 文件如下:
import random def v_code(): code = "" for i in range(5): num = random.randint(0, 9) char = chr(random.randint(65, 90)) add = random.choice([num, char]) code = code + str(add) return code print(v_code())
报错信息如下:
Traceback (most recent call last): File "E:/Gitee/python_study/Python_script/day15_module_lesson/常见的模块/random.py", line 7, in <module> import random File "E:\Gitee\python_study\Python_script\day15_module_lesson\常见的模块\random.py", line 20, in <module> print(v_code()) File "E:\Gitee\python_study\Python_script\day15_module_lesson\常见的模块\random.py", line 13, in v_code num = random.randint(0, 9) AttributeError: module 'random' has no attribute 'randint' Process finished with exit code 1
解决方法:
原来是因为命名.py文件为random,和系统的有冲突导致的。
更改了脚本的名称,就可以解决了。
这篇关于python3 运行行报错 AttributeError: module ‘random‘ has no attribute ‘randint‘的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器