471,350 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

code indentation

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!
__________________________________________________ ________________
Jul 23 '07 #1
13 1218
Steve Holden <st***@holdenweb.comwrites:
ve***********@v-programs.com wrote:
On 24 srp, 05:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
<vedrandeko...@v-programs.comescribió:
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
Jul 24 '07 #2
On 25 srp, 01:07, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
Steve Holden <st...@holdenweb.comwrites:
vedrandeko...@v-programs.com wrote:
On 24 srp, 05:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Mon, 23 Jul 2007 16:53:01 -0300, ...:::JA:::...
><vedrandeko...@v-programs.comescribió:
>>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 '07 #3
ve***********@v-programs.com 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
Jul 25 '07 #4
On 25 srp, 17:31, Wildemar Wildenburger <wilde...@freakmail.dewrote:
vedrandeko...@v-programs.com 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 '07 #5
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
Jul 25 '07 #6
* (Wed, 25 Jul 2007 11:22:03 -0700)
On 25 srp, 17:31, Wildemar Wildenburger <wilde...@freakmail.dewrote:
vedrandeko...@v-programs.com 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.
Jul 26 '07 #7
Thorsten Kampe wrote:
* (Wed, 25 Jul 2007 11:22:03 -0700)
>On 25 srp, 17:31, Wildemar Wildenburger <wilde...@freakmail.dewrote:
>>vedrandeko...@v-programs.com 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 -------------

Jul 26 '07 #8
On 26 srp, 13:43, Steve Holden <st...@holdenweb.comwrote:
Thorsten Kampe wrote:
* (Wed, 25 Jul 2007 11:22:03 -0700)
On 25 srp, 17:31, Wildemar Wildenburger <wilde...@freakmail.dewrote:
vedrandeko...@v-programs.com 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 '07 #9
ve***********@v-programs.com 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)
Jul 26 '07 #10
ve***********@v-programs.com schrieb:
On 26 srp, 13:43, Steve Holden <st...@holdenweb.comwrote:
>Thorsten Kampe wrote:
>>* (Wed, 25 Jul 2007 11:22:03 -0700)
On 25 srp, 17:31, Wildemar Wildenburger <wilde...@freakmail.dewrote:
vedrandeko...@v-programs.com 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
Jul 26 '07 #11
Steve Holden <st***@holdenweb.comwrites:
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
Jul 26 '07 #12
ve***********@v-programs.com 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
Jul 27 '07 #13
Ben Finney wrote:
Steve Holden <st***@holdenweb.comwrites:
>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 -------------

Jul 27 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
18 posts views Thread by Scott Brady Drummonds | last post: by
135 posts views Thread by Xah Lee | last post: by
8 posts views Thread by Vincent Delporte | last post: by
16 posts views Thread by DE | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.