Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83878 > unrolled thread

How to "wow" someone new to Python

Started byChris Angelico <rosuav@gmail.com>
First post2015-01-17 02:03 +1100
Last post2015-01-23 00:09 +0000
Articles 20 on this page of 23 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  How to "wow" someone new to Python Chris Angelico <rosuav@gmail.com> - 2015-01-17 02:03 +1100
    Re: How to "wow" someone new to Python Marko Rauhamaa <marko@pacujo.net> - 2015-01-16 17:20 +0200
    Re: How to "wow" someone new to Python Rustom Mody <rustompmody@gmail.com> - 2015-01-16 09:16 -0800
    Re: How to "wow" someone new to Python alex23 <wuwei23@gmail.com> - 2015-01-19 16:19 +1000
    Re: How to "wow" someone new to Python wxjmfauth@gmail.com - 2015-01-21 07:15 -0800
    Re: How to "wow" someone new to Python Steve Hayes <hayesstw@telkomsa.net> - 2015-01-21 19:59 +0200
      Re: How to "wow" someone new to Python Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-01-21 19:20 +0100
        Re: How to "wow" someone new to Python Chris Angelico <rosuav@gmail.com> - 2015-01-22 06:06 +1100
          Re: How to "wow" someone new to Python André Roberge <andre.roberge@gmail.com> - 2015-01-21 11:20 -0800
          Re: How to "wow" someone new to Python Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-01-22 00:46 +0100
        Re: How to "wow" someone new to Python Matthew Ruffalo <mmr15@case.edu> - 2015-01-21 16:20 -0500
        Re: How to "wow" someone new to Python Chris Angelico <rosuav@gmail.com> - 2015-01-22 08:26 +1100
          Re: How to "wow" someone new to Python Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2015-01-21 16:44 -0500
            Re: How to "wow" someone new to Python Alan Bawden <alan@scooby-doo.csail.mit.edu> - 2015-01-21 16:52 -0500
              Re: How to "wow" someone new to Python Paul Rubin <no.email@nospam.invalid> - 2015-01-21 14:35 -0800
              Re: How to "wow" someone new to Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-22 15:51 +1100
            Re: How to "wow" someone new to Python Mario Figueiredo <marfig@gmail.com> - 2015-01-21 23:13 +0100
        Re: How to "wow" someone new to Python Matthew Ruffalo <mmr15@case.edu> - 2015-01-21 16:46 -0500
        Re: How to "wow" someone new to Python Chris Angelico <rosuav@gmail.com> - 2015-01-22 09:22 +1100
    Re: How to "wow" someone new to Python André Roberge <andre.roberge@gmail.com> - 2015-01-21 10:34 -0800
    Re: How to "wow" someone new to Python Mario Figueiredo <marfig@gmail.com> - 2015-01-21 19:05 +0000
      Re: How to "wow" someone new to Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-22 15:39 +1100
        Re: How to "wow" someone new to Python Grant Edwards <invalid@invalid.invalid> - 2015-01-23 00:09 +0000

Page 1 of 2  [1] 2  Next page →


#83878 — How to "wow" someone new to Python

FromChris Angelico <rosuav@gmail.com>
Date2015-01-17 02:03 +1100
SubjectHow to "wow" someone new to Python
Message-ID<mailman.17792.1421420646.18130.python-list@python.org>
Scenario: You're introducing someone to Python for the first time.
S/he may have some previous programming experience, or may be new to
the whole idea of giving a computer instructions. You have a couple of
minutes to show off how awesome Python is. What do you do?

I was thinking along the lines of a simple demo in the REPL, showing
off some of Python's coolest features. But then I got stuck on the
specifics. What are Python's best coolnesses? What makes for a good
demo?

Ideally, this should be something that can be demo'd quickly and
easily, and it should be impressive without going into great details
of "and see, this is how it works on the inside". So, how would you
brag about this language?

ChrisA

[toc] | [next] | [standalone]


#83880

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-01-16 17:20 +0200
Message-ID<87fvbaah1t.fsf@elektro.pacujo.net>
In reply to#83878
Chris Angelico <rosuav@gmail.com>:

> Scenario: You're introducing someone to Python for the first time.
> S/he may have some previous programming experience, or may be new to
> the whole idea of giving a computer instructions. You have a couple of
> minutes to show off how awesome Python is. What do you do?

My experience is that if you have your "customer" try their hand on
programming and complete a simple challenge, they'll be extremely
impressed. "Did I manage that?"

On the other hand, if you want to demo your greatest achievements at the
screen, they will be left unmoved. "Even my favorite Zynga game looks
cooler than that."

> I was thinking along the lines of a simple demo in the REPL, showing
> off some of Python's coolest features. But then I got stuck on the
> specifics. What are Python's best coolnesses? What makes for a good
> demo?

I would advise steering clear of the REPL and go directly to writing a
program and executing it. Maybe the classic ASCII graphics presentation
of the sine wave:

========================================================================
#!/usr/bin/env python3

import time
import math

def main():
    for angle in range(0, 100000, 5):
        print(int((1 + math.sin(math.radians(angle))) * 35) * "*")
        time.sleep(0.1)

if __name__ == "__main__":
    main()
========================================================================

> Ideally, this should be something that can be demo'd quickly and
> easily, and it should be impressive without going into great details
> of "and see, this is how it works on the inside". So, how would you
> brag about this language?

I'd recommend not skipping the traditional boilerplate (see my example).
Be professional from the start.


Marko

[toc] | [prev] | [next] | [standalone]


#83885

FromRustom Mody <rustompmody@gmail.com>
Date2015-01-16 09:16 -0800
Message-ID<f45114df-4032-4ad2-b178-1eca33247529@googlegroups.com>
In reply to#83878
On Friday, January 16, 2015 at 8:34:20 PM UTC+5:30, Chris Angelico wrote:
> Scenario: You're introducing someone to Python for the first time.
> S/he may have some previous programming experience, or may be new to
> the whole idea of giving a computer instructions. You have a couple of
> minutes to show off how awesome Python is. What do you do?

There is this story -- maybe apocryphal -- that the tendency to vote
democratic or republican runs so deep it can be detected from 
genetic markers.

Similar things apply to programming:
Some people are drawn to a mathematical style; some are not
Some people love cute little scripts; some are left cold
Some love graphics; some dislike
etc etc
All corollary to:
Some people can think like programmers; most cant
[Who does the last quote? Steve Jobs?]

So to start with, you need to 'fingerprint' (is that the word?)
your subject.

> 
> I was thinking along the lines of a simple demo in the REPL, showing
> off some of Python's coolest features. But then I got stuck on the
> specifics. What are Python's best coolnesses? What makes for a good
> demo?

The reason I find the REPL particularly cool for such demos
[I am surprised that Marko doesn't]
is that at least to some extent you can straddle some of the
divides above.

How about a little web-scrape with beautiful-soup?
Followed by maybe a "throw the results into a csv-file
and open in the local spreadsheet"?

[toc] | [prev] | [next] | [standalone]


#84004

Fromalex23 <wuwei23@gmail.com>
Date2015-01-19 16:19 +1000
Message-ID<m9i7lf$8d2$1@dont-email.me>
In reply to#83878
On 17/01/2015 1:03 AM, Chris Angelico wrote:
> Scenario: You're introducing someone to Python for the first time.
> S/he may have some previous programming experience, or may be new to
> the whole idea of giving a computer instructions. You have a couple of
> minutes to show off how awesome Python is. What do you do?

When demoing to people with a reasonable amount of experience, I've 
found they're often impressed by showing them list comprehensions, then 
generators, then chained generators.

[toc] | [prev] | [next] | [standalone]


#84126

Fromwxjmfauth@gmail.com
Date2015-01-21 07:15 -0800
Message-ID<b131566a-dd59-4500-8165-272070da6afb@googlegroups.com>
In reply to#83878
Le vendredi 16 janvier 2015 16:04:20 UTC+1, Chris Angelico a écrit :
> Scenario: You're introducing someone to Python for the first time.
> S/he may have some previous programming experience, or may be new to
> the whole idea of giving a computer instructions. You have a couple of
> minutes to show off how awesome Python is. What do you do?
> 
> I was thinking along the lines of a simple demo in the REPL, showing
> off some of Python's coolest features. But then I got stuck on the
> specifics. What are Python's best coolnesses? What makes for a good
> demo?
> 
> Ideally, this should be something that can be demo'd quickly and
> easily, and it should be impressive without going into great details
> of "and see, this is how it works on the inside". So, how would you
> brag about this language?
> 
> ChrisA

If you are smart enough, you can use a string.
On windows, with that string can make IDLE, tkinter,
and finally Python crash. No msg at all. The
main windows just desappears. It's quite clean,
not even a Python engine in the task manager.

For the record, I discovered this when toying
with my unicode plain text editor, I can now throw away,
an editor perfectly working with py32.

jmf

[toc] | [prev] | [next] | [standalone]


#84133

FromSteve Hayes <hayesstw@telkomsa.net>
Date2015-01-21 19:59 +0200
Message-ID<82qvba51o427s4m63agk6ghekm0btg81on@4ax.com>
In reply to#83878
On Sat, 17 Jan 2015 02:03:57 +1100, Chris Angelico <rosuav@gmail.com> wrote:

>Scenario: You're introducing someone to Python for the first time.
>S/he may have some previous programming experience, or may be new to
>the whole idea of giving a computer instructions. You have a couple of
>minutes to show off how awesome Python is. What do you do?
>
>I was thinking along the lines of a simple demo in the REPL, showing
>off some of Python's coolest features. But then I got stuck on the
>specifics. What are Python's best coolnesses? What makes for a good
>demo?
>
>Ideally, this should be something that can be demo'd quickly and
>easily, and it should be impressive without going into great details
>of "and see, this is how it works on the inside". So, how would you
>brag about this language?

I can only say what made me sit up and take notice.

1. I found it already on my computer. 
2. It seemed to be used to run the Gramps genealogy program, which is quite
complex. I was impressed. 
3. When I started to look at it, I found that strings could be any length and
were not limited to swomething arbitrary, like 256 characters. 



-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk

[toc] | [prev] | [next] | [standalone]


#84134

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2015-01-21 19:20 +0100
Message-ID<54bfedf5$0$2876$e4fe514c@news.xs4all.nl>
In reply to#84133
On 21-1-2015 18:59, Steve Hayes wrote:

> 3. When I started to look at it, I found that strings could be any length and
> were not limited to swomething arbitrary, like 256 characters. 

Even more fun is that Python's primitive integer type (longs for older Python versions)
has no arbitrary limitation either.

That amazed me at the time I discovered python :)

Irmen

[toc] | [prev] | [next] | [standalone]


#84138

FromChris Angelico <rosuav@gmail.com>
Date2015-01-22 06:06 +1100
Message-ID<mailman.17921.1421867178.18130.python-list@python.org>
In reply to#84134
On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
> On 21-1-2015 18:59, Steve Hayes wrote:
>
>> 3. When I started to look at it, I found that strings could be any length and
>> were not limited to swomething arbitrary, like 256 characters.
>
> Even more fun is that Python's primitive integer type (longs for older Python versions)
> has no arbitrary limitation either.
>
> That amazed me at the time I discovered python :)

I hadn't worked with length-limited strings in basically forever
(technically BASIC has a length limit, but I never ran into it; and I
never did much with Pascal), but you're right, arbitrary-precision
integers would have impressed me a lot more if I hadn't first known
REXX. So... is there a way to show that off efficiently? Normally, any
calculation that goes beyond 2**32 has already gone way beyond most
humans' ability to hold the numbers in their heads.

ChrisA

[toc] | [prev] | [next] | [standalone]


#84140

FromAndré Roberge <andre.roberge@gmail.com>
Date2015-01-21 11:20 -0800
Message-ID<20425bf8-2862-432f-a6a9-cd7ea6d21853@googlegroups.com>
In reply to#84138
On Wednesday, 21 January 2015 15:06:33 UTC-4, Chris Angelico  wrote:
> On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong  wrote:
> > On 21-1-2015 18:59, Steve Hayes wrote:
> >
> >> 3. When I started to look at it, I found that strings could be any length and
> >> were not limited to swomething arbitrary, like 256 characters.
> >
> > Even more fun is that Python's primitive integer type (longs for older Python versions)
> > has no arbitrary limitation either.
> >
> > That amazed me at the time I discovered python :)
> 
> I hadn't worked with length-limited strings in basically forever
> (technically BASIC has a length limit, but I never ran into it; and I
> never did much with Pascal), but you're right, arbitrary-precision
> integers would have impressed me a lot more if I hadn't first known
> REXX. So... is there a way to show that off efficiently? 

How about:

 >>> def fac(n):
 ...     ans = 1
 ...     while n > 1:
 ...         ans *= n
 ...         n -= 1
 ...     return ans
 ...
 >>> a = fac(100)
 >>> a
 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
 >>> b = fac(102)
 >>> b
 961446671503512660926865558697259548455355905059659464369444714048531715130254590603314961882364451384985595980362059157503710042865532928000000000000000000000000
 >>> b//a
 10302
 >>> b//a == 102 * 101
 True

André


Normally, any
> calculation that goes beyond 2**32 has already gone way beyond most
> humans' ability to hold the numbers in their heads.
> 
> ChrisA

[toc] | [prev] | [next] | [standalone]


#84158

FromIrmen de Jong <irmen.NOSPAM@xs4all.nl>
Date2015-01-22 00:46 +0100
Message-ID<54c03a6b$0$2893$e4fe514c@news.xs4all.nl>
In reply to#84138
On 21-1-2015 20:06, Chris Angelico wrote:
> On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
>> On 21-1-2015 18:59, Steve Hayes wrote:
>>
>>> 3. When I started to look at it, I found that strings could be any length and
>>> were not limited to swomething arbitrary, like 256 characters.
>>
>> Even more fun is that Python's primitive integer type (longs for older Python versions)
>> has no arbitrary limitation either.
>>
>> That amazed me at the time I discovered python :)
> 
> I hadn't worked with length-limited strings in basically forever
> (technically BASIC has a length limit, but I never ran into it; and I
> never did much with Pascal), but you're right, arbitrary-precision
> integers would have impressed me a lot more if I hadn't first known
> REXX. So... is there a way to show that off efficiently? Normally, any
> calculation that goes beyond 2**32 has already gone way beyond most
> humans' ability to hold the numbers in their heads.
> 
> ChrisA
> 

Something silly that I just thought about  (Python 3):


number = 2 * 3 * 5 * 103    # okay.
number = number * 3120937 * 6977407 * 8431103    # hmm...
number = number * 70546381234168412430433268433712277793053956898109255590133639943
print("I know a huge number, it is:", number)
secret_message = number.to_bytes(37, "big")
print(secret_message)


Or perhaps: (after pip install pyprimes)

>>> number = 1402811054100763300785480817886711606823329164566977593890  # wow?
>>> import pyprimes.factors
>>> print(pyprimes.factors.factorise(number))
[2, 3, 5, 557, 1559, 3413, 6991, 27799, 41333, 52999, 104681, 247001, 992441, 1111211,
1299689]
>>>



Irmen

[toc] | [prev] | [next] | [standalone]


#84141

FromMatthew Ruffalo <mmr15@case.edu>
Date2015-01-21 16:20 -0500
Message-ID<mailman.17922.1421875588.18130.python-list@python.org>
In reply to#84134
On 01/21/2015 02:06 PM, Chris Angelico wrote:
> On Thu, Jan 22, 2015 at 5:20 AM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
>> On 21-1-2015 18:59, Steve Hayes wrote:
>>
>>> 3. When I started to look at it, I found that strings could be any length and
>>> were not limited to swomething arbitrary, like 256 characters.
>> Even more fun is that Python's primitive integer type (longs for older Python versions)
>> has no arbitrary limitation either.
>>
>> That amazed me at the time I discovered python :)
> I hadn't worked with length-limited strings in basically forever
> (technically BASIC has a length limit, but I never ran into it; and I
> never did much with Pascal), but you're right, arbitrary-precision
> integers would have impressed me a lot more if I hadn't first known
> REXX. So... is there a way to show that off efficiently? Normally, any
> calculation that goes beyond 2**32 has already gone way beyond most
> humans' ability to hold the numbers in their heads.
>
> ChrisA
Yes, length-unlimited strings are *extremely* useful in some
applications. I remember bitterly cursing Java's string length limit of
2 ** 31 (maybe - 1) on multiple occasions. Python's strings seem to
behave like integers in that their size is limited only by available memory.

MMR...

[toc] | [prev] | [next] | [standalone]


#84142

FromChris Angelico <rosuav@gmail.com>
Date2015-01-22 08:26 +1100
Message-ID<mailman.17923.1421875592.18130.python-list@python.org>
In reply to#84134
On Thu, Jan 22, 2015 at 8:20 AM, Matthew Ruffalo <mmr15@case.edu> wrote:
> Yes, length-unlimited strings are *extremely* useful in some
> applications. I remember bitterly cursing Java's string length limit of
> 2 ** 31 (maybe - 1) on multiple occasions. Python's strings seem to
> behave like integers in that their size is limited only by available memory.

Hmm, I don't know that you'll get much beyond 2**31 characters (even
all-ASCII characters in PEP 393) on a 32-bit Python, simply because
"available memory" is capped at 2**32 bytes minus other stuff. You'd
need a 64-bit Python to do that, and I would guess a 64-bit Java would
also raise the limit.

ChrisA

[toc] | [prev] | [next] | [standalone]


#84143

FromAlan Bawden <alan@scooby-doo.csail.mit.edu>
Date2015-01-21 16:44 -0500
Message-ID<w2dsif33j2k.fsf@scooby-doo.csail.mit.edu>
In reply to#84142
Chris Angelico <rosuav@gmail.com> writes:
> ..., and I would guess a 64-bit Java would
> also raise the limit.

Even in a 64-bit Java, the _type_ returned by String.length() is 'int',
and is thus at most (2**31 - 1).  This isn't a problem for strings,
which never get that long in practice, but for some other Java datatypes
(e.g., Buffer) it is a real problem.  Score one for untyped languages.

-- 
Alan Bawden

[toc] | [prev] | [next] | [standalone]


#84144

FromAlan Bawden <alan@scooby-doo.csail.mit.edu>
Date2015-01-21 16:52 -0500
Message-ID<w2doapr3ipl.fsf@scooby-doo.csail.mit.edu>
In reply to#84143
Alan Bawden <alan@scooby-doo.csail.mit.edu> writes:
> ...  Score one for untyped languages.

Drat.  I should have writted "dynamically typed languages".

The language has changed.  When I was a novice Lisp hacker, we were
comfortable saying that Lisp was "untyped".  But nowadays we always say
that Lisp is "dynamically typed".  I could write an essay about why...

-- 
Alan Bawden

[toc] | [prev] | [next] | [standalone]


#84149

FromPaul Rubin <no.email@nospam.invalid>
Date2015-01-21 14:35 -0800
Message-ID<87a91bahir.fsf@jester.gateway.sonic.net>
In reply to#84144
Alan Bawden <alan@scooby-doo.csail.mit.edu> writes:
> The language has changed.  When I was a novice Lisp hacker, we were
> comfortable saying that Lisp was "untyped".  But nowadays we always say
> that Lisp is "dynamically typed".  I could write an essay about why...

I'd be interested in seeing that.  Lisp of course descends from Church's
untyped lambda calculus but I didn't realize Lisp terminology about its
(runtime) type system had changed historically.  PL theorists sometimes
like to refer to runtime types as "tags" rather than types.

[toc] | [prev] | [next] | [standalone]


#84186

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-01-22 15:51 +1100
Message-ID<54c081c3$0$2761$c3e8da3$76491128@news.astraweb.com>
In reply to#84144
Alan Bawden wrote:

> Alan Bawden <alan@scooby-doo.csail.mit.edu> writes:
>> ...  Score one for untyped languages.
> 
> Drat.  I should have writted "dynamically typed languages".
> 
> The language has changed.  When I was a novice Lisp hacker, we were
> comfortable saying that Lisp was "untyped".  But nowadays we always say
> that Lisp is "dynamically typed".  I could write an essay about why...

I've always understood that strictly speaking, "untyped" refers to low-level 
languages like assembly or Forth, where everything is a machine word.

In Forth, for example, all commands operate on single words on the stack, 
except for "double" variants which operate on two words at a time. E.g. you 
might have FOO to operate on the word at the top of the stack and FOOD to 
operate on the top two words. (Actually, given Forth's reputation for 
cryptic single-character line noise, it would probably be '^ and ''^ or 
something :-) In any case, there's a single stack, and double quantities 
aren't a separate data type, they're just two words.

(Some versions of Forth are arguably typed, in that they have a separate 
stack for floating point.)

I sometimes also use "untyped" to refer to languages like Hypertalk where 
everything is a string.



-- 
Steve

[toc] | [prev] | [next] | [standalone]


#84146

FromMario Figueiredo <marfig@gmail.com>
Date2015-01-21 23:13 +0100
Message-ID<MPG.2f2a42cc23059fe1989681@nntp.aioe.org>
In reply to#84143
In article <w2dsif33j2k.fsf@scooby-doo.csail.mit.edu>, alan@scooby-
doo.csail.mit.edu says...
> Even in a 64-bit Java, the _type_ returned by String.length() is
> 'int', and is thus at most (2**31 - 1).  This isn't a problem for
> strings, which never get that long in practice, but for some other
> Java datatypes (e.g., Buffer) it is a real problem.  Score one for
> untyped languages.

Still, assuming you have enough heap size, you can still create a 500 
million character string buffer. That's one of a heck large buffer. 
Nearly twice the online encyclopedia Britannica(1), and roughly 50 times 
the longest novel ever produced (2).

And considering you can always flush the buffer, I'm finding an hard 
time looking at unlimited string length in Python as wow factor. Even if 
we consider unicode strings. 


(1) 
http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons#Comparison_of_en
cyclopedias

(2) http://en.wikipedia.org/wiki/List_of_longest_novels

[toc] | [prev] | [next] | [standalone]


#84145

FromMatthew Ruffalo <mmr15@case.edu>
Date2015-01-21 16:46 -0500
Message-ID<mailman.17924.1421877166.18130.python-list@python.org>
In reply to#84134
On 01/21/2015 04:26 PM, Chris Angelico wrote:
> On Thu, Jan 22, 2015 at 8:20 AM, Matthew Ruffalo <mmr15@case.edu> wrote:
>> Yes, length-unlimited strings are *extremely* useful in some
>> applications. I remember bitterly cursing Java's string length limit of
>> 2 ** 31 (maybe - 1) on multiple occasions. Python's strings seem to
>> behave like integers in that their size is limited only by available memory.
> Hmm, I don't know that you'll get much beyond 2**31 characters (even
> all-ASCII characters in PEP 393) on a 32-bit Python, simply because
> "available memory" is capped at 2**32 bytes minus other stuff. You'd
> need a 64-bit Python to do that, and I would guess a 64-bit Java would
> also raise the limit.
>
> ChrisA
No, Java's String.length returns an int and Strings are limited to ~2 **
31 characters even in 64-bit Java.

I do seem to have encountered some strange behavior, though: creating
very large strings with str.__mul__ seems to enter an allocation loop in
Python 3.4. With a single-character string 's', I can create the
following new strings quickly:

s * 2 ** 33
s * 2 ** 34
s * 2 ** 35
s * 2 ** 36

but s * 2 ** 38 shows some odd memory usage. I'm watching the memory
usage of a Python process steadily increase to 256GB, drop to a few MB,
climb back to 256GB, drop to a few MB, and so on. It takes a half-dozen
cycles of allocation and deallocation before the interactive interpreter
gives me another prompt.

MMR...

[toc] | [prev] | [next] | [standalone]


#84147

FromChris Angelico <rosuav@gmail.com>
Date2015-01-22 09:22 +1100
Message-ID<mailman.17925.1421878963.18130.python-list@python.org>
In reply to#84134
On Thu, Jan 22, 2015 at 8:46 AM, Matthew Ruffalo <mmr15@case.edu> wrote:
> No, Java's String.length returns an int and Strings are limited to ~2 **
> 31 characters even in 64-bit Java.

Huh, annoying. In Python, the length of a string (in characters) is
stored in a Py_ssize_t (if I recall correctly), which is, I believe, a
pointer-sized integer. So it'd be 64-bit on a 64-bit build.

> I do seem to have encountered some strange behavior, though: creating
> very large strings with str.__mul__ seems to enter an allocation loop in
> Python 3.4. With a single-character string 's', I can create the
> following new strings quickly:
>
> s * 2 ** 33
> s * 2 ** 34
> s * 2 ** 35
> s * 2 ** 36
>
> but s * 2 ** 38 shows some odd memory usage. I'm watching the memory
> usage of a Python process steadily increase to 256GB, drop to a few MB,
> climb back to 256GB, drop to a few MB, and so on. It takes a half-dozen
> cycles of allocation and deallocation before the interactive interpreter
> gives me another prompt.

That sounds like you're blooping through your page file. The exact
behaviour will depend on how much physical memory you have, how your
page file is implemented (which depends on your OS), the phase of the
moon, and what you had for breakfast three weeks ago.

ChrisA

[toc] | [prev] | [next] | [standalone]


#84136

FromAndré Roberge <andre.roberge@gmail.com>
Date2015-01-21 10:34 -0800
Message-ID<5a29c139-9cec-4638-86af-353c1f2be447@googlegroups.com>
In reply to#83878
On Friday, 16 January 2015 11:04:20 UTC-4, Chris Angelico  wrote:
> Scenario: You're introducing someone to Python for the first time.
> S/he may have some previous programming experience, or may be new to
> the whole idea of giving a computer instructions. You have a couple of
> minutes to show off how awesome Python is. What do you do?
> 
> I was thinking along the lines of a simple demo in the REPL, showing
> off some of Python's coolest features. But then I got stuck on the
> specifics. What are Python's best coolnesses? What makes for a good
> demo?
> 
> Ideally, this should be something that can be demo'd quickly and
> easily, and it should be impressive without going into great details
> of "and see, this is how it works on the inside". So, how would you
> brag about this language?
> 
> ChrisA
If you are willing to install an older version of Python (because the program I am going to mention has not been updated in years ... but it *should* work with 2.6), I'm going to suggest an odd one:  Crunchy!  (ok, I'm biased :-).

The home page is at https://code.google.com/p/crunchy/ where you can find a link to some screencasts (based on an even older version ...)   So, before you install anything, just have a quick look at the screencast to see if it's worthwhile.

A demo using Crunchy seems to  be even more impressive if the person knows some programming.

(Here is what was said about an even older version of Crunchy by people at the Omaha Python group: " Jeff gave a presentation on Crunchy ([WWW]
http://crunchy.sourceforge.net/) Talk about a gee whiz app."  [https://mail.python.org/pipermail/omaha/2007-July/000065.html])

In a nutshell, I would open the official Python tutorial in my browser, showing the official Python tutorial.   (boring)

Then, I would open the exact same page using a browser tab served by Crunchy: "magically" some text-input boxes would have been inserted allowing you to try out the code in the REPL provided by Crunchy.  Then I'd use Crunchy to launch an external app (perhaps a tkinter program), etc.

As I said at the beginning, Crunchy has not been updated in *years* ... more or less since the IPython and Sage notebooks came along...

André

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web