On Tue, Nov 29, 2011 at 3:40 PM, Mayo Adams <mayoad...@gmail.com> wrote:

>  I cant immediately see how anything in a script is
> anything other than a representation of some kind, hence the
> distinction between representamen and object does no work for me.
>

That's exactly it - when you have something like this in a file named, say
data.txt:

("This", 'is', 'a', 'silly', 'tuple')

Then that's all it is - just text data. I happens to *look* like a tuple,
but it's not. If you rename that file to data.py... well, it's still text
data. If you add an assignment operation to the line:

data = ("This", 'is', 'a', 'silly', 'tuple')

Then you could actually import it with `from data import data`. Once the
data is actually evaluated, then it's "live" - it really is a tuple, and it
can be used in tuple-ish ways.

I think the main reason to make a distinction like that is that if you
encounter a .py file with data like this:

> "__import__('os').system('echo i got you now rm-rf')"

You know it's probably going to do some bad things to your system if you
run it. If you open that in a text editor, on the other hand, it's unlikely
to do anything painful.

I think there's also some use in making the distinction between data and
code. Python provides you with /ridiculously/ easy ways to read in data. So
if you have a bunch of strings that you want in a tuple you should do
something like:

data = tuple(f.open('data.txt').readlines())

Which has the added advantage of *just* reading in strings. If you want to
convert that data into other types (integer, float, etc.) then you can
easily do it explicitly, and explicit is better than implicit.

In reality of course, all the data is just 1's and 0's floating out there,
but I think it's helpful to develop these abstractions.
HTH,
Wayne
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to