From: Eric D. <mon...@ma...> - 2011-05-24 19:28:35
|
Hello, I recently installed the VPython v.3.1 and corresponding Python versions for mac (OSX). I've been troubleshooting an old script of mine when I noticed some odd behavior. When I run my script, a line tries to import random. Oddly the shell reports that its using a file from numpy rather than from ~/python3.1/random.py. If I try to import random manually in the shell it grabs the correct module from ~/python3.1/random.py. A. Python Shell >>> import random >>> print (random.__file__) /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/random.py B. Script File >>> print (random.__file__) /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/numpy/random/__init__.py Does anyone know how to fix this? Also does anyone know what is going on? Please reply with complete instructions, as I am very very very new to all of this. Thank you all in advance! |
From: Eric D. <mon...@ma...> - 2011-05-27 19:40:42
|
The problem was with the next line of code. I should have used 'import visual.graph' rather than 'from visual.graph import *' Can anyone explain what the difference between the two calls is? Also why does visual.graph have visual.graph.random? The Problem _______________________________ import random from visual.graph import * #bad idea # imports random from numpy directory # visual.graph. does have a .random _______________________________ Solution: import visual.graph |
From: Bruce S. <Bru...@nc...> - 2011-05-27 20:35:09
|
No, import visual.graph isn't what you should use. It sounds like what you want is probably import vis.graph, or possibly import vis.graph as graph, so that you can refer to a graphing object such as gcurve as graph.gcurve. I've again appended below the information on the first page of the VPython documentation. When you import visual.graph, you're importing a package that executes from visual import *, as the documentation below points out. That in turn brings in a random function, so visual.graph.random exists. You'll probably also need to do things such as the following, depending on your needs: from vis import color # for vis.color.cyan; or import vis and refer to vis.color from numpy import arange # or import numpy and refer to numpy.arange from math import cos, exp # or import math and refer to math.cos and math.exp If you're just trying to solve the problem of making sure you get the random that you really want, you could just import that particular function first, with its own name: from wherever import random as MyRandom As to the difference between 'import visual.graph' and 'from visual.graph import *', in the first case you refer to gdots as visual.graph.gdots, whereas in the latter case you refer to gdots simply as gdots. Bruce Sherwood ------------------------------------- As a convenience to novice programmers to provide everything that is needed to get started, the statement "from visual import *" imports all of the Visual features and executes "from math import *" and "from numpy import *". It also arranges that for routines common to both math and numpy such as sqrt, the much faster math routine is used when possible (when the argument is a scalar rather than an array). If you want to import the visual objects selectively, import them from the vis module. Two simple examples: import vis vis.box(color=vis.color.orange,material=vis.materials.wood) from vis import (box, color, materials) box(color=color.orange, material=materials.wood) There are clean modules vis.controls, vis.filedialog, and vis.graph equivalent to the modules visual.controls, visual.filedialog, and visual.graph. The latter versions execute "from visual import *" and are retained because some programs expect that behavior when importing one of these modules. The documentation is written assuming that "from visual import *" is used. On Fri, May 27, 2011 at 1:40 PM, Eric Dick <mon...@ma...> wrote: > The problem was with the next line of code. I should have used > 'import visual.graph' rather than 'from visual.graph import *' > Can anyone explain what the difference between the two calls is? Also why > does visual.graph have visual.graph.random? > The Problem > _______________________________ > import random > from visual.graph import * #bad idea > # imports random from numpy directory > # visual.graph. does have a .random > _______________________________ > Solution: > import visual.graph |
From: Bruce S. <Bru...@nc...> - 2011-05-25 02:04:33
|
For someone "very very very new" to this, you ask your question very knowledgeably. From the first page of the VPython documentation: As a convenience to novice programmers to provide everything that is needed to get started, the statement "from visual import *" imports all of the Visual features and executes "from math import *" and "from numpy import *". It also arranges that for routines common to both math and numpy such as sqrt, the much faster math routine is used when possible (when the argument is a scalar rather than an array). If you want to import the visual objects selectively, import them from the vis module. Two simple examples: import vis vis.box(color=vis.color.orange,material=vis.materials.wood) from vis import (box, color, materials) box(color=color.orange, material=materials.wood) There are clean modules vis.controls, vis.filedialog, and vis.graph equivalent to the modules visual.controls, visual.filedialog, and visual.graph. The latter versions execute "from visual import *" and are retained because some programs expect that behavior when importing one of these modules. The documentation is written assuming that "from visual import *" is used. Bruce Sherwood On Tue, May 24, 2011 at 1:28 PM, Eric Dick <mon...@ma...> wrote: > Hello, > I recently installed the VPython v.3.1 and corresponding Python versions for > mac (OSX). I've been troubleshooting an old script of mine when I noticed > some odd behavior. > When I run my script, a line tries to import random. Oddly the shell > reports that its using a file from numpy rather than from > ~/python3.1/random.py. If I try to import random manually in the shell it > grabs the correct module from ~/python3.1/random.py. > A. Python Shell >>>> import random >>>> print (random.__file__) > /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/random.py > B. Script File >>>> print (random.__file__) > /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/numpy/random/__init__.py > Does anyone know how to fix this? Also does anyone know what is going on? > Please reply with complete instructions, as I am very very very new to all > of this. > Thank you all in advance! > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, > you get blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1 > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > > |