[Tutor] is it possible to embed data inside a script?

Kirk Bailey idiot1@netzero.net
Sun Jul 20 23:18:03 2003


Sure thing.

domainname="tinylist.org"
password="swordfish"
id="idiot1@netzero.net"

simple enough, but wait, there's more!

array1()='2','3','3','4','4','4','5','5','5','5','6','6','6','6','6','7','7','7','7','7','7',...

(2dice, 6 sides, in a matrix. Use ramdom.choice to pick one of them. Weighted correctly 
for 2s6)

These are simplistic examples, but sure, data is just data. You can assign it to any 
variable type in a declaration whenever you like.

Now, when this means a LOT of data, thing can get boring and real easy to get mixed up 
in the programmer's mind. Ever see a program with several HUNDRED DATA statements, read 
by a READ statement? When you go in to change something, it is EASY to get totally lost, 
espically when it is a program which does not number lines.

Why  is it important to store a lot of data IN the program?

Joseph Paish wrote:

> can a person include the data that a script processes inside the script 
> itself?  
> 
> i am in the process of converting a short perl script that processes 
> everything following __DATA__ instead of processing the contents of a 
> separate (very small) file.
> 
> 
> stripped down perl code follows :
> 
> # -------------
> my @lines = <DATA> ;
> 
> foreach (@lines) {
>     # do stripped out processing of stuff following __DATA__
>     }
> 
> __DATA__
> abc 123
> def 456
> ghi 789
> 
> # --------
> 
> 
> is there some way to achieve the same thing in python?
> 
> thanks
> 
> joe
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Promethieus
  +                              think                                +

Fnord.