code indentation

Discussion in 'Python' started by ...:::JA:::..., Jul 23, 2007.

  1. Hello,

    In my previously post I have been talk about running code with exec in......
    So now I have problem with code indentation, as Gabriel Genellina says:

    >If you are using the tokenize module as suggested some time ago, try to
    >analyze the token sequence you get using { } (or perhaps begin/end pairs
    >in your own language, that are easier to distinguish from a dictionary
    >display) and the sequence you get from the "real" python code. Then write
    >a script to transform one into another:


    >from tokenize import generate_tokens
    > from token import tok_name
    >from cStringIO import StringIO


    >def analyze(source):
    > g = generate_tokens(StringIO(source).readline)
    > for toknum, tokval, _, _, _ in g:
    > print tok_name[toknum], repr(tokval)


    >I think you basically will have to ignore INDENT, DEDENT, and replace
    >NAME+"begin" with INDENT, NAME+"end" with DEDENT.


    So......how can I do this?????????????
    I will appreciate any help!!!!!

    Regards,
    Vedran
    __________________________________________________________________ Vedran
    veki ICQ#: 264412055 Current ICQ status: + More ways to contact me Get ICQ!
    __________________________________________________________________
     
    ...:::JA:::..., Jul 23, 2007
    #1
    1. Advertising

  2. En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
    <> escribió:

    >> If you are using the tokenize module as suggested some time ago, try to
    >> analyze the token sequence you get using { } (or perhaps begin/end pairs
    >> in your own language, that are easier to distinguish from a dictionary
    >> display) and the sequence you get from the "real" python code. Then
    >> write
    >> a script to transform one into another:

    >
    >> from tokenize import generate_tokens
    >> from token import tok_name
    > >from cStringIO import StringIO

    >
    >> def analyze(source):
    > > g = generate_tokens(StringIO(source).readline)
    > > for toknum, tokval, _, _, _ in g:
    > > print tok_name[toknum], repr(tokval)

    >
    >> I think you basically will have to ignore INDENT, DEDENT, and replace
    >> NAME+"begin" with INDENT, NAME+"end" with DEDENT.

    >
    > So......how can I do this?????????????
    > I will appreciate any help!!!!!


    Try with a simple example. Let's say you want to convert this:

    for x in range(10):
    begin
    print x
    end

    into this:

    for x in range(10):
    print x

    Using the analyze() function above, the former block (pseudo-python) gives
    this sequence of tokens:

    NAME 'for'
    NAME 'x'
    NAME 'in'
    NAME 'range'
    OP '('
    NUMBER '10'
    OP ')'
    OP ':'
    NEWLINE '\n'
    NAME 'begin'
    NEWLINE '\n'
    NAME 'print'
    NAME 'x'
    NEWLINE '\n'
    NAME 'end'
    ENDMARKER ''

    The latter block ("real" python) gives this sequence:

    NAME 'for'
    NAME 'x'
    NAME 'in'
    NAME 'range'
    OP '('
    NUMBER '10'
    OP ')'
    OP ':'
    NEWLINE '\n'
    INDENT ' '
    NAME 'print'
    NAME 'x'
    DEDENT ''
    ENDMARKER ''

    If you feed this token sequence into untokenize, in response you get a
    source code equivalent to the "real" python example above. So, to convert
    your "pseudo" python into the "real" python, it's enough to convert the
    first token sequence into the second - and from that, you can reconstruct
    the "real" python code. Converting from one sequence into the other is a
    programming exercise and has nothing to do with the details of the
    tokenize module, nor is very Python-specific - looking at both sequences
    you should figure out how to convert one into the other. (Hint: a few
    additional newlines are not important)

    It is even simpler than the example given in the tokenize documentation:
    <http://docs.python.org/lib/module-tokenize.html> - which transforms
    3.1416 into Decimal("3.1416") by example.

    Once you get this simple case working, you may try what happens with this:

    for x in range(10):
    begin
    print x
    end

    and this:

    for x in range(10): begin
    print x
    end

    and later this:

    for x in range(10):
    begin
    print x
    end

    You are now using explicit begin/end pairs to group statements, so
    indentation is no more significant. You may want to preprocess the
    pseudo-python source, stripping any leading blanks, before using tokenize
    - else you'll get indentation errors (which are bogus in your
    pseudo-python dialect).

    Since this will be your own Python dialect, don't expect that someone else
    will do the work for you - you'll have to do it yourself. But it's not too
    dificult if you do the things in small steps. In case you get stuck at any
    stage and have specific questions feel free to ask.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jul 24, 2007
    #2
    1. Advertising

  3. ...:::JA:::...

    Guest

    On 24 srp, 05:20, "Gabriel Genellina" <> wrote:
    > En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
    > <> escribió:
    >
    >
    >
    > >> If you are using the tokenize module as suggested some time ago, try to
    > >> analyze the token sequence you get using { } (or perhaps begin/end pairs
    > >> in your own language, that are easier to distinguish from a dictionary
    > >> display) and the sequence you get from the "real" python code. Then
    > >> write
    > >> a script to transform one into another:

    >
    > >> from tokenize import generate_tokens
    > >> from token import tok_name
    > > >from cStringIO import StringIO

    >
    > >> def analyze(source):
    > > > g = generate_tokens(StringIO(source).readline)
    > > > for toknum, tokval, _, _, _ in g:
    > > > print tok_name[toknum], repr(tokval)

    >
    > >> I think you basically will have to ignore INDENT, DEDENT, and replace
    > >> NAME+"begin" with INDENT, NAME+"end" with DEDENT.

    >
    > > So......how can I do this?????????????
    > > I will appreciate any help!!!!!

    >
    > Try with a simple example. Let's say you want to convert this:
    >
    > for x in range(10):
    > begin
    > print x
    > end
    >
    > into this:
    >
    > for x in range(10):
    > print x
    >
    > Using the analyze() function above, the former block (pseudo-python) gives
    > this sequence of tokens:
    >
    > NAME 'for'
    > NAME 'x'
    > NAME 'in'
    > NAME 'range'
    > OP '('
    > NUMBER '10'
    > OP ')'
    > OP ':'
    > NEWLINE '\n'
    > NAME 'begin'
    > NEWLINE '\n'
    > NAME 'print'
    > NAME 'x'
    > NEWLINE '\n'
    > NAME 'end'
    > ENDMARKER ''
    >
    > The latter block ("real" python) gives this sequence:
    >
    > NAME 'for'
    > NAME 'x'
    > NAME 'in'
    > NAME 'range'
    > OP '('
    > NUMBER '10'
    > OP ')'
    > OP ':'
    > NEWLINE '\n'
    > INDENT ' '
    > NAME 'print'
    > NAME 'x'
    > DEDENT ''
    > ENDMARKER ''
    >
    > If you feed this token sequence into untokenize, in response you get a
    > source code equivalent to the "real" python example above. So, to convert
    > your "pseudo" python into the "real" python, it's enough to convert the
    > first token sequence into the second - and from that, you can reconstruct
    > the "real" python code. Converting from one sequence into the other is a
    > programming exercise and has nothing to do with the details of the
    > tokenize module, nor is very Python-specific - looking at both sequences
    > you should figure out how to convert one into the other. (Hint: a few
    > additional newlines are not important)
    >
    > It is even simpler than the example given in the tokenize documentation:
    > <http://docs.python.org/lib/module-tokenize.html> - which transforms
    > 3.1416 into Decimal("3.1416") by example.
    >
    > Once you get this simple case working, you may try what happens with this:
    >
    > for x in range(10):
    > begin
    > print x
    > end
    >
    > and this:
    >
    > for x in range(10): begin
    > print x
    > end
    >
    > and later this:
    >
    > for x in range(10):
    > begin
    > print x
    > end
    >
    > You are now using explicit begin/end pairs to group statements, so
    > indentation is no more significant. You may want to preprocess the
    > pseudo-python source, stripping any leading blanks, before using tokenize
    > - else you'll get indentation errors (which are bogus in your
    > pseudo-python dialect).
    >
    > Since this will be your own Python dialect, don't expect that someone else
    > will do the work for you - you'll have to do it yourself. But it's not too
    > dificult if you do the things in small steps. In case you get stuck at any
    > stage and have specific questions feel free to ask.
    >
    > --
    > Gabriel Genellina


    Hello,

    Sorry, now I become very nuisance and stupid but please I really need
    this.Do you remember my topic "python changing keywords name" ,and do
    you remember example that you give me for translate keywords? Can you
    give me some example script of this? Please!!!

    PS: THANKS FOR YOUR TIME!!!!!!!!!!

    Regards,

    Vedran
     
    , Jul 24, 2007
    #3
  4. ...:::JA:::...

    Steve Holden Guest

    wrote:
    > On 24 srp, 05:20, "Gabriel Genellina" <> wrote:
    >> En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
    >> <> escribió:
    >>
    >>
    >>
    >>>> If you are using the tokenize module as suggested some time ago, try to
    >>>> analyze the token sequence you get using { } (or perhaps begin/end pairs
    >>>> in your own language, that are easier to distinguish from a dictionary
    >>>> display) and the sequence you get from the "real" python code. Then
    >>>> write
    >>>> a script to transform one into another:
    >>>> from tokenize import generate_tokens
    >>>> from token import tok_name
    >>> >from cStringIO import StringIO
    >>>> def analyze(source):
    >>> > g = generate_tokens(StringIO(source).readline)
    >>> > for toknum, tokval, _, _, _ in g:
    >>> > print tok_name[toknum], repr(tokval)
    >>>> I think you basically will have to ignore INDENT, DEDENT, and replace
    >>>> NAME+"begin" with INDENT, NAME+"end" with DEDENT.
    >>> So......how can I do this?????????????
    >>> I will appreciate any help!!!!!

    >> Try with a simple example. Let's say you want to convert this:
    >>
    >> for x in range(10):
    >> begin
    >> print x
    >> end
    >>
    >> into this:
    >>
    >> for x in range(10):
    >> print x
    >>
    >> Using the analyze() function above, the former block (pseudo-python) gives
    >> this sequence of tokens:
    >>
    >> NAME 'for'
    >> NAME 'x'
    >> NAME 'in'
    >> NAME 'range'
    >> OP '('
    >> NUMBER '10'
    >> OP ')'
    >> OP ':'
    >> NEWLINE '\n'
    >> NAME 'begin'
    >> NEWLINE '\n'
    >> NAME 'print'
    >> NAME 'x'
    >> NEWLINE '\n'
    >> NAME 'end'
    >> ENDMARKER ''
    >>
    >> The latter block ("real" python) gives this sequence:
    >>
    >> NAME 'for'
    >> NAME 'x'
    >> NAME 'in'
    >> NAME 'range'
    >> OP '('
    >> NUMBER '10'
    >> OP ')'
    >> OP ':'
    >> NEWLINE '\n'
    >> INDENT ' '
    >> NAME 'print'
    >> NAME 'x'
    >> DEDENT ''
    >> ENDMARKER ''
    >>
    >> If you feed this token sequence into untokenize, in response you get a
    >> source code equivalent to the "real" python example above. So, to convert
    >> your "pseudo" python into the "real" python, it's enough to convert the
    >> first token sequence into the second - and from that, you can reconstruct
    >> the "real" python code. Converting from one sequence into the other is a
    >> programming exercise and has nothing to do with the details of the
    >> tokenize module, nor is very Python-specific - looking at both sequences
    >> you should figure out how to convert one into the other. (Hint: a few
    >> additional newlines are not important)
    >>
    >> It is even simpler than the example given in the tokenize documentation:
    >> <http://docs.python.org/lib/module-tokenize.html> - which transforms
    >> 3.1416 into Decimal("3.1416") by example.
    >>
    >> Once you get this simple case working, you may try what happens with this:
    >>
    >> for x in range(10):
    >> begin
    >> print x
    >> end
    >>
    >> and this:
    >>
    >> for x in range(10): begin
    >> print x
    >> end
    >>
    >> and later this:
    >>
    >> for x in range(10):
    >> begin
    >> print x
    >> end
    >>
    >> You are now using explicit begin/end pairs to group statements, so
    >> indentation is no more significant. You may want to preprocess the
    >> pseudo-python source, stripping any leading blanks, before using tokenize
    >> - else you'll get indentation errors (which are bogus in your
    >> pseudo-python dialect).
    >>
    >> Since this will be your own Python dialect, don't expect that someone else
    >> will do the work for you - you'll have to do it yourself. But it's not too
    >> dificult if you do the things in small steps. In case you get stuck at any
    >> stage and have specific questions feel free to ask.
    >>
    >> --
    >> Gabriel Genellina

    >
    > Hello,
    >
    > Sorry, now I become very nuisance and stupid but please I really need
    > this.Do you remember my topic "python changing keywords name" ,and do
    > you remember example that you give me for translate keywords? Can you
    > give me some example script of this? Please!!!
    >
    > PS: THANKS FOR YOUR TIME!!!!!!!!!!


    I think you may have to accept that the task you have undertaken is, for
    the moment, beyond your capabilities.

    It's unfortunate that you are having difficulty with two languages
    simultaneously: your command of English, though impressive, appears to
    be insufficient for you to explain the problem in enough detail for
    someone else to solve it for you (even if someone should feel so
    generous). Your command of Python is not enough to solve it for yourself.

    Perhaps you should re-think your approach and consider that it may take
    you longer than you anticipated.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Jul 24, 2007
    #4
  5. ...:::JA:::...

    Ben Finney Guest

    Steve Holden <> writes:

    > wrote:
    > > On 24 srp, 05:20, "Gabriel Genellina" <> wrote:
    > >> En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
    > >> <> escribió:
    > >>> So......how can I do this?????????????
    > >>> I will appreciate any help!!!!!
    > >> Try with a simple example. Let's say you want to convert this:
    > >> [...]

    > > [...] Can you give me some example script of this? Please!!!
    > >
    > > PS: THANKS FOR YOUR TIME!!!!!!!!!!

    >
    > It's unfortunate that you are having difficulty with two languages
    > simultaneously: your command of English, though impressive, appears
    > to be insufficient for you to explain the problem [...]


    And while we're on the topic of communication: The original poster
    would do well to learn that increasing the number of consecutive
    punctuation marks (!!!, ???) is a sure way to turn away many people
    who would otherwise be helpful. Sentences need at most one '!' or '?',
    adding more does not improve the chances of being taken seriously.

    --
    \ "We have to go forth and crush every world view that doesn't |
    `\ believe in tolerance and free speech." -- David Brin |
    _o__) |
    Ben Finney
     
    Ben Finney, Jul 25, 2007
    #5
  6. ...:::JA:::...

    Guest

    On 25 srp, 01:07, Ben Finney <>
    wrote:
    > Steve Holden <> writes:
    > > wrote:
    > > > On 24 srp, 05:20, "Gabriel Genellina" <> wrote:
    > > >> En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
    > > >> <> escribió:
    > > >>> So......how can I do this?????????????
    > > >>> I will appreciate any help!!!!!
    > > >> Try with a simple example. Let's say you want to convert this:
    > > >> [...]
    > > > [...] Can you give me some example script of this? Please!!!

    >
    > > > PS: THANKS FOR YOUR TIME!!!!!!!!!!

    >
    > > It's unfortunate that you are having difficulty with two languages
    > > simultaneously: your command of English, though impressive, appears
    > > to be insufficient for you to explain the problem [...]

    >
    > And while we're on the topic of communication: The original poster
    > would do well to learn that increasing the number of consecutive
    > punctuation marks (!!!, ???) is a sure way to turn away many people
    > who would otherwise be helpful. Sentences need at most one '!' or '?',
    > adding more does not improve the chances of being taken seriously.
    >
    > --
    > \ "We have to go forth and crush every world view that doesn't |
    > `\ believe in tolerance and free speech." -- David Brin |
    > _o__) |
    > Ben Finney


    Hi,

    I was only ask for help becose I don't understand this tokenize module
    so well.
    And if you can help me than please help me , but if you can't then
    please don't leave me some stupid
    messages


    Regards,

    Vedran
     
    , Jul 25, 2007
    #6
  7. wrote:
    >> And while we're on the topic of communication: The original poster
    >> would do well to learn that increasing the number of consecutive
    >> punctuation marks (!!!, ???) is a sure way to turn away many people
    >> who would otherwise be helpful. Sentences need at most one '!' or '?',
    >> adding more does not improve the chances of being taken seriously.
    >>

    >
    > And if you can help me than please help me , but if you can't then
    > please don't leave me some stupid messages
    >


    Whats stupid about this? It's sane advice.

    Which looks more serious to you:

    this:
    I can't do it!!!! Can you PLEASE help me????!!!?!

    or this:
    I don't know the answer. Can you please help me?

    Even if it makes no difference to you, to many people it does. So Ben is
    right: People *will* take your posts more seriously if you restrict your
    use of punctuation (if only because its easier to read).
    Don't feel offended, nobody was trying to put you down.

    /W
     
    Wildemar Wildenburger, Jul 25, 2007
    #7
  8. ...:::JA:::...

    Guest

    On 25 srp, 17:31, Wildemar Wildenburger <> wrote:
    > wrote:
    > >> And while we're on the topic of communication: The original poster
    > >> would do well to learn that increasing the number of consecutive
    > >> punctuation marks (!!!, ???) is a sure way to turn away many people
    > >> who would otherwise be helpful. Sentences need at most one '!' or '?',
    > >> adding more does not improve the chances of being taken seriously.

    >
    > > And if you can help me than please help me , but if you can't then
    > > please don't leave me some stupid messages

    >
    > Whats stupid about this? It's sane advice.
    >
    > Which looks more serious to you:
    >
    > this:
    > I can't do it!!!! Can you PLEASE help me????!!!?!
    >
    > or this:
    > I don't know the answer. Can you please help me?
    >
    > Even if it makes no difference to you, to many people it does. So Ben is
    > right: People *will* take your posts more seriously if you restrict your
    > use of punctuation (if only because its easier to read).
    > Don't feel offended, nobody was trying to put you down.
    >
    > /W


    HELLO,

    On this group I ask for serious help and now we talk about
    communication. Then I you don't know how to help me then please DON'T
    SAY ANYTHING

    Regards,
    Vedran
     
    , Jul 25, 2007
    #8
  9. > HELLO,
    >
    > On this group I ask for serious help and now we talk about
    > communication. Then I you don't know how to help me then please DON'T
    > SAY ANYTHING



    Your lack of command of the python language and programming concepts in
    general is only excelled by your inabillity to react properly in a
    community of friendly people that try to point out how to behave as a
    human being instead of a complete jerk.

    And given your history of ignorance of sound advice, I think I'm not
    stressing my crystal ball to much if I predict: you won't receive much
    more help here.

    Diez
     
    Diez B. Roggisch, Jul 25, 2007
    #9
  10. ...:::JA:::...

    Ben Finney Guest

    writes:

    > On this group I ask for serious help and now we talk about
    > communication.


    Yes. You're asking for volunteer help from a group of people who have
    their own priorities separate from yours. The way to garner help from
    these people is to respect their time. One excellent way to do that is
    to communicate clearly and maturely, so that your messages are easier
    (and therefore faster) to read.

    Please, before going further, read this document on how to ask
    questions the smart way:

    <URL:http://catb.org/~esr/faqs/smart-questions.html>

    > Then I you don't know how to help me then please DON'T SAY ANYTHING


    This is a volunteer group, run for the benefit of the community. We
    want to help not only you, but *anyone* who might come here asking for
    help, and especially those who are inclined to help them.

    Advice on improving communication is one good way to do that: it
    actively works toward better communication in future, which helps
    questions get answered quicker and consumes less of the helpers' time.

    --
    \ "I put contact lenses in my dog's eyes. They had little |
    `\ pictures of cats on them. Then I took one out and he ran around |
    _o__) in circles." -- Steven Wright |
    Ben Finney
     
    Ben Finney, Jul 26, 2007
    #10
  11. * (Wed, 25 Jul 2007 11:22:03 -0700)
    > On 25 srp, 17:31, Wildemar Wildenburger <> wrote:
    > > wrote:
    > > >> And while we're on the topic of communication: The original poster
    > > >> would do well to learn that increasing the number of consecutive
    > > >> punctuation marks (!!!, ???) is a sure way to turn away many people
    > > >> who would otherwise be helpful. Sentences need at most one '!' or '?',
    > > >> adding more does not improve the chances of being taken seriously.

    > >
    > > > And if you can help me than please help me , but if you can't then
    > > > please don't leave me some stupid messages

    > >
    > > Whats stupid about this? It's sane advice.
    > >
    > > Which looks more serious to you:
    > >
    > > this:
    > > I can't do it!!!! Can you PLEASE help me????!!!?!
    > >
    > > or this:
    > > I don't know the answer. Can you please help me?
    > >
    > > Even if it makes no difference to you, to many people it does. So Ben is
    > > right: People *will* take your posts more seriously if you restrict your
    > > use of punctuation (if only because its easier to read).
    > > Don't feel offended, nobody was trying to put you down.

    >
    > On this group I ask for serious help and now we talk about
    > communication. Then I you don't know how to help me then please DON'T
    > SAY ANYTHING


    You already got serious help even though you haven't realised that
    yet.

    T.
     
    Thorsten Kampe, Jul 26, 2007
    #11
  12. ...:::JA:::...

    Steve Holden Guest

    Thorsten Kampe wrote:
    > * (Wed, 25 Jul 2007 11:22:03 -0700)
    >> On 25 srp, 17:31, Wildemar Wildenburger <> wrote:
    >>> wrote:
    >>>>> And while we're on the topic of communication: The original poster
    >>>>> would do well to learn that increasing the number of consecutive
    >>>>> punctuation marks (!!!, ???) is a sure way to turn away many people
    >>>>> who would otherwise be helpful. Sentences need at most one '!' or '?',
    >>>>> adding more does not improve the chances of being taken seriously.
    >>>> And if you can help me than please help me , but if you can't then
    >>>> please don't leave me some stupid messages
    >>> Whats stupid about this? It's sane advice.
    >>>
    >>> Which looks more serious to you:
    >>>
    >>> this:
    >>> I can't do it!!!! Can you PLEASE help me????!!!?!
    >>>
    >>> or this:
    >>> I don't know the answer. Can you please help me?
    >>>
    >>> Even if it makes no difference to you, to many people it does. So Ben is
    >>> right: People *will* take your posts more seriously if you restrict your
    >>> use of punctuation (if only because its easier to read).
    >>> Don't feel offended, nobody was trying to put you down.

    >> On this group I ask for serious help and now we talk about
    >> communication. Then I you don't know how to help me then please DON'T
    >> SAY ANYTHING

    >
    > You already got serious help even though you haven't realised that
    > yet.
    >

    We should be making allowances for this particular poster on account of
    relative youth: I hadn't realised earlier, but we are dealing with a
    fourteen-year-old. Since fourteen-year-olds already know everything we
    should be honored we are being asked for help at all ;-)

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Jul 26, 2007
    #12
  13. ...:::JA:::...

    Guest

    On 26 srp, 13:43, Steve Holden <> wrote:
    > Thorsten Kampe wrote:
    > > * (Wed, 25 Jul 2007 11:22:03 -0700)
    > >> On 25 srp, 17:31, Wildemar Wildenburger <> wrote:
    > >>> wrote:
    > >>>>> And while we're on the topic of communication: The original poster
    > >>>>> would do well to learn that increasing the number of consecutive
    > >>>>> punctuation marks (!!!, ???) is a sure way to turn away many people
    > >>>>> who would otherwise be helpful. Sentences need at most one '!' or '?',
    > >>>>> adding more does not improve the chances of being taken seriously.
    > >>>> And if you can help me than please help me , but if you can't then
    > >>>> please don't leave me some stupid messages
    > >>> Whats stupid about this? It's sane advice.

    >
    > >>> Which looks more serious to you:

    >
    > >>> this:
    > >>> I can't do it!!!! Can you PLEASE help me????!!!?!

    >
    > >>> or this:
    > >>> I don't know the answer. Can you please help me?

    >
    > >>> Even if it makes no difference to you, to many people it does. So Ben is
    > >>> right: People *will* take your posts more seriously if you restrict your
    > >>> use of punctuation (if only because its easier to read).
    > >>> Don't feel offended, nobody was trying to put you down.
    > >> On this group I ask for serious help and now we talk about
    > >> communication. Then I you don't know how to help me then please DON'T
    > >> SAY ANYTHING

    >
    > > You already got serious help even though you haven't realised that
    > > yet.

    >
    > We should be making allowances for this particular poster on account of
    > relative youth: I hadn't realised earlier, but we are dealing with a
    > fourteen-year-old. Since fourteen-year-olds already know everything we
    > should be honored we are being asked for help at all ;-)
    >
    > regards
    > Steve
    > --
    > Steve Holden +1 571 484 6266 +1 800 494 3119
    > Holden Web LLC/Ltd http://www.holdenweb.com
    > Skype: holdenweb http://del.icio.us/steve.holden
    > --------------- Asciimercial ------------------
    > Get on the web: Blog, lens and tag the Internet
    > Many services currently offer free registration
    > ----------- Thank You for Reading -------------


    Hi again,

    Just one more question, can I maybe do this indentation with string
    e.g
    here is my failed example of try with string:

    kl="n=90;if n==90:print'kajmakimar'"

    for line in kl.split(";"):
    li=[]
    m=li.append(line)
    if line.endswith(':'):
    m.append("\n\t\t\t\t\t\t\t\t")
    print m

    ......so maybe if you can help me with this?

    Regards,

    Vedran

    (http://www.v-programs.com)
     
    , Jul 26, 2007
    #13
  14. wrote:
    >
    > .....so maybe if you can help me with this?


    If I understand you correctly, you're trying to make a "pretty-printer"
    in python, right? Something that will take arbitrary python source
    code, recognize the blocks and so forth, and then emit clean python code
    (text) with tabs for indents instead of spaces?

    >
    > Regards,
    >
    > Vedran
    >
    > (http://www.v-programs.com)
    >
     
    Michael L Torrie, Jul 26, 2007
    #14
  15. schrieb:
    > On 26 srp, 13:43, Steve Holden <> wrote:
    >> Thorsten Kampe wrote:
    >>> * (Wed, 25 Jul 2007 11:22:03 -0700)
    >>>> On 25 srp, 17:31, Wildemar Wildenburger <> wrote:
    >>>>> wrote:
    >>>>>>> And while we're on the topic of communication: The original poster
    >>>>>>> would do well to learn that increasing the number of consecutive
    >>>>>>> punctuation marks (!!!, ???) is a sure way to turn away many people
    >>>>>>> who would otherwise be helpful. Sentences need at most one '!' or '?',
    >>>>>>> adding more does not improve the chances of being taken seriously.
    >>>>>> And if you can help me than please help me , but if you can't then
    >>>>>> please don't leave me some stupid messages
    >>>>> Whats stupid about this? It's sane advice.
    >>>>> Which looks more serious to you:
    >>>>> this:
    >>>>> I can't do it!!!! Can you PLEASE help me????!!!?!
    >>>>> or this:
    >>>>> I don't know the answer. Can you please help me?
    >>>>> Even if it makes no difference to you, to many people it does. So Ben is
    >>>>> right: People *will* take your posts more seriously if you restrict your
    >>>>> use of punctuation (if only because its easier to read).
    >>>>> Don't feel offended, nobody was trying to put you down.
    >>>> On this group I ask for serious help and now we talk about
    >>>> communication. Then I you don't know how to help me then please DON'T
    >>>> SAY ANYTHING
    >>> You already got serious help even though you haven't realised that
    >>> yet.

    >> We should be making allowances for this particular poster on account of
    >> relative youth: I hadn't realised earlier, but we are dealing with a
    >> fourteen-year-old. Since fourteen-year-olds already know everything we
    >> should be honored we are being asked for help at all ;-)
    >>
    >> regards
    >> Steve
    >> --
    >> Steve Holden +1 571 484 6266 +1 800 494 3119
    >> Holden Web LLC/Ltd http://www.holdenweb.com
    >> Skype: holdenweb http://del.icio.us/steve.holden
    >> --------------- Asciimercial ------------------
    >> Get on the web: Blog, lens and tag the Internet
    >> Many services currently offer free registration
    >> ----------- Thank You for Reading -------------

    >
    > Hi again,
    >
    > Just one more question, can I maybe do this indentation with string
    > e.g
    > here is my failed example of try with string:
    >
    > kl="n=90;if n==90:print'kajmakimar'"
    >
    > for line in kl.split(";"):
    > li=[]
    > m=li.append(line)
    > if line.endswith(':'):
    > m.append("\n\t\t\t\t\t\t\t\t")
    > print m
    >
    > .....so maybe if you can help me with this?


    This won't work. It's impossible to know how deep to indent without any
    begin/end-tokens. Consider this simple example:

    if foo:
    print "foo"
    if bar:
    print "bar"

    is equal to

    'if foo:;print"foo";if bar:;print "bar"'

    But that could as well be

    if foo:
    print "foo"
    if bar:
    print "bar"

    So - you need some block delimiters.

    And as it has been said to you a bazzillion times: stop doing what
    you're doing. Use python. As it is. Your limited understandig of parsing
    and language design makes your task beyond your capabilites. For now.
    And the forseeable future...

    diez
     
    Diez B. Roggisch, Jul 26, 2007
    #15
  16. ...:::JA:::...

    Ben Finney Guest

    Steve Holden <> writes:

    > We should be making allowances for this particular poster on account
    > of relative youth: I hadn't realised earlier, but we are dealing
    > with a fourteen-year-old.


    I don't believe that's true. One of the great advantages of discussion
    over the internet is that one's behaviour is what is judged, without
    necessary prejudice from one's age, skin tone, facial features, or the
    like. Set against the many disadvantages of internet discussion, I
    think "judge only on basis of behaviour" is a good default.

    --
    \ "Pinky, are you pondering what I'm pondering?" "Well, I think |
    `\ so, Brain, but first you'd have to take that whole bridge |
    _o__) apart, wouldn't you?" -- _Pinky and The Brain_ |
    Ben Finney
     
    Ben Finney, Jul 27, 2007
    #16
  17. ...:::JA:::...

    Ben Finney Guest

    writes:

    > here is my failed example of try with string:
    >
    > kl="n=90;if n==90:print'kajmakimar'"
    >
    > for line in kl.split(";"):
    > li=[]
    > m=li.append(line)
    > if line.endswith(':'):
    > m.append("\n\t\t\t\t\t\t\t\t")
    > print m


    The list.append method returns None. It appends the item to the list.

    >>> lines = []
    >>> result = lines.append("foo")
    >>> print result

    None

    So, there's no need to do anything with the result of append() -- just
    continue using the list object.

    >>> print lines

    ['foo']
    >>> lines.append("bar")
    >>> print lines

    ['foo', 'bar']

    --
    \ "There are only two ways to live your life. One is as though |
    `\ nothing is a miracle. The other is as if everything is." -- |
    _o__) Albert Einstein |
    Ben Finney
     
    Ben Finney, Jul 27, 2007
    #17
  18. ...:::JA:::...

    Steve Holden Guest

    Ben Finney wrote:
    > Steve Holden <> writes:
    >
    >> We should be making allowances for this particular poster on account
    >> of relative youth: I hadn't realised earlier, but we are dealing
    >> with a fourteen-year-old.

    >
    > I don't believe that's true. One of the great advantages of discussion
    > over the internet is that one's behaviour is what is judged, without
    > necessary prejudice from one's age, skin tone, facial features, or the
    > like. Set against the many disadvantages of internet discussion, I
    > think "judge only on basis of behaviour" is a good default.
    >

    Fair enough, but I was simply suggesting we cut him some slack, not that
    we completely ignore any obnoxious behavior we might observe.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Jul 27, 2007
    #18
    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. DE
    Replies:
    16
    Views:
    823
  2. Code Indentation

    , Dec 29, 2008, in forum: VHDL
    Replies:
    0
    Views:
    410
  3. Peng Yu
    Replies:
    9
    Views:
    389
  4. Chris Rebert
    Replies:
    4
    Views:
    318
    Terry Reedy
    Sep 14, 2009
  5. Jesse B.
    Replies:
    2
    Views:
    195
    Josh Cheek
    Mar 27, 2010
Loading...

Share This Page