I am getting an error when I try to import anything or try to modify numpy statement to import anything other than from numpy import arange like from numpy import *, or add any other import statements.
I also can't make my radius random floats it says r = random.uniform(0,2) AttributeError: 'builtin_function_or_method' object has no attribute 'uniform'.
This is the error I get when I try to modify the import statements:
Traceback (most recent call last):
line 13, in <module>
rate(5)
TypeError: rate() missing 3 required positional arguments: 'pmt', 'pv', and 'fv'
Code:
from visual import *
from math import cos,sin,pi
from numpy import arange
from random import *
s = sphere(pos=[1,0,0],radius=0.1,color = color.red)
s0 = sphere(pos=[0,0,0],radius=0.25,color = color.green)
for i in arange(0,100,0.1):
rate(5)
theta = randint(0,30)
r = randint(-2,2)
x = cos(theta)
y = sin(theta)
s.pos = [x,y,r]
It is generally a bad idea to use from <some_library> import *
in scripts or programs, because that imports everything from <some_library>
into the current namespace. If any of the names in <some_library>
already exist in the current namespace, they will be redefined. It is better to do, for example, either
import numpy as np
and use the prefix np
to access the numpy
namespace (e.g. np.arange
), or explicitly import only exactly what you need in your script. For example, to import randint
from random
,
from random import randint
In your case, both numpy
and visual
define a function called rate
. (See http://vpython.org/contents/docs/rate.html and http://docs.scipy.org/doc/numpy/reference/generated/numpy.rate.html.) Apparently you had done from numpy import *
when you got the error that you reported, so your script was calling numpy.rate
and not visual.rate
.