473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1287
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
18
by: Scott Brady Drummonds | last post by:
Hi, everyeone, I recently stumbled on some code that someone else wrote that I don't like. However, I'm having trouble articulating what the bad quality of the following code is. The...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
8
by: Vincent Delporte | last post by:
Hello When I copy/paste Python code from the web, every so often, the TABs are wrong, which means that the code won't work and I have to manually reformat the code. Is there a code reformater...
16
by: DE | last post by:
Hello, Here is what I do in C++ and can not right now in python : pushMatrix() { drawStuff(); pushMatrix(); {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.