Re: idle mac os x international keyboard umlaut input

2012-01-08 Thread Some Friend

Am 08.01.12 23:12, schrieb Benjamin Kaplan:

On Sun, Jan 8, 2012 at 2:32 PM, Some Friend  wrote:

Dear Friends,
with an international keyboard on mac os 10.6
an umlaut is inserted according to the chosen
keyboard layout with alt + u followed by a,
o or u for ä, ö or ü, or with cmd + " followed
by a, o or u for ä, ö or ü.  Neither way works
in the IDLE console or file window of IDLE.
Both ways work on the python console in a terminal
window.

IDLE version 3.2.2, Phyton version 3.2.2 and
Tk version 8.5 according to IDLE ->  "About IDLE".

Names of the keyboard layouts:
"US" and "US International - PC"

Thank y'll for any Help
--


This issue came up a few weeks ago too. The conclusion was that it's a
bug in the Cocoa version of Tcl/Tk so there's unfortunately not much
that can be done from the Python side.

https://groups.google.com/group/comp.lang.python/browse_thread/thread/c7f22b059c68452a/85d11aa8f4b8b3c1


... so it's paste and copy then :-(.  Thanks for your Help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Error Importing MySQLdb

2012-01-08 Thread John Nagle

On 1/8/2012 5:23 PM, Benjamin Kaplan wrote:

On Sun, Jan 8, 2012 at 5:37 PM, davidfx  wrote:

I am not sure what file you mean.  Where should I look for the file you are 
talking about?  By the way MySQL works fine within MAMP.

Thanks for your suggestions.



Like I said, it's likely an architecture issue. If you have a 32-bit
MySQL install and are using a 64-bit Python, it won't be able to load
the client libraries. The Python install included in Lion is universal
(a single file containing both 32-bit and 64-bit executables) so if
it's loaded by a 32-bit program, it will load in 32-bit mode.


Actually, the issue is only whether you have 64-bit MySQL client 
libraries for C to which MySQLdb can link.  Those are called

"MySQL Connector/C", and here are the download pages for them.

http://dev.mysql.com/downloads/connector/c/

The actual database can (and usually should be) the 64-bit executable, 
while the libraries can be 32 or 64 bit. They communicate over a socket,

and don't even need to be on the same machine.

Unfortunately, the whole MySQLdb/Python/Connector/C versioning
setup is a mess.  See:

http://chaos.weblogs.us/archives/327

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


Re: python philosophical question - strong vs duck typing

2012-01-08 Thread John Nagle

On 1/3/2012 6:15 PM, alex23 wrote:

On Jan 4, 6:38 am, Terry Reedy  wrote:

Shredskin compiles a subset of
Python, or a subset of usages, to C, with similar benefits.


That is, of course, 'Shedskin' and 'C++' :)

+1 for either Cython or Shedskin as your next step for more performant
Python.


   I've tried Shed Skin, and it's an excellent idea that's not ready for
prime time.  One guy did it all, and it needs a greater level of effort
than that.  It does do well on numeric code.

   There's a reason for that.  If you can figure out at compile time
which variables can be represented as "int", "bool", "char" (or 
"wchar_t") and "double", performance on numeric work improves

enormously.  CPython boxes everything, including integers, in
a "CObject" object, so there's dispatching overhead just to add
two numbers.

   A type-inferring compiler has to analyze the whole program at
once, because the type of a function's arguments is determined
by its callers.  This is slow.  The alternative is to guess
what the type of something is likely to be, compile code at
run time, and be prepared to back out a bad guess.  This
requires a very complex system, but that's how PyPy does it.
Performance does not seem to reach Shed Skin levels.

   Python has some serious problems that preclude optimization.
Basically, the language is designed to be run by a naive 
(non-optimizing) interpreter, and allows things that are easy

for such an implementation but very tough to optimize.  An
example is the ability to store into the variables of a module
from outside it, and even from another thread.  Every attempt
to get rid of the Global Interpreter Lock has hit that problem.

John Nagle

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


Re: replacing __dict__ with an OrderedDict

2012-01-08 Thread alex23
On Jan 7, 2:06 am, Ian Kelly  wrote:
>  wrote:
> > Nonetheless, I'm still wondering if I could somehow replace the dict with an
> > OrderedDict.
>
> In Python 3, yes.  This is pretty much the entire use case for the new
> __prepare__ method of metaclasses.  See the "OrderedClass" example[...]

This isn't accurate. The OrderedClass example uses an OrderedDict to
remember the method creation order:

def __new__(cls, name, bases, classdict):
result = type.__new__(cls, name, bases, dict(classdict))
result.members = tuple(classdict)
return result

The instantiated objects __dict__ will still be a regularly
dictionary, while the assignment order is stored in the class
attribute .members.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An "alternative" to Learning Perl

2012-01-08 Thread Sean Wolfe
On Sun, Jan 8, 2012 at 8:44 PM, Sebastian Rooks
 wrote:
> Hello everyone,
>
> I was wondering if you could help me. I'm looking for a python
> introductory book, kind of like Learning Python only smaller (?!)
> The thing is, I travel to and from work each day for about 1,5h in each
> direction, and do most of my reading on the train :\
>
> (seriously)
>
> And I can't find one (just one) python book shorter than 500 pages that
> is worth its weight in salt.
>
> Anyone know of any, any at all?
>
> All suggestions welcomed!
>
> -- Sebastian
> --

kindle? ipad? tablet?
also there is python programming for the absolute beginner, which is
agreat book but it's pretty beginner. But well written. At least
Iliked 
it.http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002
Also byte of python ... I think there's a hardcover version you can
buyhttp://www.swaroopch.com/buybook/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:

2012-01-08 Thread Sean Wolfe
On Sun, Jan 8, 2012 at 11:38 PM, David George  wrote:
>
> Sean Wolfe wrote:
>>
>> is anybody out there?
>>
>> On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi
>>   wrote:
>>>
>>> hello ?
>>>
>
> Hello there Sean, How are you doing?
> --
> http://mail.python.org/mailman/listinfo/python-list

I'm freakin  awesome. This reply all feature is a little high tech for
me though, took me a few times to figure it out. That's done though so
on to self sustaining nuclear fusion ... brb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using an OrderedDict for __dict__ in Python 3 using __prepare__

2012-01-08 Thread Christian Heimes
Am 09.01.2012 03:21, schrieb Steven D'Aprano:
> What am I doing wrong?

You aren't doing anything wrong. It's just not possible to have
something different than a dict as a type's __dict__. It's a deliberate
limitation and required optimization. The __prepare__ hook allows to you
have a dict subclass as intermediate dict, but in the end it always
comes down to a dict.

The code in Objects/typeobject.c:type_new() copies the dict:

/* Initialize tp_dict from passed-in dict */
type->tp_dict = dict = PyDict_Copy(dict);

PyDict_Copy() takes an instance of a PyDict_Type subclass and always
returns a PyDictObject.

However you can use the __prepare__ hook to *remember* the order of
insertion, see
http://docs.python.org/py3k/reference/datamodel.html#customizing-class-creation

Christian

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


Re: Parallel Processing

2012-01-08 Thread Dave Angel

On 01/08/2012 08:46 PM, Yigit Turgut wrote:

On Jan 9, 12:02 am, Dave Angel  wrote:


Then i'd try calling separate functions (declaring them in depfuncs).
And finally I'd try some 3rd party library.

Don't think will try another package for the same task. I am now
moving on to PP + PyCUDA to harness GPU available CPU cores.

Thank you for the guidance.

Actually, I wasn't suggesting an alternative to pp, but rather 
introducing refs to libraries like numpy.  I don't know what pp's 
methodology is, but I can guess which parts are trivial, and which parts 
tend to be trickier.  Once things are in a separate process, it's best 
not to assume any shared state between the processes.  Thus I'd expect 
globals() to be copied, not shared.  And the error messages had very low 
line numbers, which I could take to mean they didn't add your imports 
and other stuff.


Point is, when i start having trouble with code that's inadequately 
documented, I try the simplest things, and work up to the complex ones.




--

DaveA

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


Re:

2012-01-08 Thread David George


Sean Wolfe wrote:

is anybody out there?

On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi
  wrote:

hello ?



Hello there Sean, How are you doing?
--
http://mail.python.org/mailman/listinfo/python-list


Using an OrderedDict for __dict__ in Python 3 using __prepare__

2012-01-08 Thread Steven D'Aprano
I'm using Python 3.1 and trying to create a class using an OrderedDict as 
its __dict__, but it isn't working as I expect.

See http://www.python.org/dev/peps/pep-3115/ for further details.

Here is my code:


from collections import OrderedDict

# The metaclass
class OrderedClass(type):
# The prepare function
@classmethod
def __prepare__(metacls, name, bases): # No keywords in this case
print('calling metaclass __prepare__')
return OrderedDict()
# The metaclass invocation
def __new__(cls, name, bases, classdict):
print('calling metaclass __new__')
for x in cls, name, bases, classdict, type(classdict):
print(' ', x)
return type.__new__(cls, name, bases, classdict)

class MyClass(metaclass=OrderedClass):
spam = 'Cardinal Biggles'
ham = 'Ethel the Aardvark'
def method1(self):
pass
def method2(self):
pass

list(MyClass.__dict__.keys())


and the results I get:

calling metaclass __prepare__
calling metaclass __new__
  
  MyClass
  ()
  OrderedDict([('__module__', '__main__'), ('spam', 'Cardinal Biggles'), 
('ham', 'Ethel the Aardvark'), ('method1', ), ('method2', )])
  

['__module__', 'method2', 'ham', 'spam', 'method1', '__dict__', 
'__weakref__', '__doc__']


I expected that the output of MyClass.__dict__.keys would match the input 
OrderedDict (ignoring the entries added later, like __module__ and 
__doc__).

And I'm completely flummoxed by the existence of 
MyClass.__dict__['__dict__'].


What am I doing wrong?



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


Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 9, 12:02 am, Dave Angel  wrote:
> On 01/08/2012 11:39 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
>
>
> > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
> > timer = pygame.time.Clock()
> > white = True
> > start = time.time()
> > end = time.time() - start
> > end2= 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 end2
> >while(end2<5):
> >  end2 = time.time() - start
> >  print end2
>
> > ppservers = ()
> > job_server = pp.Server(ppservers=ppservers)
>
> > job1 = job_server.submit(test1, (), globals=globals())
> > job2 = job_server.submit(test2, (), globals=globals())
> > result = job1()
> > result2 = job2()
>
> > print  result2
>
> > job_server.print_stats()
>
> > This *supposed to* print values of 'end' and simultaneously execute
> > test1. Eventhough I set globals parameter and nothing seems to be
> > wrong this code generates the following traceback ;
>
> > Starting pp with 2 workers
> > An error has occured during the function execution
> > Traceback (most recent call last):
> >File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
> >  __result = __f(*__args)
> >File "", line 4, in test1
> > NameError: global name 'end' is not defined
> > An error has occured during the function execution
> > Traceback (most recent call last):
> >File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
> >  __result = __f(*__args)
> >File "", line 3, in test2
> > NameError: global name 'end2' is not defined
>
> > How can this be, what am I missing ?
>
> I don't see anything on thehttp://www.parallelpython.com
>  website that indicates how it handles
> globals.  Remember this is creating a separate process, so it can't
> literally share the globals you have.  i would have expected it to
> pickle them when you say globals=globals(), but I dunno. In any case, I
> can't see any value in making end global with the "global" statement.
> I'd move the end= line inside the function, and forget about making it
> global.

globals=globals() works but not for each variable (lol). Some of them
gets recognized and some don't for some reason I couldn't figure out
yet. But that's the main scheme.
>
> The other thing you don't supply is a list of functions that might be
> called by your function.  See the depfuncs argument.  It probably
> handles all the system libraries, but I can't see how it'd be expected
> to handle pygame.

depfuncs passes the dependent functions that will/might be used at the
execution phase of the called function. PP doesn't require to set
modules for basic I/O,sys etc. Only 3rd party ones like numpy, scipy
and so on.
>
> With the limited information supplied by the website, I'd experiment
> first with simpler things.  Make two functions that are self-contained,
> and try them first.  No global statements, and no calls to pygame.
> After that much worked, then I'd try adding arguments, and then return
> values.
>

That's what I did. After investigating similar approaches to achieve
the task, I unconsciously developed an idea that 'this is not going to
be easy' and approached with that perception. Now I realize that it's
much more simple than I thought. The work it does is complex but it
requires very little effort to operate functionally.

> Then i'd try calling separate functions (declaring them in depfuncs).
> And finally I'd try some 3rd party library.

Don't think will try another package for the same task. I am now
moving on to PP + PyCUDA to harness GPU available CPU cores.

Thank you for the guidance.

On Jan 9, 2:02 am, David Hoese  wrote:
> 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

Re: Error Importing MySQLdb

2012-01-08 Thread Benjamin Kaplan
On Sun, Jan 8, 2012 at 5:37 PM, davidfx  wrote:
> I am not sure what file you mean.  Where should I look for the file you are 
> talking about?  By the way MySQL works fine within MAMP.
>
> Thanks for your suggestions.


Like I said, it's likely an architecture issue. If you have a 32-bit
MySQL install and are using a 64-bit Python, it won't be able to load
the client libraries. The Python install included in Lion is universal
(a single file containing both 32-bit and 64-bit executables) so if
it's loaded by a 32-bit program, it will load in 32-bit mode.

"file" is a command that uses heuristics to determine the type of a
file. You run it from a terminal.

$ file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):Mach-O executable i386

Try running "file /usr/local/lib/libmysqlclient.18.dylib". According
to the traceback you posted, that's the library that failed to load.

If you need to force Python to run in 32-bit mode, you can use the arch command
"arch -i386 python"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:

2012-01-08 Thread alex23
On Jan 9, 2:37 am, Sean Wolfe  wrote:
> is anybody out there?
>
> On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi
>
>  wrote:
> > hello ?

Just nod if you can hear me!

-- 
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

An "alternative" to Learning Perl

2012-01-08 Thread Sebastian Rooks
Hello everyone,

I was wondering if you could help me. I'm looking for a python
introductory book, kind of like Learning Python only smaller (?!)
The thing is, I travel to and from work each day for about 1,5h in each
direction, and do most of my reading on the train :\

(seriously)

And I can't find one (just one) python book shorter than 500 pages that
is worth its weight in salt.

Anyone know of any, any at all?

All suggestions welcomed!

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


Re: replacing __dict__ with an OrderedDict

2012-01-08 Thread Eelco
i havnt read every post in great detail, but it doesnt seem like your
actual question has been answered, so ill give it a try.

AFAIK, changing __dict__ to be an ordereddict is fundamentally
impossible in python 2. __dict__ is a builtin language construct
hardcoded into the C API. There is no way to mess with it.

Apparently this is different in python 3, but I dont know much about
that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error Importing MySQLdb

2012-01-08 Thread Dave Angel

On 01/08/2012 05:37 PM, davidfx wrote:

I am not sure what file you mean.  Where should I look for the file you are 
talking about?  By the way MySQL works fine within MAMP.

Thanks for your suggestions.

In most Linux/Unix systems, there is a file utility on the system PATH.

To find the type of a particular file, you run it as
fileunknowndata

and it'll use its heuristics to guess what kind of data you have, 
written by what software, or what type of executable you have, and 
whether it's 32 bit or 64, etc.




--

DaveA

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


Re: Error Importing MySQLdb

2012-01-08 Thread davidfx
I am not sure what file you mean.  Where should I look for the file you are 
talking about?  By the way MySQL works fine within MAMP.

Thanks for your suggestions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error Importing MySQLdb

2012-01-08 Thread Benjamin Kaplan
On Sun, Jan 8, 2012 at 4:37 PM, David George  wrote:
> Hello there,
> I have been trying for awhile now to get MySQLdb working. I am currently
> getting this error when trying to import it:
>
 import MySQLdb
>
> Traceback (most recent call last): File "", line 1, in File
> "build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File
> "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File
> "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap
> ImportError:
> dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
> 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib Referenced
> from:
> /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
> Reason: image not found
>
> Anyone know what I need to do in order to correct these errors.
>
> Thanks

MySQLdb is having trouble loading the MySQL client library. Since I
assume MySQL is installed, my best guess is that you have an
architecture problem. Your Python is probably running in 64-bit mode.
Do you have a 64-bit MySQL install? The "file" command will tell you
which architectures are in a binary if you're unsure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idle mac os x international keyboard umlaut input

2012-01-08 Thread Benjamin Kaplan
On Sun, Jan 8, 2012 at 2:32 PM, Some Friend  wrote:
> Dear Friends,
> with an international keyboard on mac os 10.6
> an umlaut is inserted according to the chosen
> keyboard layout with alt + u followed by a,
> o or u for ä, ö or ü, or with cmd + " followed
> by a, o or u for ä, ö or ü.  Neither way works
> in the IDLE console or file window of IDLE.
> Both ways work on the python console in a terminal
> window.
>
> IDLE version 3.2.2, Phyton version 3.2.2 and
> Tk version 8.5 according to IDLE -> "About IDLE".
>
> Names of the keyboard layouts:
> "US" and "US International - PC"
>
> Thank y'll for any Help
> --

This issue came up a few weeks ago too. The conclusion was that it's a
bug in the Cocoa version of Tcl/Tk so there's unfortunately not much
that can be done from the Python side.

https://groups.google.com/group/comp.lang.python/browse_thread/thread/c7f22b059c68452a/85d11aa8f4b8b3c1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Processing

2012-01-08 Thread Dave Angel

On 01/08/2012 11:39 AM, Yigit Turgut wrote:


screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
start = time.time()
end = time.time() - start
end2= 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 end2
   while(end2<5):
 end2 = time.time() - start
 print end2

ppservers = ()
job_server = pp.Server(ppservers=ppservers)

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

print  result2

job_server.print_stats()

This *supposed to* print values of 'end' and simultaneously execute
test1. Eventhough I set globals parameter and nothing seems to be
wrong this code generates the following traceback ;

Starting pp with 2 workers
An error has occured during the function execution
Traceback (most recent call last):
   File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
 __result = __f(*__args)
   File "", line 4, in test1
NameError: global name 'end' is not defined
An error has occured during the function execution
Traceback (most recent call last):
   File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
 __result = __f(*__args)
   File "", line 3, in test2
NameError: global name 'end2' is not defined

How can this be, what am I missing ?
I don't see anything on the http://www.parallelpython.com 
 website that indicates how it handles 
globals.  Remember this is creating a separate process, so it can't 
literally share the globals you have.  i would have expected it to 
pickle them when you say globals=globals(), but I dunno. In any case, I 
can't see any value in making end global with the "global" statement.  
I'd move the end= line inside the function, and forget about making it 
global.


The other thing you don't supply is a list of functions that might be 
called by your function.  See the depfuncs argument.  It probably 
handles all the system libraries, but I can't see how it'd be expected 
to handle pygame.


With the limited information supplied by the website, I'd experiment 
first with simpler things.  Make two functions that are self-contained, 
and try them first.  No global statements, and no calls to pygame.  
After that much worked, then I'd try adding arguments, and then return 
values.


Then i'd try calling separate functions (declaring them in depfuncs).  
And finally I'd try some 3rd party library.



--

DaveA

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


Error Importing MySQLdb

2012-01-08 Thread David George

Hello there,
I have been trying for awhile now to get MySQLdb working. I am currently 
getting this error when trying to import it:


>>> import MySQLdb

Traceback (most recent call last): File "", line 1, in File 
"build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File 
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File 
"build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap 
ImportError: 
dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 
2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib 
Referenced from: 
/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so 
Reason: image not found


Anyone know what I need to do in order to correct these errors.

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


Re: your feedback to my first project please

2012-01-08 Thread patr...@bierans.de
Thanks for the feedback!

I took the time reading and understanding it and to let it getting into my
bones. And I also lost time on reading more of this freaky and interesting
documentation and was testing a lot of different stuff with my enviroment.

My current code can be seen here if you are interested:

http://pastebin.com/3fz6qm9z  #AverageStack.py
http://pastebin.com/tUSGs3gb  #TestAverageStack.py

Here are my replies to your time consuming and informative replies ;)


> D'Arcy wrote: [code examples]

Python has some really interesting tricks I have not seen in php.
For example: self._data = [default] * dim  - That's nice. :)
And allowing the getter to also set a value was a nice idea.
I meant: def avg(self, value=None)
Thanks for that! :)

But I will keep some of my underscores for "private" attributes and methods.
And I googled: "dim" was basic. I know too many languages and start mixing
the keywords - shame on me. ;)


> D'Arcy and Peter wrote: [about writing testcases]

Good Eye: I wrote the tests after coding - I know that this is the wrong way.
I just wanted to start coding and after some time I decided that I shoud have
some test cases. This is no real TDD - true. ;) I'll do that right next time.


> Peter wrote: You must be doing it [writing test cases] wrong.

After thinking about it: Yupp. You are right. Having written tests to check
"private" attributes really hurts one's pride. ;)


> Peter wrote: You need "from __future__ import division"

Thanks for pointing me to it. I really would have fallen for it!


> Peter wrote: assert False, " %s, %s ?" % ("red", "yellow")

Can you do that with a.avg() instead of a string like "red"?


TIA,
Patrick


PS:

> gene wrote: [plain text emails]

Thanks for pointing me to that. But it was the mistake of my webmailer. I am
well aware of the etiquette of mailing lists. (As you can see my mail was
wordwrapped accordingly.)

But I will not blame you for full quoting my html email... *cough* ;-P  

I hope I can get my webmailer to go for plain text email. The option is set
but does not seam to apply. ?(
-- 
http://mail.python.org/mailman/listinfo/python-list


idle mac os x international keyboard umlaut input

2012-01-08 Thread Some Friend

Dear Friends,
with an international keyboard on mac os 10.6
an umlaut is inserted according to the chosen
keyboard layout with alt + u followed by a,
o or u for ä, ö or ü, or with cmd + " followed
by a, o or u for ä, ö or ü.  Neither way works
in the IDLE console or file window of IDLE.
Both ways work on the python console in a terminal
window.

IDLE version 3.2.2, Phyton version 3.2.2 and
Tk version 8.5 according to IDLE -> "About IDLE".

Names of the keyboard layouts:
"US" and "US International - PC"

Thank y'll for any Help
--
http://mail.python.org/mailman/listinfo/python-list


Re:

2012-01-08 Thread Rick Johnson
On Jan 8, 10:37 am, Sean Wolfe  wrote:
> is anybody out there?

Oh yes, in fact there are many of us who are "out there".

http://www.youtube.com/watch?v=bHNa_f28Q-s
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 8, 6:00 pm, Chris Angelico  wrote:
> On Mon, Jan 9, 2012 at 2:45 AM, Yigit Turgut  wrote:
> > job1 = job_server.submit(test1,())
> > job2 = job_server.submit(test2())
>
> The first of these passes test1 and an empty tuple as arguments to
> submit(). The second calls test2 with no arguments, then passes its
> return value to submit(), which is not what you want to do.
>
> Chris Angelico

Yes that's correct but (test1,()) doesn't do any good since it doesn't
execute the loop.

screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
timer = pygame.time.Clock()
white = True
start = time.time()
end = time.time() - start
end2= 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 end2
  while(end2<5):
end2 = time.time() - start
print end2

ppservers = ()
job_server = pp.Server(ppservers=ppservers)

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

print  result2

job_server.print_stats()

This *supposed to* print values of 'end' and simultaneously execute
test1. Eventhough I set globals parameter and nothing seems to be
wrong this code generates the following traceback ;

Starting pp with 2 workers
An error has occured during the function execution
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
__result = __f(*__args)
  File "", line 4, in test1
NameError: global name 'end' is not defined
An error has occured during the function execution
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run
__result = __f(*__args)
  File "", line 3, in test2
NameError: global name 'end2' is not defined

How can this be, what am I missing ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:

2012-01-08 Thread Sean Wolfe
is anybody out there?

On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi
 wrote:
> hello ?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
A musician must make music, an artist must paint, a poet must write,
if he is to be ultimately at peace with himself.
- Abraham Maslow
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parallel Processing

2012-01-08 Thread Chris Angelico
On Mon, Jan 9, 2012 at 2:45 AM, Yigit Turgut  wrote:
> job1 = job_server.submit(test1,())
> job2 = job_server.submit(test2())

The first of these passes test1 and an empty tuple as arguments to
submit(). The second calls test2 with no arguments, then passes its
return value to submit(), which is not what you want to do.

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


Re: Parallel Processing

2012-01-08 Thread Yigit Turgut
On Jan 8, 4:34 pm, Dave Angel  wrote:
> On 01/08/2012 08:23 AM, Yigit Turgut wrote:
>
>
>
>
>
>
>
> > Hi all,
>
> > I am trying to run two functions at the same time with Parallel
> > Processing (pp) as 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
> >    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(end2<5):
> >      end2 = time.time() - start
> >      print end
>
> > ppservers = ()
>
> > if len(sys.argv)>  1:
> >      ncpus = int(sys.argv[1])
> >      # Creates jobserver with ncpus workers
> >      job_server = pp.Server(ncpus, ppservers=ppservers)
> > else:
> >      # Creates jobserver with automatically detected number of workers
> >      job_server = pp.Server(ppservers=ppservers)
> > print "Starting PP with", job_server.get_ncpus(), "workers"
>
> > job1 = job_server.submit(test1,test2)
> > result = job1()
>
> > And the output is ;
>
> > Starting PP with 2 workers
> > Traceback (most recent call last):
> >    File "fl.py", line 46, in
> >      job1 = job_server.submit(test1,test2)
> >    File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
> >      raise TypeError("args argument must be a tuple")
> > TypeError: args argument must be a tuple
>
> > When I change job1 to just to see if it will run one function only;
> > job1 = job_server.submit(test1)
>
> > I get an output of;
>
> > NameError: global name 'end' is not defined
>
> > end variable is defined as global but I get a NameError. Anyone has an
> > idea what's going on ?
>
> First, please tell us about any external dependencies (eg. imports).
> Pygame may not matter, since there are many people here using it, but
> each of us has to hunt down something that does parallel processing with
> an interface similar to what you're using.  For the next person, the
> most likely candidate out of the dozens available 
> is:http://www.parallelpython.com/
>
> Your problem, as stated in the raise statement, is that the submit
> method is expecting a tuple for its "args argument".  Now I had to go to
> the website to find an example, but it appears that your second argument
> should have been a tuple of the arguments for your function.  See
> *      submit*(self, func, args=(), depfuncs=(), modules=(),
> callback=None, callbackargs=(), group='default', globals=None)
>
> on page:http://www.parallelpython.com/content/view/15/30/#API
>
> So you're passing it two function objects, and the second one is in the
> place where it's expecting a tuple of arguments.  Apparently you should
> be calling submit multiple times, once for each function.
>
> As for the error you get when you do that, please post the full
> traceback. I suspect that the message you did post has a typo in it, or
> that the error occurred when your source code was not as you show it
> here.  You have two variables end and end2, and only the first one is
> ever declared global.  func2() should get a different error when you run
> it; since it tries to use a local end2 before defining it.
>
> I recommend always testing your code with a single thread before trying
> to launch more complex multithread stuff.  Just call func() and func2(),
> and see if they complete, and get reasonable answers.
>
> --
>
> DaveA

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.

Re: Parallel Processing

2012-01-08 Thread Dave Angel

On 01/08/2012 08:23 AM, Yigit Turgut wrote:

Hi all,

I am trying to run two functions at the same time with Parallel
Processing (pp) as 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
   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(end2<5):
 end2 = time.time() - start
 print end

ppservers = ()

if len(sys.argv)>  1:
 ncpus = int(sys.argv[1])
 # Creates jobserver with ncpus workers
 job_server = pp.Server(ncpus, ppservers=ppservers)
else:
 # Creates jobserver with automatically detected number of workers
 job_server = pp.Server(ppservers=ppservers)
print "Starting PP with", job_server.get_ncpus(), "workers"

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

And the output is ;

Starting PP with 2 workers
Traceback (most recent call last):
   File "fl.py", line 46, in
 job1 = job_server.submit(test1,test2)
   File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
 raise TypeError("args argument must be a tuple")
TypeError: args argument must be a tuple


When I change job1 to just to see if it will run one function only;
job1 = job_server.submit(test1)

I get an output of;

NameError: global name 'end' is not defined

end variable is defined as global but I get a NameError. Anyone has an
idea what's going on ?
First, please tell us about any external dependencies (eg. imports).  
Pygame may not matter, since there are many people here using it, but 
each of us has to hunt down something that does parallel processing with 
an interface similar to what you're using.  For the next person, the 
most likely candidate out of the dozens available is:

http://www.parallelpython.com/

Your problem, as stated in the raise statement, is that the submit 
method is expecting a tuple for its "args argument".  Now I had to go to 
the website to find an example, but it appears that your second argument 
should have been a tuple of the arguments for your function.  See
*  submit*(self, func, args=(), depfuncs=(), modules=(), 
callback=None, callbackargs=(), group='default', globals=None)


on page: http://www.parallelpython.com/content/view/15/30/#API

So you're passing it two function objects, and the second one is in the 
place where it's expecting a tuple of arguments.  Apparently you should 
be calling submit multiple times, once for each function.


As for the error you get when you do that, please post the full 
traceback. I suspect that the message you did post has a typo in it, or 
that the error occurred when your source code was not as you show it 
here.  You have two variables end and end2, and only the first one is 
ever declared global.  func2() should get a different error when you run 
it; since it tries to use a local end2 before defining it.


I recommend always testing your code with a single thread before trying 
to launch more complex multithread stuff.  Just call func() and func2(), 
and see if they complete, and get reasonable answers.


--

DaveA


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


Parallel Processing

2012-01-08 Thread Yigit Turgut
Hi all,

I am trying to run two functions at the same time with Parallel
Processing (pp) as 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
  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(end2<5):
end2 = time.time() - start
print end

ppservers = ()

if len(sys.argv) > 1:
ncpus = int(sys.argv[1])
# Creates jobserver with ncpus workers
job_server = pp.Server(ncpus, ppservers=ppservers)
else:
# Creates jobserver with automatically detected number of workers
job_server = pp.Server(ppservers=ppservers)
print "Starting PP with", job_server.get_ncpus(), "workers"

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

And the output is ;

Starting PP with 2 workers
Traceback (most recent call last):
  File "fl.py", line 46, in 
job1 = job_server.submit(test1,test2)
  File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit
raise TypeError("args argument must be a tuple")
TypeError: args argument must be a tuple


When I change job1 to just to see if it will run one function only;
job1 = job_server.submit(test1)

I get an output of;

NameError: global name 'end' is not defined

end variable is defined as global but I get a NameError. Anyone has an
idea what's going on ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socketserver question

2012-01-08 Thread Bryan
K Richard Pixley wrote:
[...]
> The doc says server.shutdown(), but if I call self.server.shutdown()
> from within handler.handle(), I seem to get a deadlock, which is exactly
> what I'd expect in a single threaded system with no way to "signal" the
> server.server_forever() loop which is several frames up the stack.

Well, it's documented behavior, but not what I would have expected.
Seems to go out of its way to deadlock. Stopping the main loop from
inside a request is perfectly reasonable thing to want to do, and
single-threaded GUI's do it all the time.

It's not an up-the-stack problem. shutdown() sets a flag that will
cause the loop not to repeat, but then calls wait() for an event that
won't be signaled until the loop exits, breaking the single-threaded
case. It's bad design.

Given the library class is as it is, one solution (untested) is to
relax being single-threader for just a bit.

import thread
thread.start_new_thread(server.shutdown, ())

--
--Bryan

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


Re: How to support a non-standard encoding?

2012-01-08 Thread Thomas Rachel

Am 06.01.2012 21:00 schrieb jmfauth:


Another simple approach, os independent.

You probably do not write your code in iso-6937, but
you only need to encode/decode some bytes sequence
"on the fly". In that case, work with bytes, create
a couple of coding / decoding functions with a
created  [*] as helper. It's not so complicate.
Use  Py2 or  Py3 (the recommended
way ;-) ) as pivot encoding.


These coding/decoding functions are exactly the way to create a codec. 
I. e., it is not much more.



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


Re: multiple inheritance from list and other class

2012-01-08 Thread lars van gemerden
On Jan 8, 7:42 am, Steven D'Aprano  wrote:
> On Sat, 07 Jan 2012 17:16:22 -0800, lars van gemerden wrote:
> > Hello,
>
> > I have an error message i do not understand:
>
> > My code is in essence:
>
> The code you give works fine. It does not show the error you say it does.
> Please test your code before posting and ensure it actually fails the way
> you expect.
>
> It is perfectly fine to use multiple inheritance in the way you show.
> Here is an even simpler example:
>
> py> class Spam(object):
> ...     pass
> ...
> py> class Ham(list, Spam):
> ...     pass
> ...
> py>
> py> h = Ham([1, 2, 3])
> py>
>
> And no exception is raised.
>
> --
> Steven

Sorry for wasting you time, I found the error (had "def" instead of
"class" before B in the example), sorry about not testing, shouldn't
post at 2:00 AM.

Thanks all the same, Lars
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to support a non-standard encoding?

2012-01-08 Thread Ivan

Dear jmf, Tim

Thanks for these pointers.  They look v useful.

I'll have a go and report back (with success I hope).

Best wishes

Ivan

On 06/01/2012 20:42, Tim Wintle wrote:

On Fri, 2012-01-06 at 12:00 -0800, jmfauth wrote:

The distibution of such a codec may be a problem.


There is a register_codec method (or similar) in the codecs module.

Tim





--

Ivan A. Uemlianin
Llaisdy
Speech Technology Research and Development

i...@llaisdy.com
 www.llaisdy.com
 llaisdy.wordpress.com
  github.com/llaisdy
 www.linkedin.com/in/ivanuemlianin

"Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
 (Schiller, Beethoven)

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