From: Tony R. <To...@br...> - 2009-10-22 02:13:00
|
Why not just "import visual2"? Isn't the * somewhat discouraged? I would rather have to important math/numpy stuff myself if I need them, and let the visual.* namespace be nothing but sphere/display/etc. That's how ive seen other modules internally and seems to be the norm to only explicitly import what you need. Is that not feasible for visual? Maybe the module needs to be one version for non programmers with a huge first level namespace, and another module more properly structured for integrators. On Oct 21, 2009, at 8:48 PM, "Bruce Sherwood" <Bru...@nc...> wrote: > Here's an idea about how to unpollute in a way that wouldn't break > existing > programs. Suppose one said "from visual2 import *" to get just the > visual objects? > > Bruce Sherwood > > Guy K. Kloss wrote: >> Hi Symion, >> >> On Wed, 21 Oct 2009 20:53:30 Symion wrote: >>> I have been using Visual.random number generators and have found >>> that the >>> following Methods return as numpy arrays, which when Printed or >>> Evaluated >>> returns a list that is not separated by the usual commas. >>> >>> from visual import * >> >> Yes, this is one of the issues that I've been mentioning on the >> list before, >> caused by the snowball imports that Visual is conducting under the >> bonnet in >> the code (from math import *; from numpy import *). >> >> Therefore the namespace is quite "polluted" with modules that are >> not from >> Visual, but that also may behave in some way unexpected, as they >> come from >> different packages. >> >> In the case of random this originates from NumPy, and therefore >> returns >> NumPy's ndarray structures. >> >>> print visual.random.sample(5) # floating point list with no commas >>> print visual.random.permutation(5) # Integer list with no commas >>> print visual.random.randint(1,46,5) # Integer list with no commas >>> >>> visual.safe_eval(str(visual.random.randint(1,46,5))) # generates >>> error >>> >>> No commas between elements?! >> >> The ndarray objects are *not* lists or tuples. But they do >> implement the >> methods of the iterable interface so they behave in many ways like >> lists. As >> for your observation, their __str__() method is implemented to >> print out >> arrays separated by blanks, and not to use commas as separators, as >> well as >> other rounding style, and some truncation style on very extensive >> arrays. >> >>> A work around is to add .tolist() >> >> Or to call the list constructor: list(a_numpy_array) >> >>> visual.random.sample(5).tolist() # returns normal list of floats >>> visual.random.permutation(6).tolist() >>> visual.random.randint(1,46,5).tolist() >>> visual.safe_eval(str(visual.random.randint(1,46,5).tolist())) >> >> Be very careful what's imported, and what you're using. It might be >> not what >> you expect. That's also why an "from visual import *" can be quite >> dangerous >> for your own code, as their name spaces are *very* full and may >> mask stuff >> you're doing yourself. >> >> Guy >> > > --- > --- > --- > --------------------------------------------------------------------- > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart > your > developing skills, take BlackBerry mobile applications to market and > stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > > Tony Risinger Application Development Specialist Tel: 507-535-7563 | Fax: 507-292-5747 | Toll Free: 866-241-0639 To...@Br... http://www.brokerbin.com/ CONFIDENTIAL INFORMATION: This electronic mail message and any attached files contain information intended for the exclusive use of the specific individual(s) or entity(s) to whom it is addressed and may contain information that is propriety, privileged or confidential or otherwise exempt from disclosure. If you are not the intended recipient, please notify the sender immediately, by reply electronic mail or by telephone, of any unintended recipients so we may correct our records. Also, delete the original electronic mail and any attachments without making any copies of the electronic mail message or attachments. |