python docs search for 'print'

2012-09-04 Thread David Hoese

A friend made me aware of this:
When a python beginner (2.x) quick searches for "print" on 
docs.python.org, the print function doesn't even come up in the top 20 
results.  The print statement isn't even listed as far as I can tell.  
Is there something that can be done about this to make it easier for 
beginners?


I understand that this is a very basic search and "print" is a very 
common word and a very basic python statement, but it's pretty difficult 
for a beginner to learn when the first 5 results are about the 
disassembler and the next 5 are C functions.


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


python docs search for 'print'

2012-09-06 Thread David Hoese

On 9/5/12 3:03 PM, Grant Edwards wrote:

On 2012-09-05, Dave Angel  wrote:

>On 09/05/2012 01:47 PM, Grant Edwards wrote:
>

>>Making the site's "search" box use Google or somesuch is probably the
>>simplest solution. I'm not enough of a web guy to know how to do
>>that, but I do know that some sites do handle site search that way.
>>

>And google has some API's to make it relatively painless.  And a
>license form to fill in and send, along with your check.

I just saw the posting mentioning the pricing.  So it is a simple
simple solution, but it's probably not cheap enough...


I followed the bug reporting instructions on the docs site and emailed 
[email protected] and pointed them at this thread.  I didn't catch if 
anyone else on this thread already did it.  I guess we'll see what happens.


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


shutil _isindir

2011-10-21 Thread David Hoese

Hi,

I wasn't really sure where to post this since the python-dev list seems 
way too official.  I'm wondering/questioning the behavior of 
shutil.move.  It currently does a check for if the dst is inside the src 
directory with a _destinsrc function.  This function uses 
os.path.abspath to convert the arguments, but I think it should convert 
using os.path.realpath.  A recent problem I had with this I ended up 
asking on stackoverflow: 
http://stackoverflow.com/questions/7854608/python-shutil-move-odd-softlinking


So I was wondering if this sounds like a change that should happen in 
the shutil code or should programmers(me) just be more careful.  I feel 
like it should be in the shutil code since its getting around a checked 
case (destination inside source) and it can end up deleting information 
when a move was intended.  But then again this has been in the standard 
lib for a while now, so I'm guessing there are reasons for it...plus it 
was a dumb mistake by me.


So I guess what I'm asking is what are the reasons that _destinsrc uses 
abspath instead of realpath?  And is there a better place to ask this?


FYI, I was provided this link to the shutil.py source on SO: 
http://hg.python.org/cpython/file/d30482d51c25/Lib/shutil.py#l262


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


shutil _isindir

2011-10-22 Thread David Hoese
I was about to submit a bug report, but while testing I have figured out 
that my specific problem has been solved in Python 2.7 (server that I 
was using had 2.6 on it).  You can see the differences here:


2.6: http://hg.python.org/cpython/file/b9a95ce2692c/Lib/shutil.py
2.7: http://hg.python.org/cpython/file/d30482d51c25/Lib/shutil.py

You'll notice that in move(), there is now a check for the same file, 
which if they're not the same file you don't get unexpected deleted 
files.  If you still think I should submit a bug report let me know and

provide me with the test case...or just submit the bug yourself.

-Dave

P.S. Sorry for the original poor subject line, was a place holder
that I forgot to change.

On 10/22/2011 5:00 AM, [email protected] wrote:

Subject:
Re: shutil _isindir
From:
Steven D'Aprano 
Date:
10/22/2011 4:03 AM

To:
[email protected]


On Fri, 21 Oct 2011 22:13:06 -0500, David Hoese wrote:


>  So I guess what I'm asking is what are the reasons that _destinsrc uses
>  abspath instead of realpath?  And is there a better place to ask this?

Probably because abspath goes back to Python 1.5, while realpath is
comparatively recent only going back to 2.2, and nobody has thought to
change the code in shutil.

I recommend you raise a bug/feature request on the bug tracker,
preferably with a fix and a test demonstrating the problem.

http://bugs.python.org/

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


Re: Parallel Processing

2012-01-08 Thread David Hoese

On 1/8/12 1:45 PM, Yigit Turgut  wrote:

There are no imports other than defined on the script, which are;

import pygame
import sys
import time
import math
import pp

You are correct about  trying to pass two functions and second one is
in place where a tuple of arguments supposed to be. But what if these
functions don't have any arguments ? I tested functions test1() and
test2() seperately ; they work. Once I figure out how to run these
functions simultaneously, I will add an argument to test2 and try then
on. My main goal is to simultaneously run two functions, one of them
has one argument the other doesn't. To get familiar with parallel
processing I am experimenting now without arguments and then I will
embed the code to my application. I am experimenting with the
following ;

import pygame
import sys
import time
import math
import pp

screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
start = time.time()
end = time.time() - start

def test1():
   global end
   global white
   while(end<5):
 end = time.time() - start
 timer.tick(4) #FPS
 screen.fill((255,255,255) if white else (0, 0, 0))
 white = not white
 pygame.display.update()

def test2():
   global end
   while(end<5):
 end = time.time() - start
 print end

ppservers = ()
job_server = pp.Server(ppservers=ppservers)
print "Starting pp with", job_server.get_ncpus(), "workers"

job1 = job_server.submit(test1())
job2 = job_server.submit(test2())
result = job1()
result2 = job2()

print "Counting...", result2

job_server.print_stats()

test1() works as expected (job1) but test2() doesn't work and I get
the following traceback ;

Traceback (most recent call last):
   File "fl.py", line 33, in
 job1 = job_server.submit(test1())
   File "/usr/lib/python2.6/site-packages/pp.py", line 458, in submit
 sfunc = self.__dumpsfunc((func, ) + depfuncs, modules)
   File "/usr/lib/python2.6/site-packages/pp.py", line 629, in
__dumpsfunc
 sources = [self.__get_source(func) for func in funcs]
   File "/usr/lib/python2.6/site-packages/pp.py", line 696, in
__get_source
 sourcelines = inspect.getsourcelines(func)[0]
   File "/usr/lib/python2.6/inspect.py", line 678, in getsourcelines
 lines, lnum = findsource(object)
   File "/usr/lib/python2.6/inspect.py", line 519, in findsource
 file = getsourcefile(object) or getfile(object)
   File "/usr/lib/python2.6/inspect.py", line 441, in getsourcefile
 filename = getfile(object)
   File "/usr/lib/python2.6/inspect.py", line 418, in getfile
 raise TypeError('arg is not a module, class, method, '
TypeError: arg is not a module, class, method, function, traceback,
frame, or code object

Error is related to test1 not having an argument.  When I leave it
empty as following ;

job1 = job_server.submit(test1,())

test1 doesn't run. When I do ;

job1 = job_server.submit(test1())

Display works but I get;

TypeError: arg is not a module, class, method, function, traceback,
frame, or code object (complete traceback same as above).

And test2 doesn't work also. But when I do;

job1 = job_server.submit(test1,())
job2 = job_server.submit(test2())

I get test2 working but test1 not working. Obviously related to
argument arrangement in submit.

Hi,

I've never used pygame or Parallel Python, but I played around with the 
code you provided and did one of my favorite debugging techniques...I 
printed things out and read the output.


So one thing I did was printed the globals before the function 
definitions and inside test1().  Which the first print shows what I 
expect from calling "print globals()", then inside test1() I only get 
functions, modules, and a few other things.  So I checked the pp 
documentation and found this about the globals keyword:


globals - dictionary from which all modules, functions and classes

It also handles imports funny because I tried doing "from pprint import 
pprint" and it couldn't find it properly even though that's a function 
(it couldn't find a class that that function uses).  So I think you'll 
have to pass things in as arguments or a dependency functions as others 
have suggested.  There is also a 'modules' keyword that you can provide 
names of modules to import, which might help.  And is there a reason you 
need to use Parallel Python and can't use something more simple like 
python's "multiprocessing" or the classic "os.fork()"?  I understand 
that Parallel Python can run on remote servers in parallel...but how 
complicated is your program going to be?


I got the following to work (not sure if its what you want):
###
import pp

def test1():
start = time.time()
end = time.time() - start
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
while(end<5):
end = time.time() - start
timer.tick(4) #FPS
screen.fill((255,255,255) if white else (0, 0, 0))
white = not white
pygame.display.update()

def