ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 09 Apr 2018 02:24:28 +0200Import Sage Worksheetshttps://ask.sagemath.org/question/41924/import-sage-worksheets/ Hello, I'm looking to be able to modulate my code in the Sage Math cloud. I've done some research on the topic and it seems that one could use the `attach` syntax to bring in the methods from another worksheet. Unfortunately I get the following error when I try to attach the sagews 'test' which is in the same folder as the worksheet I'm working in.
`File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 3443, in attach
raise IOError('did not find file %r to attach' % fname)
IOError: did not find file 'test' to attach`
Can anyone help me with this issue?
Thanks,
Adam
ajmullinsMon, 09 Apr 2018 02:24:28 +0200https://ask.sagemath.org/question/41924/Import just one function from .sage filehttps://ask.sagemath.org/question/39906/import-just-one-function-from-sage-file/I have a `.sage` file that has a single function I want to import. If it were a `.py` file, I would obviously use `from temp import myfun`, but as far as I know, `.sage` files have to be imported with either `load('temp.sage')` or `attach('temp.sage')` (or preparsed, but this gets tiresome). Is there a way to import just one function from a `.sage` file?jaebondSat, 02 Dec 2017 07:21:59 +0100https://ask.sagemath.org/question/39906/Error on %attach for import __future__https://ask.sagemath.org/question/33946/error-on-attach-for-import-__future__/Hi,
using sagemath version 7.0 and 7.2, I tried to attach a file with %attach file.sage. The first line in the file is
from __future__ import division
which results in
sage: %attach file.sage
File "/home/user/.sage/temp/host/25397/file.sageTVxNnD.py", line 6
from __future__ import division
SyntaxError: from __future__ imports must occur at the beginning of the file
The error message is modified to hide user/host/... info
There is a older question on ask.sagemath /question/9071/future-import-fails-in-loading-external-cython-file/ which is addressing the same problem from 2012 on SageMath version 5.0 but there is no answer. I'm baffled that the error occurs in line 6 since the import statement is in the first line in the attached file.
Any ideas how to fix this?
temp_userTue, 28 Jun 2016 10:52:31 +0200https://ask.sagemath.org/question/33946/How do instantiate a new class properly?https://ask.sagemath.org/question/8013/how-do-instantiate-a-new-class-properly/## Background ##
I have created a new class `FeynmanGraph` that is a subclass of `Graph`. It has some extra methods, and the module in which it lives also has some extra functions. The most important method for my purposes searches for possible colorings of the vertices that satisfy certain combinatorial criteria that have to do with spanning trees. (The details are not important here.)
The code works. I should mention that I'm editing `feynman.sage` in a text editor and attaching it to a sage session in a terminal. Once a I create an instance of the class via
> `G = FeynmanGraph(...)`
everything seems to work.
Now, I created a module in which I would like to define specific graphs, with specific labeling of the vertices and edges, as well as plot positioning information. Shouldn't I be able to import the module `feynman` and make definitions such as the following?
> `from feynman import *`<br>
> `def FatY(): # a particular graph`<br>
> `G = FeynmanGraph(...)`<br>
> `...`<br>
> `return G`
When I do this, the methods for `FeynmanGraph` raise all kinds of errors of the type where they don't recognize various functions, such as `max` or `partitions_set`.
## Question ##
How do I structure the modules and classes so that I can instantiate the class properly?Sammy BlackSat, 19 Mar 2011 03:23:26 +0100https://ask.sagemath.org/question/8013/