[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

how to include text data in source code?

hyena

2/1/2008 2:29:00 PM

as the subject, I 'd like to know how to include a piece of text as input in
the source code so that I do not need to read in data from files. I remember
there is some thing like this in Perl, have no idea if python has the same
thing?

Thanks.



3 Answers

Matt McCredie

2/1/2008 3:16:00 PM

0

On Feb 1, 9:28 am, "Sun" <a...@hut.at> wrote:
> as the subject, I 'd like to know how to include a piece of text as input in
> the source code so that I do not need to read in data from files. I remember
> there is some thing like this in Perl, have no idea if python has the same
> thing?
>
> Thanks.

You can just add a big string to your file. Triple quotes will help
with that. Of course, if you are going to be entering the data into
your python file, why don't you enter it using the most appropriate
data structure. Were intending to also append to the data in the file?
I'm sure you could figure something out to do that, but there is no
inherent feature that does that automatically.

Matt

Paddy

2/1/2008 3:20:00 PM

0

On Feb 1, 2:28 pm, "Sun" <a...@hut.at> wrote:
> as the subject, I 'd like to know how to include a piece of text as input in
> the source code so that I do not need to read in data from files. I remember
> there is some thing like this in Perl, have no idea if python has the same
> thing?
>
> Thanks.

Heres a pointer to the use of the stringio module used to make text
look like a file:
http://en.wikipedia.org/wiki/Doctest#Example_3:_uniqu...

- Paddy.

hyena

2/1/2008 5:15:00 PM

0


"Matimus" <mccredie@gmail.com> wrote in message
news:7d8c32eb-244d-41b0-89e0-9dbf2c0514e6@i12g2000prf.googlegroups.com...
> On Feb 1, 9:28 am, "Sun" <a...@hut.at> wrote:
>> as the subject, I 'd like to know how to include a piece of text as input
>> in
>> the source code so that I do not need to read in data from files. I
>> remember
>> there is some thing like this in Perl, have no idea if python has the
>> same
>> thing?
>>
>> Thanks.
>
> You can just add a big string to your file. Triple quotes will help
> with that. Of course, if you are going to be entering the data into
> your python file, why don't you enter it using the most appropriate
> data structure. Were intending to also append to the data in the file?
> I'm sure you could figure something out to do that, but there is no
> inherent feature that does that automatically.
>
> Matt
Thanks you all for the answers.

The reason is that I am using pydot to deal with graphiz dot format data,
which in my case is a very simple graph, just few lines. So i was trying to
just embed this data within the code. One functiuon will read in the data
and parse it as in "dot language" format.