OT: spacing of code in Google Groups

B

beliavsky

When I copy code from a source file into a Google Groups message, the
indentation is messed up, making my Python code illegal and all my code
ugly. Are there tricks to avoid this?
 
M

mensanator

When I copy code from a source file into a Google Groups message, the
indentation is messed up, making my Python code illegal and all my code
ugly. Are there tricks to avoid this?

Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).

#import gmpy
#i = 7
#while i<100000:
## conjecture 1
#
# if ((i % 3)>0) and ((i % 5)>0):
# f = gmpy.fib(i)
# ip = gmpy.is_prime(i)
# fm = f % i
# if (fm==(i-1)) and (ip==0):
# print "fib %5d: %5d (mod %5d)" % (i,fm,i),
# print gmpy.is_prime(i)
# i += 2
#
#"""
#Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
# then i is prime
#
#run #1 print all fib(i) == i-1 (mod i) that are composite
#
#fib 5777: 5776 (mod 5777) 0 <-- counter example
#fib 10877: 10876 (mod 10877) 0 <-- counter example
#fib 17261: 17260 (mod 17261) 0
#fib 75077: 75076 (mod 75077) 0 <-- counter example
#fib 80189: 80188 (mod 80189) 0
#"""

Preview looked ok, so let's see what happens when I post it.
 
G

Grant Edwards

Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).

#import gmpy
#i = 7
#while i<100000:

I always rather liked line numbers (a-la 'can -n'). That also
makes discussion of the code easier:

1 import gmpy
2 i = 7
3 while i<100000:
4 # conjecture 1
5
6 if ((i % 3)>0) and ((i % 5)>0):
7 f = gmpy.fib(i)
8 ip = gmpy.is_prime(i)
9 fm = f % i
10 if (fm==(i-1)) and (ip==0):
11 print "fib %5d: %5d (mod %5d)" % (i,fm,i),
12 print gmpy.is_prime(i)
13 i += 2
14
15 """
16 Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
17 then i is prime
18
19 run #1 print all fib(i) == i-1 (mod i) that are composite
20
21 fib 5777: 5776 (mod 5777) 0 <-- counter example
22 fib 10877: 10876 (mod 10877) 0 <-- counter example
23 fib 17261: 17260 (mod 17261) 0
24 fib 75077: 75076 (mod 75077) 0 <-- counter example
25 fib 80189: 80188 (mod 80189) 0
26 """

Not sure what Google Groups does to it...
 
M

mensanator

Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).

#import gmpy
#i = 7
#while i<100000:
## conjecture 1
#
# if ((i % 3)>0) and ((i % 5)>0):
# f = gmpy.fib(i)
# ip = gmpy.is_prime(i)
# fm = f % i
# if (fm==(i-1)) and (ip==0):
# print "fib %5d: %5d (mod %5d)" % (i,fm,i),
# print gmpy.is_prime(i)
# i += 2
#
#"""
#Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
# then i is prime
#
#run #1 print all fib(i) == i-1 (mod i) that are composite
#
#fib 5777: 5776 (mod 5777) 0 <-- counter example
#fib 10877: 10876 (mod 10877) 0 <-- counter example
#fib 17261: 17260 (mod 17261) 0
#fib 75077: 75076 (mod 75077) 0 <-- counter example
#fib 80189: 80188 (mod 80189) 0
#"""

Preview looked ok, so let's see what happens when I post it.

In looking at this, I noticed the tabs in the code were preserved,
but the double space between "fib" and "5777" in the comments was
not. But if you click on the "show original" link, the spaces come
back, so maybe you don't to any thing except "show original" when
you want to copy source code.

Testing 1
Testing 2
Testing 3
 
M

mensanator

Grant said:
I always rather liked line numbers (a-la 'can -n'). That also
makes discussion of the code easier:

1 import gmpy
2 i = 7
3 while i<100000:
4 # conjecture 1
5
6 if ((i % 3)>0) and ((i % 5)>0):
7 f = gmpy.fib(i)
8 ip = gmpy.is_prime(i)
9 fm = f % i
10 if (fm==(i-1)) and (ip==0):
11 print "fib %5d: %5d (mod %5d)" % (i,fm,i),
12 print gmpy.is_prime(i)
13 i += 2
14
15 """
16 Conjecture #1: if i ends in 3 or 7 and fib(i) == i-1 (mod i)
17 then i is prime
18
19 run #1 print all fib(i) == i-1 (mod i) that are composite
20
21 fib 5777: 5776 (mod 5777) 0 <-- counter example
22 fib 10877: 10876 (mod 10877) 0 <-- counter example
23 fib 17261: 17260 (mod 17261) 0
24 fib 75077: 75076 (mod 75077) 0 <-- counter example
25 fib 80189: 80188 (mod 80189) 0
26 """

Not sure what Google Groups does to it...

It wrapped lines 16 and 19. But "show original" restores it.
 
S

Steve Holden

the


Try putting a # at the start of every line. Everyone should
understand what you mean (and you can always tell them to remove
the #'s once they copy the listing).
[...]
It would be helpful if submitted code were also copied to

http://rafb.net/paste/

although I don;t know how long they archive the pastings. That's a site
that gets used on the ##python IRC channel a lot, and it does make
sharing very easy.

Having said which, there's still a lot going for just using spaces
instead of tabs.

though-i-don't-know-what-ggogle-does-to-that-ly y'rs - steve
 
A

Adam DePrince

When I copy code from a source file into a Google Groups message, the
indentation is messed up, making my Python code illegal and all my code
ugly. Are there tricks to avoid this?

Subscribe to the (e-mail address removed) mailing list. Take a look at
http://python.org/community/lists.html The news group and this list are
mirrors of each other. Of course, the benefit this provides depends on
which mail client you use.


Adam DePrince
 
P

Peter Hansen

Grant said:
I always rather liked line numbers (a-la 'can -n'). That also
makes discussion of the code easier:

That, unfortunately, is somewhat harder to remove without
using a regular expression... leading hash marks # is
pretty simple to remove with almost any editor.

-Peter
 
M

M.E.Farmer

Grant said:
Not sure what Google Groups does to it...
The usual... it mangles it.
I don't get it, Google uses Python too, they know it is whitespace
signifigant.
I made a complaint several weeks ago to Google support ,
asking them too quit stripping leading whitespace,
and the sent me a reply saying they appreciated my feedback.
Maybe they just need more feedback :)
M.E.Farmer
 
J

JanC

Adam DePrince schreef:
Subscribe to the (e-mail address removed) mailing list. Take a look at
http://python.org/community/lists.html The news group and this list are
mirrors of each other. Of course, the benefit this provides depends on
which mail client you use.

I don't know if gmane keeps formating of messages intact when posting?
That could be an alternative too...

Or just use one of the free news servers, some of them even allow
connections on port 80. ;-)
 
D

Dan Bishop

M.E.Farmer said:
The usual... it mangles it.
I don't get it, Google uses Python too, they know it is whitespace
signifigant.

And for a long time, Google groups postings *were* whitespace
significant. But the new interface broke it.
I made a complaint several weeks ago to Google support,
asking them too quit stripping leading whitespace,
and the sent me a reply saying they appreciated my feedback.
Maybe they just need more feedback :)

I send them some earlier today. So far, I've only received their
auto-reply.
 
T

Terry Reedy

JanC said:
I don't know if gmane keeps formating of messages intact when posting?
That could be an alternative too...

Reading posts via gmane with Outlook Express preserves leading spaces just
fine. However, OE deletes tabs regardless of what newsgroup does.
The funny thing is that typing a tab gets converted to 4 spaces.

Terry J. Reedy
 
J

JanC

Terry Reedy schreef:
Reading posts via gmane with Outlook Express preserves leading spaces
just fine. However, OE deletes tabs regardless of what newsgroup
does.

OE is useless anyway (at least as a newsreader).

I was talking about the gmane web interface as an alternative to Google's.
They have an NNTP server but also three http-based interfaces: RSS-feed,
blog-style & framed (looks more or less like a newsreader).

....

Tested it in gmane.test, posting through their web interface preserves
whitespace.
 
J

Jacek Generowicz

Peter Hansen said:
That, unfortunately, is somewhat harder to remove without
using a regular expression...

You mean to say that your editor does not have rectangle operations ?
:)
 
P

Peter Hansen

Jacek said:
You mean to say that your editor does not have rectangle operations ?
:)

I wouldn't know.** I try quite hard to limit the features
that I have to learn and remember to a very, very small
list. Why the heck would I ever have to do "rectangle
operations" on a regular basis? ;-)

-Peter

** I'm using Scite; it probably has it. It has quite a few
features -- far more than I'll ever use. Remarkable how
simple an editor could be and still be effective... for
some people.
 
J

JanC

Peter Hansen schreef:
I wouldn't know.** I try quite hard to limit the features
that I have to learn and remember to a very, very small
list. Why the heck would I ever have to do "rectangle
operations" on a regular basis? ;-)
** I'm using Scite; it probably has it. It has quite a few
features -- far more than I'll ever use. Remarkable how
simple an editor could be and still be effective... for
some people.

Rectangular selection only works with the mouse in SciTE/Scintilla:
alt-click-drag.

Most of SciTE's (editor-)features are also available in other Scintilla
based editors.
 
J

Jacek Generowicz

Peter Hansen said:
Why the heck would I ever have to do "rectangle operations" on a
regular basis? ;-)

Well, given that all editors are cat equivalent[*], you don't _have_
to use any of their features :)

But just like Python (particularly in the hands of a skilled Python
programmer) is more productive than a Turing Machine, any featureful
editor (in the hands of an experienced user) is far more productive
than "cat > file".


[*] A bit like Turing equivalence: any program you can write in any
other editor, you could also write with "cat > file"
 
P

Peter Hansen

Jacek said:
Peter Hansen said:
Why the heck would I ever have to do "rectangle operations" on a
regular basis? ;-)

Well, given that all editors are cat equivalent[*], you don't _have_
to use any of their features :)

This "cat equivalent" thing is a red-herring. I can rarely type more
than a line of code without making a typographical error. Sometimes
I won't catch that error until a bit later. Using "cat" alone would
provide me little opportunity to fix the error, so I would never
be able to produce a working program longer than a few lines.

You might call this simply "less productive" (though I'd argue
it becomes a qualitative difference). But, okay, let's work from there...
But just like Python (particularly in the hands of a skilled Python
programmer) is more productive than a Turing Machine, any featureful
editor (in the hands of an experienced user) is far more productive
than "cat > file".

I don't disagree. I do, however, claim that the set of features
that are required to make *me* orders of magnitude more productive
than "cat" (to use your quantitative comparison) is very, very small.

And that I use less than 2% of the features most editors have.

And that if a programmer with equal abilities managed to learn to
use 98% of the features of such an editor, such that he could
readily use whichever such feature was most effective at any given
time, he would not be more than 10% more effective than I am.

But the whole argument is fairly moot... I've needed a rectangle
operation only once in the last ten years, and if I hadn't known at
the time that my editor could do it (and spent about half an hour
figuring out how it worked), I could have written a utility to
do the job faster if I'd been using Python at the time...

Cheers,
-Peter
 
S

Steve Holden

Peter Hansen wrote:

[...]
But the whole argument is fairly moot... I've needed a rectangle
operation only once in the last ten years, and if I hadn't known at
the time that my editor could do it (and spent about half an hour
figuring out how it worked), I could have written a utility to
do the job faster if I'd been using Python at the time...

Or even used cut(1) from the command line.

regards
Steve
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top