Steve Baer
04-07-2010, 10:39 PM
From Henry Segerman on our Ning site-
I was working on a project involving a mathematical object called the Hopf fibration, which lives in 4D, but you can look at projections of it into 3D. So I found a library to do the things I needed to do to calculate in 4D, and tried to import it into my script to run in Rhino, but it didn't like it. So I tried using the pickle library to precalculate my data in another script which can use the library, then unpickle in rhino python... but there's no support for pickle either!
So I ended up copying and pasting lists of numbers into the rhino python script, and that worked. I guess support for general libraries is coming? Or did I need to do something to tell it the paths to follow to find the libraries?
Hi Henry,
I realize that I "should" know a lot more about the pickle module, but it is just one of those modules I've never spent any time using. It appears that the python engine in Rhino ships with cPickle built-in which is an optimized version of pickle. This works for me on the Mac
import cPickle
def pickletest():
# save a list to a textfile using cPickle
items = ["one", "two", 3, "abc", 3.14]
filename = "/Users/Steve/pickletest.txt"
file = open( filename, 'w' )
cPickle.dump( items, file )
file.close()
# read the list out of the file
file = open( filename, 'r' )
readitems = cPickle.load(file)
file.close()
print "original = ", items
print "read = ", readitems
if( __name__ == '__main__' ):
pickletest()
I was working on a project involving a mathematical object called the Hopf fibration, which lives in 4D, but you can look at projections of it into 3D. So I found a library to do the things I needed to do to calculate in 4D, and tried to import it into my script to run in Rhino, but it didn't like it. So I tried using the pickle library to precalculate my data in another script which can use the library, then unpickle in rhino python... but there's no support for pickle either!
So I ended up copying and pasting lists of numbers into the rhino python script, and that worked. I guess support for general libraries is coming? Or did I need to do something to tell it the paths to follow to find the libraries?
Hi Henry,
I realize that I "should" know a lot more about the pickle module, but it is just one of those modules I've never spent any time using. It appears that the python engine in Rhino ships with cPickle built-in which is an optimized version of pickle. This works for me on the Mac
import cPickle
def pickletest():
# save a list to a textfile using cPickle
items = ["one", "two", 3, "abc", 3.14]
filename = "/Users/Steve/pickletest.txt"
file = open( filename, 'w' )
cPickle.dump( items, file )
file.close()
# read the list out of the file
file = open( filename, 'r' )
readitems = cPickle.load(file)
file.close()
print "original = ", items
print "read = ", readitems
if( __name__ == '__main__' ):
pickletest()