EuroPython 2013: Call for Proposals ending soon!

2013-02-26 Thread mena
Call for Proposals for EuroPython 2013 is open. It will run until March 5th, 
23:59:59 CET, so don't waste time, hurry up!

Visit our webpage: https://ep2013.europython.eu/call-for-proposals/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Python Newbie

2013-02-26 Thread Larry Hudson

On 02/24/2013 02:43 PM, piterrr.dolin...@gmail.com wrote:
snip

...  But for the moment I am trying to imitate familiar ground.

snip
This is EXACTLY why you're having trouble grasping Python.  Python is a different language and 
requires a different mind-set and different approach.  In this, it is NO different from ANY 
other new (to you) programming language.


Of course, don't forget general programming principles -- how to approach a problem, how to 
select algorithms, and such.  These apply to any language, but the details of syntax and such 
ARE different in different languages.  Trying to apply these old details to a new language only 
hinders your learning process, it definitely does NOT help.


Actually, your comments and questions make me wonder HOW you are trying to learn Python.  All 
the things you're asking about are clearly and completely discussed in any decent book or 
tutorial.  It makes me speculate that you're simply trying to use a Python reference instead of 
something that actually teaches anything.  A reference may give you the rules and syntax, but 
not much about how to apply them properly.


Please think about finding some better fundamental material -- there is a LOT available.  And 
please quit trying to force Python to be something it isn't.  That is never going to be 
effective and definitely harmful to your learning.


snip

I wanted Python to register what type of variable I'm after...


Python variables do NOT have any data type.  The objects they reference have data types. 
Variables can be assigned and RE-assigned to any data type at any time.  Again, I emphasize, 
QUIT THINKING IN ANOTHER LANGUAGE, it simply doesn't work.  You might like it if it were so, but 
it simply does not match reality.


 -=- Larry -=-

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


Re: installation

2013-02-26 Thread Ned Deily
In article 445bf19a-2093-4910-97a5-7f23d6e64...@insightbb.com,
 Steve Pruitt steve.pru...@insightbb.com wrote:

 I installed Python 3.3 for the Mac (10.6.8), but I did not get the 
 interpreter installed.  I get IDLE and the Launcher, but no interpreter.  At 
 least I can't find it.
 
 I thought maybe it updated /System/Library/Frameworks/Python.framework.  No 
 luck.  I guess my question is how do I get the latest interpreter installed?

If you used one of the python.org installers for OS X, it installs into 
/Library/Frameworks/Python.framework.  /System/Library/Frameworks is 
where the Apple-supplied Pythons are located.  You should not attempt to 
alter or delete files there.

To use the new Python you should ensure that the framework bin directory 
is added to the front of your shell PATH environment variable.  For 
Python 2 installs, the installer does this automatically by default. For 
Python 3 installs, the installer does not.  However you can double-click 
the Update Shell Profile command in the /Applications/Python 3.3 folder.  
After it completes, open a new terminal window and you should find that 
python3.3 is now available.  You can also manually edit your 
.bash_profile or other relevant shell startup file:

PATH=/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}
export PATH

-- 
 Ned Deily,
 n...@acm.org

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


nested loops

2013-02-26 Thread leonardo

hi everyone,

i have the following program:

import time
count_timer = int(raw_input('how many seconds?: '))
for i in range(count_timer, 0, -1):
print i
time.sleep(1)
print 'blast off!'


this is the result:

how many seconds?: 5
5
4
3
2
1
blast off!

how can i have it print  a row of stars beside each number, like this?:

how many seconds?: 5
5 * * * * *
4 * * * *
3 * * *
2 * *
1 *
blast off!


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


Re: nested loops

2013-02-26 Thread Sven
Here's one solution

import time
count_timer = int(raw_input('how many seconds?: '))
for i in range(count_timer, 0, -1):
print i,
print * * i
time.sleep(1)
print 'blast off!'


On 25 February 2013 22:46, leonardo tampucciol...@libero.it wrote:

 hi everyone,

 i have the following program:

 import time
 count_timer = int(raw_input('how many seconds?: '))
 for i in range(count_timer, 0, -1):
 print i
 time.sleep(1)
 print 'blast off!'


 this is the result:

 how many seconds?: 5
 5
 4
 3
 2
 1
 blast off!

 how can i have it print  a row of stars beside each number, like this?:

 how many seconds?: 5
 5 * * * * *
 4 * * * *
 3 * * *
 2 * *
 1 *
 blast off!


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




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


Re: nested loops

2013-02-26 Thread leonardo

thanks for the help, it works


Il 26/02/2013 10.58, Sven ha scritto:

Here's one solution

import time
count_timer = int(raw_input('how many seconds?: '))
for i in range(count_timer, 0, -1):
||print i,
print * * i
time.sleep(1)
print 'blast off!'


On 25 February 2013 22:46, leonardo tampucciol...@libero.it 
mailto:tampucciol...@libero.it wrote:


hi everyone,

i have the following program:

import time
count_timer = int(raw_input('how many seconds?: '))
for i in range(count_timer, 0, -1):
print i
time.sleep(1)
print 'blast off!'


this is the result:

how many seconds?: 5
5
4
3
2
1
blast off!

how can i have it print  a row of stars beside each number, like
this?:

how many seconds?: 5
5 * * * * *
4 * * * *
3 * * *
2 * *
1 *
blast off!


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





--
./Sven


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


EuroPython 2013: Call for Proposals ending soon!

2013-02-26 Thread mena
Call for Proposals for EuroPython 2013 is open. It will run until March 5th, 
23:59:59 CET, so don't waste time, hurry up!

Visit our webpage: https://ep2013.europython.eu/call-for-proposals/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IMAP4_SSL and OpenSSL compatibility

2013-02-26 Thread Antoine Pitrou
W. Martin Borgert debacle at debian.org writes:
 
 When I add an ssl_version argument to the call to
 ssl.wrap_socket() in imaplib.IMAP4_SSL.open(), I can connect to
 the Exchange server without problems:
 
 self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile,
   ssl_version = ssl.PROTOCOL_SSLv3)
 
 Would it make sense, to make this change in the Python standard
 library?

There is already the ssl_context option for that:
http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4_SSL

Regards

Antoine.


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


Nuitka now supports Python 3.2

2013-02-26 Thread Steven D'Aprano
Nuitka now supports Python 3.2 syntax and compiles the full CPython 3.2 
test suite.

http://nuitka.net/posts/nuitka-release-040.html


What is Nuitka?

Nuitka is an implementation of Python written in C++. At the moment it is 
claimed to be about 2.5 times as fast as CPython running the pystone 
benchmark. Future plans including using type inference and whole program 
analysis to optimize Python code using C++ native types.

Unlike PyPy, which is a JIT compiler, Nuitka is intended as a static 
optimizing compiler.


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


Do you feel bad because of the Python docs?

2013-02-26 Thread Steven D'Aprano
One week ago, JoePie91 wrote a blog post challenging the Python 
community and the state of Python documentation, titled:

The Python documentation is bad, and you should feel bad.

http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-
and-you-should-feel-bad/

It is valuable to contrast and compare the PHP and Python docs:

http://php.net/manual/en/index.php
http://www.python.org/doc/

There's no doubt that one of PHP's strengths, perhaps its biggest 
strength, is the good state of documentation. But should we feel bad 
about Python's docs? I don't think that either the Python documentation 
or community is as bad as JoePie91 suggests. (Well, I won't speak for the 
people on Freenode's #python. It took me approximately three minutes to 
be banned from there, with no warning or explanation.)

Another response to the blog post, by one of the core developers:

http://blog.briancurtin.com/posts/why-i-dont-feel-so-bad.html



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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Chris Angelico
On Tue, Feb 26, 2013 at 11:54 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 One week ago, JoePie91 wrote a blog post challenging the Python
 community and the state of Python documentation, titled:

 The Python documentation is bad, and you should feel bad.

 http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-
 and-you-should-feel-bad/

 It is valuable to contrast and compare the PHP and Python docs:

 http://php.net/manual/en/index.php
 http://www.python.org/doc/

There are some issues with the Googleability of the Python docs at the
moment. It's much easier to find the official page of PHP's docs than
Python's. Trouble is, the official page of PHP docs is a lot less
helpful... like he says, it's in some cases flat-out wrong. And then
you go read the comments underneath in the hope of learning what you
need to know... and you find a pile of junk even worse than the main
docs, but with the occasional useful gem so you can't dismiss it out
of hand. (But it's buried among loads of code whose primary purpose is
to explain why there's so much bad PHP code out there.)

His experiment (name all the possible error conditions) is one that
I guarantee you will fail in EVERY language. Even in Java, where a
method has to declare every exception it might throw, makes an
exception (if you'll excuse the pun) for runtime errors... such as
division by zero. So if I write a function that takes two arguments,
divides one by the other, and adds three, then I don't need to declare
that it might bomb if you give it zero and zero. Will it be in the
docs? Unlikely.

The lack of examples is a valid concern. However, PHP isn't actually
that much better, because the prolific examples don't always help.
Examples are no panacea.

Final point: NO-ONE IS FIXING THIS. I wonder how many docs patches
he's submitted, how many newbies he's courteously and competently
assisted.

The complaints about the community definitely do not apply to
python-list. So I'd say that's a fairly good fallback: if you can't
find what you need in the docs, and you've made a genuine effort to do
so, ask on c.l.p/p-l and you'll likely get a response within a day -
sometimes within the hour. (If Giacomo says he will respond within the
hour, he will respond... within the hour!)

tl;dr: Nothing's perfect but it ain't as bad as all tharrt.

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


Re: Small program ideas

2013-02-26 Thread Vytas D.
Hello,

Some more ideas:

1. Implement sin(), cos(), tan() etc. The accuracy could be supplied as a
parameter to the program. The correctness can be checked very easily with
implemented versions.

2. Read a string/file and look for palindromes (the group of words that can
read from both ends: A toyota, Madam in Eden, I'm Adam...)

3. Read a string/file and draw that string on the screen in a whirlpool
way. Counter-clockwise sample of the string: abigsnake:
sgi
nab
ake

4. Print first n Fibonacci numbers.

5. Calculate Pi value for the specified accuracy. From wiki: ...
irrational number, including π, can be represented by an infinite series of
nested fractions So it won't be very complicated to implement.

6. Implement dos2unix/unix2dos

7. Calculator, that gets a string, put data into a tree and after
calculates the value.

Vytas D.


On Tue, Feb 26, 2013 at 6:15 AM, Dave Angel da...@davea.name wrote:

 On 02/25/2013 10:48 PM, eli m wrote:

 On Friday, February 15, 2013 7:22:41 PM UTC-8, eli m wrote:

 Any small program ideas? I would prefer to stick to command line ones.
 Thanks.


 Thank you guys for the suggestions. Any more?


 There are all kinds of things you could do.  First, consider something
 that might be useful.

 1) checksum all the files in a directory tree, using various checksum
 algorithms.

 2) Convert one kind of file to another.

 3) Calculate time between two dates

 4) Write some part of a backup system.  For example, copy files from a
 directory tree into a specified directory, stopping when the size totals
 N.N gig, and keeping track of which files have been so processed, so that
 after burning that directory to DVD, you can repeat the process. As a
 bonus, add a utility  datafile to the top of that directory, so that the
 DVD can be self-checking.

 Then try something interesting:

 1) find the nth prime, for example the 1000th prime

 2) Find all perfect numbers under a trillion

 3) solve the puzzles on http://projecteuler.net

 4) Build a spell checker, using a combination of a standard
 dictionary-list and custom entries.  Bonus question - Make it smart enough
 to only spell-check comments and literal strings, when applied to files
 with an extension of .py


 --
 DaveA
 --
 http://mail.python.org/**mailman/listinfo/python-listhttp://mail.python.org/mailman/listinfo/python-list

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


RE: Nuitka now supports Python 3.2

2013-02-26 Thread Andriy Kornatskyy

Steven,

Just in case... pypy1.9 runs this test 22x faster than cpython2.7, see below.

python2.7 -c from test import pystone;[pystone.main() for i in range(10)]
Pystone(1.1) time for 5 passes = 0.62
This machine benchmarks at 80645.2 pystones/second
...
Pystone(1.1) time for 5 passes = 0.53
This machine benchmarks at 94339.6 pystones/second


pypy-1.9/bin/pypy -c from test import pystone;[pystone.main() for i in 
range(10)]

Pystone(1.1) time for 5 passes = 0.116008
This machine benchmarks at 431005 pystones/second
...
Pystone(1.1) time for 5 passes = 0.024002
This machine benchmarks at 2.08316e+06 pystones/second

Thanks.

Andriy Kornatskyy



 From: steve+comp.lang.pyt...@pearwood.info
 Subject: Nuitka now supports Python 3.2
 Date: Tue, 26 Feb 2013 12:18:56 +
 To: python-list@python.org

 Nuitka now supports Python 3.2 syntax and compiles the full CPython 3.2
 test suite.

 http://nuitka.net/posts/nuitka-release-040.html


 What is Nuitka?

 Nuitka is an implementation of Python written in C++. At the moment it is
 claimed to be about 2.5 times as fast as CPython running the pystone
 benchmark. Future plans including using type inference and whole program
 analysis to optimize Python code using C++ native types.

 Unlike PyPy, which is a JIT compiler, Nuitka is intended as a static
 optimizing compiler.


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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Roy Smith
In article mailman.2541.1361884843.2939.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 There are some issues with the Googleability of the Python docs at the
 moment. It's much easier to find the official page of PHP's docs than
 Python's. Trouble is, the official page of PHP docs is a lot less
 helpful... like he says, it's in some cases flat-out wrong. And then
 you go read the comments underneath in the hope of learning what you
 need to know... and you find a pile of junk even worse than the main
 docs, but with the occasional useful gem so you can't dismiss it out
 of hand. (But it's buried among loads of code whose primary purpose is
 to explain why there's so much bad PHP code out there.)

Having lived through a year of PHP hell, I've developed a theory about 
the PHP ecosystem (i.e. docs, forums, user community, etc) vs. the 
Python ecosystem.

When people ask PHP questions, the questions tend to be phrased as what 
do I type to get X, and the answers come back that way too.  The forums 
are full of, I had the same problem.  Somebody told me to do this.  I 
don't really understand it, but it worked for me and maybe it'll work 
for you too.

The Python ecosystem is much more about understanding what's actually 
happening.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Zero Piraeus
:

On 26 February 2013 08:54, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 One week ago, JoePie91 wrote a blog post challenging the Python
 community and the state of Python documentation [...]

 [...] should we feel bad about Python's docs?

The Python docs are my first port of call when I know the module (and
maybe the function) I want to use, but can't remember exactly how it
works. For that, and for me, they're very good.

I can also usually find the section I want if I'm answering a beginner
question on Stack Overflow and want to provide an explanatory link,
but if I weren't already familiar with the docs, I think it's quite
unlikely I'd find the relevant page easily. I agree with joepie91 that
the information on fundamental stuff is poorly organised.

 I don't think that either the Python documentation
 or community is as bad as JoePie91 suggests.

I think he has a point, albeit exaggerated, regarding the community -
or at least python-list, which is the part with which I'm familiar.
This list can be a little imposing for beginners, and its habit of
veering away from the original question into an esoteric discussion of
the language, while entertaining and educational to read for *me*,
might well end up causing OP to scratch their head.

I don't think it's intended, but sometimes there's also the sense that
regulars here are trying, not entirely successfully, to hide their
impatience with simple questions. I don't hang out at python-tutor, so
maybe it's better there (in which case, maybe its existence needs to
be better advertised).

I think Stack Overflow is a little better at that, possibly because
the rep system there encourages grinding in the MMORPG sense, and
easy questions get a bunch of people piling on with answers almost
instantaneously.

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Devin Jeanpierre
On Tue, Feb 26, 2013 at 7:54 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 There's no doubt that one of PHP's strengths, perhaps its biggest
 strength, is the good state of documentation. But should we feel bad
 about Python's docs? I don't think that either the Python documentation
 or community is as bad as JoePie91 suggests.

Who's we? As a user of Python I feel no responsibility for the state
of Python's documentation ;)

Do I feel like it could be improved? Sure. I've never understood why
Python doesn't document information about possible errors inside the
function documentations. Instead, you have to read the exception
documentation to find out when it might be raised, and then the exact
error conditions aren't always clearly specified at all.

My understanding from talking to members of the development team has
been that this is by design, so I've of course never submitted a
patch.

 (Well, I won't speak for the
 people on Freenode's #python. It took me approximately three minutes to
 be banned from there, with no warning or explanation.)

I'm an op in #python. If you can provide logs or a nickname I could
look into this with whoever banned you (if the ban hasn't expired
already!) However, you should appreciate that, having only been there
for three minutes, you may not have understood the expectations
#python sets on tone or subject matter. It is markedly more strict
than comp.lang.python. Also, bans aren't explained (except possibly in
the kickban message, but that's rare) unless you ask about them. It's
very easy to infer a reason from context, explanations take time (if
you explain before the ban), and PMs to a just-banned person never go
well (if you explain after the ban).


As to whether or not JoePie91's observations are correct for
#python... all the observations would apply to #python except for the
ostrich and source-reading complaints, albeit viewed through a very
negative light. I would disagree with his explanations for the reasons
for things, and his ranking of the importance of things.

IMHO the most important flaw in #python is that it's unwelcoming to
new programmers, but I can't think of a decent way to fix that.
Tutoring new programmers takes a huge amount of time. At the moment I
figure that the best we can hope to do is identify them before we
confuse the hell out of them by telling them to use classes,
generators, higher order functions, and other intermediate to advanced
topics. Unfortunately, we're not good at this. (Yet? :)


By the way, interestingly enough, JoePie91 was in #python discussing
his blog post for a bit. It was a fun conversation.

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Chris Angelico
On Wed, Feb 27, 2013 at 12:56 AM, Roy Smith r...@panix.com wrote:
 When people ask PHP questions, the questions tend to be phrased as what
 do I type to get X, and the answers come back that way too.  The forums
 are full of, I had the same problem.  Somebody told me to do this.  I
 don't really understand it, but it worked for me and maybe it'll work
 for you too.

A problem that's majorly exacerbated by the myriad ways of doing some
things, with some of those ways deprecated and others theoretically
plausible but hopelessly impractical.

Here's an actual example that came up today at work. Suppose you have
a user-provided string that's supposed to contain a URL, and you need
to ensure that it doesn't have a trailing slash, so you can later add
/foo or /bar. (Or alternatively, ensure that it DOES have a
trailing slash. Either works.) Start the timer, go find out how to do
it. Assume you are broadly familiar with PHP, and know how to do the
basics of string handling, and are competent at searching the web.
Ready? Go!

I'll wait for you to come back.

... Okay, some of you are back now. Just giving the stragglers time to
finish losing their marbles...

Alright. Here's what I found in a recreation of today's search.
Google search: php last character of string

http://php.net/manual/en/function.substr.php
-- okay, so I can use substr, but not string indexing, to find out
what the last character is
-- Returns the extracted part of string; or FALSE on failure, or an
empty string. What kind of failures result in FALSE, and what kind in
an empty string?

http://stackoverflow.com/questions/4427172/find-last-character-in-a-string-in-php
Comment on question: There are more than 10 ways of doing this!
The accepted answer, fortunately, is a good one. Use rtrim. Okay.
That's nice. But look at the other answers: one mentions substr (as
above, that's half the question); one suggests the unwieldy form of
indexing from the back (with an explicit strlen); one answers
altogether the wrong question (suggesting the use of basename); and
one... suggests a regular expression. Now you have two problems.

And just to add to the pile of ways this could be done, the first
response in this thread
https://forums.digitalpoint.com/threads/how-to-get-last-character-in-string.796134/
suggests *reversing the string* and indexing from the front.

Maybe you tried different search terms and got better results, I don't
know. This wasn't the only search I did in trying to find the best way
to do this, but it was the one with the most amusing results.

The original rant specifically excluded sites like Stack Overflow as
valid sources, which in a way is fair enough. But it wasn't from
php.net that I got that information.

Okay. Now I'll try it again, for Python.
Google search: python last character of string
First result:
3.1.2 Strings
docs.python.org/release/1.5.1p1/tut/strings.html
Besides numbers, Python can also manipulate strings, which can be
expressed ... word[-1] # The last character 'A'  word[-2] # The
last-but-one character 'p' ...

The use of code with directly connected comments means that I can read
this part of the solution right there, without even clicking the link.
Search Engine Optimization FTW.

Searching for the second part, by adding the word 'remove' to the
search, brings up more third-party sites - for PHP:
http://www.if-not-true-then-false.com/2010/php-remove-last-character-from-string/
and for Python:
https://groups.google.com/forum/?fromgroups#!topic/comp.lang.python/TIX5u3Zhikc
http://stackoverflow.com/questions/9639754/python-remove-last-char-from-string-and-return-it

In both cases, answering the question, but not from the language's own
site. Forcing the matter with a site: search brings up poor results
for both languages. Python gives me:
http://docs.python.org/release/2.6/library/string.html
but nothing about slicing. PHP: Take your pick of functions, and I
hope you already know what they do, because the snippets don't help
you choose:
substr, rtrim, chop (which, once you go to the page, reveals itself to
be an alias for rtrim), strrpos, substr_replace, strstr

I'd have to say that, in the shoot-out, both languages died on their
own merits, but stood on the merits of third-party support. Fifteen
years ago, I would have called that a critical failure; in the 90s, I
would search for information only from official sources. But these
days, forum archives and blogs are some of the best way to find what
you need - granted, Sturgeon's Law applies, but frankly that applies
to a lot of documentation too (and Google's fairly good at helping you
find the 10%).

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


Re: Small program ideas

2013-02-26 Thread Neil Cerutti
On 2013-02-26, Vytas D. vytasd2...@gmail.com wrote:
 Some more ideas:

If you like puzzles but not math, then The Python Challenge is an
interesting destination. You'll be thrown head first into Python
libraries you might not otherwise not be interested, like PIL.
Command line apps are not the norm in the challenge.

http://www.pythonchallenge.com/

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


Re: Shebang line on Windows?

2013-02-26 Thread Anssi Saari
Michael Torrie torr...@gmail.com writes:

 Actually, the shell isn't involved in parsing the shebang line at all.
 That's actually done in the kernel by the program loader.  So it's the
 kernel that has a problem with it; wonder if Linus would accept a patch
 to ignore the tailing CR?

Worth a try in my opinion. There's some historical information about the
shebang at http://www.in-ulm.de/~mascheck/various/shebang/ There's a
table which says Linux since 2.4.0 removes trailing whitespace from the
shebang line. I guess Linux doesn't count CR as whitespace in this
context.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nested loops

2013-02-26 Thread Alister
On Mon, 25 Feb 2013 23:46:11 +0100, leonardo wrote:

 hi everyone,
 
 i have the following program:
 
 import time count_timer = int(raw_input('how many seconds?: '))
 for i in range(count_timer, 0, -1):
  print i time.sleep(1)
 print 'blast off!'
 
 
 this is the result:
 
 how many seconds?: 5 5
 4
 3
 2
 1
 blast off!
 
 how can i have it print  a row of stars beside each number, like this?:
 
 how many seconds?: 5 5 * * * * *
 4 * * * *
 3 * * *
 2 * *
 1 *
 blast off!

you could try simply changing your print statement to


print %s %s%(i,* * i)

:-)

-- 
Someone in DAYTON, Ohio is selling USED CARPETS to a SERBO-CROATIAN
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-26 Thread Matej Cepl
On 2013-02-23, 15:51 GMT, Chris Angelico wrote:
 When you learn your first language, you think you're learning to
 program, but that's not really accurate. Once you've learned half a
 dozen, you begin to understand something of the art of coding as
 distinct from any particular language; after that, you can learn any
 language fairly easily.

And then you find out that to be REALLY good in one language, you 
have to focus on one language, because otherwise you are writing 
in some kind of mishmash. The point is that you don’t need to 
know any language but to at home in the whole universe of 
libraries, idioms, patterns, etc. and if you can manage to be 
REALLY at home in more than one (or let’s say two) universes, you 
are better than most (professional programmers) I know.

Shakespeare wasn’t good in writing German poetry, as far as 
I know.

Matěj
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webbrowser.open(./documentation/help.html)-- No Go in Windows

2013-02-26 Thread Matej Cepl
On 2013-02-25, 03:37 GMT, llanitedave wrote:
 url_link = file:/// + fullpath

Isn't this too many slashes. On Linux I get URI

file:usr/share/doc/whatever.html

which is just too many slashes (it should be three, two for the 
protocol, one for the root directory).

Matěj
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-26 Thread Matej Cepl
On 2013-02-23, 18:44 GMT, jmfauth wrote:
 Very easy to explain: wrong, incorrect, naive unicode
 handling.

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


Re: Small program ideas

2013-02-26 Thread Matej Cepl
On 2013-02-26, 03:48 GMT, eli m wrote:
 On Friday, February 15, 2013 7:22:41 PM UTC-8, eli m wrote:
 Any small program ideas? I would prefer to stick to command line 
 ones. Thanks.

 Thank you guys for the suggestions. Any more?

1) Clone git repository from https://github.com/mcepl/html2text
2) Switch to fix_tests branch
3) Fix all tests running the testsuite with python3.3

You will help a good thing, contribute to the Aaron Swartz memory (yes, 
*that* Aaron Swartz is the original author of the module), and learn 
about python more than by any silly simple demos (hint: pdb is your 
friend).

It is not difficult, just time consuming.

Best,

Matěj
-- 
http://mail.python.org/mailman/listinfo/python-list


Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)

2013-02-26 Thread Matej Cepl
Hi,

as my method to commemorate Aaron Swartz, I have decided to port his 
html2text to work fully with the latest python 3.3. After some time 
dealing with various bugs, I have now in my repo 
https://github.com/mcepl/html2text (branch python3) working solution 
which works all the way to python 3.2 (inclusive; 
https://travis-ci.org/mcepl/html2text). However, the last problem 
remains. This

liRun this command:
prels -l *.html/pre/li
li?/li

should lead to

  * Run this command: 

ls -l *.html

  * ?

but it doesn’t. It leads to this (with python 3.3 only)

* Run this command: 
  ls -l *.html
  
* ?

Does anybody know about something which changed in modules re or 
html.parser between 3.2 and 3.3, which could influence this script?

Thanks,

Matěj Cepl
-- 
http://mail.python.org/mailman/listinfo/python-list


Writing to same file from two threads

2013-02-26 Thread Jens Thoms Toerring
Hi,

   I noticed in someone elses program that it writes single
lines to the same file from (what I call for loss of a better
name) the main thread of the program and from a thread sub-
sequentally started. This got me worried if it might result
in garbled output (i.e. having some output from A inside a
line written by B or vice versae) because the main thread or
the other thread could be interrupted during a call of write().
Is this a valid concern (and thus locking the file object is
required before writing to it) or am I guaranteed that this
can't happen? In the latter case I would be grateful for an
explanation what mechanism is responsible for this never to
happen.
  Thanks and best regards, Jens

PS: I already have determined experimentally that a context
switch definitely can happen between two calls of write()
(and I expected nothing else), what I'm worried about are
context switches somewhere within the very innards of what
write() does.
-- 
  \   Jens Thoms Toerring  ___  j...@toerring.de
   \__  http://toerring.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Steven D'Aprano
On Wed, 27 Feb 2013 01:26:47 +1100, Chris Angelico wrote:

 And just to add to the pile of ways this could be done, the first
 response in this thread
 https://forums.digitalpoint.com/threads/how-to-get-last-character-in-
string.796134/
 suggests *reversing the string* and indexing from the front.

Oooh, deja vu! It's like it's 1988 and I'm learning to program in 
Hypertalk all over again!



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


Re: stmplib MIMEText charset weirdness

2013-02-26 Thread Adam W.
On Tuesday, February 26, 2013 2:10:28 AM UTC-5, Steven D'Aprano wrote:
 On Mon, 25 Feb 2013 20:00:24 -0800, Adam W. wrote:
 
 The documentation for MIMEText is rather terse, but it implies that the 
 
 parameter given should be a string, not bytes:
 
 
 
 http://docs.python.org/3.2/library/email.mime#email.mime.text.MIMEText
 
 
 
 If I provide a string, it seems to work fine:
 
 


Ok, working under the assumption you need to provide it a string, it still 
leaves the question why adding the header after the fact (to a string input) 
does not produce the same result as declaring the encoding type inline.

 
 
  As opposed to:
 
 
 
  text = MIMEText('❤¥'.encode('utf-8'), 'html', 'utf-8')
 
  text.as_string()
 
  'Content-Type: text/html; charset=utf-8\nMIME-Version:
 
  1.0\nContent-Transfer-Encoding: base64\n\n4p2kwqU=\n'
 
 
 
 
 
 My wild guess is that it is an accident (possibly a bug) that the above 
 
 works at all. I think it shouldn't; MIMEText is expecting a string, and 
 
 you provide a bytes object. The documentation for the email package 
 
 states:
 
 
 
 
 
 [quote]
 
 Here are the major differences between email version 5.0 and version 4:
 
 
 
 All operations are on unicode strings. Text inputs must be strings, 
 
 text outputs are strings. Outputs are limited to the ASCII character set 
 
 and so can be encoded to ASCII for transmission. Inputs are also limited 
 
 to ASCII; this is an acknowledged limitation of email 5.0 and means it 
 
 can only be used to parse email that is 7bit clean.
 
 [end quote]
 
 
 
 http://docs.python.org/3.2/library/email.html
 

I find this limitation hard to believe, why bother with encoding flags if it 
can only ever accept ASCII anyway?

The reason this issue came up was because I was adding the header after like in 
my examples and it wasn't working, so I Google'd around and found this 
Stackoverflow: 
http://stackoverflow.com/questions/10295530/how-to-set-a-charset-in-email-using-smtplib-in-python-2-7

Which seemed to be doing exactly what I wanted, with the only difference is the 
inline deceleration of utf-8, with that change it started working as desired...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread notbob
On 2013-02-26, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 The Python documentation is bad, and you should feel bad.

Ahh!  A point at which I can interject.

As a rank green python noob, I definitely hava an opinion on python
documentation and it's not entirely flattering.  OTOH, it's hard to
toss any other single linux based documentation up as a sterling
example.  IOW, I've seen worse.  How am I learning about python?

Several sources.  The Non-Programmer's Tutorial docs from wikibooks
was a false start.  It goes for about 2 pages before I realized
they've snuck in some python syntax without explaining it.  So, I jump
over to The Python Tutorial, which immediately leaves me submerged,
as it's waaay over my clueless head.  I flounder around and
desperately grab onto Basic Python over at About.com.  Finally, I'm
rescued!

Whoda thunk it?  I usta despise About.com.  But, they've matured
greatly since their early days.  I'm not a programmer.  In fact I
really dislike programming.  But, as a long time linux user, I really
need to learn a useful higher language.  And here is this website that
takes me by the hand and speaks to me like what I am.  Dumb as a post
and disinterested.  But, they are patient.  They explain basic
programming concepts before launching into specifics.  When they do
get specific, they use simple examples that make sense.  The don't
toss in syntax they haven't fully explained.  Great site and the one
I'm now using to progress.  I'm sure the other sites I've named will
become helpful, eventually, but now I can move forward with
confidence.

Are python doc sites perfect?  No.  I've yet to come upon anything
that clarifies why's and wherefores and the differences between the CMI
IDLE and the GUI IDLE.  And boy, are they different!  OTOH, as I said,
I've seen worse Linux docs.  BitchX or zsh?  What docs!?  Even the man
pages took me a long time to figure out.  Bluefish?  Krita?
Puh-leeze!  emacs?  It's a wonder I can use it at all.  ;)

Despite all that, I'd say python documentation is better than a poke
in the eye with a sharp stick.  I'm sure the official pages will make
more sense to me when I understand more.  As it is, they jes toss out
lc-letter like I know what they're talking about.  They explain it a
little bit, but I still hadda wiki it to get the full story.

As a person with some technical writing experience, I know how
difficult it can be.  I had to be careful about who I was writing for,
engineers or laymen.  It's the same with programming docs.  Writing
tutorials about python as if I jes came from 5 yrs as a C programmer
is not in the least bit helpful to a beginner like myself.  Sometimes,
one jes hasta hunt for the right flavor.  

nb

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


Re: Difference in RE between 3.2 and 3.3 (or Aaron Swartz memorial)

2013-02-26 Thread Terry Reedy

On 2/21/2013 4:22 PM, Matej Cepl wrote:

as my method to commemorate Aaron Swartz, I have decided to port his
html2text to work fully with the latest python 3.3. After some time
dealing with various bugs, I have now in my repo
https://github.com/mcepl/html2text (branch python3) working solution
which works all the way to python 3.2 (inclusive;
https://travis-ci.org/mcepl/html2text). However, the last problem
remains. This

liRun this command:
prels -l *.html/pre/li
li?/li

should lead to

   * Run this command:

 ls -l *.html

   * ?

but it doesn’t. It leads to this (with python 3.3 only)

 * Run this command:
   ls -l *.html

 * ?

Does anybody know about something which changed in modules re or
http://docs.python.org/3.3/whatsnew/changelog.html between 3.2 and 3.3, which 
could influence this script?


Search the changelob or 3.3 misc/News for items affecting those two 
modules. There are at least 4.

http://docs.python.org/3.3/whatsnew/changelog.html

It is faintly possible that the switch from narrow/wide builds to 
unified builds somehow affected that. Have you tested with 2.7/3.2 on 
both narrow and wide unicode builds?


--
Terry Jan Reedy


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


Re: yield expression

2013-02-26 Thread Colin J. Williams

On 24/02/2013 7:36 PM, Ziliang Chen wrote:

Hi folks,
When I am trying to understand yield expression in Python2.6, I did the following coding. I have difficulty understanding why 
val will be None ? What's happening under the hood? It seems to me very time the counter resumes to execute, it will assign 
count to val, so val should NOT be None all the time.

Thanks !

code snippet:

  def counter(start_at=0):
  count = start_at
  while True:
  val = (yield count)
  if val is not None:
  count = val
  else:
  print 'val is None'
  count += 1


Perhaps it's becaoue (teild count) is a statement.  Statements do not 
return a value.


Colin W.




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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Adam W.
I think learning a language from the documentation is an unreasonable 
expectation and burden for the authors.

Buy a book, take a class, they are designed to provide you with a path from 
start to finish in a sensible manner, the documentation in my opinion is 
supposed to be a reference and a refresher with an assumed level of basic 
fundamentals.

I'm currently taking a class in ARM assembly, the notion that I should expect 
to plop the thousand+ page reference manual on my desk and just get to it is 
absurd.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yield expression

2013-02-26 Thread Ian Kelly
On Tue, Feb 26, 2013 at 9:34 AM, Colin J. Williams c...@ncf.ca wrote:
 Perhaps it's becaoue (teild count) is a statement.  Statements do not return
 a value.

yield is a bit of an odd duck in that it's both a statement and an
expression.  Compare:

http://docs.python.org/3/reference/simple_stmts.html#the-yield-statement

http://docs.python.org/3/reference/expressions.html#yieldexpr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groupby behaviour

2013-02-26 Thread Ian Kelly
On Tue, Feb 26, 2013 at 9:27 AM, andrea crotti
andrea.crott...@gmail.com wrote:
 So I was trying to use groupby (which I used in the past), but I
 noticed a very strange thing if using list on
 the result:

As stated in the docs:


The returned group is itself an iterator that shares the underlying
iterable with groupby(). Because the source is shared, when the
groupby() object is advanced, the previous group is no longer visible.
So, if that data is needed later, it should be stored as a list:

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


Re: IMAP4_SSL and OpenSSL compatibility

2013-02-26 Thread W. Martin Borgert

Quoting Antoine Pitrou solip...@pitrou.net:

W. Martin Borgert debacle at debian.org writes:

When I add an ssl_version argument to the call to
ssl.wrap_socket() in imaplib.IMAP4_SSL.open(), I can connect to
the Exchange server without problems:

self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile,
  ssl_version = ssl.PROTOCOL_SSLv3)

Would it make sense, to make this change in the Python standard
library?


There is already the ssl_context option for that:
http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4_SSL


Many thanks! Two more questions:

 1. Is there any plan to backport this Python = 3.3 feature to
Python 2?

 2. Would the following lines be correct for Python 3.3?

 import imaplib
 IMAP4_SSL(192.168.1.1., ssl_context =  
SSLContext(ssl.PROTOCOL_SSLv3))


Cheers

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Andrew Berg
On 2013.02.26 10:19, notbob wrote:
  zsh?  What docs!?
You mean other than the gigantic user manual?
http://zsh.sourceforge.net/Doc/

-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: yield expression

2013-02-26 Thread Dave Angel

On 02/26/2013 11:34 AM, Colin J. Williams wrote:

On 24/02/2013 7:36 PM, Ziliang Chen wrote:

Hi folks,
When I am trying to understand yield expression in Python2.6, I did
the following coding. I have difficulty understanding why val will
be None ? What's happening under the hood? It seems to me very time
the counter resumes to execute, it will assign count to val, so
val should NOT be None all the time.

Thanks !

code snippet:

  def counter(start_at=0):
  count = start_at
  while True:
  val = (yield count)
  if val is not None:
  count = val
  else:
  print 'val is None'
  count += 1


Perhaps it's becaoue (teild count) is a statement.  Statements do not
return a value.

Colin W.






'yield count' is a yield_expression, not always a statement.  If it were 
the first thing in a statement, it'd be a yield_stmt



See the docs: http://docs.python.org/2/reference/simple_stmts.html

assignment_stmt ::=  (target_list =)+ (expression_list | yield_expression)

and  http://docs.python.org/2/reference/expressions.html

yield_atom   ::=  ( yield_expression )
yield_expression ::=  yield [expression_list]

The value produced by the yield expression is produced by   a.send() 
method.  This allows an approximation to coroutines.


I believe this dual usage of yield started in Python 2.5


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


Re: yield expression

2013-02-26 Thread Vytas D.
Hi,

You are using yield incorrectly. yield works like return, but it can
return more than once from the same function. Functions that yield
produce a so called generator object. This generator object gives you
values every time you call it.

The generator works very interesting way. It starts like normal function
and goes until it finds yield and returns the value. The state of
generator is saved - it is like it is put to sleep until you call it again.
So the next time you call generator() it runs from the point it returned
last time and will return you another value.

Simple sample of making and using generator (prints forever, so just kill
with CTRL+C).

def counter(start_at=0):
Returns integer each time called

count = start_at
while True:
yield count
count += 1

def main():
generator = counter()

while True:
print(next(generator))


if __name__ == '__main__':
main()


Hope helps.

Vytas D.



On Tue, Feb 26, 2013 at 4:34 PM, Colin J. Williams c...@ncf.ca wrote:

 On 24/02/2013 7:36 PM, Ziliang Chen wrote:

 Hi folks,
 When I am trying to understand yield expression in Python2.6, I did the
 following coding. I have difficulty understanding why val will be None
 ? What's happening under the hood? It seems to me very time the counter
 resumes to execute, it will assign count to val, so val should NOT be
 None all the time.

 Thanks !

 code snippet:
 
   def counter(start_at=0):
   count = start_at
   while True:
   val = (yield count)
   if val is not None:
   count = val
   else:
   print 'val is None'
   count += 1


 Perhaps it's becaoue (teild count) is a statement.  Statements do not
 return a value.

 Colin W.



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

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


Re: groupby behaviour

2013-02-26 Thread andrea crotti
2013/2/26 Ian Kelly ian.g.ke...@gmail.com:
 On Tue, Feb 26, 2013 at 9:27 AM, andrea crotti
 andrea.crott...@gmail.com wrote:
 So I was trying to use groupby (which I used in the past), but I
 noticed a very strange thing if using list on
 the result:

 As stated in the docs:

 
 The returned group is itself an iterator that shares the underlying
 iterable with groupby(). Because the source is shared, when the
 groupby() object is advanced, the previous group is no longer visible.
 So, if that data is needed later, it should be stored as a list:
 
 --
 http://mail.python.org/mailman/listinfo/python-list


I should have read more carefully sorry, I was in the funny situation
where it would have actually worked in the production code but it was
failing in the unit tests (because I was using list only there).

It's very weird though this sharing and still doesn't really look
rightl, is it done just for performance reasons?
-- 
http://mail.python.org/mailman/listinfo/python-list


python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Robin Becker
In python 2 I was able to improve speed of reportlab using a C extension to 
optimize some heavily used methods.


so I was able to do this


class A:
.
def method(self,...):
   


try:
from extension import c_method
import new
A.method = new.instancemethod(c_method,None,A)
except:
pass

and if the try succeeds our method is bound as a class method ie is unbound and 
works fine when I call it.


In python 3 this doesn't seem to work at all. In fact the new module is gone. 
The types.MethodType stuff doesn't seem to work.


Is there a way in Python 3.3 to make this happen? This particular method is 
short, but is called many times so adding python wrapping layers is not a good 
way forward.


If the above cannot be made to work (another great victory for Python 3) then is 
there a way to bind an external method to the instance without incurring too 
much overhead.


Alternatively could it make sense to implement an accelerated basetype that just 
contains the accelerated methods of class A. I could then imagine doing 
something like


try:
from extension import class c_baseA as baseA
except:
class baseA:
   def method()

class A(baseA):
.

presumably I then get some kind of penalty for the base class lookup, but how 
bad is that?

--
Robin Becker

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


Re: Writing to same file from two threads

2013-02-26 Thread Paul Rubin
j...@toerring.de (Jens Thoms Toerring) writes:
 in garbled output (i.e. having some output from A inside a
 line written by B or vice versae) because the main thread or

Yes they do get garbled like that.  Preferred Python style is put a
single thread in charge of all the i/o to that file, and communicate
with it by message passing through Queue objects.  That is safer than
directly using locks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: groupby behaviour

2013-02-26 Thread Paul Rubin
andrea crotti andrea.crott...@gmail.com writes:
 It's very weird though this sharing and still doesn't really look
 rightl, is it done just for performance reasons?

It could consume unbounded amounts of memory otherwise.  E.g. if there
are millions of items in the group.

If you're not worried about that situation it's simplest to just
convert each group to a list for processing it:

   for k,g in groupby(...):
  gs = list(g)
  # do stuff with gs

calling list(g) reads all the elements in the group, advancing groupby's
internal iterator to the next group.  Since you've copied out all the
group elements, you don't have to worry about the sharing effect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread MRAB

On 2013-02-26 14:26, Chris Angelico wrote:

On Wed, Feb 27, 2013 at 12:56 AM, Roy Smith r...@panix.com wrote:

When people ask PHP questions, the questions tend to be phrased as what
do I type to get X, and the answers come back that way too.  The forums
are full of, I had the same problem.  Somebody told me to do this.  I
don't really understand it, but it worked for me and maybe it'll work
for you too.


A problem that's majorly exacerbated by the myriad ways of doing some
things, with some of those ways deprecated and others theoretically
plausible but hopelessly impractical.

Here's an actual example that came up today at work. Suppose you have
a user-provided string that's supposed to contain a URL, and you need
to ensure that it doesn't have a trailing slash, so you can later add
/foo or /bar. (Or alternatively, ensure that it DOES have a
trailing slash. Either works.) Start the timer, go find out how to do
it. Assume you are broadly familiar with PHP, and know how to do the
basics of string handling, and are competent at searching the web.
Ready? Go!

I'll wait for you to come back.

... Okay, some of you are back now. Just giving the stragglers time to
finish losing their marbles...

Alright. Here's what I found in a recreation of today's search.
Google search: php last character of string

http://php.net/manual/en/function.substr.php
-- okay, so I can use substr, but not string indexing, to find out
what the last character is
-- Returns the extracted part of string; or FALSE on failure, or an
empty string. What kind of failures result in FALSE, and what kind in
an empty string?


[snip]
The page http://php.net/manual/en/function.substr.php says:

Description
string substr ( string $string , int $start [, int $length ] )

OK. It then goes on to say:

Parameters
string
The input string. Must be one character or longer.

What? The input string can't be an empty string?

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


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Dave Angel

On 02/26/2013 12:21 PM, Robin Becker wrote:

In python 2 I was able to improve speed of reportlab using a C extension
to optimize some heavily used methods.

so I was able to do this


class A:


That creates an old-style class in  Python 2.x.  They've been obsolete 
for many years.  You want to derive from object:

class  A(object):

Once you do, Python 2 and Python 3 should work the same.  I can't help 
with the rest, unfortunately.



 .
 def method(self,...):



try:
 from extension import c_method
 import new
 A.method = new.instancemethod(c_method,None,A)
except:
 pass

and if the try succeeds our method is bound as a class method ie is
unbound and works fine when I call it.

In python 3 this doesn't seem to work at all. In fact the new module is
gone. The types.MethodType stuff doesn't seem to work.

Is there a way in Python 3.3 to make this happen? This particular method
is short, but is called many times so adding python wrapping layers is
not a good way forward.

If the above cannot be made to work (another great victory for Python 3)
then is there a way to bind an external method to the instance without
incurring too much overhead.

Alternatively could it make sense to implement an accelerated basetype
that just contains the accelerated methods of class A. I could then
imagine doing something like

try:
 from extension import class c_baseA as baseA
except:
 class baseA:
def method()

class A(baseA):
 .

presumably I then get some kind of penalty for the base class lookup,
but how bad is that?



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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread notbob
On 2013-02-26, Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2013.02.26 10:19, notbob wrote:
  zsh?  What docs!?
 You mean other than the gigantic user manual?
 http://zsh.sourceforge.net/Doc/

This document was generated by Simon Ruderich on July 24, 2012

'bout damn time!!  ;)

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Tim Chase
On 2013-02-26 17:54, notbob wrote:
   zsh?  What docs!?
  You mean other than the gigantic user manual?
  http://zsh.sourceforge.net/Doc/
 
 This document was generated by Simon Ruderich on July 24, 2012
 
 'bout damn time!!  ;)

Generated...from source that has been around for ages:

http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=history;f=Doc;hb=dd3b0506f99e690f521d9bf449dea47a51502cb2;pg=11

which suggests that they've been actively maintained since 1999-2000
or so.

-tkc


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


Re: Python Newbie

2013-02-26 Thread rurpy
On 02/26/2013 01:32 AM, Larry Hudson wrote:
 On 02/24/2013 02:43 PM, piterrr.dolin...@gmail.com wrote:
 snip
 ...  But for the moment I am trying to imitate familiar ground.
 snip
 This is EXACTLY why you're having trouble grasping Python.  Python is a 
 different language and 
 requires a different mind-set and different approach.  In this, it is NO 
 different from ANY 
 other new (to you) programming language.

No.  Programming languages have far more in common with other 
languages than differences.  This is particularly true of Python 
which has always seemed to me as a very well-selected compilation 
of existing programming language features rather than consisting 
of groundbreaking new concepts. 

 Of course, don't forget general programming principles -- how to approach a 
 problem, how to 
 select algorithms, and such.  These apply to any language, but the details of 
 syntax and such 
 ARE different in different languages.  Trying to apply these old details to a 
 new language only 
 hinders your learning process, it definitely does NOT help.
 
 Actually, your comments and questions make me wonder HOW you are trying to 
 learn Python.  All 
 the things you're asking about are clearly and completely discussed in any 
 decent book or 
 tutorial.  It makes me speculate that you're simply trying to use a Python 
 reference instead of 
 something that actually teaches anything.  A reference may give you the rules 
 and syntax, but 
 not much about how to apply them properly.

That is sadly true of the Python reference manuals (Language 
and Library) but need not and should not be true in general.  
There is no reason why someone with basic programming experience
in another similar language should not be able to learn a new 
language from its *well written* reference manuals.

 Please think about finding some better fundamental material -- there is a LOT 
 available.  And 
 please quit trying to force Python to be something it isn't.  That is never 
 going to be 
 effective and definitely harmful to your learning.

Part of learning, indeed much of the value in learning, a new 
language when one already knows several others, is mentally 
unifying the things that are similar in the old and new languages,
and distinguishing what is different.

You do NOT need to throw out everything you learned about those
other language to learn new one.  Thinking of the features of the 
new language in terms of the old one is a necessary part of this
process.  I still think in terms of C pointers when thinking 
about how Python references objects.  The problem arises when
when one assumes that syntax that looks similar *should* behave 
similarly.

As for migrating idioms from the previous language to the new
one, such as adding redundant parenthesis around the conditional
expression in an if statement, I think it is relatively
harmless.  Contrary to previous claims, it will NOT result
in an unmaintainable mess.  I doubt if any maintainabilty 
difference in such code could even be measured other than that
caused by a prima-donna-ish eew, I'm not going to work on
that code because I think it is UGLY! effect.  Perhaps if
we were talking about a program manager setting such idioms
in stone for 100's of kilolines of code it would be different
but for the OPs situation, I see no harm in it.
If it helps the OP transition to python, then I say do it.

For the record, I did much the same thing coming to Python from
Perl.  After a while I came to the common view that such parens
were more noise than clarifying but I reached that conclusion 
based on my own experience rather than being bludgeoned into
it by extreme predictions of doom read here.

 snip
 I wanted Python to register what type of variable I'm after...
 
 Python variables do NOT have any data type.  The objects they reference have 
 data types. 
 Variables can be assigned and RE-assigned to any data type at any time.  
 Again, I emphasize, 
 QUIT THINKING IN ANOTHER LANGUAGE, it simply doesn't work.  You might like it 
 if it were so, but 
 it simply does not match reality.

I have no problem interpreting the OP's statement (as quoted 
above) as meaning that he wanted to use a Python variable to 
consistently reference a particular type and wanted a name 
that would remind him of that type. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Peter Otten
Robin Becker wrote:

 In python 2 I was able to improve speed of reportlab using a C extension
 to optimize some heavily used methods.
 
 so I was able to do this
 
 
 class A:
  .
  def method(self,...):
 
 
 
 try:
  from extension import c_method
  import new
  A.method = new.instancemethod(c_method,None,A)
 except:
  pass
 
 and if the try succeeds our method is bound as a class method ie is
 unbound and works fine when I call it.
 
 In python 3 this doesn't seem to work at all. In fact the new module is
 gone. The types.MethodType stuff doesn't seem to work.
 
 Is there a way in Python 3.3 to make this happen? This particular method
 is short, but is called many times so adding python wrapping layers is not
 a good way forward.
 
 If the above cannot be made to work (another great victory for Python 3)
 then is there a way to bind an external method to the instance without
 incurring too much overhead.

Hm, according to my random measurement your clever approach incurs more 
overhead than the straight-forward way that continues to work in Python 3:

$ python -m timeit -s 'from new import instancemethod
 from math import sqrt
 class A(int): pass
 A.m = instancemethod(sqrt, None, A)
 a = A(42)
 ' 'a.m()'
100 loops, best of 3: 0.5 usec per loop
$ python -m timeit -s 'from math import sqrt
 class A(int):
 def m(self):
 return sqrt(self)
 a = A(42)
 ' 'a.m()'
100 loops, best of 3: 0.473 usec per loop


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


Re: yield expression

2013-02-26 Thread Colin J. Williams

On 26/02/2013 12:07 PM, Vytas D. wrote:

Hi,

You are using yield incorrectly. yield works like return, but it can
return more than once from the same function. Functions that yield
produce a so called generator object. This generator object gives you
values every time you call it.

The generator works very interesting way. It starts like normal function
and goes until it finds yield and returns the value. The state of
generator is saved - it is like it is put to sleep until you call it
again. So the next time you call generator() it runs from the point it
returned last time and will return you another value.

Simple sample of making and using generator (prints forever, so just
kill with CTRL+C).

def counter(start_at=0):
 Returns integer each time called

 count = start_at
 while True:
 yield count
 count += 1

def main():
 generator = counter()

 while True:
 print(next(generator))


if __name__ == '__main__':
 main()


Hope helps.

Vytas D.



On Tue, Feb 26, 2013 at 4:34 PM, Colin J. Williams c...@ncf.ca
mailto:c...@ncf.ca wrote:

On 24/02/2013 7:36 PM, Ziliang Chen wrote:

Hi folks,
When I am trying to understand yield expression in Python2.6,
I did the following coding. I have difficulty understanding why
val will be None ? What's happening under the hood? It seems
to me very time the counter resumes to execute, it will assign
count to val, so val should NOT be None all the time.

Thanks !

code snippet:

   def counter(start_at=0):
   count = start_at
   while True:
   val = (yield count)
   if val is not None:
   count = val
   else:
   print 'val is None'
   count += 1


Perhaps it's becaoue (teild count) is a statement.  Statements do
not return a value.

Colin W.



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



Yes, it's very helpful.  Thanks also to the other two responders.

This brings us back to the OP question.  Why not  val = (yield count)?

Colin W.


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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Terry Reedy

On 2/26/2013 7:54 AM, Steven D'Aprano wrote:

One week ago, JoePie91 wrote a blog post challenging the Python
community and the state of Python documentation, titled:

The Python documentation is bad, and you should feel bad.

http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-
and-you-should-feel-bad/


To me, this is a lying troll rant worth less than most of RantingRick's 
posts.



It is valuable to contrast and compare the PHP and Python docs:

http://php.net/manual/en/index.php
http://www.python.org/doc/


The contrast has been discussed before on python-list and even pydev. To 
repeat: in my opinion, and that of most core developers, the python docs 
are superior. It is Joe's lie to equate difference of opinion with 
indifference.


Python has a nice Tutorial for beginners. It is an integral part of the 
doc set. To ignore that (and the indexes) in discussing the usability of 
Python docs by beginners is to lie. (If beginners who actually read the 
tutorial have problems with particular paragraphs, improvements can be 
and have been made.)


Examples: Once startup is explained, the rest of the tutorial is about 
half text and half example. I think that is a good balance. Anyone who 
reads the tutorial knows how to call a function. I think doubling the 
size of the Library *Reference* with trivial, repetitive examples like:


 len([1,2,3])
3

would be a negative for reference use*. Python has a super-duper 
interactive mode for trying things like this oneself, and that teaches 
*better* than just reading the same thing. (And if the tutorial never 
discusses len() and its generic use for all concrete collections, it 
should.)


* Anyone who disagrees can go to
http://www.lightbird.net/py-by-example/builtin-functions.html
where you can find that and other examples for builtins and about 30 
modules. Actually, I can imagine that some beginners would benefit from 
this page as an extension of the tutorial. This site may be an outcome 
of the previous discussion, which more or less ended with the fact that 
anyone who wanted to produce php-style Python docs was free to do so.


Searching: it is true that the Python docs are written for being read by 
people, rather than by search engines#. It has a hand-crafted index 
(yes, it still needs patches) that will get you most places, especially 
for anyone who has read the tutorial to get the basics. For 'length of a 
list' one can find 'len() (built-in function)' and find that 'len' 
indeed mean length and, more generally, size.


# Anyone who wants to could develop an seo-optimized python-by-function 
website that goes into exquisite details for each function on a separate 
page.


len(collection) = count
Built-in function len() allows one to find the
* length or size of a list
* length or size of a tuple
* length or size of an array
* length or size of a string
* length or size of a bytes
* length or size of a bytearray
* length or size of a memoryview
* size of a set
* size of a frozenset
* size of a dict or dictionary
* size of dict view
* size of user-defined collecton class instances

Returns 0 for empty collections. Raises TypeError for inputs that are 
not collections or that do not support len() calls, because they do not 
have a properly written .__len__ methods.


If I were involved, I would *not* junk-up such pages with random user 
posts. Anything worth being added should be incorporated into the entry 
itself.


--
Terry Jan Reedy

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread notbob
On 2013-02-26, Tim Chase python.l...@tim.thechases.com wrote:

 which suggests that they've been actively maintained since 1999-2000
 or so.

in various guises, dating back to the man pages.  Not all as
thorough as the latest manual.  Perhaps I shoulda qualified usable
docs.  ;)

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Devin Jeanpierre
On Tue, Feb 26, 2013 at 11:38 AM, Adam W. awasile...@gmail.com wrote:
 I think learning a language from the documentation is an unreasonable 
 expectation and burden for the authors.

That's how I learned it. The Python tutorial, together with the stdlib
reference manual, are often recommended to beginners to Python in
order to learn it. The combination of the documentation and consulting
other programmers helped me learn the language just fine.

 Buy a book, take a class, they are designed to provide you with a path from 
 start to finish in a sensible manner, the documentation in my opinion is 
 supposed to be a reference and a refresher with an assumed level of basic 
 fundamentals.

I would assert it isn't very kind to those even with basic fundamentals.

For example, under precisely what circumstances does int() raise
TypeError? You won't find that under either int's documentation, or
TypeError's documentation, you have to look it up under __int__, which
is _not_ a basic fundamental. And rather than helping you along the
way, the documentation for int() actively misleads you by its
implicature that the only acceptable types are strings, ints, and
floats. And then even if you have the foresight to remember oh yeah,
isn't there a special method for this?, you have to find the
documentation for __int__, which is itself is three quarters of the
way down this massive page:
http://docs.python.org/2/reference/datamodel.html .

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Mitya Sirenef

On 02/26/2013 07:54 AM, Steven D'Aprano wrote:

One week ago, JoePie91 wrote  a blog post challenging the Python

 community and the state of Python documentation, titled:

 The Python documentation is bad, and you should feel bad.

 http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-
 and-you-should-feel-bad/

 It is valuable to contrast and compare the PHP and Python docs:

 http://php.net/manual/en/index.php
 http://www.python.org/doc/

 There's no doubt that one of PHP's strengths, perhaps its biggest
 strength, is the good state of documentation. But should we feel bad
 about Python's docs? I don't think that either the Python documentation
 or community is as bad as JoePie91 suggests. (Well, I won't speak for 
the

 people on Freenode's #python. It took me approximately three minutes to
 be banned from there, with no warning or explanation.)

 Another response to the blog post, by one of the core developers:

 http://blog.briancurtin.com/posts/why-i-dont-feel-so-bad.html





I think the issue with python documentation is that it ignores the 95/5
rule: 95% of people who land on a module's page are only looking for 5%
of its information. So ideally it'd be separated in two different pages
or two sections of the same page, something like:

===

Hi, chances are you are the 95% of people who isn't interested in the
intricacies, obscure edge cases et cetera. Here are the few common use
cases for this module:

...

...

...

===

Hi, the section above obviously did not suit your needs, so you must be
in the 5% who has no choice but to either read through or at least
glance through, or use search, to find what you need in the following
umpteen million of screenfuls:

... * 100


===

Why doesn't Python do that? Quite simply, it's a lot more work: you have
to separate most useful parts from the rest, which involves judgement
calls and will cause some disagreement and ultimately won't be perfect.
Once done, two separate sections need to be mainained and kept in sync.
It's important that they don't contradict each other.

Right now places like SO and mailing list act like the first section I
described. The issue is that they're not always up to date and not
guaranteed to be correct, are not in a consistent style and depth, are
not centralized.

 -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Is life not a thousand times too short for us to bore ourselves?
Friedrich Nietzsche

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread nn
On Feb 26, 11:19 am, notbob not...@nothome.com wrote:
 On 2013-02-26, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

  The Python documentation is bad, and you should feel bad.

 Ahh!  A point at which I can interject.

 As a rank green python noob, I definitely hava an opinion on python
 documentation and it's not entirely flattering.  OTOH, it's hard to
 toss any other single linux based documentation up as a sterling
 example.  IOW, I've seen worse.  How am I learning about python?

 Several sources.  The Non-Programmer's Tutorial docs from wikibooks
 was a false start.  It goes for about 2 pages before I realized
 they've snuck in some python syntax without explaining it.  So, I jump
 over to The Python Tutorial, which immediately leaves me submerged,
 as it's waaay over my clueless head.  I flounder around and
 desperately grab onto Basic Python over at About.com.  Finally, I'm
 rescued!

 Whoda thunk it?  I usta despise About.com.  But, they've matured
 greatly since their early days.  I'm not a programmer.  In fact I
 really dislike programming.  But, as a long time linux user, I really
 need to learn a useful higher language.  And here is this website that
 takes me by the hand and speaks to me like what I am.  Dumb as a post
 and disinterested.  But, they are patient.  They explain basic
 programming concepts before launching into specifics.  When they do
 get specific, they use simple examples that make sense.  The don't
 toss in syntax they haven't fully explained.  Great site and the one
 I'm now using to progress.  I'm sure the other sites I've named will
 become helpful, eventually, but now I can move forward with
 confidence.

 Are python doc sites perfect?  No.  I've yet to come upon anything
 that clarifies why's and wherefores and the differences between the CMI
 IDLE and the GUI IDLE.  And boy, are they different!  OTOH, as I said,
 I've seen worse Linux docs.  BitchX or zsh?  What docs!?  Even the man
 pages took me a long time to figure out.  Bluefish?  Krita?
 Puh-leeze!  emacs?  It's a wonder I can use it at all.  ;)

 Despite all that, I'd say python documentation is better than a poke
 in the eye with a sharp stick.  I'm sure the official pages will make
 more sense to me when I understand more.  As it is, they jes toss out
 lc-letter like I know what they're talking about.  They explain it a
 little bit, but I still hadda wiki it to get the full story.

 As a person with some technical writing experience, I know how
 difficult it can be.  I had to be careful about who I was writing for,
 engineers or laymen.  It's the same with programming docs.  Writing
 tutorials about python as if I jes came from 5 yrs as a C programmer
 is not in the least bit helpful to a beginner like myself.  Sometimes,
 one jes hasta hunt for the right flavor.

 nb

For me on the other hand. The Python tutorial has been the most useful
tutorial I have ever used. I had experience with Basic and Pascal.
Most other tutorials go too slow for me and I loose interest. The
python one just kept going and after reading the dozen pages in a
couple of hours I had enough of an idea about the language to start
doing the things I was interested in.

The only thing that confused me at first was finding functions like
open or input and string methods. I lost a bit of time searching
in the language reference until I found out that they are in the
Library reference: I didn't think of open as a library. But now I
have no problem; all I need is found under Library reference in
section 2 and 4 and starting with section 6. I also use the global
module index when I already have an idea what I am looking for.

What it could have is better searching capability and a way to see
more examples. Examples would clutter the documentation so maybe they
should be collapsible, but you can never have enough examples. As
Einstein said:
“Example isn't another way to teach, it is the only way to teach”
Outside of the tutorial there are not a lot of succinct examples of
more advanced uses of the different keywords and builtins. Thankfully
for the libraries there is Python Module of the Week for people that
know about it.

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


Re: Python Newbie

2013-02-26 Thread Jean-Michel Pichavant

- Original Message -
 Hi guys,
 
 Question. Have this code
 
 intX = 32  # decl + init int var
 intX_asString = None   # decl + init with NULL string var
 
 intX_asString = intX.__str__ ()# convert int to string
 
 What are these ugly underscores for?
 _str___
 
 Peter
 --
 http://mail.python.org/mailman/listinfo/python-list

I can't wait for the 

intX_asString_asBool = intX_asString.__bool__()

if (intX_asString_asBool == True):
  # do something 

;-)

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-26 Thread Ethan Furman

On 02/26/2013 10:23 AM, ru...@yahoo.com wrote:

On 02/26/2013 01:32 AM, Larry Hudson wrote:

Python variables do NOT have any data type.


I have no problem interpreting the OP's statement
as meaning that he wanted to use a Python variable to
consistently reference a particular type and wanted a name
that would remind him of that type.


Which is all well and good, so long as the OP also realizes that the name does not have any restriction's on it from 
Python's side, and certain functions will end up pointing the name at a different object with a possibly different type 
than his original, as in my int/float example.


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


facebook

2013-02-26 Thread 23alagmy
facebook

http://goo.gl/7nUIp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Mark Lawrence

On 26/02/2013 18:38, Peter Otten wrote:

Robin Becker wrote:


In python 2 I was able to improve speed of reportlab using a C extension
to optimize some heavily used methods.

so I was able to do this


class A:
  .
  def method(self,...):
 


try:
  from extension import c_method
  import new
  A.method = new.instancemethod(c_method,None,A)
except:
  pass

and if the try succeeds our method is bound as a class method ie is
unbound and works fine when I call it.

In python 3 this doesn't seem to work at all. In fact the new module is
gone. The types.MethodType stuff doesn't seem to work.

Is there a way in Python 3.3 to make this happen? This particular method
is short, but is called many times so adding python wrapping layers is not
a good way forward.

If the above cannot be made to work (another great victory for Python 3)
then is there a way to bind an external method to the instance without
incurring too much overhead.


Hm, according to my random measurement your clever approach incurs more
overhead than the straight-forward way that continues to work in Python 3:

$ python -m timeit -s 'from new import instancemethod

from math import sqrt
class A(int): pass
A.m = instancemethod(sqrt, None, A)
a = A(42)
' 'a.m()'

100 loops, best of 3: 0.5 usec per loop
$ python -m timeit -s 'from math import sqrt

class A(int):
 def m(self):
 return sqrt(self)
a = A(42)
' 'a.m()'

100 loops, best of 3: 0.473 usec per loop




c:\Users\Mark\MyPythonpython
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 
bit (Intel)] on win32

Type help, copyright, credits or license for more information.
 import new
Traceback (most recent call last):
  File stdin, line 1, in module
ImportError: No module named 'new'

--
Cheers.

Mark Lawrence

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


Re: nested loops

2013-02-26 Thread Anssi Saari
leonardo tampucciol...@libero.it writes:

 how can i have it print  a row of stars beside each number, like this?:

 how many seconds?: 5
 5 * * * * *
 4 * * * *
 3 * * *
 2 * *
 1 *
 blast off!

You could use the repetition operator * since you have the number of
repetitions needed in i. Alternatively, considering the subject, you'd
just add another for loop to print the stars and spaces.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Newbie

2013-02-26 Thread Piterrr
Jean-Michel Pichavant jeanmic...@sequans.com wrote in message 
news:mailman.2567.1361905815.2939.python-l...@python.org...


- Original Message -

Hi guys,

Question. Have this code

intX = 32  # decl + init int var
intX_asString = None   # decl + init with NULL string var

intX_asString = intX.__str__ ()# convert int to string

What are these ugly underscores for?
_str___

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


I can't wait for the

intX_asString_asBool = intX_asString.__bool__()

if (intX_asString_asBool == True):
 # do something

;-)

JM


As serious a character as I am, I had good laughs at this. Don't you all 
like my questions for all the exitainment they offer?


The __str__ issue was a genuine question. I'm glad to find there is also a 
__bool_ () method, shall I need it. :-) Please note, this is not how I write 
my code. I'm not that bad a programmer, it's just Python which is so 
different that I am doing what I need to help clarify things and help me 
out.


I don't find this post offensive, even though JM is deliberately making fun 
of me. But to his credit, it is funny indeed. Let's laugh 2gether!


This reminds me, when I first started working with databases and saw an 
error msg which said that my query had ambiguous columns I laughed for 1/2 
hr. I found it incredibly exitaining that a 100% deterministic piece of 
hardware could have the word ambiguous in its internal dictionary.


:-))

Peter 


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


Re: stmplib MIMEText charset weirdness

2013-02-26 Thread Terry Reedy

On 2/25/2013 11:00 PM, Adam W. wrote:

Can someone explain to me why I can't set the charset after the fact.


Email was revised to v.6 for 3.3, so the immediate answer to both your 
why questions is 'because email was not revised yet'.



text = MIMEText('❤¥'.encode('utf-8'), 'html')


In 3.3 this fails immediately with
AttributeError: 'bytes' object has no attribute 'encode'
because when _charset is not given, MIMEText.__init__ test encodes to 
discover what it should be

if _charset is None:
try:
_text.encode('us-ascii')
_charset = 'us-ascii'
except UnicodeEncodeError:
_charset = 'utf-8'


text = MIMEText('❤¥'.encode('utf-8'), 'html', 'utf-8')


If one provides bytes, one must provide the charset and MIMEText assumes 
you are not lying.



text.as_string()
Content-Type: text/html; charset=utf-8

 MIME-Version: 1.0
 Content-Transfer-Encoding: base64


4p2kwqU=



Side question:
text = MIMEText('❤¥', 'html')
text.set_charset('utf-8')


This is redundant here. This method is inherited from Message and 
appears pretty useless for the subclass.



text.as_string()
'MIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\nContent-Type:

 text/html;charset=utf-8\n\n❤¥'


Why is it now 8-bit encoding?


Bug fixed in 3.3. Output now same as above. Use 3.3 for email unless you 
cannot due to other dependencies not yet being available.


--
Terry Jan Reedy


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


Re: Writing to same file from two threads

2013-02-26 Thread Jens Thoms Toerring
Paul Rubin no.email@nospam.invalid wrote:
 j...@toerring.de (Jens Thoms Toerring) writes:
  in garbled output (i.e. having some output from A inside a
  line written by B or vice versae) because the main thread or

 Yes they do get garbled like that.  Preferred Python style is put a
 single thread in charge of all the i/o to that file, and communicate
 with it by message passing through Queue objects.  That is safer than
 directly using locks.

Thank you for confirmig my suspicion;-) But you have induced
another question: why is using a Queue safer than locking (not
that I doubt that it might be more elegant etc.). Is it safer
because it's less likely that one gets it wrong (e.g. by for-
grtting to acquire the lock) or is there something inherently
unsafe about locks?

  Thank you and best regards, Jens
-- 
  \   Jens Thoms Toerring  ___  j...@toerring.de
   \__  http://toerring.de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Peter Otten
Mark Lawrence wrote:

 On 26/02/2013 18:38, Peter Otten wrote:
 Robin Becker wrote:

 In python 2 I was able to improve speed of reportlab using a C extension
 to optimize some heavily used methods.

 so I was able to do this


 class A:
   .
   def method(self,...):
  


 try:
   from extension import c_method
   import new
   A.method = new.instancemethod(c_method,None,A)
 except:
   pass

 and if the try succeeds our method is bound as a class method ie is
 unbound and works fine when I call it.

 In python 3 this doesn't seem to work at all. In fact the new module is
 gone. The types.MethodType stuff doesn't seem to work.

 Is there a way in Python 3.3 to make this happen? This particular method
 is short, but is called many times so adding python wrapping layers is
 not a good way forward.

 If the above cannot be made to work (another great victory for Python 3)
 then is there a way to bind an external method to the instance without
 incurring too much overhead.

 Hm, according to my random measurement your clever approach incurs more
 overhead than the straight-forward way that continues to work in Python
 3:

 $ python -m timeit -s 'from new import instancemethod
 from math import sqrt
 class A(int): pass
 A.m = instancemethod(sqrt, None, A)
 a = A(42)
 ' 'a.m()'
 100 loops, best of 3: 0.5 usec per loop
 $ python -m timeit -s 'from math import sqrt
 class A(int):
  def m(self):
  return sqrt(self)
 a = A(42)
 ' 'a.m()'
 100 loops, best of 3: 0.473 usec per loop


 
 c:\Users\Mark\MyPythonpython
 Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32
 bit (Intel)] on win32
 Type help, copyright, credits or license for more information.
   import new
 Traceback (most recent call last):
File stdin, line 1, in module
 ImportError: No module named 'new'

I did the timing in Python 2 of course, to demonstrate that the feature the 
OP is missing in Python 3 offers no advantage in the Python version where it 
/is/ available. 

Does my previous post make sense now?


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


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Ethan Furman

On 02/26/2013 09:21 AM, Robin Becker wrote:

In python 2 I was able to improve speed of reportlab using a C extension to 
optimize some heavily used methods.

so I was able to do this


class A:
 .
 def method(self,...):



try:
 from extension import c_method
 import new
 A.method = new.instancemethod(c_method,None,A)
except:
 pass

and if the try succeeds our method is bound as a class method ie is unbound and 
works fine when I call it.

In python 3 this doesn't seem to work at all. In fact the new module is gone. 
The types.MethodType stuff doesn't seem to
work.

Is there a way in Python 3.3 to make this happen? This particular method is 
short, but is called many times so adding
python wrapping layers is not a good way forward.


Dumb question, but have you tried just assigning it?  In Py3 methods are just 
normal functions...

8--
  class A():
  pass

  A.method = c_method
8--

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


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Peter Otten
Ethan Furman wrote:

 On 02/26/2013 09:21 AM, Robin Becker wrote:
 In python 2 I was able to improve speed of reportlab using a C extension
 to optimize some heavily used methods.

 so I was able to do this


 class A:
  .
  def method(self,...):
 


 try:
  from extension import c_method
  import new
  A.method = new.instancemethod(c_method,None,A)
 except:
  pass

 and if the try succeeds our method is bound as a class method ie is
 unbound and works fine when I call it.

 In python 3 this doesn't seem to work at all. In fact the new module is
 gone. The types.MethodType stuff doesn't seem to work.

 Is there a way in Python 3.3 to make this happen? This particular method
 is short, but is called many times so adding python wrapping layers is
 not a good way forward.
 
 Dumb question, but have you tried just assigning it?  In Py3 methods are
 just normal functions...
 
 8--
class A():
pass
 
A.method = c_method
 8--

The problem is that functions implemented in C don't support the descriptor 
protocol (they don't have a __get__() method). So

 from math import sqrt
 class A(int):
... pass
... 
 A.c = sqrt
 A.py = lambda self: sqrt(self)
 a = A(42)
 a.py()
6.48074069840786
 a.c()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: sqrt() takes exactly one argument (0 given)


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


Re: Python Newbie

2013-02-26 Thread Chris Angelico
On Wed, Feb 27, 2013 at 6:42 AM, Piterrr piotr...@optonline.net wrote:
 This reminds me, when I first started working with databases and saw an
 error msg which said that my query had ambiguous columns I laughed for 1/2
 hr. I found it incredibly exitaining that a 100% deterministic piece of
 hardware could have the word ambiguous in its internal dictionary.

Enjoy your laugh (laughter's good!), but there are a couple of wrong
assumptions here. The hardware doesn't use the word ambiguous, and
the SQL engine (which is what does) isn't 100% deterministic. Or to be
more technically correct, it's 100% deterministic with such a large
set of inputs (many of which are outside your access, let alone
control) that it may as well have a random component.  Also, there's
nothing strange about ambiguity: Go and get the cornflour and the
icing sugar. Put some of it into the cake mix. - what should you put
in? Some of each? That's what the database has been asked to do, and
it's not clear what should be done.

Sorry to be the wet blanket on your joke (I think that metaphor's as
mixed as cake batter), but facts is facts :)

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


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Christian Heimes
Am 26.02.2013 21:19, schrieb Ethan Furman:
 Dumb question, but have you tried just assigning it?  In Py3 methods are
 just normal functions...
 
 8--
   class A():
   pass
 
   A.method = c_method
 8--

That doesn't work with builtin functions because they don't implement
the descriptor protocol:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Feb  8 2013, 00:38:29)
[GCC 4.7.2] on linux
Type help, copyright, credits or license for more information.
 class Example:
... id = id
...
 Example().id()
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: id() takes exactly one argument (0 given)

You can use PyInstanceMethod_Type to wrap a builtin method in something
that acts like a normal method. I implemented the type for Python 3000
when I removed the unbound method object. It's not available to pure
Python code except for testing:

 import _testcapi
 class Example:
... id = _testcapi.instancemethod(id)
...
 Example().id()
140525206026320

The C code is rather simple and small. You can easily re-implement in
Python, too.

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Rotwang

On 26/02/2013 12:54, Steven D'Aprano wrote:

One week ago, JoePie91 wrote a blog post challenging the Python
community and the state of Python documentation, titled:

The Python documentation is bad, and you should feel bad.

http://joepie91.wordpress.com/2013/02/19/the-python-documentation-is-bad-
and-you-should-feel-bad/

It is valuable to contrast and compare the PHP and Python docs:

http://php.net/manual/en/index.php
http://www.python.org/doc/

There's no doubt that one of PHP's strengths, perhaps its biggest
strength, is the good state of documentation. But should we feel bad
about Python's docs?


I strongly disagree with most of what the author writes. To start with, 
there's this:


  Let’s start out with a simple example. Say you are a developer that
  just started using PHP, and you want to know how to get the current
  length of an array. You fire up a browser and Google for “PHP array
  length site:php.net”. The first result is spot-on, and one minute
  later, you know that count($arr) will suffice.

  Now let’s say that you wish to do the same in Python. In this case,
  you would Google for “Python list length site:docs.python.org”, and
  the first result is… a page with several chapters on standard types?

It seems to me that this is /completely/ the wrong way for a developer 
who's new to Python to go about learning the language. If you don't know 
enough Python to be familiar with len(), the sensible thing to is not to 
try coding by finding out individual language features as and when you 
need them, but to read the tutorial, systematically from start to 
finish. This list is continually being bombarded with questions from 
people who tried the former only to become stuck when something didn't 
work the way they thought it should (I've been guilty of this too), 
because knowing vocabulary is not the same thing as knowing how a 
language works. The majority of such questions could have been answered 
by simply reading the tutorial. More still could be answered by reading 
the language reference, which really isn't very long.


That's not to say that experienced users don't need to look things up, 
but then why would one restrict a web search to docs.python.org? Almost 
every question I've had about how to do something in Python has already 
been asked at StackExchange, and Google will find it.


  When you Google for something, you will end up on a page that
  explains a lot of things, including what you’re looking for. But how
  are you supposed to know where on the page it is, or whether it’s
  even on the page at all? The problem here is that the particular
  operation you are trying to find documentation on, does not have its
  own page.

And the solution is Ctrl-f.

  The general norm for the Python community appears to be that if you
  are not already familiar with the language, you do not deserve help.
  If you do something in a less-than-optimal way, other Python
  developers will shout about how horrible you are without bothering to
  explain much about what you did wrong. When you ask out of curiosity
  how a certain thing works, and that thing is considered a bad
  practice, you will get flamed like there’s no tomorrow – even if you
  had no intention of ever implementing it.

This is not my experience at all. Even when asking questions that I 
could have answered myself if I had RTFM, I've received helpful advice 
and nothing that could be construed as a flame. I don't know how this 
compares to other programming language communities, but it's much 
friendlier to newcomers here than, say, sci.math (whose competent 
regulars are understandably suspicious of people asking idiotic 
questions, given how many of those people turn out to be cranks).


  PHP solves [ambiguity] by having examples for every single function
  and class. If you’re not sure what is meant with a certain sentence in
  the description, you just look at one of the included examples, and
  all ambiguity is removed. It’s immediately obvious how to use things.

Python solves this by having an interactive interpreter. The tutorial 
goes to the trouble of pointing out that [i]t helps to have a Python 
interpreter handy for hands-on experience.


  If you are an experienced developer, then you are most likely in a
  very bad position to judge how beginner-friendly the documentation
  for a language is.

  [...]

  Most of all, accept that your personal experiences with Python, as an
  experienced developer, are not worth very much. Listen to the newbies
  when they tell you the documentation is hard to read or find stuff in.

But I'm not an experienced developer. I'm an amateur hobbyist who came 
to learn Python having only had any real programming experience with BBC 
BASIC and OPL (both as a child). I read the tutorial, then I read the 
language reference, now I'm reading the library reference. They're all fine.



--
I have made a thing that superficially resembles music:


Re: Python Newbie

2013-02-26 Thread rurpy
On Tuesday, February 26, 2013 11:59:51 AM UTC-7, Ethan Furman wrote:
 On 02/26/2013 10:23 AM, ru...@yahoo.com wrote:
  On 02/26/2013 01:32 AM, Larry Hudson wrote:
  Python variables do NOT have any data type.
  I have no problem interpreting the OP's statement
  as meaning that he wanted to use a Python variable to
  consistently reference a particular type and wanted a name
  that would remind him of that type.
 
 Which is all well and good, so long as the OP also realizes
 that the name does not have any restriction's on it from 
 Python's side, and certain functions will end up pointing
 the name at a different object with a possibly different type 
 than his original, as in my int/float example.

Which I presume he did, given that he responded to your post with:

On Sunday, February 24, 2013 5:08:06 PM UTC-7, piterrr@gmail.com wrote:
[...]
 Yes I did see that it is possible to redefine the type of a variable.
 But I don't think I would ever do this intentionally; need to be really 
 careful with Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Jason Swails
Just to throw in my 2c -- in the same way that 'a picture is worth a
thousand words', an interactive interpreter is worth volumes of
documentation (especially one with such a nice help()/__doc__
functionality).  It's worth pointing out that 'interpreter' appears in the
original rant once (according to ctrl-F, whole thing was tl;dr):

Want to know how the Python interpreter deals with input Y? Read the
source. And so on, and so on.

Not: Open up an interpreter and input Y

You aren't sure what errors are thrown by a particular function?  Fire up
an interpreter and feed the function junk.  You'll get your answer faster
than you can Google, and often learn neat stuff along the way. (I recall
one of RR's posts that actually had some good tips to
learn-via-interpreter).

Also, I'll bet the way I learned Python effectively would seem like
nails-on-a-chalkboard to others -- and vice versa.  The 'one-size-fits-all'
doesn't work for documentation.  Complete and concise often battle, with no
clear winner.

And his representation of the Python community does not appear to be
representative of my experience (threads begun via trolling rants
notwithstanding).  But he's ranting on his blog; not a big deal really.

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


Re: Small program ideas

2013-02-26 Thread eli m
On Monday, February 25, 2013 10:15:24 PM UTC-8, Dave Angel wrote:
 On 02/25/2013 10:48 PM, eli m wrote:
 
  On Friday, February 15, 2013 7:22:41 PM UTC-8, eli m wrote:
 
  Any small program ideas? I would prefer to stick to command line ones. 
  Thanks.
 
 
 
  Thank you guys for the suggestions. Any more?
 
 
 
 
 
 There are all kinds of things you could do.  First, consider something 
 
 that might be useful.
 
 
 
 1) checksum all the files in a directory tree, using various checksum 
 
 algorithms.
 
 
 
 2) Convert one kind of file to another.
 
 
 
 3) Calculate time between two dates
 
 
 
 4) Write some part of a backup system.  For example, copy files from a 
 
 directory tree into a specified directory, stopping when the size totals 
 
 N.N gig, and keeping track of which files have been so processed, so 
 
 that after burning that directory to DVD, you can repeat the process. 
 
 As a bonus, add a utility  datafile to the top of that directory, so 
 
 that the DVD can be self-checking.
 
 
 
 Then try something interesting:
 
 
 
 1) find the nth prime, for example the 1000th prime
 
 
 
 2) Find all perfect numbers under a trillion
 
 
 
 3) solve the puzzles on http://projecteuler.net
 
 
 
 4) Build a spell checker, using a combination of a standard 
 
 dictionary-list and custom entries.  Bonus question - Make it smart 
 
 enough to only spell-check comments and literal strings, when applied to 
 
 files with an extension of .py
 
 
 
 
 
 -- 
 
 DaveA

How hard would it be to change one file to another and would it be a 
small-medium sized program?

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


Re: Small program ideas

2013-02-26 Thread Joshua Landau
On 26 February 2013 22:47, eli m techgeek...@gmail.com wrote:

 How hard would it be to change one file to another and would it be a
 small-medium sized program?


How do you want to change it? Like rename a file (os.rename)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread emile

On 02/26/2013 11:00 AM, nn wrote:

 What it could have is better searching capability and a way to see
 more examples. Examples would clutter the documentation so maybe they
 should be collapsible, but you can never have enough examples.

A good resource (although only covering up to v2.3) is effbot's guide to 
the standard library available at


  http://effbot.org/zone/librarybook-index.htm

It's pretty much _all_ examples.

Emile



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


Re: Small program ideas

2013-02-26 Thread eli m
On Tuesday, February 26, 2013 4:22:10 PM UTC-8, Joshua Landau wrote:
 On 26 February 2013 22:47, eli m techg...@gmail.com wrote:
 
 
 
 
 
 How hard would it be to change one file to another and would it be a 
 small-medium sized program?
 
 
 How do you want to change it? Like rename a file (os.rename)?

I want to change the file type.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Mark Janssen
On Tue, Feb 26, 2013 at 4:54 AM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 There's no doubt that one of PHP's strengths, perhaps its biggest
 strength, is the good state of documentation. But should we feel bad
 about Python's docs?


I don't think so at all.  I think the python docs are quite well organized.
 Who googles for python knowledge when you can just go to the official site
and use the doc search?

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Rick Johnson
On Tuesday, February 26, 2013 4:17:22 PM UTC-6, Jason Swails wrote:
 Just to throw in my 2c -- in the same way that 'a picture
 is worth a thousand words', an interactive interpreter is
 worth volumes of documentation (especially one with such a
 nice help()/__doc__ functionality).

Yes! I don't even know why people care about the Python docs anyway. One of the 
most under-appreciated (and maybe even unknown) aspects of the Python language 
is the power of doc strings and the help function. Not to mention the awesome 
introspection capabilities via a few built-in functions:

id(obj)
isinstance(obj, type)
issubclass(obj, klass)
repr(obj)
type(obj)
bool(obj)
dir(obj)
...


As for the docs: 

I would say that if you are searching for a particular something (and the 
help function has failed you), then skip the docs and use Google instead. The 
docs only seem to work well when read in a linear fashion; with exception of 
the global module index and the language reference sections.

As for the official tutorial, do yourself a favor and DON'T read it (or never 
read it) until AFTER you are comfortable with python. It's not so much that the 
tutorial is lacking, it's more that the tutorial uses poor example code and as 
such is an abomination. That's my opinion anyway. There are tons of great 
python tutorials on the web.

 You aren't sure what errors are thrown by a particular
 function?  Fire up an interpreter and feed the function
 junk.  You'll get your answer faster than you can Google,
 and often learn neat stuff along the way. 

Yes! Interactive sessions are what make python so damn great! If you don't have 
an editor window and a shell window open when writing (python) code, you are 
doing something wrong.

 (I recall one of
 RR's posts that actually had some good tips to learn-via-
 interpreter).

I don't remember the exact thread off-hand, but i must admit you can find loads 
of great information in my threads! :-P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Chris Angelico
On Wed, Feb 27, 2013 at 12:15 PM, Mark Janssen
dreamingforw...@gmail.com wrote:
 On Tue, Feb 26, 2013 at 4:54 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:

 There's no doubt that one of PHP's strengths, perhaps its biggest
 strength, is the good state of documentation. But should we feel bad
 about Python's docs?

 I don't think so at all.  I think the python docs are quite well organized.
 Who googles for python knowledge when you can just go to the official site
 and use the doc search?

I'm not sure if you're trolling or not... The python.org search is one
of its weakest attributes; on the main http://python.org/ search, it's
now been replaced by a Google site-search, but the box on the side in
http://docs.python.org/ still gives the annoyingly slow internal
search. So no, I don't go to the official site search, I use Google
(with or without site:python.org to restrict the results - most often
without).

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Jerome Covington
Hi I'm a Python enthusiast who originally found the Python docs at
python.org to be one of the main reasons that my enthusiasm was fed. Also
the thoughtful presence of docstrings throughout good projects and
libraries gives me the feeling that finding out how to do something in
Python is just as easy as finding out how to do something else in PHP.

-- 
Regards,
Jerome
Music http://www.jeromecovington.com/music/ || Web
Devhttp://www.jeromecovington.com/dev/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Terry Reedy

On 2/26/2013 1:52 PM, Devin Jeanpierre wrote:


I would assert it isn't very kind to those even with basic fundamentals.

For example, under precisely what circumstances does int() raise
TypeError? You won't find that under either int's documentation, or
TypeError's documentation, you have to look it up under __int__, which
is _not_ a basic fundamental. And rather than helping you along the
way, the documentation for int() actively misleads you by its
implicature that the only acceptable types are strings, ints, and
floats. And then even if you have the foresight to remember oh yeah,
isn't there a special method for this?, you have to find the
documentation for __int__, which is itself is three quarters of the
way down this massive page:
http://docs.python.org/2/reference/datamodel.html


Have you opened an issue, or checked for existing issue? I would be open 
to the idea that entries like that for int should not be overly type 
specific and imply that the defaults are the only possibilities.
Perhaps there should be a cross-reference to corresponding special 
methods. Perhaps that idea might be opposed. I am not sure. Perhaps 
Built-in Functions needs a bit more general explanatory text at the top.


--
Terry Jan Reedy

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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Terry Reedy

On 2/26/2013 1:58 PM, Mitya Sirenef wrote:


I think the issue with python documentation is that it ignores the 95/5
rule: 95% of people who land on a module's page are only looking for 5%
of its information. So ideally it'd be separated in two different pages
or two sections of the same page, something like:

===


Hi, chances are you are the 95% of people who isn't interested in the
intricacies, obscure edge cases et cetera. Here are the few common use
cases for this module:

...

...

...

===


Hi, the section above obviously did not suit your needs, so you must be
in the 5% who has no choice but to either read through or at least
glance through, or use search, to find what you need in the following
umpteen million of screenfuls:

... * 100


===


Why doesn't Python do that?


We are not literally going to write text like that, but we did recently 
re-organized the doc for one module specifically to put the most 
commonly used stuff (about the 'convenience' functions) at the top 
instead of buried where it was.



Quite simply, it's a lot more work: you have
to separate most useful parts from the rest, which involves judgement
calls and will cause some disagreement and ultimately won't be perfect.
Once done, two separate sections need to be mainained and kept in sync.


In the case above, there is no duplication to be kept in sync. More the 
problem is that people working of the docs tend to either leave or move 
on to code. Report like 'This section is unclear' are not too helpful 
either.


--
Terry Jan Reedy

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


Re: yield expression

2013-02-26 Thread Dave Angel

On 02/26/2013 01:44 PM, Colin J. Williams wrote:

On 26/02/2013 12:07 PM, Vytas D. wrote:

Hi,

You are using yield incorrectly. yield works like return, but it can
return more than once from the same function. Functions that yield
produce a so called generator object. This generator object gives you
values every time you call it.

The generator works very interesting way. It starts like normal function
and goes until it finds yield and returns the value. The state of
generator is saved - it is like it is put to sleep until you call it
again. So the next time you call generator() it runs from the point it
returned last time and will return you another value.

Simple sample of making and using generator (prints forever, so just
kill with CTRL+C).

def counter(start_at=0):
 Returns integer each time called

 count = start_at
 while True:
 yield count
 count += 1

def main():
 generator = counter()

 while True:
 print(next(generator))


if __name__ == '__main__':
 main()


Hope helps.

Vytas D.



On Tue, Feb 26, 2013 at 4:34 PM, Colin J. Williams c...@ncf.ca
mailto:c...@ncf.ca wrote:

On 24/02/2013 7:36 PM, Ziliang Chen wrote:

Hi folks,
When I am trying to understand yield expression in Python2.6,
I did the following coding. I have difficulty understanding why
val will be None ? What's happening under the hood? It seems
to me very time the counter resumes to execute, it will assign
count to val, so val should NOT be None all the time.

Thanks !

code snippet:

   def counter(start_at=0):
   count = start_at
   while True:
   val = (yield count)
   if val is not None:
   count = val
   else:
   print 'val is None'
   count += 1


Perhaps it's becaoue (teild count) is a statement.  Statements do
not return a value.

Colin W.



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



Yes, it's very helpful.  Thanks also to the other two responders.

This brings us back to the OP question.  Why not  val = (yield count)?

Colin W.




Repeating a misconception doesn't make it any more true.  yield is both 
an expression and a statement.  Nothing wrong with the statement

val = (yield count)

although he apparently wasn't making any good use of the possible return 
value, since he observed it was always None.  That's just because he 
didn't use the send method in the calling function.


Most links I see on a web search explain only the expression form of 
yield, which is why i took a lot of time building the response I did 
earlier.



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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Steven D'Aprano
On Tue, 26 Feb 2013 17:48:27 +, MRAB wrote:

 On 2013-02-26 14:26, Chris Angelico wrote:
 On Wed, Feb 27, 2013 at 12:56 AM, Roy Smith r...@panix.com wrote:
 When people ask PHP questions, the questions tend to be phrased as
 what do I type to get X, and the answers come back that way too. 
 The forums are full of, I had the same problem.  Somebody told me to
 do this.  I don't really understand it, but it worked for me and maybe
 it'll work for you too.

 A problem that's majorly exacerbated by the myriad ways of doing some
 things, with some of those ways deprecated and others theoretically
 plausible but hopelessly impractical.

 Here's an actual example that came up today at work. Suppose you have a
 user-provided string that's supposed to contain a URL, and you need to
 ensure that it doesn't have a trailing slash, so you can later add
 /foo or /bar. (Or alternatively, ensure that it DOES have a
 trailing slash. Either works.) Start the timer, go find out how to do
 it. Assume you are broadly familiar with PHP, and know how to do the
 basics of string handling, and are competent at searching the web.
 Ready? Go!

 I'll wait for you to come back.

 ... Okay, some of you are back now. Just giving the stragglers time to
 finish losing their marbles...

 Alright. Here's what I found in a recreation of today's search. Google
 search: php last character of string

 http://php.net/manual/en/function.substr.php -- okay, so I can use
 substr, but not string indexing, to find out what the last character is
 -- Returns the extracted part of string; or FALSE on failure, or an
 empty string. What kind of failures result in FALSE, and what kind in
 an empty string?

 [snip]
 The page http://php.net/manual/en/function.substr.php says:
 
  Description
  string substr ( string $string , int $start [, int $length ] )
 
 OK. It then goes on to say:
 
  Parameters
  string
  The input string. Must be one character or longer.
 
 What? The input string can't be an empty string?

Huh, this is PHP. You're lucky it doesn't say:

The input string. Must be one character or longer, except for the case-
insensitive string 'something-magical-happens-here'.

*wink*


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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Mitya Sirenef

Subject:   Re: Do you feel bad because of the Python docs?  To:
python-list@python.org Cc:Bcc:
-=-=-=-=-=-=-=-=-=# Don't remove this line #=-=-=-=-=-=-=-=-=- On
 02/26/2013 09:00 PM, Terry Reedy wrote:

On 2/26/2013 1:58 PM, Mitya  Sirenef wrote:


 I think the issue with python documentation is that it ignores the
 95/5 rule: 95% of people who land on a module's page are only looking
 for 5% of its information. So ideally it'd be separated in two
 different pages or two sections of the same page, something like:

 
===



 Hi, chances are you are the 95% of people who isn't interested in the
 intricacies, obscure edge cases et cetera. Here are the few common
 use cases for this module:

 ...

 ...

 ...

 
===



 Hi, the section above obviously did not suit your needs, so you must
 be in the 5% who has no choice but to either read through or at least
 glance through, or use search, to find what you need in the following
 umpteen million of screenfuls:

 ... * 100


 
===



 Why doesn't Python do that?

 We are not literally going to write text like that, but we did
 recently re-organized the doc for one module specifically to put the
 most commonly used stuff (about the 'convenience' functions) at the
 top instead of buried where it was.


Yes, I didn't mean it would be literally worded like that :-).





 Quite simply, it's a lot more work: you have to separate most useful
 parts from the rest, which involves judgement calls and will cause
 some disagreement and ultimately won't be perfect. Once done, two
 separate sections need to be mainained and kept in sync.

 In the case above, there is no duplication to be kept in sync. More
 the problem is that people working of the docs tend to either leave or
 move on to code. Report like 'This section is unclear' are not too
 helpful either.



I don't think that would work in the general case, for all modules,
because the 'inclusive' section should not be missing items that
logically belong there. For example, if I'm looking through string
formatting subsection, it would be confusing if some items were missing
because they were moved to the top together with other items from
different subsections.

In addition, the 'inclusive' section would have some advanced notes that
would not be included in the first section, even if items themselves may
be there.


For example, let's take timedelta section:

http://docs.python.org/2/library/datetime.html#timedelta-objects


At the end of this section there is a dozen lines of helpful examples.

I think vast majority of visitors need these examples (not a complete
list, just an example of examples), and it would be ideal if they were
shown at the very top of the page, without the need to scroll down:



from datetime import  timedelta, datetime

 three_days = timedelta(days=3)
 datetime.now()
datetime.datetime(2013, 2, 26, 21, 45, 44, 371334)

datetime.now() +  three_days

datetime.datetime(2013, 3, 1, 21, 45, 34, 427403)

old_date =  datetime(2013, 2, 10)

 if datetime.now() - old_date  timedelta(days=10):
...  print(It's been more than 10 days since %s % old_date)
It's been more than 10 days since 2013-02-10 00:00:00

year =  timedelta(weeks=40, days=84, hours=23,

...  minutes=50, seconds=600)  # adds up to 365 days

year.total_seconds()

31536000.0


(As a side note, I think it would be better if sections in datetime were
in separate pages, it would be easier to google and the navbar on the
left side is very crowded and rather hard to read - often I find myself
missing stuff that's in there and ending up just scrolling down through
the document until I find what I need -- it might be better if section
numbers were not included there, font for keywords was not fixed width
font, and topics didn't wrap so much - in case of datetime, all of the
topics have enough horizontal space not to wrap and yet 3 out of 7 do wrap!)


Of course, it can be argued that these are minor issues, that relevant
parts of documentation are still quite easy to get to, and if it takes a
few minutes longer, it's not the end of the world.

In my view, such small matters are more important than it looks, because
working on a project requires focus and if you spend just a few minutes
hunting around the doc pages, you start to lose the larger picture of
your design... I tend to remember the most important modules out of
standard lib because I've worked with them a lot in the last few years,
but I imagine it can be tough for people who program a bit as a hobby or
as a small part of their job.

I don't mean to say that Python docs are terrible, though. They're quite
good, especially as more examples were added in the last few years, but
if 

Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Rick Johnson
On Tuesday, February 26, 2013 7:48:51 PM UTC-6, Terry Reedy wrote:
 On 2/26/2013 1:52 PM, Devin Jeanpierre wrote:
  
  [...snip legit complaint...]
  
 Have you opened an issue, or checked for existing issue? I would be open 
 to the idea that entries like that for int should not be overly type 
 specific and imply that the defaults are the only possibilities.

Terry (with all due respect), do you /really/ expect that people have the time 
to open an issue on the bug tracker? Do you really think that everyone who uses 
python even knows about the bug tracker? Do you really think that people will 
believe that their opinion is worthy of placing on the bug tracker? Do you 
really?

I think most will just end up ignoring the docs and either be forced to give up 
on Python or look for documentation elsewhere. Now, you could react to that 
truth by saying:

 Well, who cares! The docs are the docs and if people can't grok them then too 
bad for them because i think they are awesome.

Sadly (in actuality) it's too bad for *you* Terry (along with the many other 
people who maintain docs) when you ignore the many request for changes. 
Remember, if people just ignore the docs because of these abominations you and 
everyone else are basically wasting your time maintaining the docs! Do you 
understand this fact?

Terry Implies: We will write the docs how *we* see fit, and to hell with your 
feeble misunderstandings. You are beneath us! *We* are the anointed ones. *We* 
know everything!
 
Look i know your intentions are noble, and yes my wording was a bit 
theatrically unfair, but this is /exactly/ how people are interpreting your 
intentions Terry. Please don't become a zealot. Python will never be perfect! I 
can assure you.

And besides, is a bug tracker /really/ the place to voice the many legitimate 
problems concerning python's documentation or stdlib? Forgive me, but I thought 
bug trackers where for tracking ,umm... well, BUGS! 

This is why i mentioned the need for an official PyWarts (group or list) so 
these folks will have a platform to voice their frustrations. A very PUBLIC and 
very ACCESSIBLE and very WELL KNOWN platform. Because if IS NOT all three of 
these things, then it IS nothing.

But you cannot just hand them a microphone and then stick your fingers in your 
ears. You need to /listen/ carefully and try to place yourself into their 
shoes. I can assure you that the Python docs, and the language itself, could 
use some polishing. Stop taking these complaints personally and start listening 
with an objective ear; please?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small program ideas

2013-02-26 Thread Dave Angel

On 02/26/2013 05:47 PM, eli m wrote:

On Monday, February 25, 2013 10:15:24 PM UTC-8, Dave Angel wrote:

On 02/25/2013 10:48 PM, eli m wrote:


On Friday, February 15, 2013 7:22:41 PM UTC-8, eli m wrote:



Any small program ideas? I would prefer to stick to command line ones. Thanks.







Thank you guys for the suggestions. Any more?








There are all kinds of things you could do.  First, consider something

that might be useful.



1) checksum all the files in a directory tree, using various checksum

algorithms.



2) Convert one kind of file to another.

  snip



How hard would it be to change one file to another and would it be a 
small-medium sized program?



Depends on the kinds of the two files.  To convert an Excel spreadsheet 
file to a csv file might be a lot of work, thousands of lines, not to 
mention having to dig up the docs.  But to convert a DOS text file (with 
lines ending cr/lf) into a Unix text file (with lines ending lf)  would 
be a dozen lines, shrinkable to 3 with lots of experience.  (And I'd 
probably prefer the dozen line version)


Other conversions might be somewhere in between.  You could do data 
compression, like bzip, using the modules in the standard library.


Note that utility commands may exist, but it can be instructive to do it 
by hand anyway, to learn how.


Look at the following libraries, and see how you could write the glue to 
make them into useful file conversion utilities.  Then test them against 
the standard equivalents, to make sure your code really work.

alib, gzip, bz2, zipfile, tarfile, csv, ConfigParser, robotparser, ...



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


Re: Do you feel bad because of the Python docs?

2013-02-26 Thread Mitya Sirenef

On 02/26/2013 10:09 PM, Mitya Sirenef wrote:

(As a side note, I think it  would be better if sections in datetime were

 in separate pages, it would be easier to google and the navbar on the
 left side is very crowded and rather hard to read - often I find myself
 missing stuff that's in there and ending up just scrolling down through
 the document until I find what I need -- it might be better if section
 numbers were not included there, font for keywords was not fixed width
 font, and topics didn't wrap so much - in case of datetime, all of the
 topics have enough horizontal space not to wrap and yet 3 out of 7 do 
wrap!)


In regard to Python doc topic menu readability -- compare to the django
topic menu:

https://docs.djangoproject.com/en/dev/topics/db/queries/

It's ridiculous how much more readable it is, at least to my eyes!

 -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Re: python 3 problem: how to convert an extension method into a class Method

2013-02-26 Thread Steven D'Aprano
On Tue, 26 Feb 2013 17:21:16 +, Robin Becker wrote:

 In python 2 I was able to improve speed of reportlab using a C extension
 to optimize some heavily used methods.
 
 so I was able to do this
 
 
 class A:
  .
  def method(self,...):
 
 
 
 try:
  from extension import c_method
  import new
  A.method = new.instancemethod(c_method,None,A)
 except:
  pass

Why are you suppressing and ignoring arbitrary errors here? That doesn't 
sound good. Surely a better way would be:

import new
try:
from extension import c_method
except ImportError:
pass
else:
A.method = new.instancemethod(c_method, None, A)



 and if the try succeeds our method is bound as a class method ie is
 unbound and works fine when I call it.
 
 In python 3 this doesn't seem to work at all. In fact the new module is
 gone. The types.MethodType stuff doesn't seem to work.

I've never tried this with a function written in C, but for one written 
in Python all you need is this:

A.method = c_method


Try that and see if it works with your function written in C. I expect 
that it will, provided that the function is written as a method 
descriptor. I don't know enough about C extensions to tell you how to do 
that, sorry.



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


Re: Small program ideas

2013-02-26 Thread Chris Angelico
On Wed, Feb 27, 2013 at 2:27 PM, Dave Angel da...@davea.name wrote:
 But to convert a DOS text file (with lines ending cr/lf) into a Unix text
 file (with lines ending lf)  would be a dozen lines, shrinkable to 3 with
 lots of experience.  (And I'd probably prefer the dozen line version)

Code golf!

open(outfile,wb).write(open(infile,rb).read().replace(\r,))

No particular reason, and I'd probably prefer a 3-6 line version of
it, but it's fun to do it as one :)

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


Searching for a replacement for PIL

2013-02-26 Thread Thorsten Kiefer

Hi,
my actual program imports ImageTk, to generate TK compatible images.
But it seems like PIL is no longer supported.
Is there a replacement for draw Images at high rates into TKinter GUIs ?

Best regards
Thorsten
--
http://mail.python.org/mailman/listinfo/python-list


Re: Searching for a replacement for PIL

2013-02-26 Thread Chris Rebert
On Tue, Feb 26, 2013 at 10:17 PM, Thorsten Kiefer thorstenkie...@gmx.de wrote:
 Hi,
 my actual program imports ImageTk, to generate TK compatible images.
 But it seems like PIL is no longer supported.

Have you investigated the Pillow fork?
https://pypi.python.org/pypi/Pillow/

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


[issue13555] cPickle MemoryError when loading large file (while pickle works)

2013-02-26 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f3f23ecdb1c6 by Serhiy Storchaka in branch '2.7':
Issue #13555: Fix an integer overflow check.
http://hg.python.org/cpython/rev/f3f23ecdb1c6

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13555
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13555] cPickle MemoryError when loading large file (while pickle works)

2013-02-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for the report. Standard tests do not cover pickling/unpickling to 
real files.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13555
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17298] Twisted test failure triggered by change in 2.7 branch

2013-02-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If this is a duplicate, it should be fixed by f3f23ecdb1c6.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17299] Test cPickle with real files

2013-02-26 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Currently cPickle module tested only with cStringIO.StringIO. However cPickle 
uses different code for cStringIO.StringIO, for file objects, and for general 
IO streams (i.e. io.BytesIO). Last two cases are not covered by tests.

--
components: Tests
messages: 183028
nosy: alexandre.vassalotti, pitrou, serhiy.storchaka
priority: normal
severity: normal
stage: needs patch
status: open
title: Test cPickle with real files
type: enhancement
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17299
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16932] urlparse fails at parsing www.python.org:80/

2013-02-26 Thread Senthil Kumaran

Senthil Kumaran added the comment:

I am noticing this one late. Sorry for that.
I agree that this is docs issue and I would like to fix it in this way.

Give the doc example as:

 urlparse('www.cwi.nl/%7Eguido/Python.html')
ParseResult(scheme='', netloc='', path='www.cwi.nl/%7Eguido/Python.html', 
params='', query='', fragment='')

Instead of

 urlparse('www.cwi.nl:80/%7Eguido/Python.html')

Which introduces a trick :80 parsing and invokes the rule that Georg pointed 
out in the message. If I recollect, the point of the example was to point out 
that URLs (following 1808 RFC) should start with // for their netloc to be 
identified. Otherwise it is path.

A : on PORT without the scheme : is really tricky for any application, so 
it is right thing for the parser to identify anything before : as scheme and 
the implementation here is correct.

So, instead of fixing the example to identify the scheme as www.cwi.nl which 
is quite meaningless, the better way to fix the example will be, change the 
example to urlparse('www.cwi.nl/%7Eguido/Python.html') and the result remains 
the same.

I am going ahead with the fix. Thanks.

--
resolution: invalid - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16932
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13555] cPickle MemoryError when loading large file (while pickle works)

2013-02-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I have opened issue17299 for testing issue.

--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13555
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14468] Update cloning guidelines in devguide

2013-02-26 Thread Ezio Melotti

Ezio Melotti added the comment:

I went through all the messages on this issue, and I'll address them here.  
There's enough material for two new issues (advanced FAQs, and improvements 
about Windows docs), and a few minor issues that can be discussed and fixed as 
part of this issues before closing it.


Chris in msg178927:

 I would break up the 20 lines of command-line commands.

Those are supposed to provide a complete overview, the individual commands are 
explained with inline comments, and more in details in the following section.  
Is that OK?

 I would also state (or link to) something about forward-porting from
 3.x to 3.y and that 2.7 should be kept separate

This should be covered now.

 I would also say (or link to) something about pushing all branches
 simultaneously.

This is not stated explicitly, but the fact that there's a single hg push at 
end implies it.  It might be mentioned somewhere together with hg out.

 Lastly, might it be worth explicitly dividing the Mercurial stuff into 
 separate sections for (1) everyone, and (2) committers?

This is done, explicitly in the FAQs, and more implicitly in committing.rst.  
Committing.rst is written mainly for developers, whereas other parts of the 
devguide are more generic and valid for everyone.


Chris in msg178983:

 If applying to 2.7 or 3.2, etc. loses information (which has been 
 more often the case for me), then instead of merging I null-merge and 
 reapply the original patch.

This could be a FAQ.


Ezio in msg179853:

 At the end of committing.rst I can add a link to the committers 
 faqs in faqs.rst, and add more FAQs there.  Everything about null
 merges, head merges, merge conflicts, long-term development branches 
 etc. will go to faqs.rst.

This still needs to be done, and should be covered in a separate Add 
'advanced' mercurial FAQs for committers. issue.


Terry in msg182625:

 On Windows, ~/.hgrc is $HOME$/mercurial.ini.

This could either be mentioned right there, or if there are multiple 
occurrences of it, we could add a FAQs that briefly explains what .hgrc is and 
where to find it on Linux and Windows and link to it.

 with TortoiseHG/Workbench, one should better use the Settings dialogs 
 than edit directly.

This could also be mentioned in the aforementioned FAQ.


Terry in msg182633:

 Given the obnoxiousness of Command Prompt, and how foreign it is to working 
 on  Windows, I think maybe there should be an addendum *somewhere*, 
 About  run `make patchcheck`. The current Committing page gives
 (or ./python.exe Tools/scripts/patchcheck.py on Windows) as the windows
 equivalent. './' does not work on Windows. '.\' will, [...]

I suggest to create a new issue like Improve Windows instructions in the 
devguide and mention all these issues.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14468
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12641] Remove -mno-cygwin from distutils

2013-02-26 Thread Martin Fiers

Martin Fiers added the comment:

This also affects our software. I agree with Dan (danmbox): I don't understand; 
so many people depend on it and yet an out-of-the-box solution doesn't work.

I don't want to break the distutils package of our users because we use mingw. 
Within one Python script, I managed to fix it using this before the setup call:

if isWindows():

Fix bug in cygwinccompiler: removed -mno-cygwin. This is fixed in 
cygwinccompiler_new.
We hacked the distutils.ccompiler : def new_compiler : It uses 
sys.modules to fetch the compiler
By modifying the sys.modules, we can choose our own compiler version.
(this is a bug that's out there for quite some time)

import cygwinccompiler_new
import distutils.cygwinccompiler
import sys
sys.modules[distutils.cygwinccompiler] = cygwinccompiler_new

..if I then later run setup(...), it will use my new cygwinccompiler_new, that 
has the '-mno-cygwin' line removed.

However, when you want to install new packages using pip from the command-line, 
I cannot find a suitable fix (except if I would replace the 
distutils.cygwinccompiler before pip'ing, then put it back). For afaik, 
distutils cannot be virtualenv'ed, right? So we cannot even fix the issue in a 
virtual environment.

If it is not possible to find out what version of gcc implemented it first; 
can't you simply use a pragmatic solution and run
gcc -mno-cygwin: if it gives an error, then remove the option. That would 
need the least testing and would fix the issue.

--
nosy: +Martin.Fiers

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12641
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17263] crash when tp_dealloc allows other threads

2013-02-26 Thread Charles-François Natali

Charles-François Natali added the comment:

And here's a patch.

--
keywords: +patch
Added file: http://bugs.python.org/file29244/thread_local_concurrent.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17263
___--- Python-3.3.0/Modules/_threadmodule.c2013-02-26 08:37:05.0 
+
+++ python/Modules/_threadmodule.c  2013-02-26 08:48:24.0 +
@@ -769,6 +769,7 @@
 local_clear(localobject *self)
 {
 PyThreadState *tstate;
+PyInterpreterState *interp;
 Py_CLEAR(self-args);
 Py_CLEAR(self-kw);
 Py_CLEAR(self-dummies);
@@ -776,13 +777,18 @@
 /* Remove all strong references to dummies from the thread states */
 if (self-key
  (tstate = PyThreadState_Get())
- tstate-interp) {
-for(tstate = PyInterpreterState_ThreadHead(tstate-interp);
-tstate;
-tstate = PyThreadState_Next(tstate)) {
+ (interp = tstate-interp)) {
+for (tstate = PyInterpreterState_ThreadHead(interp);
+ tstate;) {
 if (tstate-dict 
-PyDict_GetItem(tstate-dict, self-key))
+PyDict_GetItem(tstate-dict, self-key)) {
 PyDict_DelItem(tstate-dict, self-key);
+/* the list of threads could have been altered, restart from
+ * the head */
+tstate = PyInterpreterState_ThreadHead(interp);
+} else {
+tstate = PyThreadState_Next(tstate);
+}
 }
 }
 return 0;
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15034] Document best practices for exceptions

2013-02-26 Thread Ezio Melotti

Ezio Melotti added the comment:

I'm removing the devguide component and update the title accordingly.

--
components: +Documentation -Devguide
title: Devguide should document best practices for stdlib exceptions - 
Document best practices for exceptions

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15034
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >