how to include text data in source code?

Discussion in 'Python' started by Sun, Feb 1, 2008.

  1. Sun

    Sun Guest

    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.
    Sun, Feb 1, 2008
    #1
    1. Advertising

  2. Sun

    Matimus Guest

    On Feb 1, 9:28 am, "Sun" <> 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
    Matimus, Feb 1, 2008
    #2
    1. Advertising

  3. Sun

    Paddy Guest

    On Feb 1, 2:28 pm, "Sun" <> 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:_unique_words.py

    - Paddy.
    Paddy, Feb 1, 2008
    #3
  4. Sun

    Sun Guest

    "Matimus" <> wrote in message
    news:...
    > On Feb 1, 9:28 am, "Sun" <> 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.
    Sun, Feb 1, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cloud Burst
    Replies:
    11
    Views:
    1,011
  2. Author Tarun Tyagi
    Replies:
    0
    Views:
    692
    Author Tarun Tyagi
    Dec 29, 2004
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    880
    Andreas Bogenberger
    Feb 22, 2008
  4. Malcolm Greene
    Replies:
    1
    Views:
    421
    Martin v. Loewis
    Apr 16, 2010
  5. Replies:
    0
    Views:
    585
Loading...

Share This Page