gpt4 book ai didi

python - AttributeError: 'module' 对象没有属性 'lowercase'

转载 作者:太空狗 更新时间:2023-10-29 23:59:21 27 4
gpt4 key购买 nike

我想我在导入 pylab 时遇到了问题。导入 numpy 时会出现类似的错误。这是我的代码

from math import radians, sin, cos
from pylab import plot, xlabel, ylabel, title, show

v0=input("Enter v0 (m/s)...")
alpha0=input("enter alpha0 (degrees)...")
g=input("Enter g (m/s^2)..")

radalpha0=radians(alpha0)
t_inc=0.01
t=0
i=0
x=[]
y=[]

x.append(v0*cos(radalpha0)*t)
y.append(v0*sin(radalpha0)*t-0.5*g*t*t)

while y[i]>=0:
i=i+1
t=t+t_inc
x.append(v0*cos(radalpha0)*t)
y.append(v0*sin(radalpha0)*t-0.5*g*t*t)

xlabel('x')
ylabel('x')
plot(x,y)
title('Motion in two dimensions')
show()

我得到了这个输出

Traceback (most recent call last):
File "2d_motion.py", line 2, in <module>
from pylab import plot, xlabel, ylabel, title, show
File "/usr/lib64/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/usr/lib64/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in <module>
from pyparsing import Literal, ZeroOrMore, \
File "/usr/lib/python2.7/site-packages/pyparsing.py", line 109, in <module>
alphas = string.lowercase + string.uppercase
AttributeError: 'module' object has no attribute 'lowercase'

语法有问题吗?

我在 fedora18 上使用 python2.7。

最佳答案

2020 年附录:注意 string.lowercase 仅适用于 Python 2。

在 Python 3 中,使用 string.ascii_lowercase 而不是 string.lowercase

Python 3.6.8 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
>>> import string
>>> string.lowercase
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'string' has no attribute 'lowercase'
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'

关于python - AttributeError: 'module' 对象没有属性 'lowercase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20552481/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com