On Thu, Sep 15, 2011 at 6:23 PM, Rajeev Singh <[email protected]> wrote:
> On Thu, Sep 15, 2011 at 4:56 PM, Andrew Francis <[email protected]> wrote:
>> Hi all,
>>
>> I'm new to this group; thanks for having me.
>>
>> I have generated a large number of text files (several lots of 81
>> files) with the intention of reading them back into another sage
>> program (via the command line).  The text filenames were generated by
>> the line
>>
>>    outputfilename="Dropbox/simdata_g1%sk%sc%seps%s.sage"%
>> (g1int,kint,gridc,grideps)
>>
>> so that the file names have a number of variables, and a typical file
>> is of form simdata_g18k1c2eps3.sage.  No problem this far.
>>
>> The files are of a form that should be sage-readable, for instance one
>> line is
>> Lpeak = 0.00101546953017314
>>
>> I now want to use these files to generate some further output, reading
>> them into a loop as follows:
>>
>> def grid_plot(grid,gamma,kappa):
>>    for gridc in [0..8]:
>>        for grideps in [0..8]:
>>            load 'Dropbox/SAGE-outputs-5genes/gamma5kappa3/
>> simdata_g15k3c%seps%s.sage'%(cstr,epsstr)
>>            blah blah
>>
>> I am hoping to extract and use values such as that of Lpeak above.
>>
>> However while I am able to load a file for particular values of the
>> parameters *outside* the def statement (using exactly the same load
>> statement), I have been unable to make sage run through my files and
>> extract the values inside them.  The error I get is:
>>
>> ValueError: argument (="'Dropbox/SAGE-outputs-5genes/gamma5kappa3/
>> simdata_g15k3c%seps%s.sage'%(cstr,epsstr)") to load or attach must
>> have extension py, pyx, sage, spyx, or m
>>
>> Clearly the file does have a correct extension (.sage), as the same
>> command works fine outside the def statement.  So is there a problem
>> loading files generically inside a function definition?  Is there some
>> other way around this?
>>
>> Thanks,
>> Andrew
>>
>> --
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to 
>> [email protected]
>> For more options, visit this group at 
>> http://groups.google.com/group/sage-support
>> URL: http://www.sagemath.org
>>
>
> Hi,
>
> The following works -
>
>>>> from sage.all import load, Integer
>>>> import os
>>>> for i in range(10):
> ...  os.system('echo a = %d > %d.sage' %(i,i))  # generating files
> 0.sage, 1.sage, etc
> ...
>
>>>> for i in range(10):
> ...  load('%d.sage' %i)
> ...  print a
>
> This gives the expected output. By the way I don't see your filename
> changing inside the loop.
>
> Rajeev
>

Missed one point earlier. Even the following works as expected (which
was your question I guess) -

>>> def f():
...  for i in range(10):
...   load('%d.sage' %i)
...   print a
...
>>> f()

Rajeev

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to