antimony icon indicating copy to clipboard operation
antimony copied to clipboard

possible to send list?

Open zelogik opened this issue 9 years ago • 4 comments
trafficstars

Hi,

I don't know if it's a missing feature or a I have a brainless issue.

Trying to add script like:

list = [0,1,20,99] output('List', list)

To making a kind of iteration array without symmetric step, for exporting to an 2D form, but without luck. Any way to doing it? Thanks, Regards.

zelogik avatar Aug 27 '16 20:08 zelogik

I tested this out without any issues: list

Code for range:

import fab

title('range')
input('n', int)
output('ns', list(range(n)))

Code for double:

import fab

title('double')
input('ns', list)
output('ds', list([n*2 for n in ns]))

Two things to be careful about:

  • Naming a variable list shadows the list type, which may be unwise
  • Python 3 replaces lists with generators in many places, e.g. range – wrap in a list call to force conversions

mkeeter avatar Aug 27 '16 21:08 mkeeter

Hi,

Yes my question was unclear. Of course naming a variable with "list" is stupid, IDE normally color it, and my python is a little rusted ;-)

I don't exactly want to sending a list, but int(float,double) each element one by one, more like:

import fab

title('range')
coordonate = [ 0, 10, 20, 100]
for i in coordonate
   output('ns', i)

But of course I have an: Datum was already defined in this script.

zelogik avatar Aug 28 '16 13:08 zelogik

That's because every Datum (e.g. something defined with input or output) must have a unique name. You could create one output per item in the list with the following:

import fab

title('range')
coordinate = [0, 10, 20, 100]
for i,c in enumerate(coordinate):
   output('ns%i' % i, c)

which will create outputs ns0 = 0, ns1 = 10, ns2 = 20, etc.

mkeeter avatar Aug 28 '16 14:08 mkeeter

So there is no way to make a simple 'array' style things with "random" iteration.

For example to make multiple 2D Circle/rectangle and each with coordinate_x = [0, 10, 20, 100] and coordinate_y = [0, 0, 0, 0]

zelogik avatar Aug 29 '16 08:08 zelogik