Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread John Bokma
Chris Angelico  writes:

> On Fri, Apr 1, 2011 at 8:57 AM, geremy condra  wrote:
>> I know it's tongue-in-cheek, but please, please, please don't do this.
>
> It would be more secure to base64 it and then rot13 the output.

Rot-13 twice, to make it even more secure ;-)


-- 
John Bokma   j3b

Blog: http://johnbokma.com/Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl & Python Development: http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 8:57 AM, geremy condra  wrote:
> I know it's tongue-in-cheek, but please, please, please don't do this.

It would be more secure to base64 it and then rot13 the output.

Chris Angelico
/me is feeling evil today

=== Begin Base-Rotten 64-13 ===
FKDtq291oTDtLzHtoJ9lMFOmMJA1pzHtqT8tLzSmMGL0VTy0VTShMPO0nTIhVUWiqQRmVUEbMFOi
qKEjqKDhQDbAPxAbpzymVRShM2IfnJAiQDbioJHtnKZtMzIyoTyhMlOyqzyfVUEiMTS5QDb=
=== End Base-Rotten 64-13 ===
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread geremy condra
On Thu, Mar 31, 2011 at 2:43 PM, eryksun ()  wrote:
> On Thursday, March 31, 2011 4:35:42 PM UTC-4, Chris Angelico wrote:
>>
>> I was trolling, I know the reasons behind it. Anyway, most people
>> don't share code by email! (Actually, since you seem to be the author
>> of that page - could you address that particular point? I think it's
>> probably as big an issue as any of the others, to today's coders -
>> "code semantics get destroyed by forums/email/etc/etc/etc".)
>>
>> Solution: All emailed code should begin with
>> from __future__ import braces
>> And there you are, out of your difficulty at once!
>
> You could paste it as a base64 stream, such as:
>
>
>> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
>> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI=
>
>
> Then decode and exec:
>
> In [1]: import base64
>
> In [2]: %cpaste
> Pasting code; enter '--' alone on the line to stop.
> :code="""> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
> :> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI="""
> :--
>
> In [3]: print base64.b64decode(code)
> def spam():
>    print "Spam! Lovely spam! Lovely spam!"
>
> In [4]: exec(base64.b64decode(code))
>
> In [5]: spam()
> Spam! Lovely spam! Lovely spam!

I know it's tongue-in-cheek, but please, please, please don't do this.

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread eryksun ()
On Thursday, March 31, 2011 4:35:42 PM UTC-4, Chris Angelico wrote:
>
> I was trolling, I know the reasons behind it. Anyway, most people
> don't share code by email! (Actually, since you seem to be the author
> of that page - could you address that particular point? I think it's
> probably as big an issue as any of the others, to today's coders -
> "code semantics get destroyed by forums/email/etc/etc/etc".)
> 
> Solution: All emailed code should begin with
> from __future__ import braces
> And there you are, out of your difficulty at once!

You could paste it as a base64 stream, such as:


> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI=


Then decode and exec:

In [1]: import base64

In [2]: %cpaste
Pasting code; enter '--' alone on the line to stop.
:code="""> ZGVmIHNwYW0oKToNCiAgICBwcmludCAiU3BhbSEg
:> TG92ZWx5IHNwYW0hIExvdmVseSBzcGFtISI="""
:--

In [3]: print base64.b64decode(code)
def spam():
print "Spam! Lovely spam! Lovely spam!"

In [4]: exec(base64.b64decode(code))

In [5]: spam()
Spam! Lovely spam! Lovely spam!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 1:35 PM, Chris Angelico  wrote:

> On Fri, Apr 1, 2011 at 4:54 AM, Dan Stromberg  wrote:
> >
> > http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
> >
>
> I was trolling, I know the reasons behind it. Anyway, most people
> don't share code by email! (Actually, since you seem to be the author
> of that page - could you address that particular point? I think it's
> probably as big an issue as any of the others, to today's coders -
> "code semantics get destroyed by forums/email/etc/etc/etc".)
>
> Solution: All emailed code should begin with
> from __future__ import braces
> And there you are, out of your difficulty at once!
>

Updated:

http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html

Another I can only partially refute: If you're having an e-mail discussion
about code, some mailers like to reformat your code into a paragraph.
Needless to say, this is bad for pretty much all code, but pathological for
Python and other languages that use whitespace in a manner distinct from
basic paragraph-filling.

Some alternatives:

   - Use a proper code review tool instead - EG
Rietveld.

   - Use a wiki instead - sometimes with a  tag (EG,
   on Wikipedia ).
   - Use HTML e-mail and a  tag
  - Except this'll have problems with real <'s and >'s - which are
  common in Python and other languages.
  - You can pipe your Python through this
sedcommand to deal with real <'s and
>'s
 - sed -e 's//\>/g'
  - Note that this is no more onerous than running code through a code
  beautifier
   - Use a non-borken MUA like
   mutt  for such communications
   - Mail your code as an attachment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 4:54 AM, Dan Stromberg  wrote:
>
> http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
>

I was trolling, I know the reasons behind it. Anyway, most people
don't share code by email! (Actually, since you seem to be the author
of that page - could you address that particular point? I think it's
probably as big an issue as any of the others, to today's coders -
"code semantics get destroyed by forums/email/etc/etc/etc".)

Solution: All emailed code should begin with
from __future__ import braces
And there you are, out of your difficulty at once!

Chris Angelico
tongue still firmly stuck in cheek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Dan Stromberg
On Thu, Mar 31, 2011 at 9:18 AM, Chris Angelico  wrote:

> On Fri, Apr 1, 2011 at 3:12 AM, eryksun ()  wrote:
> > There appears to be a formatting error here.
>
> So remind me again why Python likes whitespace to be significant?
>
> 
>

http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Chris Angelico
On Fri, Apr 1, 2011 at 3:12 AM, eryksun ()  wrote:
> There appears to be a formatting error here.

So remind me again why Python likes whitespace to be significant?



:)

Chris Angelico
PS. Yes, I know "remind me again" is redundant. You have to make
mistakes when you troll, it's a moral imperative!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread eryksun ()
On Wednesday, March 30, 2011 11:03:09 PM UTC-4, JosephS wrote:
> print "How old are you?", age = raw_input()
> print "How tall are you?", height = raw_input()
> print "How much do you weigh?", weight = raw_input()
> print "So, you're %r old, %r tall and %r heavy." % ( age, height,
> weight)
> Note:
> Notice that we put a , (comma) at the end of each print line. This is
> so that print doesn’t end the line with a newline and go to the next
> line.
> What You Should See
> Extra Credit
> 1. Go online and find out what Python’s raw_input does.
> $ python ex11.py How old are you?
> 35 How tall are you?
> 6'2" How much do you weigh? 180lbs
> So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
> 
> Related to escape sequences, try to find out why the last line has
> ’6\’2"’ with that \’ sequence. See how the single-quote needs to be
> escaped because otherwise it would end the string?

There appears to be a formatting error here. The following works:

print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight)

Regarding the escape sequence, your're using %r which shows the representation 
(repr) of the string. For example:

In [1]: [x for x in height]
Out[1]: ['6', "'", '2', '"']

In [2]: print height
6'2"

In [3]: [x for x in repr(height)]
Out[3]: ["'", '6', '\\', "'", '2', '"', "'"]

In [4]: print repr(height)
'6\'2"'

The characters stored in height are just 6'2", but you couldn't input the 
string like that as a variable since Python uses quotes to demarcate a string 
literal. The backslash escapes the quote so that the interpreter will treat it 
as a regular character. It's unnecessary to escape the double quote, on the 
other hand, since this string literal is marked with single quotes. If the 
string were instead inputted with double quotes, then the final double quote 
would have to be escaped, such as the following: height = "6'2\"". Finally, 
notice that in the output representation of the characters of repr(height) 
(Out[3]) that the backslash itself has to be escaped. Otherwise it would be 
interpreted as escaping the single quote that follows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learn Python the Hardway exercise 11 question 4

2011-03-31 Thread Steven D'Aprano
On Wed, 30 Mar 2011 20:03:09 -0700, Joseph Sanoyo wrote:

> print "How old are you?", age = raw_input() print "How tall are you?",
> height = raw_input() print "How much do you weigh?", weight =
> raw_input() print "So, you're %r old, %r tall and %r heavy." % ( age,
> height, weight)
> Note:
> Notice that we put a , (comma) at the end of each print line. This is so
> that print doesn’t end the line with a newline and go to the next line.
> What You Should See
> Extra Credit
> 1. Go online and find out what Python’s raw_input does. $ python ex11.py
> How old are you?
> 35 How tall are you?
> 6'2" How much do you weigh? 180lbs
> So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
> 
> Related to escape sequences, try to find out why the last line has
> ’6\’2"’ with that \’ sequence. See how the single-quote needs to be
> escaped because otherwise it would end the string?

I'm sorry, are you asking a question and expecting an answer, replying to 
somebody else's question, or just sharing something you thought was 
interesting?


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Learn Python the Hardway exercise 11 question 4

2011-03-30 Thread Joseph Sanoyo
print "How old are you?", age = raw_input()
print "How tall are you?", height = raw_input()
print "How much do you weigh?", weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % ( age, height,
weight)
Note:
Notice that we put a , (comma) at the end of each print line. This is
so that print doesn’t end the line with a newline and go to the next
line.
What You Should See
Extra Credit
1. Go online and find out what Python’s raw_input does.
$ python ex11.py How old are you?
35 How tall are you?
6'2" How much do you weigh? 180lbs
So, you're '35' old, '6\'2"' tall and '180lbs' heavy.

Related to escape sequences, try to find out why the last line has
’6\’2"’ with that \’ sequence. See how the single-quote needs to be
escaped because otherwise it would end the string?
-- 
http://mail.python.org/mailman/listinfo/python-list