Re: Best Scripting Language for Embedded Work?

2013-07-10 Thread Christian Gollwitzer

Hi David,

you have multi-posted this to comp.lang.tcl. Please don't do that - use 
crossposting and a proper follow-up (as I did now)


Am 10.07.13 03:29, schrieb David T. Ashley:

We develop embedded software for 32-bit micros using Windows as the
development platform.


Robert's answer made me hesitate - what exactly is your platform? Are 
you writing the scripts for the embedded platform, or for Windows, or 
does the embedded controller run Windows RT or something like this?



We are seeking a general purpose scripting language to automate
certain tasks, like cleaning out certain directories of certain types
of files in preparation for ZIP'ing, generating certain source files
automatically, etc.

Selection criteria:

a)Should be able to compile the script interpreter as a monolithic
executable (no .DLL dependencies, etc.) for easy versioning and
distribution of the script interpreter.  (Note that I'm not asking
that the script be a single executable, just the interpreter.  To run
a script you'd need both the script and the interpreter.  The script
would be a text file, and the interpreter would be a single .EXE.)


You are referring to tclkits. Yes, it's indeed possible to compile Tcl 
into a statically linked binary, and C extension packages can be 
statically linked, too. But tclkits are cheating: There are some files 
like the standard library (i.e. init.tcl, the clock command etc., 
unicode encondings...) which are packed into a database and attached to 
the tclkit. The tclkit then opens itself via the file system to read 
these files. I don't know if this is possible in a typical embedded 
system. If you are really talking about Windows, no issue.


Python has similar capabilities, look for pyinstaller or py2exe.


b)Should be extensible, in that one could add commands or library
functions to the script interpreter in C (for efficiency), and the
whole script interpreter could again consist of a single executable
with no other dependencies.  (Note that I'm not asking that the script
be a single executable, just the interpreter.  To run a script you'd
need both the script and the interpreter.  The script would be a text
file, and the interpreter would be a single .EXE.)


That is possible in Tcl using static packages. In Python I don't know, 
but I think it should be possible.



c)Should be able to spawn compilers and capture the output, do file
I/O, and all the other minor expected stuff.


no real issue

d)Graphical capability would be nice.


For GUI Python relies on either Tcl/Tk, wxwidgets, QT, GTK... I think it 
is possible to assemble these into a packaged binary, too. However it 
will be a rather large thing in the end.



I know that Tcl/Tk would do all of the above, but what about Python?
Any other alternatives?


I think Tcl/Tk is a really good match, especially if you are trying to 
do GUI, which is very easy there. Also most scripting stuff is available 
out of the box. Another option might be Lua


http://www.lua.org/

Very compact (a static binary is about ~200K), clean synatx, relatively 
fast. OTOH, the standard library is of course not so extensive as for 
Tcl or Python.


Bash is also an option, because it is some kind of standard for 
scripting. But on Windows it seems alien and you'd need something like 
MobaXTerm to get it into a single file.


Christian

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


Re: Best Scripting Language for Embedded Work?

2013-07-10 Thread Stefan Behnel
Christian Gollwitzer, 10.07.2013 09:03:
> http://www.lua.org/
> 
> Very compact (a static binary is about ~200K), clean synatx, relatively
> fast. OTOH, the standard library is of course not so extensive as for Tcl
> or Python.

"not so extensive" is a rather bold understatement. ISTM that most projects
that use Lua build their own eco-system around it, or integrate Lua into
their existing eco-system, with the obvious drawbacks for code reuse across
different projects and user bases.

Stefan


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


Re: crack a router passcode

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 6:59 AM, Dave Angel  wrote:
> On 07/09/2013 12:06 PM, Ferrous Cranus wrote:
>
>  
>
>>>
>> What is the reason of a spambot? Spam a usenet forum to gain what?
>>
>
> Spam is unsolicited advertising.  A bot is a robot, or other automated
> device.  So Spambots on a usenet newsgroup send apparently innocent
> questions that also contain links to their websites, or the trash they're
> pushing.  Somebody here claimed that the trash got stripped from the message
> before it went out to us.

Yeah. The bottom of the original message had these words: "used
computers in chennai". The most likely reason for that is that there
was an  around that, which got stripped at some point (maybe
the post got converted from HTML to plain text somewhere). So these
postings are being approximately useless, and will hopefully
eventually stop.

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


Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
A moderator who calls himself “animuson” on Stack Overflow doesn’t
want to face the truth. He has deleted all my postings regarding Python
regular expression matching being extremely slow compared to Perl.
Additionally my account has been suspended for 7 days. Such a dickwad.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-10 Thread Xue Fuqiao
On Mon, Jul 8, 2013 at 2:54 PM, Giorgos Tzampanakis
 wrote:
> On 2013-07-06, Skip Montanaro wrote:
>> * movement between the mouse and the keyboard
>
> Avoid at all costs. Use an editor that never needs the mouse (emacs or
> vim).

I don't use vim often, but for Emacs, I think mouse is often needed:

* It is especially handy for selecting and deleting text.
* Mouse wheel gives you fine control.  You can scroll by a few lines,
  but scroll-{up, down}-command can't.  For programmers working on
  source code, this is especially nice.
* There is mouse3.el[fn:1], which is very convenient.

Footnotes:

[fn:1] http://www.emacswiki.org/emacs/mouse3.el

--
Best regards, Xue Fuqiao.
http://www.gnu.org/software/emacs/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with 'self' and 'set_usage'

2013-07-10 Thread L O'Shea
On Tuesday, 9 July 2013 18:03:41 UTC+1, L O'Shea  wrote:
> Hi all,
> 
> I'm interning and have been given the job of extending a program that has 
> been written by someone else. I've never used Python before so it's a bit of 
> a struggle but I've got to say I'm loving the language so far.
> 
> 
> 
> In on of the scripts there is
> 
> 
> 
> def set_usage(self,s):
> 
> self.usage_str = s
> 
> 
> 
> Could anyone shed some light on this? I can't find mention of this anywhere 
> in any Python documentation or anywhere else in the code where usage_str 
> might be defined. Can you just create variables in that object by writing 
> self.name = "david" self.hobby = "fishing"??
> 
> 
> 
> If this is any help it is used later in the program (or in other scripts) like
> 
> 
> 
> prog.set_usage("""%prog  [options] """)
> 
> 
> 
> Thanks for your help, I have spent a good while googling python docs, code 
> snippets and reading through a Python book I have on my desk to no avail.
> 
> 
> 
> Cheers in advance.

Thanks for the advice everyone that was really helpful! Gotta love the USA/UK 
time difference I can post a question here at the end of the day and it be 
answered by morning - Not that it took any of you very long!
Stay tuned for more Python questions :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
> A moderator who calls himself “animuson” on Stack Overflow doesn’t
> want to face the truth. He has deleted all my postings regarding Python
> regular expression matching being extremely slow compared to Perl.
> Additionally my account has been suspended for 7 days. Such a dickwad.

And this matters... how? What are we supposed to do about it? We are
not the Python Secret Underground, which emphatically does not exist.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:

> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>> to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>> Additionally my account has been suspended for 7 days. Such a dickwad.
> 
> And this matters... how? What are we supposed to do about it? We are not
> the Python Secret Underground, which emphatically does not exist.

Of course not, because if it did 


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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>> want to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> And this matters... how? What are we supposed to do about it? We are
> not the Python Secret Underground, which emphatically does not exist.
>
> ChrisA

You aren’t supposed to do squat about it. I just wanted to mention it
to the Python evangelists, who need to see the light.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 6:32 PM, Mats Peterson  wrote:
> Chris Angelico  wrote:
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>> want to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are
>> not the Python Secret Underground, which emphatically does not exist.
>>
>> ChrisA
>
> You aren’t supposed to do squat about it. I just wanted to mention it
> to the Python evangelists, who need to see the light.

Your post hits me squarely between the eyes, leaving an "Uhh?"-shaped hole.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Steven D'Aprano  wrote:
> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>>> to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are not
>> the Python Secret Underground, which emphatically does not exist.
>
> Of course not, because if it did 

Because if it did what? :p

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson  wrote:
> Steven D'Aprano  wrote:
>> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>>
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
 A moderator who calls himself “animuson” on Stack Overflow doesn’t want
 to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.
 Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are not
>>> the Python Secret Underground, which emphatically does not exist.
>>
>> Of course not, because if it did
>
> Because if it did what? :p

Then they would have full control of this list and what gets pos
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Babel i18n package has new maintainers

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 08:55:46 +0200, Stefan Behnel wrote:

> Hi,
> 
> I've been looking for a Python package for formatting international
> dates, numbers and monetary values 
[...]
> https://github.com/mitsuhiko/babel
>
> Since it took me quite a while to figure this out, I thought I'd post
> this here to make others aware of it.

Thanks Stefan, it's good to see informative posts about Python packages. 
I personally don't need it, but I'll keep it in mind for the future.


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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>> want to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> And this matters... how? What are we supposed to do about it? We are
> not the Python Secret Underground, which emphatically does not exist.
>
> ChrisA

I fear you don’t even know what a regular expression is. Then this of
course won’t affect you whatsoever.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-10 Thread wxjmfauth
For those who are interested. The official proposal request
for the encoding of the Latin uppercase letter Sharp S in
ISO/IEC 10646; DIN (The German Institute for Standardization)
proposal is available on the web. A pdf with the rationale.
I do not remember from where I got it, probably from a German
web site.

Fonts:
I'm observing the inclusion of this glyph since years. More
and more fonts are supporting it. Available in many fonts,
it is suprisingly not available in Cambria (at least the version
I'm using). STIX does not includes it, it has been requested. Ditto,
for the Latin Modern, the default bundle of fonts for the Unicode
TeX engines.

Last but not least, Python.
Thanks to the Flexible String Representation, it is not
necessary to mention the disastrous, erratic behaviour of
Python, when processing text containing it. It's more than
clear, a serious user willing to process the contain of
'DER GROẞE DUDEN' (a reference German dictionary) will be
better served by using something else.

The irony is that this Flexible String Representation has
been created by a German.

jmf

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:32 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
 A moderator who calls himself “animuson” on Stack Overflow doesn’t
 want to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.
 Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> You aren’t supposed to do squat about it. I just wanted to mention it
>> to the Python evangelists, who need to see the light.
>
> Your post hits me squarely between the eyes, leaving an "Uhh?"-shaped hole.
>
> ChrisA

I fear you don’t even know what a regular expression is. Then this will
of course not affect you.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson  wrote:
>> Steven D'Aprano  wrote:
>>> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>>>
 On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
> to face the truth. He has deleted all my postings regarding Python
> regular expression matching being extremely slow compared to Perl.
> Additionally my account has been suspended for 7 days. Such a dickwad.

 And this matters... how? What are we supposed to do about it? We are not
 the Python Secret Underground, which emphatically does not exist.
>>>
>>> Of course not, because if it did
>>
>> Because if it did what? :p
>
> Then they would have full control of this list and what gets pos

Ahhh so this is pos, right? Telling the truth? Interesting.

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson  wrote:
>> Steven D'Aprano  wrote:
>>> On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
>>>
 On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
> to face the truth. He has deleted all my postings regarding Python
> regular expression matching being extremely slow compared to Perl.
> Additionally my account has been suspended for 7 days. Such a dickwad.

 And this matters... how? What are we supposed to do about it? We are not
 the Python Secret Underground, which emphatically does not exist.
>>>
>>> Of course not, because if it did
>>
>> Because if it did what? :p
>
> Then they would have full control of this list and what gets pos

Have you ever compared the regular expression performance between Perl
and Python? If not, keep quiet.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:32 AM, Mats Peterson  wrote:
> Chris Angelico  wrote:
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>> want to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are
>> not the Python Secret Underground, which emphatically does not exist.
>>
>> ChrisA
>
> You aren’t supposed to do squat about it. I just wanted to mention it
> to the Python evangelists, who need to see the light.

It's well known that regular expressions are slow.  I wouldn't know
how they compare to Perl, which I don't use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:

> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
> to face the truth. He has deleted all my postings regarding Python
> regular expression matching being extremely slow compared to Perl.

That's by design. We don't want to make the same mistake as Perl, where 
every problem is solved by a regular expression:

http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/

so we deliberately make regexes as slow as possible so that programmers 
will look for a better way to solve their problem. If you check the 
source code for the re engine, you'll find that for certain regexes, it 
busy-waits for anything up to 30 seconds at a time, deliberately wasting 
cycles.

The same with Unicode. We hate French people, you see, and so in an 
effort to drive everyone back to ASCII-only text, Python 3.3 introduces 
some memory optimizations that ensures that Unicode strings work 
correctly and are up to four times smaller than they used to be. You 
should get together with jmfauth, who has discovered our dastardly plot 
and keeps posting benchmarks showing how on carefully contrived micro-
benchmarks using a beta version of Python 3.3, non-ASCII string 
operations can be marginally slower than in 3.2.


> Additionally my account has been suspended for 7 days. Such a dickwad.

I cannot imagine why he would have done that.


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


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Russel Walker
I didn't do a good job of explaining it cos I didn't want it to be a TLDR; but 
I could've added a little more. To clarify:

Expr is just a way to represent simple arithmetic expressions for a calculator. 
Because the expression has to be modified and built over time, and evaluated 
from left to right and not by operator precedence, I thought it would be 
simpler to do it this way.

Say the calculation in the calculator is currently at:
1 + 2 * 3

Now lets expand it out to see how it gets to this point.

dial 1: (1) >>> x = Expr(1) # the base case
dial +: ((1) + )>>> x = Expr(x, '+')
dial 2: ((1) + 2)   >>> x.val = 2
dial *: (((1) + 2) + )  >>> x = Expr(x, '+')
dial 3: (((1) + 2) + 3) >>> x.val = 3

I think it's called 'binary tree' but not entirely sure if that's correct.


So I think understand what you guys are saying now.

There is the name x and the class instance (the object) which exists somewhere 
in memory that x points to. self is just another name that points to the same 
object (not self in general but the argument passed to the self parameter when 
a method is called). However if the code inside the method reassigns self to 
some other object, it doesn't change the fact that x still refers to the 
original object. So self is just a local variable (an argument). The name self 
has no relevance to to the name x other than the fact that they point to the 
same object. So reassigning self has no effect on x. But modifying the object 
that self points to, does affect x because it points to the same object. Is 
this correct?


So when you call x.somemethod() it's not passing x as the self argument, it's 
actually passing the object that x points to as the self argument. And that 
object has know knowledge of the fact that x points to it, or does it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 6:42 PM, Mats Peterson  wrote:
> Chris Angelico  wrote:
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>> want to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are
>> not the Python Secret Underground, which emphatically does not exist.
>>
>> ChrisA
>
> I fear you don’t even know what a regular expression is. Then this of
> course won’t affect you whatsoever.

I know what regular expressions are. I've used them in Perl, PHP,
JavaScript, Python, C++, Pike, and numerous text editors (which may
have been backed by one of the above languages, or may have been
something else). Doesn't change the fact that I have no idea what the
significance is of your post.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:42 AM, Mats Peterson  wrote:
> Chris Angelico  wrote:
>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>> want to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> And this matters... how? What are we supposed to do about it? We are
>> not the Python Secret Underground, which emphatically does not exist.
>>
>> ChrisA
>
> I fear you don’t even know what a regular expression is. Then this of
> course won’t affect you whatsoever.

Troll.  A quick search of my Gmail archives turns up 18 threads in
which Chris has used the phrase "regular expression".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Russel Walker
On Wednesday, July 10, 2013 12:20:47 AM UTC+2, Ian wrote:
> On Tue, Jul 9, 2013 at 4:18 PM, Ian Kelly  wrote:
> 
> > If you actually want to modify the current object, you would need to
> 
> > do something like:
> 
> >
> 
> > def expand(self):
> 
> > import copy
> 
> > self.expr = Expr(self.expr, self.op, self.val)
> 
> > self.op = choice('+-*/')
> 
> > self.val = choice('12345')
> 
> 
> 
> Minus the "import copy".  I modified the code before sending and
> 
> forgot to remove that.

Yes! This is exactly it. Thanks :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 6:42 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
 A moderator who calls himself “animuson” on Stack Overflow doesn’t
 want to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.
 Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> I fear you don’t even know what a regular expression is. Then this of
>> course won’t affect you whatsoever.
>
> I know what regular expressions are. I've used them in Perl, PHP,
> JavaScript, Python, C++, Pike, and numerous text editors (which may
> have been backed by one of the above languages, or may have been
> something else). Doesn't change the fact that I have no idea what the
> significance is of your post.
>
> ChrisA

You do? And you haven't noticed the inferior performance of regular
expressions in Python compared to Perl? Then you obviously haven't
used them a lot.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 2:42 AM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> On Wed, Jul 10, 2013 at 5:55 PM, Mats Peterson  wrote:
 A moderator who calls himself “animuson” on Stack Overflow doesn’t
 want to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.
 Additionally my account has been suspended for 7 days. Such a dickwad.
>>>
>>> And this matters... how? What are we supposed to do about it? We are
>>> not the Python Secret Underground, which emphatically does not exist.
>>>
>>> ChrisA
>>
>> I fear you don’t even know what a regular expression is. Then this of
>> course won’t affect you whatsoever.
>
> Troll.  A quick search of my Gmail archives turns up 18 threads in
> which Chris has used the phrase "regular expression".

Not a troll. It's just hard to convince Python users that their beloved
language would have inferior regular expression performance to Perl.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:
>> Then they would have full control of this list and what gets pos
>
> Ahhh so this is pos, right? Telling the truth? Interesting.

I don't know what you mean by that, but since the joke appears to have
flown over your head, I'll explain it.  Steven's "pos" was clearly
meant to be the word "posted", before his sentence got cut off by the
Python Secret Underground.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:
>>> Then they would have full control of this list and what gets pos
>>
>> Ahhh so this is pos, right? Telling the truth? Interesting.
>
> I don't know what you mean by that, but since the joke appears to have
> flown over your head, I'll explain it.  Steven's "pos" was clearly
> meant to be the word "posted", before his sentence got cut off by the
> Python Secret Underground.

Being snotty, are we?

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 7:01 PM, Mats Peterson  wrote:
> Chris Angelico  wrote:
>> I know what regular expressions are. I've used them in Perl, PHP,
>> JavaScript, Python, C++, Pike, and numerous text editors (which may
>> have been backed by one of the above languages, or may have been
>> something else). Doesn't change the fact that I have no idea what the
>> significance is of your post.
>>
>> ChrisA
>
> You do? And you haven't noticed the inferior performance of regular
> expressions in Python compared to Perl? Then you obviously haven't
> used them a lot.

That would be correct. Why have I not used them all that much? Because
Python has way better ways of doing many things. Regexps are
notoriously hard to debug, largely because a nonmatching regex can't
give much information about _where_ it failed to match, and when I
parse strings, it's more often with (s)scanf notation instead - stuff
like this (Pike example as Python doesn't, afaik, have scanf support):

> data="Hello, world! I am number 42.";
> sscanf(data,"Hello, %s! I am number %d.",foo,x);
(3) Result: 2
> foo;
(4) Result: "world"
> x;
(5) Result: 42

Or a more complicated example:

sscanf(Stdio.File("/proc/meminfo")->read(),"%{%s: %d%*s\n%}",array data);
mapping meminfo=(mapping)data;

That builds up a mapping (Pike terminology for what Python calls a
dict) with the important information out of /proc/meminfo, something
like this:

([
  "MemTotal": 2026144,
  "MemFree": 627652,
  "Buffers": 183572,
  "Cached": 380724,
  . etc etc
])

So, no. I haven't figured out that Perl's regular expressions
outperform Python's or Pike's or SciTE's, because I simply don't need
them all that much. With sscanf, I can at least get a partial match,
which tells me where to look for the problem.

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


WiFi problems with iPhone 4

2013-07-10 Thread oswaldclem
Hi, I have Been looking into it and I can't find anything. My son's iPhone 4
( iOS 6), according to him, is on and off from our wifi all by itself.

Basically, when hé goes on YouTube before 8 am it is on 3G, even if we have
wifi on. And the signal is strong enough. Is there a setting That he could
have used, unknowingly or not, That can do this? 



-
used iphone 
--
View this message in context: 
http://python.6.x6.nabble.com/WiFi-problems-with-iPhone-4-tp5024342.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 6:50 PM, Mats Peterson  wrote:
> Have you ever compared the regular expression performance between Perl
> and Python? If not, keep quiet.

I think I can see why you were suspended.

You and jmf should have a lot of fun together, I think.

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


Buying a used iPhone 5

2013-07-10 Thread oswaldclem
I'm planning on buying a used ATT iPhone 5 off of craigslist, and i've been
reading on how some people sell their iPhones to people and later on
blacklisting it, screwing the buyer over, or how people are mistakenly
buying already blacklisted iPhones. I was wondering if there's a way I can
prevent this? I was thinking of meeting at an ATT store to make sure it's
not blacklisted and to make sure it's not connected to any account that
could black list it. Would that be a good idea? 



-
used iphone 
--
View this message in context: 
http://python.6.x6.nabble.com/Buying-a-used-iPhone-5-tp5024345.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 10:12, Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:
>>> Then they would have full control of this list and what gets pos
>>
>> Ahhh so this is pos, right? Telling the truth? Interesting.
>
> I don't know what you mean by that, but since the joke appears to have
> flown over your head, I'll explain it.  Steven's "pos" was clearly
> mea

What? I don't understand.
-- 
http://mail.python.org/mailman/listinfo/python-list


iTunes not detecting iPhone

2013-07-10 Thread oswaldclem
I just received a used iPhone I purchased on Amazon. I took the phone out of
the box and turned it on. The Apple logo appeared, then a "connect to
iTunes" screen appeared, with the text "No SIM card installed" over the
connect to iTunes graphic.

I installed my SIM (which I know works, as I just pulled it from my other
iPhone), but have a very weak signal... but that's not my issue right now.
After putting in my SIM, I connect my cable to my PC and opened iTunes. Then
I connected the new iPhone to the cable and waited for iTunes to detect it.
Nothing. I tried shutting down iTunes and restarting, shutting down and
restarting the phone... still nothing.



-
used iphone 
--
View this message in context: 
http://python.6.x6.nabble.com/iTunes-not-detecting-iPhone-tp5024343.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Iphone 3gs Problem

2013-07-10 Thread oswaldclem
I have a problem with my iPhone 3gs,

It was Jailbreaked with cydia and then one day it stoped working, all it
says is connect to itunes, and when I connect it to Itunes it say restore
iphone, when I do that it get stuck on waiting for iphone, it have been
stuck on that for 6 hours without doing anything so I dont know what to do!
I realy need help please!



-
used iphone 
--
View this message in context: 
http://python.6.x6.nabble.com/Iphone-3gs-Problem-tp5024344.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Robert Kern

On 2013-07-10 10:52, Joshua Landau wrote:

On 10 July 2013 10:12, Ian Kelly  wrote:

On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:

Then they would have full control of this list and what gets pos


Ahhh so this is pos, right? Telling the truth? Interesting.


I don't know what you mean by that, but since the joke appears to have
flown over your head, I'll explain it.  Steven's "pos" was clearly
mea


What? I don't understand.


Look, it's perfectly obvi

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 08:55, Mats Peterson  wrote:
> . [anumuson from Stack Overflow] has deleted all
> my postings regarding Python regular expression matching being
> extremely slow compared to Perl. Additionally my account has been
> suspended for 7 days. .

Whilst I don't normally respond to trolls, I'm actually curious.

Do you have any non-trivial, properly benchmarked real-world examples
that this affects, remembering to use full Unicode support in Perl (as
Python has it by default)?

Remember to try on both major CPython versions, and PyPy -- all of
which are in large-scale usage. Remember not just to use the builtin
re module, as most people also use https://pypi.python.org/pypi/regex
and https://code.google.com/p/re2/ when they are appropriate, so
pathological cases for re aren't actually a concern anyone cares
about.

If you actually can satisfy these basic standards for a comparison (as
I'm sure any competent person with so much bravo could) I'd be willing
to converse with you. I'd like to see these results where Python compares
as "extremely slow". Note that, by your own wording, a 30% drop is irrelevant.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Antoon Pardon
Op 10-07-13 11:03, Mats Peterson schreef:
> Not a troll. It's just hard to convince Python users that their beloved
> language would have inferior regular expression performance to Perl.

All right, you have convinced me. Now what? Why should I care?

-- 
Antoon Pardon

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
Google Groups is writing about your recently sent mail to "Joshua
Landau". Unfortunately this address has been discontinued from usage
for the foreseeable future. The sent message is displayed below:

On 10 July 2013 12:08, Robert Kern  wrote:
>
> On 2013-07-10 10:52, Joshua Landau wrote:
>>
>>
>> On 10 July 2013 10:12, Ian Kelly  wrote:
>>>
>>>
>>>
>>>
>>> On Wed, Jul 10, 2013 at 2:46 AM, Mats Peterson  wrote:
>
>
> Then they would have full control of this list and what gets pos
>




 Ahhh so this is pos, right? Telling the truth? Interesting.

>>>
>>>
>>>
>>>
>>> I don't know what you mean by that, but since the joke appears to have
>>>
>>> flown over your head, I'll explain it.  Steven's "pos" was clearly
>>>
>>> mea
>>>
>>
>>
>>
>>
>> What? I don't understand.
>>
>
>
>
>
> Look, it's perfectly obvi
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Steve Simmons
Steven D'Aprano  wrote:

>On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>want
>> to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>
>That's by design. We don't want to make the same mistake as Perl, where
>
>every problem is solved by a regular expression:
>
>http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>
>so we deliberately make regexes as slow as possible so that programmers
>
>will look for a better way to solve their problem. If you check the 
>source code for the re engine, you'll find that for certain regexes, it
>
>busy-waits for anything up to 30 seconds at a time, deliberately
>wasting 
>cycles.
>
>The same with Unicode. We hate French people, you see, and so in an 
>effort to drive everyone back to ASCII-only text, Python 3.3 introduces
>
>some memory optimizations that ensures that Unicode strings work 
>correctly and are up to four times smaller than they used to be. You 
>should get together with jmfauth, who has discovered our dastardly plot
>
>and keeps posting benchmarks showing how on carefully contrived micro-
>benchmarks using a beta version of Python 3.3, non-ASCII string 
>operations can be marginally slower than in 3.2.
>
>
>> Additionally my account has been suspended for 7 days. Such a
>dickwad.
>
>I cannot imagine why he would have done that.
>
>
>-- 
>Steven
>-- 
>http://mail.python.org/mailman/listinfo/python-list

:-)  Thank you.

Sent from a Galaxy far far away-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Skip Montanaro
> ... meant to be the word "posted", before his sentence got cut off by the
> Python Secret Underground.

Argh! That which shall not be named!  Please, for the sake of all that
is right, please only use the initials, PS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Benedict Verheyen
Op Wed, 10 Jul 2013 12:12:10 +0100, schreef Joshua Landau:


> 
> Do you have any non-trivial, properly benchmarked real-world examples
> that this affects, remembering to use full Unicode support in Perl (as
> Python has it by default)?
> 

Indeed, as Joshua says, instead of going through all the effort to talk 
about it, why don't you show us that Python is slower in regexs than perl.
That's at least relevant bandwdith.

Next, if Python is slower, there might be ways to improve the performance.

Last, if there is a SPU (Secret Python Underground), I want to j


-- 
Benedict Verheyen   Debian, Python and Django user
GnuPG Public Key 0x712CBB8D

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Antoon Pardon  wrote:
> Op 10-07-13 11:03, Mats Peterson schreef:
>> Not a troll. It's just hard to convince Python users that their beloved
>> language would have inferior regular expression performance to Perl.
>
> All right, you have convinced me. Now what? Why should I care?
>

Right. Why should you. And who cares about you?

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 13:01, Mats Peterson  wrote:
> Antoon Pardon  wrote:
>> Op 10-07-13 11:03, Mats Peterson schreef:
>>> Not a troll. It's just hard to convince Python users that their beloved
>>> language would have inferior regular expression performance to Perl.
>>
>> All right, you have convinced me. Now what? Why should I care?
>>
>
> Right. Why should you. And who cares about you?

Not the Python Se
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Joshua Landau  wrote:
> On 10 July 2013 08:55, Mats Peterson  wrote:
>> . [anumuson from Stack Overflow] has deleted all
>> my postings regarding Python regular expression matching being
>> extremely slow compared to Perl. Additionally my account has been
>> suspended for 7 days. .
>
> Whilst I don't normally respond to trolls, I'm actually curious.
>
> Do you have any non-trivial, properly benchmarked real-world examples
> that this affects, remembering to use full Unicode support in Perl (as
> Python has it by default)?
>
> Remember to try on both major CPython versions, and PyPy -- all of
> which are in large-scale usage. Remember not just to use the builtin
> re module, as most people also use https://pypi.python.org/pypi/regex
> and https://code.google.com/p/re2/ when they are appropriate, so
> pathological cases for re aren't actually a concern anyone cares
> about.
>
> If you actually can satisfy these basic standards for a comparison (as
> I'm sure any competent person with so much bravo could) I'd be willing
> to converse with you. I'd like to see these results where Python compares
> as "extremely slow". Note that, by your own wording, a 30% drop is irrelevant.

I haven't provided a "real-world" example, since I expect you Python
Einsteins to be able do an A/B test between Python and Perl yourselves 
(provided you know Perl, of course, which I'm afraid is not always the
case). And why would I use any "custom" version of Python, when I don't
have to do that with Perl?

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Steven D'Aprano  wrote:
> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>> to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>
> That's by design. We don't want to make the same mistake as Perl, where 
> every problem is solved by a regular expression:
>
> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>
> so we deliberately make regexes as slow as possible so that programmers 
> will look for a better way to solve their problem. If you check the 
> source code for the re engine, you'll find that for certain regexes, it 
> busy-waits for anything up to 30 seconds at a time, deliberately wasting 
> cycles.
>
> The same with Unicode. We hate French people, you see, and so in an 
> effort to drive everyone back to ASCII-only text, Python 3.3 introduces 
> some memory optimizations that ensures that Unicode strings work 
> correctly and are up to four times smaller than they used to be. You 
> should get together with jmfauth, who has discovered our dastardly plot 
> and keeps posting benchmarks showing how on carefully contrived micro-
> benchmarks using a beta version of Python 3.3, non-ASCII string 
> operations can be marginally slower than in 3.2.
>
>
>> Additionally my account has been suspended for 7 days. Such a dickwad.
>
> I cannot imagine why he would have done that.
>
>

You're obviously trying hard to be funny. It fails miserably.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Chris Angelico
On Wed, Jul 10, 2013 at 10:13 PM, Mats Peterson  wrote:
> Steven D'Aprano  wrote:
>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>>
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>>> to face the truth. He has deleted all my postings regarding Python
>>> regular expression matching being extremely slow compared to Perl.
>>
>> That's by design. We don't want to make the same mistake as Perl, where
>> every problem is solved by a regular expression:
>>
>> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>>
>> so we deliberately make regexes as slow as possible so that programmers
>> will look for a better way to solve their problem. If you check the
>> source code for the re engine, you'll find that for certain regexes, it
>> busy-waits for anything up to 30 seconds at a time, deliberately wasting
>> cycles.
>>
>> The same with Unicode. We hate French people, you see, and so in an
>> effort to drive everyone back to ASCII-only text, Python 3.3 introduces
>> some memory optimizations that ensures that Unicode strings work
>> correctly and are up to four times smaller than they used to be. You
>> should get together with jmfauth, who has discovered our dastardly plot
>> and keeps posting benchmarks showing how on carefully contrived micro-
>> benchmarks using a beta version of Python 3.3, non-ASCII string
>> operations can be marginally slower than in 3.2.
>>
>>
>>> Additionally my account has been suspended for 7 days. Such a dickwad.
>>
>> I cannot imagine why he would have done that.
>>
>>
>
> You're obviously trying hard to be funny. It fails miserably.

Either that or it's funny only to other Australians.

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


Turn off Genius on iPhone

2013-07-10 Thread oswaldclem
How do I turn off the genius button on the iPhone ? I keep hitting it
whenever I want to scrub to the middle of through a song. It's pretty
annoying. 



-
used iphone 
--
View this message in context: 
http://python.6.x6.nabble.com/Turn-off-Genius-on-iPhone-tp5024341.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 12:14, Antoon Pardon  wrote:
> Op 10-07-13 11:03, Mats Peterson schreef:
>> Not a troll. It's just hard to convince Python users that their beloved
>> language would have inferior regular expression performance to Perl.
>
> All right, you have convinced me. Now what? Why should I care?

Isn't it obvious? Regex-based macros!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Mats Peterson
Chris Angelico  wrote:
> On Wed, Jul 10, 2013 at 7:01 PM, Mats Peterson  wrote:
>> Chris Angelico  wrote:
>>> I know what regular expressions are. I've used them in Perl, PHP,
>>> JavaScript, Python, C++, Pike, and numerous text editors (which may
>>> have been backed by one of the above languages, or may have been
>>> something else). Doesn't change the fact that I have no idea what the
>>> significance is of your post.
>>>
>>> ChrisA
>>
>> You do? And you haven't noticed the inferior performance of regular
>> expressions in Python compared to Perl? Then you obviously haven't
>> used them a lot.
>
> That would be correct. Why have I not used them all that much? Because
> Python has way better ways of doing many things. Regexps are
> notoriously hard to debug, largely because a nonmatching regex can't
> give much information about _where_ it failed to match, and when I
> parse strings, it's more often with (s)scanf notation instead - stuff
> like this (Pike example as Python doesn't, afaik, have scanf support):
>
>> data="Hello, world! I am number 42.";
>> sscanf(data,"Hello, %s! I am number %d.",foo,x);
> (3) Result: 2
>> foo;
> (4) Result: "world"
>> x;
> (5) Result: 42
>
> Or a more complicated example:
>
> sscanf(Stdio.File("/proc/meminfo")->read(),"%{%s: %d%*s\n%}",array data);
> mapping meminfo=(mapping)data;
>
> That builds up a mapping (Pike terminology for what Python calls a
> dict) with the important information out of /proc/meminfo, something
> like this:
>
> ([
>   "MemTotal": 2026144,
>   "MemFree": 627652,
>   "Buffers": 183572,
>   "Cached": 380724,
>   . etc etc
> ])
>
> So, no. I haven't figured out that Perl's regular expressions
> outperform Python's or Pike's or SciTE's, because I simply don't need
> them all that much. With sscanf, I can at least get a partial match,
> which tells me where to look for the problem.
>
> ChrisA

You're showing by these examples what regular expressions mean to you.

Mats

-- 
Mats Peterson
http://alicja.homelinux.com/~mats/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Skip Montanaro
> Either that or it's funny only to other Australians.

Or the Dutch.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Paul Scott

On 10/07/2013 14:22, Chris Angelico wrote:
Either that or it's funny only to other Australians. ChrisA 


As a South African, I found it funny too, but then again, we often get 
confused.


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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 13:35, Skip Montanaro  wrote:
>> Either that or it's funny only to other Australians.
>
> Or the Dutch.

Or us Brits.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Skip Montanaro
On Wed, Jul 10, 2013 at 7:39 AM, Joshua Landau  wrote:
> On 10 July 2013 13:35, Skip Montanaro  wrote:
>>> Either that or it's funny only to other Australians.
>>
>> Or the Dutch.
>
> Or us Brits.

Hells bells...  It appears everyone found it funny except the trolls.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Benedict Verheyen
Op Wed, 10 Jul 2013 12:06:06 +, schreef Mats Peterson:

> I haven't provided a "real-world" example, since I expect you Python
> Einsteins to be able do an A/B test between Python and Perl yourselves
> (provided you know Perl, of course, which I'm afraid is not always the
> case). 

I don't know perl so I can't compare.

> And why would I use any "custom" version of Python, when I don't
> have to do that with Perl?

If you're able to do that with Perl, and Perl is faster that Python,
why would you want to bother with Python?
Seems like you already have a fast alternative you like.

-- 
Benedict Verheyen   Debian, Python and Django user
GnuPG Public Key 0x712CBB8D

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


Prime number generator

2013-07-10 Thread Chris Angelico
And now for something completely different.

I knocked together a prime number generator, just for the fun of it,
that works like a Sieve of Eratosthenes but unbounded. It keeps track
of all known primes and the "next composite" that it will produce -
for instance, after yielding 13, the prime map will be {2: 20, 3: 18,
5: 20, 7: 21, 11: 22, 13: 26}, each one mapped to the first multiple
greater than 13.

Notable in the algorithm is an entire lack of division, or even
multiplication. Everything is done with addition.

So, a few questions. Firstly, is there a stdlib way to find the key
with the lowest corresponding value? In the above map, it would return
3, because 18 is the lowest value in the list. I want to do this with
a single pass over the dictionary. Secondly, can the "while
ihttp://mail.python.org/mailman/listinfo/python-list


Re: Buying a used iPhone 5

2013-07-10 Thread Rodrick Brown
Die


On Wed, Jul 10, 2013 at 6:49 AM, oswaldclem  wrote:

> I'm planning on buying a used ATT iPhone 5 off of craigslist, and i've been
> reading on how some people sell their iPhones to people and later on
> blacklisting it, screwing the buyer over, or how people are mistakenly
> buying already blacklisted iPhones. I was wondering if there's a way I can
> prevent this? I was thinking of meeting at an ATT store to make sure it's
> not blacklisted and to make sure it's not connected to any account that
> could black list it. Would that be a good idea?
>
>
>
> -
> used iphone
> --
> View this message in context:
> http://python.6.x6.nabble.com/Buying-a-used-iPhone-5-tp5024345.html
> Sent from the Python - python-list mailing list archive at Nabble.com.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best Scripting Language for Embedded Work?

2013-07-10 Thread Grant Edwards
On 2013-07-10, David T  Ashley  wrote:

> We develop embedded software for 32-bit micros using Windows as the
> development platform.
>
> We are seeking a general purpose scripting language to automate
> certain tasks, like cleaning out certain directories of certain types
> of files in preparation for ZIP'ing, generating certain source files
> automatically, etc.

That's what a command shell is for.  Since windows doesn't come with a
real one, I'd recommend installing Cygwin and then using bash, make,
etc.

Better yet.  Abandon windows and switch to an OS environment intended 
for software development rather than generating time-wasting
power-point presentations.

-- 
Grant Edwards   grant.b.edwardsYow! Look!  A ladder!
  at   Maybe it leads to heaven,
  gmail.comor a sandwich!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread memilanuk

On 07/10/2013 05:39 AM, Joshua Landau wrote:

On 10 July 2013 13:35, Skip Montanaro  wrote:

Either that or it's funny only to other Australians.


Or the Dutch.


Or us Brits.



Or the Yanks...

Normally I kill-file threads like this pretty early on, but I have to 
admit - I'm enjoying watching y'all play with the troll this time ;)


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


Re: Prime number generator

2013-07-10 Thread Bas
On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote:
[...]
> So, a few questions. Firstly, is there a stdlib way to find the key
> with the lowest corresponding value? In the above map, it would return
> 3, because 18 is the lowest value in the list. I want to do this with
> a single pass over the dictionary. 

In [1]: prime = {2: 20, 3: 18, 5: 20, 7: 21, 11: 22, 13: 26}

In [2]: smallest_key = min(prime.iteritems(), key=lambda k_v: k_v[1])[0]

In [3]: smallest_key
Out[3]: 3

Still trying to figure out your algorithm ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moder ator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 08:46:44 +, Mats Peterson wrote:

> Chris Angelico  wrote:
>> On Wed, Jul 10, 2013 at 6:33 PM, Mats Peterson 
>> wrote:
>>> Steven D'Aprano  wrote:
 On Wed, 10 Jul 2013 18:26:19 +1000, Chris Angelico wrote:
[...]
> And this matters... how? What are we supposed to do about it? We are
> not the Python Secret Underground, which emphatically does not
> exist.

 Of course not, because if it did
>>>
>>> Because if it did what? :p
>>
>> Then they would have full control of this list and what gets pos
> 
> Ahhh so this is pos, right? Telling the truth? Interesting.


Mats, I fear you have misunderstood. If the Python Secret Underground 
existed, which it most certainly does not, it would absolutely not have 
the power to censor people's emails or cut them off in the middle of



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


Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 12:35 AM, Bas  wrote:
> On Wednesday, July 10, 2013 4:00:59 PM UTC+2, Chris Angelico wrote:
> [...]
>> So, a few questions. Firstly, is there a stdlib way to find the key
>> with the lowest corresponding value? In the above map, it would return
>> 3, because 18 is the lowest value in the list. I want to do this with
>> a single pass over the dictionary.
>
> In [1]: prime = {2: 20, 3: 18, 5: 20, 7: 21, 11: 22, 13: 26}
>
> In [2]: smallest_key = min(prime.iteritems(), key=lambda k_v: k_v[1])[0]
>
> In [3]: smallest_key
> Out[3]: 3

Well, that does answer the question. Unfortunately the use of lambda
there has a severe performance cost (roughly doubles the total run
time, when I ask for the thousandth prime), without majorly improving
readability. I'll bear it in mind if there's a way to make that work
on either readability or performance, but otherwise, I'll stick with
the explicit loop. Thanks anyway!

> Still trying to figure out your algorithm ...

It's pretty simple. (That's a bad start, I know!) Like the Sieve of
Eratosthenes, it locates prime numbers, then deems every multiple of
them to be composite. Unlike the classic sieve, it does the "deem"
part in parallel. Instead of marking all the multiples of 2 first,
then picking three and marking all the multiples of 3, then 5, etc,
this function records the fact that it's up to (say) 42 in marking
multiples of 2, and then when it comes to check if 43 is prime or not,
it moves to the next multiple of 2. This requires memory to store the
previously-known primes, similarly to other methods, but needs no
multiplication or division.

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


Re: Default scope of variables

2013-07-10 Thread Ian Kelly
On Tue, Jul 9, 2013 at 11:54 PM, Frank Millman  wrote:
> You had me worried there for a moment, as that is obviously an error.
>
> Then I checked my actual code, and I find that I mis-transcribed it. It
> actually looks like this -
>
> with db_session as conn:
> db_session.transaction_active = True
> conn.cur.execute(...)
>
> I am still not quite sure what your objection is to this. It feels
> straightforward to me.
>
> Here is one possible answer. Whenever I want to commit a transaction I have
> to add the extra line. There is a danger that I could mis-spell
> 'transaction_active', in which case it would not raise an error, but would
> not commit the transaction, which could be a hard-to-trace bug. Using your
> approach, if I mis-spelled 'db_session.connect()', it would immediately
> raise an error.
>
> Is that your concern, or are there other issues?

Yes, that is one concern.  Another is that since you mistakenly typed
"conn" instead of "db_session" once, you might make the same mistake
again in actual code, with the same effect (unless the conn object
doesn't allow arbitrary attributes, which is a possibility).  Another
is that the code adheres better to the DRY principle if you don't need
to copy that line all over the place.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 15:00, Chris Angelico  wrote:
> And now for something completely different.
>
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded. It keeps track
> of all known primes and the "next composite" that it will produce -
> for instance, after yielding 13, the prime map will be {2: 20, 3: 18,
> 5: 20, 7: 21, 11: 22, 13: 26}, each one mapped to the first multiple
> greater than 13.
>
> Notable in the algorithm is an entire lack of division, or even
> multiplication. Everything is done with addition.
>
> So, a few questions. Firstly, is there a stdlib way to find the key
> with the lowest corresponding value?

Of course there is.

> In the above map, it would return
> 3, because 18 is the lowest value in the list. I want to do this with
> a single pass over the dictionary. Secondly, can the "while
> i It's almost asking for
> it, but not quite there. Thirdly, is there any sort of half-sane
> benchmark that I can compare this code to?

Of course there is. I have no clue what, though.

> And finally, whose wheel
> did I reinvent here?

Mine :P. That just proves the algorithm is older still, though. You
also did it much more neatly and much more slowly, though. The trick
is to avoid that repeated effort of finding the minimum in the dict by
just keeping a sorted list.

I've mocked that up just now:

# Faster code #
from blist import sortedlist

def generate_primes():
primes = sortedlist()
primes.add([4, 2])

yield 2
i = 3

while True:
next_nonprime, prime_factor = primes.pop(0)

for prime in range(i, next_nonprime):
yield prime
primes.add([prime*2, prime])

i = next_nonprime + 1

primes.add([next_nonprime + prime_factor, prime_factor])
# No longer code #

> What name would this algorithm have?

I'll call it "the flamingo".

> Code tested on Python 3.3, would probably run fine on pretty much any
> Python that supports yield, though I don't have a Py2.2 to test from
> __future__ import generators on!
>
> ChrisA
>
> # -- start --
def generate_primes():
"""Generate an infinite series of prime numbers."""
i = 2
yield 2

primes = {2:2} # Map a prime number to its next composite (but
bootstrap with 2:2)
while True:
prm = min(primes, key=primes.__getitem__)
smallest = primes[prm]

primes[prm] += prm

for prm in range(i, smallest):
yield prm
primes[i] = 2*i

i = smallest + 1

gen=generate_primes()
for i in range(30):
print(next(gen),end="\t") # Star Trek?
print()
> # -- end --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread bas
On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
> Well, that does answer the question. Unfortunately the use of lambda
> there has a severe performance cost [ ...]
If you care about speed, you might want to check the heapq module. Removing the 
smallest item and inserting a new item in a heap both cost O(log(N)) time, 
while finding the minimum in a dictionary requires iterating over the whole 
dictionary, which cost O(N) time.

(untested)
#before loop
from heapq import *
primes = [(2,2)] #heap of tuples (multiple, prime). start with 1 item, so no 
need for heapify

#during loop
smallest, prm = heappop(primes)
heappush(primes, (smallest+prm, prm))

#when new prime found
heappush(primes, (i+i, i))

> > Still trying to figure out your algorithm ...
> It's pretty simple.  [...]
I understand what you are trying, but it is not immediately clear to me that it 
works correctly if for example a smallest factor appears twice in the list. I 
don't have time for it now, but it for sure can be simplified. The while loop, 
for example, can be replaced by an if, since it will never execute more than 
once (since if i is prime > 2, i+1 will be divisible by 2)


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


ANN: psutil 1.0.0 released

2013-07-10 Thread Giampaolo Rodola'
Hi there folks,
I'm pleased to announce the 1.0.0 release of psutil:
http://code.google.com/p/psutil/

=== About ===

psutil is a module providing an interface for retrieving information
on all running processes and system utilization (CPU, memory, disks,
network, users) in a portable way by using Python.
It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris,
both 32-bit and 64-bit, with Python versions from 2.4 to 3.3 by using
a single code base.

=== New features ===

This new release finally includes support for Sun Solaris systems!
I wish to thank Justin Venus who first wrote a prototype in Cython
which I then converted in C (full story here:
https://code.google.com/p/psutil/issues/detail?id=18).
Complete list of bugfixes and enhancements is here:
https://psutil.googlecode.com/hg/HISTORY

=== Compatitility notes ===

There's a couple of things you may want to know in terms of backward
compatibility:

 * Process.get_connections() 'status' field is no longer a string but
a constant object (psutil.CONN_*)
 * Process.get_connections() 'local_address' and 'remote_address'
fields have been renamed to 'laddr' and 'raddr'
 * psutil.network_io_counters() has been renamed to psutil.net_io_counters()

There are still aliases for the old names. They will issue a
DeprecationWarning though.

=== Links ===

* Home page: http://code.google.com/p/psutil
* Source tarball: http://psutil.googlecode.com/files/psutil-1.0.0.tar.gz
* API Reference: http://code.google.com/p/psutil/wiki/Documentation

Please try out this new release and let me know if you experience any
problem by filing issues on the bug tracker.
Thanks in advance and hooray for the new Solaris support! ;-)

All the best,


--- Giampaolo Rodola'

http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
http://code.google.com/p/pysendfile/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 10:00, Steven D'Aprano  wrote:
> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>
>> A moderator who calls himself “animuson” on Stack Overflow doesn’t want
>> to face the truth. He has deleted all my postings regarding Python
>> regular expression matching being extremely slow compared to Perl.
>
> That's by design. We don't want to make the same mistake as Perl, where
> every problem is solved by a regular expression:
>
> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>
> so we deliberately make regexes as slow as possible so that programmers
> will look for a better way to solve their problem. If you check the
> source code for the re engine, you'll find that for certain regexes, it
> busy-waits for anything up to 30 seconds at a time, deliberately wasting
> cycles.

I hate to sound like this but do you realise that this is exactly what
you're arguing for when saying that sum() shouldn't use "+="?

(There is no spite in the above sentence, but it sounds like there is.
There is however no way obvious to me to remove it without changing
the sentence's meaning.)

> The same with Unicode. We hate French people,

And for good damn reason too. They're ruining our language, á mon avis.

> you see, and so in an
> effort to drive everyone back to ASCII-only text, Python 3.3 introduces
> some memory optimizations that ensures that Unicode strings work
> correctly and are up to four times smaller than they used to be. You
> should get together with jmfauth, who has discovered our dastardly plot
> and keeps posting benchmarks showing how on carefully contrived micro-
> benchmarks using a beta version of Python 3.3, non-ASCII string
> operations can be marginally slower than in 3.2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-10 Thread Ethan Furman

On 07/09/2013 10:54 PM, Frank Millman wrote:


"Ian Kelly"  wrote in message
news:calwzidnf3obe0enf3xthlj5a40k8hxvthveipecq8+34zxy...@mail.gmail.com...

On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman  wrote:

You could also do it like this:

 def updating(self):
 self.transaction_active = True
 return self


Yes, that would be simpler.  I was all set to point out why this
doesn't work, and then I noticed that the location of the
"transaction_active" attribute is not consistent in the original code.
The DbSession class places it on self, and then the example usage
places it on the connection object (which I had based my version on).
Since that seems to be a source of confusion, it demonstrates another
reason why factoring this out is a good thing.


You had me worried there for a moment, as that is obviously an error.

Then I checked my actual code, and I find that I mis-transcribed it. It
actually looks like this -

 with db_session as conn:
 db_session.transaction_active = True
 conn.cur.execute(...)

I am still not quite sure what your objection is to this. It feels
straightforward to me.

Here is one possible answer. Whenever I want to commit a transaction I have
to add the extra line. There is a danger that I could mis-spell
'transaction_active', in which case it would not raise an error, but would
not commit the transaction, which could be a hard-to-trace bug. Using your
approach, if I mis-spelled 'db_session.connect()', it would immediately
raise an error.

Is that your concern, or are there other issues?


That concern is big enough.  I've been bitten by that type of thing enough in my own code to want to avoid it where 
possible.  Plus the `with db_session.updating() as conn:` saves keystrokes.  ;)


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


Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 1:43 AM, Joshua Landau  wrote:
>> So, a few questions. Firstly, is there...
> Of course there is.
>
>> Secondly, can the...
> Of course it can.
>
>> Thirdly, is there...
> Of course there is. I have no clue what, though.

Heh, I guess I was asking for that kind of response :)

> The trick
> is to avoid that repeated effort of finding the minimum in the dict by
> just keeping a sorted list.
>
> I've mocked that up just now:
>
> # Faster code #
> from blist import sortedlist

Hmm, blist isn't part of the standard library, so I'd have to hunt
that down. Presumably it's on PyPI.

>> What name would this algorithm have?
> I'll call it "the flamingo".

Guess that's as good a name as any!

> def generate_primes():
> """Generate an infinite series of prime numbers."""
> i = 2
> yield 2
>
> primes = {2:2} # Map a prime number to its next composite (but
> bootstrap with 2:2)
> while True:
> prm = min(primes, key=primes.__getitem__)
> smallest = primes[prm]
>
> primes[prm] += prm
>
> for prm in range(i, smallest):
> yield prm
> primes[i] = 2*i
>
> i = smallest + 1
>
> gen=generate_primes()
> for i in range(30):
> print(next(gen),end="\t") # Star Trek?
> print()

And once again, a version that's slower than the original. This one
does at least have the advantage of readability, though, and it's only
a little slower, so I'd say this is the current winner. I would still
replace 2*i with i+i for the sake of boasting "no multiplication",
though :)

In terms of the "one pass" criterion I put on the find-smallest
algorithm, I had been seeking to avoid anything that involved constant
lookups into primes[]. But this solution does look very clean and
simple. I think.

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


Re: Prime number generator

2013-07-10 Thread Steven D'Aprano
On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote:

> And now for something completely different.
> 
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded.
[...]
> So, a few questions. Firstly, is there a stdlib way to find the key with
> the lowest corresponding value? In the above map, it would return 3,
> because 18 is the lowest value in the list. 

Not from a dict, but with a list you would probably use the bisect module.


> I want to do this with a
> single pass over the dictionary. Secondly, can the "while i i+=1" loop become a for...range? It's almost asking for it, but not
> quite there. Thirdly, is there any sort of half-sane benchmark that I
> can compare this code to? And finally, whose wheel did I reinvent here?
> What name would this algorithm have?

I can't directly answer that question, but I can make a shameless plug 
for this:

https://pypi.python.org/pypi/pyprimes

If your prime generator performs better than, or worse than, all of those 
in the above module, I may have to steal it from you :-)



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


Re: ANN: psutil 1.0.0 released

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 17:46:13 +0200, Giampaolo Rodola' wrote:

> Hi there folks,
> I'm pleased to announce the 1.0.0 release of psutil:
> http://code.google.com/p/psutil/

Congratulations on the 1.0.0 release!



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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 6:06 AM, Mats Peterson  wrote:
> Joshua Landau  wrote:
>> If you actually can satisfy these basic standards for a comparison (as
>> I'm sure any competent person with so much bravo could) I'd be willing
>> to converse with you. I'd like to see these results where Python compares
>> as "extremely slow". Note that, by your own wording, a 30% drop is 
>> irrelevant.
>
> I haven't provided a "real-world" example, since I expect you Python
> Einsteins to be able do an A/B test between Python and Perl yourselves
> (provided you know Perl, of course, which I'm afraid is not always the
> case). And why would I use any "custom" version of Python, when I don't
> have to do that with Perl?

Well, I'm certainly not about to do the comparison myself.  I only
have so much time, and presently I am not sufficiently motivated about
this topic to invest any time in it.  A suggestion:  *you* brought up
the subject, so if you want us to pay attention to your claims, then
*you* had better be prepared to get your hands dirty and do the actual
work to support it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: psutil 1.0.0 released

2013-07-10 Thread Jurko Gospodnetić

  Hi.


I'm pleased to announce the 1.0.0 release of psutil:
http://code.google.com/p/psutil/


  Great! :-)

  Btw. any change you can put up a prebuilt installer for a 64-bit 
built with Python 3.3? You have one for Python 3.2 
(http://code.google.com/p/psutil/downloads/list), but the version for 
Python 3.3 is not there.


  Best regards,
Jurko Gospodnetić

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


Re: StackOverflowmoderator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 09:03:24 +, Mats Peterson wrote:

> Not a troll. It's just hard to convince Python users that their beloved
> language would have inferior regular expression performance to Perl.

I can't speak for others, but I've known for many years that Python's 
regex implementation was slower than Perl's. So what? Do you have a patch?


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


Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 8:00 AM, Chris Angelico  wrote:
> And now for something completely different.
>
> I knocked together a prime number generator, just for the fun of it,
> that works like a Sieve of Eratosthenes but unbounded. It keeps track
> of all known primes and the "next composite" that it will produce -
> for instance, after yielding 13, the prime map will be {2: 20, 3: 18,
> 5: 20, 7: 21, 11: 22, 13: 26}, each one mapped to the first multiple
> greater than 13.

Cool! I have a similar generator, and instead of mapping primes to
next composites, it maps next composites to lists of primes.  It works
using increment-by-2 and checking the dictionary rather than searching
for the min of the dictionary.  You could though adapt that data
structure and just use min(prime) to find the next composite (although
as somebody else noted, a heap would probably be more efficient).

The other interesting thing about my sieve is that it's a recursive
generator.  I'll dig it up later and share it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 1:47 AM, bas  wrote:
> On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
>> Well, that does answer the question. Unfortunately the use of lambda
>> there has a severe performance cost [ ...]
> If you care about speed, you might want to check the heapq module. Removing 
> the smallest item and inserting a new item in a heap both cost O(log(N)) 
> time, while finding the minimum in a dictionary requires iterating over the 
> whole dictionary, which cost O(N) time.

Ehh, speed isn't the ultimate. I was just trying to avoid something
that worked out ridiculously slow (a Python function call IS quite
slow). I haven't profiled the code to find out where the bulk of the
time is spent, but switching in the lambda-based version doubled total
run time, so I didn't like it :)

> (untested)
> #before loop
> from heapq import *
> primes = [(2,2)] #heap of tuples (multiple, prime). start with 1 item, so no 
> need for heapify
>
> #during loop
> smallest, prm = heappop(primes)
> heappush(primes, (smallest+prm, prm))
>
> #when new prime found
> heappush(primes, (i+i, i))

Ahh, that's the bit I should have thought of! Of course.

My original thought experiment had involved basically a really long
list, like the classic Sieve but getting longer as time moves on, with
composites replaced by None and primes with their next-markers, which
I then collapsed to a dict. Always I was thinking in terms of indexing
with the prime to get its next composite. Here's the code involving
heapq:

# -- start --
def primes():
"""Generate an infinite series of prime numbers."""
from heapq import heappush,heappop
i=2
yield 2
prime=[(2,2)] # Heap
while True:
smallest, prm = heappop(prime)
heappush(prime, (smallest+prm, prm))
while i> > Still trying to figure out your algorithm ...
>> It's pretty simple.  [...]
> I understand what you are trying, but it is not immediately clear to me that 
> it works correctly if for example a smallest factor appears twice in the 
> list. I don't have time for it now, but it for sure can be simplified. The 
> while loop, for example, can be replaced by an if, since it will never 
> execute more than once (since if i is prime > 2, i+1 will be divisible by 2)

Ah, good point. Again, I originally was starting from 1, so the while
loop was necessary to catch 2 and 3 in the first run. When I changed
it to start at 2 and explicitly yield it first, I didn't notice to
change that.

It works correctly with the smallest multiple appearing twice because
it won't yield primes until the smallest value is higher than the
current next-prime. So when it's just yielded 11, for instance, both
the 2 and 3 slots hold 12; advancing one of those does nothing,
advancing the other allows the bottom loop to notice that 13 is now
lower than the minimum value (which will then be 14).

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Ethan Furman

On 07/10/2013 08:54 AM, Joshua Landau wrote:

On 10 July 2013 10:00, Steven D'Aprano  wrote:

On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:


A moderator who calls himself “animuson” on Stack Overflow doesn’t want
to face the truth. He has deleted all my postings regarding Python
regular expression matching being extremely slow compared to Perl.


That's by design. We don't want to make the same mistake as Perl, where
every problem is solved by a regular expression:

http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/

so we deliberately make regexes as slow as possible so that programmers
will look for a better way to solve their problem. If you check the
source code for the re engine, you'll find that for certain regexes, it
busy-waits for anything up to 30 seconds at a time, deliberately wasting
cycles.


I hate to sound like this but do you realise that this is exactly what
you're arguing for when saying that sum() shouldn't use "+="?


my_obj = SomeKoolClass()
my_obj.modify_in_some_kool_way()
new_result = sum([SKC1, SKC2, SKC3], my_obj)

Guess what?  You've just changed my_obj.

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joel Goldstick
call your mom


On Wed, Jul 10, 2013 at 12:18 PM, Ethan Furman  wrote:

> On 07/10/2013 08:54 AM, Joshua Landau wrote:
>
>> On 10 July 2013 10:00, Steven D'Aprano  wrote:
>>
>>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>>>
>>>  A moderator who calls himself “animuson” on Stack Overflow doesn’t want
 to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.

>>>
>>> That's by design. We don't want to make the same mistake as Perl, where
>>> every problem is solved by a regular expression:
>>>
>>> http://neilk.net/blog/2000/06/**01/abigails-regex-to-test-for-**
>>> prime-numbers/
>>>
>>> so we deliberately make regexes as slow as possible so that programmers
>>> will look for a better way to solve their problem. If you check the
>>> source code for the re engine, you'll find that for certain regexes, it
>>> busy-waits for anything up to 30 seconds at a time, deliberately wasting
>>> cycles.
>>>
>>
>> I hate to sound like this but do you realise that this is exactly what
>> you're arguing for when saying that sum() shouldn't use "+="?
>>
>
> my_obj = SomeKoolClass()
> my_obj.modify_in_some_kool_**way()
> new_result = sum([SKC1, SKC2, SKC3], my_obj)
>
> Guess what?  You've just changed my_obj.
>
> --
> ~Ethan~
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 2:01 AM, Steven D'Aprano
 wrote:
> On Thu, 11 Jul 2013 00:00:59 +1000, Chris Angelico wrote:
>> Thirdly, is there any sort of half-sane benchmark that I
>> can compare this code to? And finally, whose wheel did I reinvent here?
>> What name would this algorithm have?
>
> I can't directly answer that question, but I can make a shameless plug
> for this:
>
> https://pypi.python.org/pypi/pyprimes
>
> If your prime generator performs better than, or worse than, all of those
> in the above module, I may have to steal it from you :-)

Ha, that's what I was hoping for. My algorithm outperforms several of
yours! Look!

Rosuav: 0.10868923284942639
awful_primes: 16.55546780386893
naive_primes1: 2.6105180965737276
naive_primes2: 1.358270674066116
trial_division: 0.06926075800136644
turner: 0.5736550315752424
croft: 0.007141969160883832
sieve: 0.01786707528470899
cookbook: 0.014790147909859996
wheel: 0.015050236831779529

Okay, so I outperform only algorithms listed as toys... :| Here's
similar figures, going to a higher cutoff (I kept it low for the sake
of awful_primes) and using only the algos designed for real use:

Rosuav: 2.1318494389650082
croft: 0.11628042111497416
sieve: 0.26868582459502566
cookbook: 0.21551174800149164
wheel: 0.4761577239565362

I didn't seriously think that this would outperform mathematically
proven and efficient algorithms, it was just a toy. But at least now I
know: It's roughly 20 times slower than a leading algo. And that's
after the bas-suggested improvement of using a heap.

But hey. If you want the code, you're welcome to it - same with anyone
else. Here's the heap version as used in the above timings. MIT
license.

def primes():
"""Generate an infinite series of prime numbers."""
from heapq import heappush,heappop
i=2
yield 2
prime=[(2,2)] # Heap
while True:
smallest, prm = heappop(prime)
heappush(prime, (smallest+prm, prm))
if ihttp://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 10:16 AM, Ian Kelly  wrote:
> The other interesting thing about my sieve is that it's a recursive
> generator.  I'll dig it up later and share it.

As promised.  Apologies for the excessive commenting.  As noted, this
implementation is a recursive generator, which is done so that the
primes in the sieve can go only up to the square root of the current
prime, rather than tossing in every prime seen so far.

from collections import defaultdict
from itertools import count, islice

def primes():
yield 2
# Set up the data structures.  multiples implements the sieve as a dict
# that marks upcoming composite numbers and records the prime factors
# that disqualified them.
multiples = defaultdict(list)
# subgen is a recursive sub-generator that supplies prime factors to be fed
# into the sieve.  islice is used to skip 2 (since we only consider odd
# numbers) and 3 (since we can't get it from subgen before we've yielded it
# below).
subgen = islice(primes(), 2, None)
# Initialize the sieve with the first prime factor q.
q = 3
# When we reach threshold (the square of the last prime added to the sieve),
# it's time to add another prime to the sieve.  By construction, threshold
# is always an odd composite.
threshold = q * q
multiples[threshold].append(q + q)
# The main loop tries every odd integer, starting with 3.
for p in count(3, 2):
if p in multiples:
# p is composite.  Discard the entry from multiples and mark the
# next odd multiple of each prime factor that disqualified p.
# Because the multiples dict actually stores the doubles of the
# prime factors, they need only be added once to get to the next
# odd multiple.
for q in multiples[p]:
multiples[p + q].append(q)
del multiples[p]
if p == threshold:
# All primes up to the previous q ** 2 have been generated.
# Get the next prime factor q and add it to the sieve.
q = subgen.next()
threshold = q * q
multiples[threshold].append(q + q)
else:
# p is prime.  Yay!
yield p
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Chris Angelico
On Thu, Jul 11, 2013 at 2:54 AM, Ian Kelly  wrote:
> As promised.  Apologies for the excessive commenting.  As noted, this
> implementation is a recursive generator, which is done so that the
> primes in the sieve can go only up to the square root of the current
> prime, rather than tossing in every prime seen so far.
>


Nice. Comes in at 0.23369310904039478 in my oh-so-scientific
benchmarking, so it's comparable to several of Steven's algorithms.
Runs on Python 3.3 with just the tiny tweak of converting iter.next()
to next(iter).

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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 16:54:02 +0100, Joshua Landau wrote:

> On 10 July 2013 10:00, Steven D'Aprano  wrote:
>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>>
>>> A moderator who calls himself “animuson” on Stack Overflow doesn’t
>>> want to face the truth. He has deleted all my postings regarding
>>> Python regular expression matching being extremely slow compared to
>>> Perl.
>>
>> That's by design. We don't want to make the same mistake as Perl, where
>> every problem is solved by a regular expression:
>>
>> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-
numbers/
>>
>> so we deliberately make regexes as slow as possible so that programmers
>> will look for a better way to solve their problem. If you check the
>> source code for the re engine, you'll find that for certain regexes, it
>> busy-waits for anything up to 30 seconds at a time, deliberately
>> wasting cycles.
> 
> I hate to sound like this but do you realise that this is exactly what
> you're arguing for when saying that sum() shouldn't use "+="?

You're referencing an off-list conversation, which will probably confuse 
most others reading this.

I don't agree with that. Apart from one throw-away comment where I said 
that sometimes it is handy to have a trivial example of an O(N**2) 
algorithm for teaching purposes, I have never made any suggestion that 
having sum(lists) be slow was a good thing in and of itself. My argument 
has always been that there are costs as well as benefits to changing sum 
of lists to use += instead of + and I'm not convinced that the benefits 
outweigh those costs.

Quite frankly, looking at the pure-Python version of sum that Sergey has 
posted, I *really* hope he is a better C programmer than Python 
programmer, because his pure-Python version is so full of bugs it is 
ridiculous.  But now I'm also referring to posts off-list :-)



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


Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 17:15, Chris Angelico  wrote:
> On Thu, Jul 11, 2013 at 1:47 AM, bas  wrote:
>> On Wednesday, July 10, 2013 5:12:19 PM UTC+2, Chris Angelico wrote:
>>> Well, that does answer the question. Unfortunately the use of lambda
>>> there has a severe performance cost [ ...]
>> If you care about speed, you might want to check the heapq module. Removing 
>> the smallest item and inserting a new item in a heap both cost O(log(N)) 
>> time, while finding the minimum in a dictionary requires iterating over the 
>> whole dictionary, which cost O(N) time.

Actually, because it's a list under the hood I'd imagine push and pop
still take O(n) time :/.

> Ehh, speed isn't the ultimate. I was just trying to avoid something
> that worked out ridiculously slow (a Python function call IS quite
> slow). I haven't profiled the code to find out where the bulk of the
> time is spent, but switching in the lambda-based version doubled total
> run time, so I didn't like it :)
>
>> (untested)
>> #before loop
>> from heapq import *
>> primes = [(2,2)] #heap of tuples (multiple, prime). start with 1 item, so no 
>> need for heapify
>>
>> #during loop
>> smallest, prm = heappop(primes)
>> heappush(primes, (smallest+prm, prm))
>>
>> #when new prime found
>> heappush(primes, (i+i, i))
>
> Ahh, that's the bit I should have thought of! Of course.
>
> My original thought experiment had involved basically a really long
> list, like the classic Sieve but getting longer as time moves on, with
> composites replaced by None and primes with their next-markers, which
> I then collapsed to a dict. Always I was thinking in terms of indexing
> with the prime to get its next composite. Here's the code involving
> heapq:
>
> # -- start --
> def primes():
> """Generate an infinite series of prime numbers."""
> from heapq import heappush,heappop
> i=2
> yield 2
> prime=[(2,2)] # Heap
> while True:
> smallest, prm = heappop(prime)
> heappush(prime, (smallest+prm, prm))
> while i yield i
> heappush(prime, (i+i, i))
> i+=1
> if i==smallest: i+=1
>
> gen=primes()
> print([next(gen) for i in range(10)])
> for i in range(1000):
> next(gen) # Star Trek?
> print("The next prime number is:",next(gen))
> # -- end --
>
> And that's significantly shorter, clearer, AND faster than the original. 
> Thanks!

AFAICT, that's exactly my code but using a less-efficient storage
medium and a *much* more efficient sorting mechanism. It'd be
interesting what could happen if heapq didn't reject blists -- they
have better efficiency for changing list sizes (which this code does a
lot of).

Thanks for the heads-up on heapq, by the way -- it's new to me and a
blimmin' good idea.

PS: It's faster to use heapreplace(...) than
heappop(...);heappush(...) but it only saves a few %.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 18:15, Steven D'Aprano
 wrote:
> On Wed, 10 Jul 2013 16:54:02 +0100, Joshua Landau wrote:
>
>> On 10 July 2013 10:00, Steven D'Aprano  wrote:
>>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>>>
 A moderator who calls himself “animuson” on Stack Overflow doesn’t
 want to face the truth. He has deleted all my postings regarding
 Python regular expression matching being extremely slow compared to
 Perl.
>>>
>>> That's by design. We don't want to make the same mistake as Perl, where
>>> every problem is solved by a regular expression:
>>>
>>> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-
> numbers/
>>>
>>> so we deliberately make regexes as slow as possible so that programmers
>>> will look for a better way to solve their problem. If you check the
>>> source code for the re engine, you'll find that for certain regexes, it
>>> busy-waits for anything up to 30 seconds at a time, deliberately
>>> wasting cycles.
>>
>> I hate to sound like this but do you realise that this is exactly what
>> you're arguing for when saying that sum() shouldn't use "+="?
>
> You're referencing an off-list conversation, which will probably confuse
> most others reading this.
>
> I don't agree with that. Apart from one throw-away comment where I said
> that sometimes it is handy to have a trivial example of an O(N**2)
> algorithm for teaching purposes, I have never made any suggestion that
> having sum(lists) be slow was a good thing in and of itself.

I might be misattributing posts then. Or... YOU'RE IN DENIAL!

Who wins? You decide!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Joshua Landau
On 10 July 2013 17:18, Ethan Furman  wrote:
> On 07/10/2013 08:54 AM, Joshua Landau wrote:
>>
>> On 10 July 2013 10:00, Steven D'Aprano  wrote:
>>>
>>> On Wed, 10 Jul 2013 07:55:05 +, Mats Peterson wrote:
>>>
 A moderator who calls himself “animuson” on Stack Overflow doesn’t want
 to face the truth. He has deleted all my postings regarding Python
 regular expression matching being extremely slow compared to Perl.
>>>
>>>
>>> That's by design. We don't want to make the same mistake as Perl, where
>>> every problem is solved by a regular expression:
>>>
>>>
>>> http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
>>>
>>> so we deliberately make regexes as slow as possible so that programmers
>>> will look for a better way to solve their problem. If you check the
>>> source code for the re engine, you'll find that for certain regexes, it
>>> busy-waits for anything up to 30 seconds at a time, deliberately wasting
>>> cycles.
>>
>>
>> I hate to sound like this but do you realise that this is exactly what
>> you're arguing for when saying that sum() shouldn't use "+="?
>
>
> my_obj = SomeKoolClass()
> my_obj.modify_in_some_kool_way()
> new_result = sum([SKC1, SKC2, SKC3], my_obj)
>
> Guess what?  You've just changed my_obj.

You're extrapolating too quickly. The first "+" is a copying "+", the
rest add in-place to the new object. Thus, no unexpected side effect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stack Overflow bans Mats Peterson (was Re: ....)

2013-07-10 Thread Terry Reedy

On 7/10/2013 3:55 AM, Mats Peterson wrote:

A moderator who calls himself “animuson” on Stack Overflow doesn’t
want to face the truth. He has deleted all my postings regarding Python
regular expression matching being extremely slow compared to Perl.
Additionally my account has been suspended for 7 days. Such a dickwad.


Your opinion of "animuson" is off-topic for this list.

StackOverflow is explicitly for technical questions with technical 
answers. I believe opinions, languages comparisions, and flamebaits in 
general are explicitly banned and subject to removal and possible 
banning. So are subterfuges like phrasing banned topics as questions.


Given your behavior here, I am 90+% sure animuson's action was appropriate.

--
Terry Jan Reedy


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


Re: Prime number generator

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau  wrote:
>>> If you care about speed, you might want to check the heapq module. Removing 
>>> the smallest item and inserting a new item in a heap both cost O(log(N)) 
>>> time, while finding the minimum in a dictionary requires iterating over the 
>>> whole dictionary, which cost O(N) time.
>
> Actually, because it's a list under the hood I'd imagine push and pop
> still take O(n) time :/.

It shouldn't.  You can implement push by appending the new item and
then getting it into the right place by performing O(log n) swaps.
Likewise for pop, you can update the heap with O(log n) swaps and then
removing the tail element.  Appending or removing the tail element of
a list is amortized O(1).

> PS: It's faster to use heapreplace(...) than
> heappop(...);heappush(...) but it only saves a few %.

The problem with heapreplace here is that the value to be pushed
is dependent on the value returned by pop.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Prime number generator

2013-07-10 Thread Joshua Landau
On 10 July 2013 19:56, Ian Kelly  wrote:
> On Wed, Jul 10, 2013 at 11:47 AM, Joshua Landau  wrote:
 If you care about speed, you might want to check the heapq module. 
 Removing the smallest item and inserting a new item in a heap both cost 
 O(log(N)) time, while finding the minimum in a dictionary requires 
 iterating over the whole dictionary, which cost O(N) time.
>>
>> Actually, because it's a list under the hood I'd imagine push and pop
>> still take O(n) time :/.
>
> It shouldn't.  You can implement push by appending the new item and
> then getting it into the right place by performing O(log n) swaps.
> Likewise for pop, you can update the heap with O(log n) swaps and then
> removing the tail element.  Appending or removing the tail element of
> a list is amortized O(1).

Genius. Bas replied off-list that it won't matter too much anyway as
they're over-allocated, but this makes tons of sense.

>> PS: It's faster to use heapreplace(...) than
>> heappop(...);heappush(...) but it only saves a few %.
>
> The problem with heapreplace here is that the value to be pushed
> is dependent on the value returned by pop.

That's fine because indexing is much faster than pop. The "few %" was
a real statistic from working, timed code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Terry Reedy

On 7/10/2013 4:58 AM, Russel Walker wrote:


There is the name x and the class instance (the object) which exists
somewhere in memory that x points to. self is just another name that
points to the same object (not self in general but the argument
passed to the self parameter when a method is called). However if the
code inside the method reassigns self to some other object, it
doesn't change the fact that x still refers to the original object.
So self is just a local variable (an argument).


Yes, parameters *names* are the initial local names of the function. 
Calling the first parameter of instancemethods 'self' is a convention, 
not a requirement.


> The name self has no

relevance to to the name x other than the fact that they point to the
same object. So reassigning self has no effect on x. But modifying
the object that self points to, does affect x because it points to
the same object. Is this correct?


Yes. Multiple names for one objects are 'aliases'. Being able to modify 
a object with multiple names in different namespaces is both a boon and 
bug bait.



So when you call x.somemethod() it's not passing x as the self


Python does not pass'x': it is 'call-by-object', not 'call-by-name'.


argument, it's actually passing the object that x points to as the
self argument. And that object has know knowledge of the fact that x
points to it, or does it?


Some objects (modules, classes, functions) have definition names 
(.__name__ attributes) that are used in their representations (as in 
tracebacks). But they have no knowledge of their namespace names.




--
Terry Jan Reedy

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


Re: Best Scripting Language for Embedded Work?

2013-07-10 Thread Johann Hibschman
David T. Ashley  writes:

> We develop embedded software for 32-bit micros using Windows as the
> development platform.
...
> I know that Tcl/Tk would do all of the above, but what about Python?
> Any other alternatives?

Given that list, I'd say just use Tcl and be done.  You could force the
square peg of python into that round hole, but I doubt it'd be worth the
effort.

Cheers,
Johann
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Russel Walker
On Wednesday, July 10, 2013 9:33:25 PM UTC+2, Terry Reedy wrote:
> On 7/10/2013 4:58 AM, Russel Walker wrote:
> 
> 
> 
> > There is the name x and the class instance (the object) which exists
> 
> > somewhere in memory that x points to. self is just another name that
> 
> > points to the same object (not self in general but the argument
> 
> > passed to the self parameter when a method is called). However if the
> 
> > code inside the method reassigns self to some other object, it
> 
> > doesn't change the fact that x still refers to the original object.
> 
> > So self is just a local variable (an argument).
> 
> 
> 
> Yes, parameters *names* are the initial local names of the function. 
> 
> Calling the first parameter of instancemethods 'self' is a convention, 
> 
> not a requirement.
> 
> 
> 
>  > The name self has no
> 
> > relevance to to the name x other than the fact that they point to the
> 
> > same object. So reassigning self has no effect on x. But modifying
> 
> > the object that self points to, does affect x because it points to
> 
> > the same object. Is this correct?
> 
> 
> 
> Yes. Multiple names for one objects are 'aliases'. Being able to modify 
> 
> a object with multiple names in different namespaces is both a boon and 
> 
> bug bait.
> 
> 
> 
> > So when you call x.somemethod() it's not passing x as the self
> 
> 
> 
> Python does not pass'x': it is 'call-by-object', not 'call-by-name'.
> 
> 
> 
> > argument, it's actually passing the object that x points to as the
> 
> > self argument. And that object has know knowledge of the fact that x
> 
> > points to it, or does it?
> 
> 
> 
> Some objects (modules, classes, functions) have definition names 
> 
> (.__name__ attributes) that are used in their representations (as in 
> 
> tracebacks). But they have no knowledge of their namespace names.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Thanks Terry, I did read all that twice just to make sure it sunk in and it was 
really clear and helpful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Twisted and argparse

2013-07-10 Thread writeson
Hi all,

I'm trying to write an Twisted program that uses the Application object (and 
will run with twistd) and I'd like to parse command line arguments. The Twisted 
documentation shows how to use a Twisted thing called usage.Options. However to 
me this looks a lot like the older Python module getopts. Is there a way to use 
the argparse module with a Twisted Application?

Thanks!
Doug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the general development using Python

2013-07-10 Thread Ian Kelly
On Tue, Jul 9, 2013 at 10:49 PM, CM  wrote:
> Can all the installation of the runtimes be done with an installer that is 
> itself an .exe, like with PyInstaller?  If so, that's probably fine.

It should be noted that PyInstaller is confusingly named.  It actually
creates standalone executables, not installers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Buying a used iPhone 5

2013-07-10 Thread Fábio Santos
On 10 Jul 2013 15:15, "Rodrick Brown"  wrote:
>
> Die
>
>
> On Wed, Jul 10, 2013 at 6:49 AM, oswaldclem  wrote:
>>
>> I'm planning on buying a used ATT iPhone 5 off of craigslist, and i've
been
>> reading on how some people sell their iPhones to people and later on
>> blacklisting it, screwing the buyer over, or how people are mistakenly
>> buying already blacklisted iPhones. I was wondering if there's a way I
can
>> prevent this? I was thinking of meeting at an ATT store to make sure it's
>> not blacklisted and to make sure it's not connected to any account that
>> could black list it. Would that be a good idea?
>>

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


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Russel Walker
I've been mucking around with this silly class pretty much the whole day and my 
eyes are about closing now so this is the solution for now I think. Please feel 
free to drop any suggestions. I think I mostly just ended up shaving off allot 
of extraneous responsibility for the class, that and inheriting from list. I 
wanted to try it and it seems to fit (I think).

Maybe tomorrow I'll try it inheriting from instead since that is immutable. 
Should've probably thought of that before right this moment, as I had quite a 
time with "maximum recursion depth exceeded".


class LRExpression(list):
"""
Construct for 'left to right' algebraic expressions.
"""

def __init__(self, *args):
list.__init__(self, args[:1])
for x in args[1:]:
self.append(x)

def __str__(self):
return '(%s)' % ' '.join(map(str, self))

def evaluate(self):
return eval(str(self))

def append(self, x):
if len(self) < 3:
list.append(self, x)
else:
oldself = LRExpression(*self)
self.__init__(oldself)
self.append(x)


def test():
a = LRExpression(1)
a.append('+')
a.append(2)
a.append('*')
a.append(3)
try:
print 'repr:', repr(a)
print 'str:', a
print "should be 9:", a.evaluate()
except Exception as er:
print er

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


Re: the general development using Python

2013-07-10 Thread CM

> I was mainly talking in the context of the original post, where it 
> seems something slightly different was meant. If you're deploying to
> customers, you'd want to offer them an installer. At least, I think
> you would. That's different from packing Python into a .exe file and
> pretending it's good-to-go.

It depends.  In some sense, probably an .exe is the very simplest thing you can 
provide a user:  they download and move it to where they want, the click on it, 
it runs.   It *is* good-to-go, isn't it?  (btw, I know at least one person I've 
read on a forum who just won't use any installer--he feels it can put stuff on 
his computer where he doesn't have good easy control of it.)

Sometimes an installer might be preferable, especially if there are data or 
image files or tutorials or something that go with the .exe (that weren't, for 
some reason, bundled inside it).  

> If they don't want it installed, again the best thing to do is an
> archive with some "executable" (possibly a batch file or something --
> you Windows people would know better what you need) that just runs
> "python main_file.py". Then get them to extract + click. That's 2
> operations, and a lot faster than some silly install process.

But that's pretty much what the .exe that py2exe makes does anyway.  It just 
kind of hides it all inside the .exe file.

> There are a lot of ways of making an installer, and my current few 
> Googles have shown that distutils comes with a way of making .msi
> files¹, and there's also http://wix.tramontana.co.hu/. Some random
> internet guy reccomended https://code.google.com/p/omaha/, but I've no
> idea if it's appropriate. There's also
> http://nsis.sourceforge.net/Main_Page. Again, I'm no Windows user so
> I'm talking by guessing.

And InnoSetup, which I've used to good effect.

> These are saner solutions because they focus on installing rather than 
> pretending that a .exe file with a packaged Python is anything like a
> compiled C source.

I don't think most informed users of, say, py2exe think that.  I think they see 
it as "freezing" the application for single-file portability.  The fact that 
people will refer to it as "compiling it to an exe" is unfortunate, yes.

Again, for anyone selling software, just make as few steps as possible for the 
user.  Using py2exe (which is easy to do) to freeze a lot of .py scripts into 
one easily deployed app passes that test.  So does any simple method you 
mentioned, I'm sure.  It all gets us to the same place, right?




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


Re: Stack Overflow moderator “animuson”

2013-07-10 Thread Steven D'Aprano
On Wed, 10 Jul 2013 18:53:34 +0100, Joshua Landau wrote:

> I might be misattributing posts then. Or... YOU'RE IN DENIAL!

Ranting Rick? Is that you? 

:-)


> Who wins? You decide!

Ah, definitely not RR :-)


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


Re: Recursive class | can you modify self directly?

2013-07-10 Thread Ian Kelly
On Wed, Jul 10, 2013 at 4:50 PM, Russel Walker  wrote:
> def append(self, x):
> if len(self) < 3:
> list.append(self, x)
> else:
> oldself = LRExpression(*self)
> self.__init__(oldself)
> self.append(x)

It's probably not wise to be re-calling __init__ after the class has
been initialized, although it seems to work.  I would instead use
slice assignment to replace the list contents:

self[:] = [oldself]

That said, the problem with inheriting from list is that it allows
your class to be used in a lot of ways lists can be used that are
probably not appropriate.  For example, continuing on from your test
function:

>>> len(a)
3

Why 3?  Because that's the length of the list.  But the caller would
probably expect the length to have something to do with the size of
the expression, not the list.

>>> '*' in a   # Is the '*' operator used in a?
True
>>> '+' in a   # What about the '+' operator?
False

Again, this happens because the "in" operator is only looking at the
list itself, not at sublists.  But an expression container would
probably be expected to return True for both of those.  These cases
can of course be easily overridden in the subclass, but what about
something harder, like slicing?  How should that be expected to work
with an LRExpression?

This isn't to say that you shouldn't necessarily use a list if it
helps you implement the behavior you want, but having the LRExpression
*be* a list is probably wrong.


Finally, based on what you're doing here, I think you would be better
off using something like the OOP Builder pattern.  There will be two
distinct classes: the "LRExpression" class that composes a tree
structure, and an "ExpressionBuilder" class that does the work of
actual assembly.  It could look something like this:

class LRExpression(object):
def __init__(self, expr, op, value):
self.expr = expr
self.op = op
self.value = value
def __str__(self):
return '(%s %s %s)' % (self.expr, self.op, self.value)
def evaluate(self):
# Subject to the usual warning that eval() should
# never be used with untrusted input
return eval(str(self))

class ExpressionBuilder(object):
def __init__(self):
self.parts = []
def append(self, part):
self.parts.append(part)
def build(self):
expr = self.parts[0]
for i in xrange(1, len(self.parts), 2):
op, value = self.parts[i:i+2]
expr = LRExpression(expr, op, value)
return expr

def test():
a = ExpressionBuilder()
a.append(1)
a.append('+')
a.append(2)
a.append('*')
a.append(3)
expr = a.build()
print expr
print expr.evaluate()

>>> test()
((1 + 2) * 3)
9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2013-07-10 Thread Chris Nash
The first item in a sequence is at index zero because it is that far away from 
the beginning. The second item is one away from the beginning. That is the 
reason for zero-based indexing.

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


Re: the general development using Python

2013-07-10 Thread Joshua Landau
On 11 July 2013 00:18, CM  wrote:
>
>> I was mainly talking in the context of the original post, where it
>> seems something slightly different was meant. If you're deploying to
>> customers, you'd want to offer them an installer. At least, I think
>> you would. That's different from packing Python into a .exe file and
>> pretending it's good-to-go.
>
> It depends.  In some sense, probably an .exe is the very simplest thing you 
> can provide a user:  they download and move it to where they want, the click 
> on it, it runs.   It *is* good-to-go, isn't it?  (btw, I know at least one 
> person I've read on a forum who just won't use any installer--he feels it can 
> put stuff on his computer where he doesn't have good easy control of it.)

Yeah, but why keep shipping the Python interpreter? If you choose the
installer route, you don't have to keep shipping it -- it's only
downloaded if you need it. If not, then you don't download it again.

> Sometimes an installer might be preferable, especially if there are data or 
> image files or tutorials or something that go with the .exe (that weren't, 
> for some reason, bundled inside it).
>
>> If they don't want it installed, again the best thing to do is an
>> archive with some "executable" (possibly a batch file or something --
>> you Windows people would know better what you need) that just runs
>> "python main_file.py". Then get them to extract + click. That's 2
>> operations, and a lot faster than some silly install process.
>
> But that's pretty much what the .exe that py2exe makes does anyway.  It just 
> kind of hides it all inside the .exe file.

The problem is that it hides it all inside the .exe file. And I'm not
suggesting putting Python inside the archive -- just the runtime
dependencies.

>> There are a lot of ways of making an installer .
>> These are saner solutions because they focus on installing rather than
>> pretending that a .exe file with a packaged Python is anything like a
>> compiled C source.
>
> I don't think most informed users of, say, py2exe think that.  I think they 
> see it as "freezing" the application for single-file portability.  The fact 
> that people will refer to it as "compiling it to an exe" is unfortunate, yes.

Fair enough.

> Again, for anyone selling software, just make as few steps as possible for 
> the user.  Using py2exe (which is easy to do) to freeze a lot of .py scripts 
> into one easily deployed app passes that test.  So does any simple method you 
> mentioned, I'm sure.  It all gets us to the same place, right?

But I still think my way is better. Perhaps I'm just too pragmatic
about these things. This was triggered by the OP's original request --
he sounds very much like he doesn't actually want this -- and it seems
to have stuck. I don't know if being pragmatic is a bad thing, though.

In the end, something like this is best solved with a bit of A/B
testing¹. Sit a couple of your audience down, give them the best
implementation of each strategy (starting from the website) for some
trivialised module and see what they think. If it turns out that being
pragmatic does have compromises, I'm not going to argue with the data.
I'd still be grumpy, though.

¹ This of course assumes you care enough to do so.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >