Re: authentication with python-ldap

2013-05-26 Thread Dieter Maurer
Jorge Alberto Diaz Orozco wrote at 2013-5-25 14:00 -0400:
I have been doing the same thing and I tried to use java for testing the 
credentials and they are correct. It works perfectly with java.
I really don´t know what we´re doing wrong.

Neither do I.

But the error message definitely originates from the LDAP server.
This means that the server sees different things for the
(successful) Java connection and the (unsuccessful) Python connection.
Maybe, you can convince your LDAP server administrator to configure
a form of logging that allows you to compare the two requests
(this may not be easy - because sensitive information is involved).
Comparing the requests may provide valuable clues towards the cause
of the problem.

One may also try some guesswork: There is an important difference
between Java and Python 2. Java uses unicode as the typical type
for text variables while in Python 2, you use normally the type str
for text. str means no unicode but encoded text.
When the Java-LDAP bridge passes text to the LDAP server, it must
encode the text - and maybe, it uses the correct encoding
(the one the LDAP server expects). The Python-LDAP bridge, on the other
hand, does not get unicode but str and likely passes the str
values directly. Thus, if your str values do not use the correct
encoding (the one expected by the LDAP server), things will not
work out correctly.

I expect the LDAP server to expect the utf-8 encoding.
In this case, problems could be expected when the data
passed on to the LDAP server contains non ascii characters
while all ascii data should not see problems.



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


TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Hello this is the following snippet that is causing me the error i mention in 
the Subject:


try:
cur.execute( '''SELECT url, hits FROM counters ORDER BY hits 
DESC''' )

data = cur.fetchall()
for row in data:
(url, hits) = row

print( trtdcentera 
href='http://superhost.gr/?show=logpage=%s'font color=tomato size=5 %s 
/a/td ) % (url, url)
print( tdcenterfont color=cyan size=5 %s 
/a/td/tr ) % (hits)
except pymysql.ProgrammingError as e:
print( repr(e) )


you can slso see it at:

http://superhost.gr/?show=stats
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote:

 Hello this is the following snippet that is causing me the error i mention
 in the Subject:

 print( trtdcentera href='http://superhost.gr/?show=logpage=%s'font 
 color=tomato size=5 %s /a/td ) % (url, url)

Hint (Python 3):

 print(a=%s, b=%s) % (1, 2)
a=%s, b=%s
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

 print(a=%s, b=%s % (1, 2))
a=1, b=2


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


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Τη Κυριακή, 26 Μαΐου 2013 11:23:40 π.μ. UTC+3, ο χρήστης Peter Otten έγραψε:
 Νίκος Γκρ33κ wrote:
 
 
 
  Hello this is the following snippet that is causing me the error i mention
 
  in the Subject:
 
 
 
  print( trtdcentera 
  href='http://superhost.gr/?show=logpage=%s'font color=tomato size=5 %s 
  /a/td ) % (url, url)
 
 
 
 Hint (Python 3):
 
 
 
  print(a=%s, b=%s) % (1, 2)
 
 a=%s, b=%s
 
 Traceback (most recent call last):
 
   File stdin, line 1, in module
 
 TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

  print(a=%s, b=%s % (1, 2))
 
 a=1, b=2

Thank you very much Peter, so as it seems in Python 3.3.1 all substitutuons 
must be nested in print().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CrazyHTTPd - HTTP Daemon in Python

2013-05-26 Thread Fábio Santos
On 26 May 2013 05:18, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On 26/05/2013 04:55, cdorm...@gmail.com wrote:

 This is a small little Project that I have started. Its a light little
Web Server (HTTPd) coded in python. Requirements: Python 2.7 = And Linux /
BSD. I believe this could work in a CLI Emulator in windows too.
 Welcome to check out the website powered by CrazyHTTPd:
http://web.crazycoder.me:14081/index.html

 Please Email me with any bugs, errors, and/or comments about my little
project: cdorm...@gmail.com


 IMHO writing a project right now that is limited to Python 2 is about as
much use as a chocolate teapot.

 --
 If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.

 Mark Lawrence

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

Agreed. And you should work on WSGI support too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote:

 Thank you very much Peter, so as it seems in Python 3.3.1 all
 substitutuons must be nested in print().

Yes; in other words: 

In Python 3 print() is a function.


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


Re: CrazyHTTPd - HTTP Daemon in Python

2013-05-26 Thread Marc Christiansen
Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 26/05/2013 04:55, cdorm...@gmail.com wrote:
 This is a small little Project that I have started. Its a light
 little Web Server (HTTPd) coded in python. Requirements: Python 2.7
 = And Linux / BSD. I believe this could work in a CLI Emulator in
 windows too.
 Welcome to check out the website powered by CrazyHTTPd:
 http://web.crazycoder.me:14081/index.html

 Please Email me with any bugs, errors, and/or comments about my
 little project: cdorm...@gmail.com

 
 IMHO writing a project right now that is limited to Python 2 is about as 
 much use as a chocolate teapot.

I.e. not very useful, but slightly more so than you would expect:
http://www.thenakedscientists.com/HTML/content/kitchenscience/exp/how-useless-is-a-chocolate-teapot/

Adiaŭ
Marc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Perhaps cna you help a bit with tha too:
used to work in 2.6 but not with 3.3.1

#!/usr/bin/python3
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, os, sys
from http import cookies


# initialize cookie
cookie = cookies.SimpleCookie( os.environ.get('HTTP_COOKIE') )
cookie.load( cookie )
nikos = cookie.get('nikos')


# if visitor cookie does exist
if nikos:
msg = ΑΠΟ ΤΗΝ ΕΠΟΜΕΝΗ ΕΠΙΣΚΕΨΗ ΣΟΥ ΘΑ ΣΕ ΥΠΟΛΟΓΙΖΩ ΩΣ ΕΠΙΣΚΕΠΤΗ 
ΑΥΞΑΝΟΝΤΑΣ ΤΟΝ ΜΕΤΡΗΤΗ!
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = -1 #this cookie will expire now
else:
msg = ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΝ ΣΕ ΕΙΔΑ, ΔΕΝ ΣΕ ΞΕΡΩ, ΔΕΝ ΣΕ ΑΚΟΥΣΑ! ΘΑ 
ΕΙΣΑΙ ΠΛΕΟΝ Ο ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!
cookie['nikos'] = 'admin'
cookie['nikos']['path'] = '/'
cookie['nikos']['expires'] = 60*60*24*30*12 #this cookie 
will expire in a year


print ( Content-type: text/html; charset=utf-8\n )
print( cookie, msg )
sys.exit(0)

ima getting internal server error.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Piping processes works with 'shell = True' but not otherwise.

2013-05-26 Thread Luca Cerone
 
 Can you please help me understanding what's the difference between the two 
 cases? 
 

Hi guys has some of you ideas on what is causing my issue?
-- 
http://mail.python.org/mailman/listinfo/python-list


Short-circuit Logic

2013-05-26 Thread Ahmed Abdulshafy
Hi,
I'm having a hard time wrapping my head around short-circuit logic that's used 
by Python, coming from a C/C++ background; so I don't understand why the 
following condition is written this way!

 if not allow_zero and abs(x)  sys.float_info.epsilon:
print(zero is not allowed)

The purpose of this snippet is to print the given line when allow_zero is False 
and x is 0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Error when trying to sort and presnt a dictionary in python 3.3.1

2013-05-26 Thread Νίκος Γκρ33κ
python3 pelatologio.py gives  me error in this line:

Traceback (most recent call last):
  File pelatologio.py, line 283, in lt;modulegt;
''' % (months[key], key) )
KeyError: 1

The code is:

#populating months into a dropdown menu
years = ( 2010, 2011, 2012, 2013 )
months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 
'Μάϊος':5, 'Ιούνιος':6, \
   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 
'Νοέμβριος':11, 'Δεκέμβριος':12 }

print('''
form method=post action=
select name=month
''')

for key in sorted( months.values() ):
print('''
option value=%s %s /option
''' % (months[key], key) )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short-circuit Logic

2013-05-26 Thread Roy Smith
In article 5f101d70-e51f-4531-9153-c92ee2486...@googlegroups.com,
 Ahmed Abdulshafy abdulsh...@gmail.com wrote:

 Hi,
 I'm having a hard time wrapping my head around short-circuit logic that's 
 used by Python, coming from a C/C++ background; so I don't understand why the 
 following condition is written this way!
 
  if not allow_zero and abs(x)  sys.float_info.epsilon:
 print(zero is not allowed)
 
 The purpose of this snippet is to print the given line when allow_zero is 
 False and x is 0.

I don't understand your confusion.  Short-circuit evaluation works in 
Python exactly the same way it works in C.  When you have a boolean 
operation, the operands are evaluated left-to-right, and evaluation 
stops as soon as the truth value of the expression is known.

In C, you would write:

   if (p  p-foo) {
blah();
}

to make sure that you don't dereference a null pointer.  A similar 
example in Python might be:

if d and d[foo]:
blah()

which protects against trying to access an element of a dictionary if 
the dictionary is None (which might happen if d was an optional argument 
to a method and wasn't passed on this invocation).

But, none of that applies to your example.  The condition is

not allow_zero and abs(x)  sys.float_info.epsilon:

it's safe to evaluate abs(x)  sys.float_info.epsilon no matter what 
the value of not allow_zero.  For the purposes of understanding your 
code, you can pretend that short-circuit evaluation doesn't exist!

So, what is your code doing that you don't understand?
-- 
http://mail.python.org/mailman/listinfo/python-list


Solving the problem of mutual recursion

2013-05-26 Thread Peter Brooks
I'm not sure if this'll interest anybody, but I expect that I'm going
to get some mutual recursion in my simulation, so I needed to see how
python handled it. Unfortunately, it falls over once it detects a
certain level of recursion. This is reasonable as, otherwise, the
stack eventually over-fills.

Mostly the recommendation, when this happens, is to re-write the code
as loops. Of course, that's not as satisfactory as using recursion.

The problem really is that the methods or functions called recursively
never exit because they're waiting for the return of the function
they've called. Now, if your recursion relies upon knowing what's
returned, then this solution won't help you. Often, though, you're not
interested in what's returned and would just like the routine to exit
once it's called itself, or another process, recursively.

If that's the case, this solution, using threads, allows you to have
functions call themselves, or each other, indefinitely. It works OK on
a macbook pro and the thread count varies from 2-3, so it handles the
thread queuing well. I'm not sure how well this will work on other
architecture - it'd be interesting to know if anybody tries it.

#!/usr/bin/python
# Two functions, Jim and Fred, call each other recursively and
indefinitely, while the main program continues to execute as well
import threading, time

def jim(arg,count):
print Running jim:, arg,count, Thread Count
,threading.active_count()
thread = threading.Thread(target=fred, args=( From Jim ,count
+1))
thread.start()
print count, Jim complete. Thread
Count,threading.active_count()

def fred(arg,counter):
print Running fred:, arg,counter
thread = threading.Thread(target=jim, args=( From Fred
,counter+1))
thread.start()
print counter,Fred complete,threading.currentThread()


thread = threading.Thread(target=jim, args=( From Main,0))
thread.start()
print Jim run from main
count = 0
while True:
count += 1
print 'In main program',count
-- 
http://mail.python.org/mailman/listinfo/python-list


Output from to_bytes

2013-05-26 Thread Mok-Kong Shen

I don't understand why with the code:

   for k in range(8,12,1):
 print(k.to_bytes(2,byteorder='big'))

one gets the following output:

   b'\x00\x08'
   b'\x00\t'
   b'\x00\n'
   b'\x00\x0b'

I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'.
Anyway, how could I get the output in the forms I want?

Thanks in advance.

M. K. Shen


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


Re: Short-circuit Logic

2013-05-26 Thread Steven D'Aprano
On Sun, 26 May 2013 04:11:56 -0700, Ahmed Abdulshafy wrote:

 Hi,
 I'm having a hard time wrapping my head around short-circuit logic
 that's used by Python, coming from a C/C++ background; so I don't
 understand why the following condition is written this way!
 
  if not allow_zero and abs(x)  sys.float_info.epsilon:
 print(zero is not allowed)

Follow the logic.

If allow_zero is a true value, then not allow_zero is False, and the 
and clause cannot evaluate to true. (False and X is always False.) So 
print is not called.

If allow_zero is a false value, then not allow_zero is True, and the 
and clause depends on the second argument. (True and X is always X.) So
abs(x)  sys.float_info.epsilon is tested, and if that is True, print is 
called.

By the way, I don't think much of this logic. Values smaller than epsilon 
are not necessarily zero:

py import sys
py epsilon = sys.float_info.epsilon
py x = epsilon/1
py x == 0
False
py x * 3 == 0
False
py x + epsilon == 0
False
py x + epsilon == epsilon
False

The above logic throws away many perfectly good numbers and treats them 
as zero even though they aren't.


 The purpose of this snippet is to print the given line when allow_zero
 is False and x is 0.

Then the snippet utterly fails at that, since it prints the line for many 
values of x which can be distinguished from zero. The way to test whether 
x equals zero is:

x == 0

What the above actually tests for is whether x is so small that (1.0+x) 
cannot be distinguished from 1.0, which is not the same thing. It is also 
quite arbitrary. Why 1.0? Why not (0.0001+x)? Or (0.0001+x)? Or 
(1.0+x)?



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


Re: Error when trying to sort and presnt a dictionary in python 3.3.1

2013-05-26 Thread Peter Otten
Νίκος Γκρ33κ wrote:

 python3 pelatologio.py gives  me error in this line:
 
 Traceback (most recent call last):
   File pelatologio.py, line 283, in lt;modulegt;
 ''' % (months[key], key) )
 KeyError: 1
 
 The code is:
 
 #populating months into a dropdown menu
 years = ( 2010, 2011, 2012, 2013 )
 months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4,
 'Μάϊος':5, 'Ιούνιος':6, \ 'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9,
 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }

You have keys and values mixed up...
 
 print('''
 form method=post action=
 select name=month
 ''')
 
 for key in sorted( months.values() ):

and calling the value key doesn't help there.

 print('''
 option value=%s %s /option
 ''' % (months[key], key) )

At some point you have to admit that coding isn't your cup of tea.
Or Ouzo ;(

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


Re: Error when trying to sort and presnt a dictionary in python 3.3.1

2013-05-26 Thread Νίκος Γκρ33κ
Τη Κυριακή, 26 Μαΐου 2013 3:20:19 μ.μ. UTC+3, ο χρήστης Peter Otten έγραψε:

 At some point you have to admit that coding isn't your cup of tea.
 Or Ouzo ;(

And i didn't evne drank anyhting, iam sober! Imagine what i would have written 
if i had some shots of Ouzo :-)

I chnage my code to:

months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 
'Μάϊος':5, 'Ιούνιος':6, \
   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 
'Νοέμβριος':11, 'Δεκέμβριος':12 }

print('''
form method=post action=
select name=month
''')

for key in sorted( months.keys() ):
print('''
option value=%s %s /option
''' % (months[key], key) )

print('''
/select '''


Now, iam not getting any eroor from cmd when i 'python3 pelatologio.py' 
verythign interprets normally wiyohut an error.

BUT i kepp getting an internal server error when i try to run the script via a 
browser (Chrome).

python3 path is ok
uploaded as ascii
chmoded to 755 ok.

How in cmd i get no error while on browser i get internal server error?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Anyone seeign somethign wrong?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Chris Angelico
On Sun, May 26, 2013 at 11:00 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 Anyone seeign somethign wrong?

Yes. You're posting requests, then bumping the thread two hours later
as though you're entitled to a response quicker than that. Plus, the
problems you're seeing ought to be solved by the 2to3 utility. Use it.
Look at its output.

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


Re: Output from to_bytes

2013-05-26 Thread Chris Angelico
On Sun, May 26, 2013 at 10:02 PM, Mok-Kong Shen
mok-kong.s...@t-online.de wrote:
 I don't understand why with the code:

for k in range(8,12,1):
  print(k.to_bytes(2,byteorder='big'))

 one gets the following output:

b'\x00\x08'
b'\x00\t'
b'\x00\n'
b'\x00\x0b'

 I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'.
 Anyway, how could I get the output in the forms I want?

They are. If you compare them, you'll find they're identical:

 b'\x00\t' == b'\x00\x09'
True
 b'\x00\n' == b'\x00\x0a'
True

It's just a representation issue. The repr() of a bytes tries to go
for the shorter representation \n rather than the more verbose \x0a.
(Though I'm not sure why it doesn't also shorten \x00 to \0 - maybe
the \0 notation isn't deemed Pythonic, even though it does work just
fine.) So what you want is a more fixed representation.

What you may find useful here is that iterating over the bytes object
produces integers:

 list(b'\0\t')
[0, 9]

So you might be able to do something like this:

 print(''.join(('\\x%02x'%x for x in b'\0\t')))
\x00\x09

Or, in your whole loop:

 for k in range(8,12,1):
print(''.join(('\\x%02x'%x for x in k.to_bytes(2,byteorder='big'

\x00\x08
\x00\x09
\x00\x0a
\x00\x0b

Does that help?

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


RE: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Carlos Nepomuceno

 Date: Sun, 26 May 2013 06:00:51 -0700
 Subject: Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 
 'tuple'
 From: nikos.gr...@gmail.com
 To: python-list@python.org

 Anyone seeign somethign wrong?
 --
 http://mail.python.org/mailman/listinfo/python-list

I don't know any module 'http' in Python standard library.

Think you mean the 'http.cookies' module in Python 3.   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread nagia . retsina
Τη Κυριακή, 26 Μαΐου 2013 4:10:02 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
 On Sun, May 26, 2013 at 11:00 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 
  Anyone seeign somethign wrong?
 
 
 
 Yes. You're posting requests, then bumping the thread two hours later
 
 as though you're entitled to a response quicker than that. Plus, the
 
 problems you're seeing ought to be solved by the 2to3 utility. Use it.
 
 Look at its output.
 
 
 
 ChrisA

There is a tool that convert python 2.6.x code = python 3.x ?

Can you post a link to that toll plz?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ldap module and base64 oncoding

2013-05-26 Thread Michael Ströder
Joseph L. Casale wrote:
 I have some data I am working with that is not being interpreted as a string 
 requiring
 base64 encoding when sent to the ldif module for output.
 
 The base64 string parsed is ZGV0XDMzMTB3YmJccGc= and the raw string is 
 det\3310wbb\pg.
 I'll admit my understanding of the handling requirements of non ascii data in 
 2.7 is weak
 and as such I am failing at adjusting the regex that deduces is the string 
 contains characters
 requiring base64 encoding when being output.

I'm not sure what exactly you're asking for.
Especially is not being interpreted as a string requiring base64 encoding is
written without giving the right context.

So I'm just guessing that this might be the usual misunderstandings with use
of base64 in LDIF. Read more about when LDIF requires base64-encoding here:

http://tools.ietf.org/html/rfc2849

To me everything looks right:

Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type help, copyright, credits or license for more information.
 'ZGV0XDMzMTB3YmJccGc='.decode('base64').decode('utf-8')
u'det\\3310wbb\\pg'


What do you think is a problem?

Ciao, Michael.

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


Re: Solving the problem of mutual recursion

2013-05-26 Thread Jussi Piitulainen
Peter Brooks writes:

 I'm not sure if this'll interest anybody, but I expect that I'm
 going to get some mutual recursion in my simulation, so I needed to
...
 returned, then this solution won't help you. Often, though, you're
 not interested in what's returned and would just like the routine to
 exit once it's called itself, or another process, recursively.
 
 If that's the case, this solution, using threads, allows you to have
 functions call themselves, or each other, indefinitely. It works OK
 on a macbook pro and the thread count varies from 2-3, so it handles

... hard to resist ... but somehow I manage ... whew ...

A light-weighter way is to have each task end by assigning the next
task and returning, instead of calling the next task directly. When a
task returns, a driver loop will call the assigned task, which again
does a bounded amount of work, assigns the next task, and returns.
Tasks can even pass parameters in the same way.

Like so, Dr. Fred keeps adding to a pile as long as there is a pile,
and Mr. Jim keeps taking from it as long as it's there to take from:

from random import choice

def fred():
global fun, arg
print('Fred adds 1')
fun, arg = choice((fred, jim)), arg + 1

def jim():
global fun, arg
print('Jim takes 1')
fun, arg = choice((fred, jim)), arg - 1

if __name__ == '__main__':
fun, arg = choice((fred, jim)), 3
while arg:
print('Pile is', arg, end = '\t')
fun()
else:
print('Pile is gone')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ldap module and base64 oncoding

2013-05-26 Thread Michael Ströder
Joseph L. Casale wrote:
 Can you give an example of the code you have?
 
 I actually just overrode the regex used by the method in the LDIFWriter class 
 to be far more broad
 about what it interprets as a safe string.

Are you sure that you fully understood RFC 2849 before doing this?
Which version of python-ldap are you using?

 I really need to properly handle reading, manipulating and
 writing non ascii data to solve this...

Module ldif in python-ldap does that for you based on RFC 2849.
Without seeing your code using it I cannot tell what's wrong.

 Shame there is no ldap module (with the ldifwriter) in Python 3.

1. The module ldif is stand-alone. So you could easily make it available for
Python 3.

2. Shame is the wrong term here. Personally I currently have no requirement
to use Python 3 and I'm quite busy with other things. So contributors are
welcome. But they should be willing to do some serious work giving continous
support - not only a half-baken patch.

Ciao, Michael.

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


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 1:00 AM,  nagia.rets...@gmail.com wrote:
 Τη Κυριακή, 26 Μαΐου 2013 4:10:02 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
 On Sun, May 26, 2013 at 11:00 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:

  Anyone seeign somethign wrong?



 Yes. You're posting requests, then bumping the thread two hours later

 as though you're entitled to a response quicker than that. Plus, the

 problems you're seeing ought to be solved by the 2to3 utility. Use it.

 Look at its output.



 ChrisA

 There is a tool that convert python 2.6.x code = python 3.x ?

 Can you post a link to that toll plz?

You have its name. You have Google. You have a mailing list that is
getting tired of you not putting in any effort.

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


Re: Solving the problem of mutual recursion

2013-05-26 Thread Roy Smith
In article qota9nhu6ag@ruuvi.it.helsinki.fi,
 Jussi Piitulainen jpiit...@ling.helsinki.fi wrote:

 A light-weighter way is to have each task end by assigning the next
 task and returning, instead of calling the next task directly. When a
 task returns, a driver loop will call the assigned task, which again
 does a bounded amount of work, assigns the next task, and returns.
 Tasks can even pass parameters in the same way.

Yup.  I've used this pattern for building state machines.  Each state is 
a function which returns the next state (or, sometimes, a (next_state, 
output) tuple).  The top level loop ends up looking very much like yours:

state = start
while state != end:
   state, output = state(get_next_input())
   print output


 
 Like so, Dr. Fred keeps adding to a pile as long as there is a pile,
 and Mr. Jim keeps taking from it as long as it's there to take from:
 
 from random import choice
 
 def fred():
 global fun, arg
 print('Fred adds 1')
 fun, arg = choice((fred, jim)), arg + 1
 
 def jim():
 global fun, arg
 print('Jim takes 1')
 fun, arg = choice((fred, jim)), arg - 1
 
 if __name__ == '__main__':
 fun, arg = choice((fred, jim)), 3
 while arg:
 print('Pile is', arg, end = '\t')
 fun()
 else:
 print('Pile is gone')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Τη Κυριακή, 26 Μαΐου 2013 6:24:55 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:
 On Mon, May 27, 2013 at 1:00 AM,  nagia.rets...@gmail.com wrote:
 
  Τη Κυριακή, 26 Μαΐου 2013 4:10:02 μ.μ. UTC+3, ο χρήστης Chris Angelico 
  έγραψε:
 
  On Sun, May 26, 2013 at 11:00 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com 
  wrote:
 
 
 
   Anyone seeign somethign wrong?
 
 
 
 
 
 
 
  Yes. You're posting requests, then bumping the thread two hours later
 
 
 
  as though you're entitled to a response quicker than that. Plus, the
 
 
 
  problems you're seeing ought to be solved by the 2to3 utility. Use it.
 
 
 
  Look at its output.
 
 
 
 
 
 
 
  ChrisA
 
 
 
  There is a tool that convert python 2.6.x code = python 3.x ?
 
 
 
  Can you post a link to that toll plz?
 
 
 
 You have its name. You have Google. You have a mailing list that is
 
 getting tired of you not putting in any effort.
 
 
 
 ChrisA

Yes i saw it its name is 2to3 conversion but my code is already written in 
python3

i ahve written in line byu line from sctatrch ,much like pelatologio.py
which when i intreprtet in via cmd i get no errors.

i dont understand why iam receiving  an internal server error for both in 
browser mdoe though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error when trying to sort and presnt a dictionary in python 3.3.1

2013-05-26 Thread Νίκος Γκρ33κ
Τη Κυριακή, 26 Μαΐου 2013 3:58:12 μ.μ. UTC+3, ο χρήστης Νίκος Γκρ33κ έγραψε:
 Τη Κυριακή, 26 Μαΐου 2013 3:20:19 μ.μ. UTC+3, ο χρήστης Peter Otten έγραψε:
 
 
 
  At some point you have to admit that coding isn't your cup of tea.
 
  Or Ouzo ;(
 
 
 
 And i didn't evne drank anyhting, iam sober! Imagine what i would have 
 written if i had some shots of Ouzo :-)
 
 
 
 I chnage my code to:
 
 
 
 months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 
 'Μάϊος':5, 'Ιούνιος':6, \
 
  'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 
 'Νοέμβριος':11, 'Δεκέμβριος':12 }
 
 
 
 print('''
 
 form method=post action=
 
   select name=month
 
 ''')
 
   
 
 for key in sorted( months.keys() ):
 
   print('''
 
   option value=%s %s /option
 
   ''' % (months[key], key) )
 
   
 
 print('''
 
   /select '''
 
 
 
 
 
 Now, iam not getting any eroor from cmd when i 'python3 pelatologio.py' 
 verythign interprets normally wiyohut an error.
 
 
 
 BUT i kepp getting an internal server error when i try to run the script via 
 a browser (Chrome).
 
 
 
 python3 path is ok
 
 uploaded as ascii
 
 chmoded to 755 ok.
 
 
 
 How in cmd i get no error while on browser i get internal server error?

Its okey i made it work, it wasnt an actuap python issue but an .htaccess and 
.htpasswd problem.

All fine now!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Νίκος Γκρ33κ
Here is the live error log coming form apacher when i request the webpage form 
browser:

== /usr/local/apache/logs/error_log ==
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] suexec failure: could 
not open log file
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script 
headers: koukos.py
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script 
headers: koukos.py

what is that suexec?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with implementing callback functions using ctypes

2013-05-26 Thread Shriramana Sharma
On Friday, May 24, 2013 8:56:28 AM UTC+5:30, Dan Stromberg wrote:
 Cython is good. So is the new cffi, which might be thought of as a 
 safer (API-level) version of ctypes (which is ABI-level).

Hi -- can you clarify what is this new CFFI and where I can get it? In the 
Python 3 library reference I seem to see only CTypes.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Ldap module and base64 oncoding

2013-05-26 Thread Joseph L. Casale
 I'm not sure what exactly you're asking for.
 Especially is not being interpreted as a string requiring base64 encoding is
 written without giving the right context.
 
 So I'm just guessing that this might be the usual misunderstandings with use
 of base64 in LDIF. Read more about when LDIF requires base64-encoding here:
 
 http://tools.ietf.org/html/rfc2849
 
 To me everything looks right:
 
 Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
 Type help, copyright, credits or license for more information.
  'ZGV0XDMzMTB3YmJccGc='.decode('base64').decode('utf-8')
 u'det\\3310wbb\\pg'
 
 
 What do you think is a problem?

Michael,
Thanks for the reply. The issues I am sure are in my code, I read the ldif 
source file and up
with a values such as 'det\3310wbb\pg' after the base64 encoded entries are 
decoded.

The problem I am having is when I add this to an add/mod entry list and write 
it back out.
As it does not get re-encoded to base64 the ldif file ends up seeing a text 
entry with a ^]
character which if I re-read it with the parser it causes the handle method to 
break midway
through the entry dict and so the last half re-appears disjoint without a dn.

Like I said, I am pretty sure its my poor misunderstanding of decoding and 
encoding.
I am using the build from http://www.lfd.uci.edu/~gohlke/pythonlibs/ on a 
windows
2008 r2 server.

I have re-implemented handle to create a cidict holding all the dn/entry's that 
are parsed as
I then perform some processing such as manipulating attribute values in the 
entry dict. I
am pretty sure I am breaking things here. The data I am reading is coming from 
utf-16-le
encoded files and has Unicode characters as the source directory is globally 
available, being
written to in just about every country.

Is there a process for manipulating/adding data to the entry dict before I 
write it out that I
should adhere to? For example, if I am adding a new attribute to be composed of 
part of
another parsed attr for use in a modlist:

  {'customAttr': ['foo.{}.bar'.format(entry['uid'])]}

By looking at the value from above, 'det\3310wbb\pg', I gather the entry dict 
was parsed
into byte strings. I should have decoded this, where as some of the data is 
Unicode and
as such I should have encoded it?

I really appreciate the time.

Grazie per tutto,
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Νίκος Γκρ33κ
This is the code that although correct becaus it works with englisg(standARD 
ASCII letters) it wont with Greek:

if( log ):
name = log
# print specific client header info
cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', 
(name,) )
data = cur.fetchone()
===

The following is the live output of: tail -F /usr/local/apache/logs/error_log 


[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Error in 
sys.excepthook:, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 
'ascii' codec can't encode characters in position 2050-2056: ordinal not in 
range(128), referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] , referer: 
http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Original exception 
was:, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Traceback (most recent 
call last):, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11]   File 
pelatologio.py, line 122, in module, referer: 
http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] 
cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', (name,) ), 
referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11]   File 
/opt/python3/lib/python3.3/site-packages/pymysql/cursors.py, line 108, in 
execute, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] query = 
query.encode(charset), referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 
'latin-1' codec can't encode characters in position 46-52: ordinal not in 
range(256), referer: http://superhost.gr/cgi-bin/pelatologio.py


I can udnerstand that this is an encoding issue but i dont knwo how to fix this.
please help.

The search works only for english letters as expected but my cleints have Greek 
name and surnames.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Mark Lawrence

On 26/05/2013 16:24, Chris Angelico wrote:

On Mon, May 27, 2013 at 1:00 AM,  nagia.rets...@gmail.com wrote:

Τη Κυριακή, 26 Μαΐου 2013 4:10:02 μ.μ. UTC+3, ο χρήστης Chris Angelico έγραψε:

On Sun, May 26, 2013 at 11:00 PM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:


Anyone seeign somethign wrong?




Yes. You're posting requests, then bumping the thread two hours later

as though you're entitled to a response quicker than that. Plus, the

problems you're seeing ought to be solved by the 2to3 utility. Use it.

Look at its output.



ChrisA


There is a tool that convert python 2.6.x code = python 3.x ?

Can you post a link to that toll plz?


You have its name. You have Google. You have a mailing list that is
getting tired of you not putting in any effort.

ChrisA



Not to mention double spaced google crap :(

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Mark Lawrence

On 26/05/2013 17:10, Νίκος Γκρ33κ wrote:

Here is the live error log coming form apacher when i request the webpage form 
browser:

== /usr/local/apache/logs/error_log ==
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] suexec failure: could 
not open log file
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission denied
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script 
headers: koukos.py
[Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of script 
headers: koukos.py

what is that suexec?



What has this got to do with Python?

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Solving the problem of mutual recursion

2013-05-26 Thread Peter Brooks
On May 26, 5:09 pm, Jussi Piitulainen jpiit...@ling.helsinki.fi
wrote:

 A light-weighter way is to have each task end by assigning the next
 task and returning, instead of calling the next task directly. When a
 task returns, a driver loop will call the assigned task, which again
 does a bounded amount of work, assigns the next task, and returns.
 Tasks can even pass parameters in the same way.

Yes, that's true - there are a number of ways of making it linear.

What I'm particularly pleased about with my method is the parallelism
that it achieves - with so little effort! The simulation is going to
be computationally intense and this is going to make sure that the
CPUs are all giving it their best shot. When I run this on my macbook,
the python interpreter takes over 140% of CPU - with a bit of fine-
tuning, it should be possible to have more concurrent threads and to
use the four cores optimally.

Naturally I'll need to be careful with the concurrency, but this is so
simple and clean that it should be easy to avoid the main problems
with accessing the same variables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Wolfgang Keller
  Both the concept and actually implemented examples of so-called web
  applications prove that they are just plain garbage and hopelessly
  unusable for anything remotely resembling actual screenwork.
 
  HTML forms may be at best useful for web shops, but for actual
  screenwork, HTML is not a valid GUI, no matter how much javascript
  you add to it.
 
 All depends on your requirements.

Obivously, if your requirements are to be compliant with latest IT
management fads and to not give a darn for end-user productivity or
even legal requirements for screen workplace ergonomics...

 For the Yosemite Project, I wanted the networking aspect, so the web
 browser UI was a good one.

From the description this looks like a simble database CRUD
application. Somethign like that is definitely easier to implement and
to deploy and a *lot* more functional with any of the RAD frameworks
available for Python.

And just like HTML never was a valid GUI framework and never will be
one, HTTP will never be a suitable transport layer for a RPC protocol.

Sincerely,

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


Cutting a deck of cards

2013-05-26 Thread RVic
Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie

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


Re: Cutting a deck of cards

2013-05-26 Thread MRAB

On 26/05/2013 18:52, RVic wrote:

Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie


The list from its start up to, but excluding, index 'i' is cards[ : i],
and the list from index 'i' to its end is cards[i : ].

Now concatenate them those slices.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Kamlesh Mutha
I guess, you will have to use list slicing mechanism to achieve the desired
result.

Hope this helps,

Cheers,
Kamlesh





On Sun, May 26, 2013 at 11:22 PM, RVic rvinc...@gmail.com wrote:

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at some
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of
 that to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it must be
 a simple line or two in Python, but I am really stuck here). Anyone have
 any direction they can give me on this? Thanks, RVic, python newbie

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




-- 
Faith waiting in the heart of a seed promises a miracle of life which it
can not prove!
-Ravindranath Tagore
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Solving the problem of mutual recursion

2013-05-26 Thread Carlos Nepomuceno

 Date: Sun, 26 May 2013 10:21:05 -0700
 Subject: Re: Solving the problem of mutual recursion
 From: peter.h.m.bro...@gmail.com
 To: python-list@python.org

 On May 26, 5:09 pm, Jussi Piitulainen jpiit...@ling.helsinki.fi
 wrote:

 A light-weighter way is to have each task end by assigning the next
 task and returning, instead of calling the next task directly. When a
 task returns, a driver loop will call the assigned task, which again
 does a bounded amount of work, assigns the next task, and returns.
 Tasks can even pass parameters in the same way.

 Yes, that's true - there are a number of ways of making it linear.

 What I'm particularly pleased about with my method is the parallelism
 that it achieves - with so little effort! The simulation is going to
 be computationally intense and this is going to make sure that the
 CPUs are all giving it their best shot. When I run this on my macbook,
 the python interpreter takes over 140% of CPU - with a bit of fine-
 tuning, it should be possible to have more concurrent threads and to
 use the four cores optimally.

 Naturally I'll need to be careful with the concurrency, but this is so
 simple and clean that it should be easy to avoid the main problems
 with accessing the same variables.
 --
 http://mail.python.org/mailman/listinfo/python-list

Python threads run in the same process and won't run concurrently:

CPython implementation detail: In CPython, due to the Global Interpreter Lock, 
only one thread can execute Python code at once (even though certain 
performance-oriented libraries might overcome this limitation). If you want 
your application to make better use of the computational resources of 
multi-core machines, you are advised to use multiprocessing. However, threading 
is still an appropriate model if you want to run multiple I/O-bound tasks 
simultaneously.[1]

How can you get 140% of CPU? IS that a typo??

[1] http://docs.python.org/2/library/threading.html 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Solving the problem of mutual recursion

2013-05-26 Thread Peter Brooks
On 26 May, 20:09, Carlos Nepomuceno carlosnepomuc...@outlook.com
wrote:
 









  Date: Sun, 26 May 2013 10:21:05 -0700
  Subject: Re: Solving the problem of mutual recursion
  From: peter.h.m.bro...@gmail.com
  To: python-l...@python.org

  On May 26, 5:09 pm, Jussi Piitulainen jpiit...@ling.helsinki.fi
  wrote:

  A light-weighter way is to have each task end by assigning the next
  task and returning, instead of calling the next task directly. When a
  task returns, a driver loop will call the assigned task, which again
  does a bounded amount of work, assigns the next task, and returns.
  Tasks can even pass parameters in the same way.

  Yes, that's true - there are a number of ways of making it linear.

  What I'm particularly pleased about with my method is the parallelism
  that it achieves - with so little effort! The simulation is going to
  be computationally intense and this is going to make sure that the
  CPUs are all giving it their best shot. When I run this on my macbook,
  the python interpreter takes over 140% of CPU - with a bit of fine-
  tuning, it should be possible to have more concurrent threads and to
  use the four cores optimally.

  Naturally I'll need to be careful with the concurrency, but this is so
  simple and clean that it should be easy to avoid the main problems
  with accessing the same variables.
  --
 http://mail.python.org/mailman/listinfo/python-list

 Python threads run in the same process and won't run concurrently:

 CPython implementation detail: In CPython, due to the Global Interpreter 
 Lock, only one thread can execute Python code at once (even though certain 
 performance-oriented libraries might overcome this limitation). If you want 
 your application to make better use of the computational resources of 
 multi-core machines, you are advised to use multiprocessing. However, 
 threading is still an appropriate model if you want to run multiple I/O-bound 
 tasks simultaneously.[1]

 How can you get 140% of CPU? IS that a typo??

No, on a multi-core machine it's normal. The machine shows python
running multiple threads - and the number of threads change as the
program runs. Perhaps the OS/X implementation of python does allow
concurrency when others don't. It certainly looks like it!


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


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 Date: Sun, 26 May 2013 10:52:14 -0700
 Subject: Cutting a deck of cards
 From: rvinc...@gmail.com
 To: python-list@python.org

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at some 
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that 
 to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it must be a 
 simple line or two in Python, but I am really stuck here). Anyone have any 
 direction they can give me on this? Thanks, RVic, python newbie

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


list(range(13 * 4 * decks)) == range(13 * 4 * decks)

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


Re: Future standard GUI library

2013-05-26 Thread Roy Smith
In article 20130526194310.9cdb1be80b42c7fdf0ba5...@gmx.net,
 Wolfgang Keller felip...@gmx.net wrote:

 HTTP will never be a suitable transport layer for a RPC protocol.

What, in particular, is wrong with HTTP for doing RPC?  RPC is pretty 
straight-forward.  Take this method, run it over there, with these 
arguments, and give me back the result.  HTTP handles that just fine, 
with your choice of XML, JSON, or whatever turns you on for the content 
encoding.

There are protocols that are more efficient (mostly binary ones like 
Thrift and Protocol Buffers), but for a lot of things, the simplicity 
and convenience of HTTP is worth than the efficiency hit.  It's really 
nice to be able to slap together HTTP components like load balancers and 
caches by just editing a few config files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread RVic
Ah, brilliant -- yes, this is so much more elegant in Python:

#now cut the cards
x = random.randrange(2,range(13 * 4 * decks))
cards = cards[x:]+cards[:x]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Νίκος Γκρ33κ
Any idea how to correct this encoding issue?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Solving the problem of mutual recursion

2013-05-26 Thread Carlos Nepomuceno

 Date: Sun, 26 May 2013 11:13:12 -0700
 Subject: Re: Solving the problem of mutual recursion
 From: peter.h.m.bro...@gmail.com
 To: python-list@python.org
[...]
 How can you get 140% of CPU? IS that a typo??

 No, on a multi-core machine it's normal. The machine shows python
 running multiple threads - and the number of threads change as the
 program runs. Perhaps the OS/X implementation of python does allow
 concurrency when others don't. It certainly looks like it!


I pretty sure it doesn't run on multiple cores on Linux and Windows.

I've tested it and have been trying to find a better way achieve concurrency in 
Python. One of the ways is the multiprocessing module[1].

Do Mac OS shows 140% CPU load when more than a single core is been used? lol 
Apple sucks!!! lol


[1] http://docs.python.org/2/library/multiprocessing.html   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Roy Smith
In article 4d02f46f-8264-41bf-a254-d1c204696...@googlegroups.com,
 RVic rvinc...@gmail.com wrote:

 Suppose I have a deck of cards, and I shuffle them
 
 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)
 
 So now I have an array of cards. I would like to cut these cards at some 
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that 
 to the top half of the cards array.
 
 For some reason, I can't see how this can be done (I know that it must be a 
 simple line or two in Python, but I am really stuck here). Anyone have any 
 direction they can give me on this? Thanks, RVic, python newbie

import random
i = random.randrange(len(cards))
cut1 = cards[:i]
cut2 = cards[i:]

I haven't thought too much about the boundary conditions, but that's the 
general idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Future standard GUI library

2013-05-26 Thread Carlos Nepomuceno

 From: felip...@gmx.net
 Subject: Re: Future standard GUI library
 Date: Sun, 26 May 2013 19:43:10 +0200
 To: python-list@python.org
[...]
 one, HTTP will never be a suitable transport layer for a RPC protocol.

 Sincerely,

 Wolfgang


Please give me an example of a suitable transport layer for a RPC protocol.   
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Help with implementing callback functions using ctypes

2013-05-26 Thread Carlos Nepomuceno
https://cffi.readthedocs.org/en/release-0.6/


 Date: Sun, 26 May 2013 09:12:10 -0700
 Subject: Re: Help with implementing callback functions using ctypes
 From: samj...@gmail.com
 To: python-list@python.org

 On Friday, May 24, 2013 8:56:28 AM UTC+5:30, Dan Stromberg wrote:
 Cython is good. So is the new cffi, which might be thought of as a
 safer (API-level) version of ctypes (which is ABI-level).

 Hi -- can you clarify what is this new CFFI and where I can get it? In the 
 Python 3 library reference I seem to see only CTypes.
 --
 http://mail.python.org/mailman/listinfo/python-list   
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 3:43 AM, Wolfgang Keller felip...@gmx.net wrote:
 For the Yosemite Project, I wanted the networking aspect, so the web
 browser UI was a good one.

 From the description this looks like a simble database CRUD
 application. Somethign like that is definitely easier to implement and
 to deploy and a *lot* more functional with any of the RAD frameworks
 available for Python.

 And just like HTML never was a valid GUI framework and never will be
 one, HTTP will never be a suitable transport layer for a RPC protocol.

No, it's basically a modified version of a file browser; you get a
directory listing, you can browse subdirectories, and selecting a file
causes an action to happen on the server. You also have some action
buttons that provide a measure of control: click a button and
something is done (eg a key is pressed, or a 'killall' command is
fired). The browser works just fine.

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


Re: Solving the problem of mutual recursion

2013-05-26 Thread Peter Brooks
On 26 May, 20:22, Carlos Nepomuceno carlosnepomuc...@outlook.com
wrote:
 

  Date: Sun, 26 May 2013 11:13:12 -0700
  Subject: Re: Solving the problem of mutual recursion
  From: peter.h.m.bro...@gmail.com
  To: python-l...@python.org
 [...]
  How can you get 140% of CPU? IS that a typo??

  No, on a multi-core machine it's normal. The machine shows python
  running multiple threads - and the number of threads change as the
  program runs. Perhaps the OS/X implementation of python does allow
  concurrency when others don't. It certainly looks like it!

 I pretty sure it doesn't run on multiple cores on Linux and Windows.

 I've tested it and have been trying to find a better way achieve concurrency 
 in Python. One of the ways is the multiprocessing module[1].

 Do Mac OS shows 140% CPU load when more than a single core is been used? 
 lol Apple sucks!!! lol

It's not uncommon - HP-UX does exactly the same thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with implementing callback functions using ctypes

2013-05-26 Thread Dan Stromberg
On Sun, May 26, 2013 at 9:12 AM, Shriramana Sharma samj...@gmail.comwrote:

 On Friday, May 24, 2013 8:56:28 AM UTC+5:30, Dan Stromberg wrote:
  Cython is good. So is the new cffi, which might be thought of as a
  safer (API-level) version of ctypes (which is ABI-level).

 Hi -- can you clarify what is this new CFFI and where I can get it? In the
 Python 3 library reference I seem to see only CTypes.


CFFI is like CTypes, but it allows you to do things like see C preprocessor
symbols.

https://cffi.readthedocs.org/en/release-0.6/

I don't think it comes with CPython, at least not yet.  But I believe it
comes with the latest Pypy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Solving the problem of mutual recursion

2013-05-26 Thread Ian Kelly
On Sun, May 26, 2013 at 12:13 PM, Peter Brooks
peter.h.m.bro...@gmail.com wrote:
 No, on a multi-core machine it's normal. The machine shows python
 running multiple threads - and the number of threads change as the
 program runs. Perhaps the OS/X implementation of python does allow
 concurrency when others don't. It certainly looks like it!

I'm pretty sure that CPython uses the GIL regardless of platform.  And
yes you can have multiple OS-level threads, but because of the GIL
only one will actually be running at a time.  Other possibilities
include:

1) You're using a different implementation of Python that does not
have a GIL, e.g. Jython or IronPython (well, probably not the latter).
 I believe PyPy also has a GIL-less version, although I don't think
this is in the current release yet.

2) You're using a fork of CPython that removes the GIL.  There are a
number of these, but none to my knowledge that are able to maintain
the performance of CPython for a single thread.

3) You're mistakenly looking at multiple Python processes that are
running simultaneously and adding their usages together.

4) The utility you're using is reporting the process CPU usage incorrectly.

5) Maybe for some reason the Mac OS X build of CPython is using
spin-locks in the GIL.  I can't imagine why this would be the case.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Michael Torrie
On 05/26/2013 11:43 AM, Wolfgang Keller wrote:
 And just like HTML never was a valid GUI framework and never will be
 one, HTTP will never be a suitable transport layer for a RPC protocol.

On good thing web development has brought us is the knowledge that
modularization and layers are a brilliant idea.  Your back end exposes
services and business logic, and your front end can be in HTMLv5 and
Javascript, or QtQuick, PyGTK, or Visual Studio.  If you do need a
native interface, it's a heck of a lot easier to rewrite just the
frontend then the entire stack.  Who cares how the RPC is done; that's
an implementation detail.  HTTP does happen to work well though.  Why do
you say it is not suitable?

 From the description this looks like a simble database CRUD
 application. Somethign like that is definitely easier to implement and
 to deploy and a *lot* more functional with any of the RAD frameworks
 available for Python.

Chuckle.  Simple CRUD, eh.  Almost all apps involve database CRUD
interactions.  And often in highly complex ways using business logic.

Maybe it would have been faster to develop, but ultimately less useful
and require more development time in the long run.  suppose I now want
the app natively on my phone (because that's all the rage).  It's an
iPhone.  Oh.  Apple doesn't support Python.  Okay, rewrite the works,
including business logic, in Objective C.  Now I want it on my android
phone.  Oops rewrite the stack again in Java.

Since his application by nature is network oriented (client/server I
presume since he mentions multiple users), sticking it on a web server
and having the front end be separate (be it HTML or not) gives him the
flexibility to rapidly build native screenable UIs for his app on any
platform he chooses, something your philosophy does not allow for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno carlosnepomuc...@outlook.com wrote:
 
 Date: Sun, 26 May 2013 10:52:14 -0700
 Subject: Cutting a deck of cards
 From: rvinc...@gmail.com
 To: python-list@python.org

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at
 some random point (between 1 and 13 * 4 * decks - 1, moving the lower
 half of that to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it
 must be a simple line or two in Python, but I am really stuck here).
 Anyone have any direction they can give me on this? Thanks, RVic,
 python newbie

 --
 http://mail.python.org/mailman/listinfo/python-list
 
 
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 
 ;)

Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
False

Adiaŭ
Marc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Roy Smith
In article mailman.2193.1369597318.3114.python-l...@python.org,
 Michael Torrie torr...@gmail.com wrote:

 On good thing web development has brought us is the knowledge that
 modularization and layers are a brilliant idea.

Modularization and layers were a brilliant idea long before the web came 
around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ldap module and base64 oncoding

2013-05-26 Thread Michael Ströder
Joseph L. Casale wrote:
 I'm not sure what exactly you're asking for.
 Especially is not being interpreted as a string requiring base64 encoding 
 is
 written without giving the right context.

 So I'm just guessing that this might be the usual misunderstandings with use
 of base64 in LDIF. Read more about when LDIF requires base64-encoding here:

 http://tools.ietf.org/html/rfc2849

 To me everything looks right:

 Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
 Type help, copyright, credits or license for more information.
 'ZGV0XDMzMTB3YmJccGc='.decode('base64').decode('utf-8')
 u'det\\3310wbb\\pg'


 What do you think is a problem?
 
 Thanks for the reply. The issues I am sure are in my code, I read the ldif 
 source file and up
 with a values such as 'det\3310wbb\pg' after the base64 encoded entries are 
 decoded.
 
 The problem I am having is when I add this to an add/mod entry list and write 
 it back out.
 As it does not get re-encoded to base64 the ldif file ends up seeing a text 
 entry with a ^]
 character which if I re-read it with the parser it causes the handle method 
 to break midway
 through the entry dict and so the last half re-appears disjoint without a dn.
 
 Like I said, I am pretty sure its my poor misunderstanding of decoding and 
 encoding.
 I am using the build from http://www.lfd.uci.edu/~gohlke/pythonlibs/ on a 
 windows
 2008 r2 server.
 
 I have re-implemented handle to create a cidict holding all the dn/entry's 
 that are parsed as
 I then perform some processing such as manipulating attribute values in the 
 entry dict. I
 am pretty sure I am breaking things here. The data I am reading is coming 
 from utf-16-le
 encoded files and has Unicode characters as the source directory is globally 
 available, being
 written to in just about every country.

Processing LDIF is one thing, doing LDAP operations another.

LDIF itself is meant to be ASCII-clean. But each attribute value can carry any
byte sequence (e.g. attribute 'jpegPhoto'). There's no further processing by
module LDIF - it simply returns byte sequences.

The access protocol LDAPv3 mandates UTF-8 encoding for Unicode strings on the
wire if attribute syntax is DirectoryString, IA5String (mainly ASCII) or 
similar.

So if you're LDIF input returns UTF-16 encoded attribute values for e.g.
attribute 'cn' or 'o' or another attribute not being of OctetString or Binary
syntax something's wrong with the producer of the LDIF data.

 Is there a process for manipulating/adding data to the entry dict before I 
 write it out that I
 should adhere to? For example, if I am adding a new attribute to be composed 
 of part of
 another parsed attr for use in a modlist:
 
   {'customAttr': ['foo.{}.bar'.format(entry['uid'])]}
 
 By looking at the value from above, 'det\3310wbb\pg', I gather the entry dict 
 was parsed
 into byte strings. I should have decoded this, where as some of the data is 
 Unicode and
 as such I should have encoded it?

I wonder what the string really is. At least the base64-encoding you provided
before decodes as UTF-8 but I'm not sure whether it's the right sequence of
Unicode code points you're expecting.

 'ZGV0XDMzMTB3YmJccGc='.decode('base64').decode('utf-8')
u'det\\3310wbb\\pg'

I still can't figure out what you're really doing though. I'd recommend to
strip down your operations to a very simple test code snippet illustrating the
issue and post that here.

Ciao, Michael.

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


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 From: usenetm...@solar-empire.de
[...]
 Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 False

 Adiaŭ
 Marc


What does list(range(13 * 4 * decks)) returns in Python 3?
  
-- 
http://mail.python.org/mailman/listinfo/python-list


I want to know how to implement concurrent threads in Python

2013-05-26 Thread Daniel Gagliardi
I want to know how to implement concurrent threads in Python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short-circuit Logic

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote:


  if not allow_zero and abs(x)  sys.float_info.epsilon:
 print(zero is not allowed)


The reason for the order is to do the easy calculation first and the 
harder one only if the first passes.




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


Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno carlosnepomuc...@outlook.com wrote:
 
 From: usenetm...@solar-empire.de
 [...]
 Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 False
 
 What does list(range(13 * 4 * decks)) returns in Python 3?  
 

A list of course. But Py3 range is very similar to Py2 xrange, it
returns a range object.

Adiaŭ
Marc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short-circuit Logic

2013-05-26 Thread Roy Smith
In article mailman.2196.1369599562.3114.python-l...@python.org,
 Terry Jan Reedy tjre...@udel.edu wrote:

 On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote:
 
if not allow_zero and abs(x)  sys.float_info.epsilon:
   print(zero is not allowed)
 
 The reason for the order is to do the easy calculation first and the 
 harder one only if the first passes.

This is a particularly egregious case of premature optimization.  You're 
worried about how long it takes to execute abs(x)?  That's silly.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: serialize a class to XML and back

2013-05-26 Thread Chris Rebert
On May 23, 2013 3:42 AM, Schneider j...@globe.de wrote:

 Hi list,

 how can I serialize a python class to XML? Plus a way to get the class
back from the XML?

There's pyxser: http://pythonhosted.org/pyxser/

 My aim is to store instances of this class in a database.

Honestly, I would avoid XML if you can. Consider using JSON (Python
includes the `json` module in the std lib) or pickle instead. Compared to
XML: The former is more standardized (in the context of serializing
objects) and less verbose; the latter is more efficient (if you don't care
about cross-language accessibility); both have more convenient APIs.

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


Re: Output from to_bytes

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 8:02 AM, Mok-Kong Shen wrote:

for k in range(8,12,1):
  print(k.to_bytes(2,byteorder='big'))


http://bugs.python.org/issue9951
http://bugs.python.org/issue3532

import binascii as ba
for k in range(8,12,1):
print(ba.hexlify(k.to_bytes(2,byteorder='big')))

b'0008'
b'0009'
b'000a'
b'000b'


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


Re: serialize a class to XML and back

2013-05-26 Thread Roy Smith
In article mailman.2197.1369600623.3114.python-l...@python.org,
 Chris Rebert c...@rebertia.com wrote:

 On May 23, 2013 3:42 AM, Schneider j...@globe.de wrote:
 
  Hi list,
 
  how can I serialize a python class to XML? Plus a way to get the class
 back from the XML?
 
 There's pyxser: http://pythonhosted.org/pyxser/
 
  My aim is to store instances of this class in a database.
 
 Honestly, I would avoid XML if you can. Consider using JSON (Python
 includes the `json` module in the std lib) or pickle instead. Compared to
 XML: The former is more standardized (in the context of serializing
 objects) and less verbose; the latter is more efficient (if you don't care
 about cross-language accessibility); both have more convenient APIs.

Some other points...

If you care about efficiency and want to use json, don't use the one 
that comes packaged with the standard library.  There are lots of 
third-party json packages (ujson is the one we use) which are 
significantly faster.  Not sure if that's true of the newest python 
releases, but it was certainly true in 2.6.

The advantage of pickle over json is that pickle can serialize many 
types of objects that json can't.  The other side of the coin is that 
pickle is python-specific, so if you think you'll ever need to read your 
data from other languages, pickle is right out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 12:36 PM, Νίκος Γκρ33κ wrote:

This is the code that although correct becaus it works with englisg(standARD 
ASCII letters) it wont with Greek:

if( log ):
name = log
# print specific client header info
cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', 
(name,) )
data = cur.fetchone()
===

The following is the live output of: tail -F /usr/local/apache/logs/error_log 


[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Error in 
sys.excepthook:, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 
'ascii' codec can't encode characters in position 2050-2056: ordinal not in 
range(128), referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] , referer: 
http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Original exception 
was:, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] Traceback (most recent 
call last):, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11]   File pelatologio.py, line 
122, in module, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] 
cur.execute('''SELECT hits, money FROM clients WHERE name = %s''', (name,) ), 
referer: http://superhost.gr/cgi-bin/pelatologio.py



[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11]   File 
/opt/python3/lib/python3.3/site-packages/pymysql/cursors.py, line 108, in 
execute, referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] query = 
query.encode(charset), referer: http://superhost.gr/cgi-bin/pelatologio.py
[Sun May 26 19:24:04 2013] [error] [client 46.12.46.11] UnicodeEncodeError: 
'latin-1' codec can't encode characters in position 46-52: ordinal not in 
range(256), referer: http://superhost.gr/cgi-bin/pelatologio.py


This appears to be an issue with your mysql database and how you set it 
up.. It is using charset='latin-1' whereas you need it to consistently 
use charset='utf8' both for storing strings and for retrieval. Check the 
mysql manual or ask on a mysql list for how to do that. I have no idea 
so don't ask me, or send mail to my emall address.



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


Re: This mail never gets delivered. Any ideas why?

2013-05-26 Thread Νίκος Γκρ33κ
I'am receiving this now after some tries:

A problem occurred in a Python script. Here is the sequence of function calls 
leading up to the error, in the order they occurred.

 /home/nikos/public_html/cgi-bin/metrites.py in ()
139 else:
140 sp = subprocess.Popen(['mail', '-f', FROM, '-s', 'Mail 
from Guest', 'supp...@superhost.gr'], stdin=subprocess.PIPE)
=  141 sp.communicate( MESSAGE )
142 status = sp.wait()
143 if status:
sp = subprocess.Popen object, sp.communicate = bound method 
Popen.communicate of subprocess.Popen object, MESSAGE = 
'kdsjfksdjkfjksdjfs\r\n\t'
 /opt/python3/lib/python3.3/subprocess.py in communicate(self=subprocess.Popen 
object, input='kdsjfksdjkfjksdjfs\r\n\t', timeout=None)
901 if input:
902 try:
=  903 self.stdin.write(input)
904 except IOError as e:
905 if e.errno != errno.EPIPE and e.errno != 
errno.EINVAL:
self = subprocess.Popen object, self.stdin = _io.BufferedWriter name=5, 
self.stdin.write = built-in method write of _io.BufferedWriter object, input 
= 'kdsjfksdjkfjksdjfs\r\n\t'
TypeError: 'str' does not support the buffer interface 
  args = ('str' does not support the buffer interface,) 
  with_traceback = built-in method with_traceback of TypeError object
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Ian Foote

On 26/05/13 20:41, Michael Torrie wrote:

On 05/26/2013 11:43 AM, Wolfgang Keller wrote:

snip


Maybe it would have been faster to develop, but ultimately less useful
and require more development time in the long run.  suppose I now want
the app natively on my phone (because that's all the rage).  It's an
iPhone.  Oh.  Apple doesn't support Python.  Okay, rewrite the works,
including business logic, in Objective C.  Now I want it on my android
phone.  Oops rewrite the stack again in Java.

Kivy (http://kivy.org) is a python library that can be used to write 
python apps for Linux, Windows, MaxOSX, Android and IOS.


Regards,
Ian F
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 3:54 PM, Carlos Nepomuceno wrote:



From: usenetm...@solar-empire.de

[...]

Not in Python3.x

decks = 6
list(range(13 * 4 * decks)) == range(13 * 4 * decks)

False

Adiaŭ
Marc



What does list(range(13 * 4 * decks)) returns in Python 3?  


A list, obviously. What you should ask is what range returns in Python 
3, and you should install python 3 and try it, and list its attributes.




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


Re: Piping processes works with 'shell = True' but not otherwise.

2013-05-26 Thread Chris Rebert
On May 24, 2013 7:06 AM, Luca Cerone luca.cer...@gmail.com wrote:

 Hi everybody,
 I am new to the group (and relatively new to Python)
 so I am sorry if this issues has been discussed (although searching for
topics in the group I couldn't find a solution to my problem).

 I am using Python 2.7.3 to analyse the output of two 3rd parties programs
that can be launched in a linux shell as:

  program1 | program2

 To do this I have written a function that pipes program1 and program2
(using subprocess.Popen) and the stdout of the subprocess, and a function
that parses the output:

 A basic example:

 from subprocess import Popen, STDOUT, PIPE
 def run():
   p1 = Popen(['program1'], stdout = PIPE, stderr = STDOUT)
   p2 = Popen(['program2'], stdin = p1.stdout, stdout = PIPE, stderr =
STDOUT)

Could you provide the *actual* commands you're using, rather than the
generic program1 and program2 placeholders? It's *very* common for
people to get the tokenization of a command line wrong (see the Note box in
http://docs.python.org/2/library/subprocess.html#subprocess.Popen for some
relevant advice).

   p1.stdout.close()
   return p2.stdout


 def parse(out):
   for row in out:
 print row
 #do something else with each line
   out.close()
   return parsed_output


 # main block here

 pout = run()

 parsed = parse(pout)

 #--- END OF PROGRAM #

 I want to parse the output of 'program1 | program2' line by line because
the output is very large.

 When running the code above, occasionally some error occurs (IOERROR:
[Errno 0]).

Could you provide the full  complete error message and exception traceback?

 However this error doesn't occur if I code the run() function as:

 def run():
   p = Popen('program1 | program2', shell = True, stderr = STDOUT, stdout
= PIPE)
   return p.stdout

 I really can't understand why the first version causes errors, while the
second one doesn't.

 Can you please help me understanding what's the difference between the
two cases?

One obvious difference between the 2 approaches is that the shell doesn't
redirect the stderr streams of the programs, whereas you /are/ redirecting
the stderrs to stdout in the non-shell version of your code. But this is
unlikely to be causing the error you're currently seeing.

You may also want to provide /dev/null as p1's stdin, out of an abundance
of caution.

Lastly, you may want to consider using a wrapper library such as
http://plumbum.readthedocs.org/en/latest/ , which makes it easier to do
pipelining and other such fancy things with subprocesses, while still
avoiding the many perils of the shell.

Cheers,
Chris
--
Be patient; it's Memorial Day weekend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want to know how to implement concurrent threads in Python

2013-05-26 Thread Andrew Berg
On 2013.05.26 14:10, Daniel Gagliardi wrote:
 I want to know how to implement concurrent threads in Python
With the threading module in the standard library.
http://docs.python.org/3.3/library/threading.html

There are plenty of tutorials on this out there; we'll be happy to help if 
you're stuck on something specific.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Future standard GUI library

2013-05-26 Thread Michael Torrie
On 05/26/2013 01:45 PM, Roy Smith wrote:
 In article mailman.2193.1369597318.3114.python-l...@python.org,
  Michael Torrie torr...@gmail.com wrote:
 
 On good thing web development has brought us is the knowledge that
 modularization and layers are a brilliant idea.
 
 Modularization and layers were a brilliant idea long before the web came 
 around.

True.  Though it seems like it fell out of fashion for a long time.  I
went to school before the advent of web development and though we talked
about modularization and coupling in software engineering, really it was
all rather monolithic.  Web development changed our focus back to where
it should have been all along.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want to know how to implement concurrent threads in Python

2013-05-26 Thread Andrew Berg
On 2013.05.26 16:21, Daniel Gagliardi wrote:
 shutup bitch! i do know python cannot concurrent threads. want a workaround
You're a charming fellow. I'm sure everyone will flock to help you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short-circuit Logic

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 4:22 PM, Roy Smith wrote:

In article mailman.2196.1369599562.3114.python-l...@python.org,
  Terry Jan Reedy tjre...@udel.edu wrote:


On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote:


   if not allow_zero and abs(x)  sys.float_info.epsilon:
  print(zero is not allowed)


The reason for the order is to do the easy calculation first and the
harder one only if the first passes.


This is a particularly egregious case of premature optimization.  You're
worried about how long it takes to execute abs(x)?  That's silly.


This is a particularly egregious case of premature response. You're 
ignoring an extra name lookup and two extra attribute lookups. That's silly.


That's beside the fact that one *must* choose, so any difference is a 
reason to act rather than being frozen like Buridan's ass.

http://en.wikipedia.org/wiki/Buridan%27s_ass

If you wish, replace 'The reason' with 'A reason'. I also the logical 
flow as better with the order given.






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


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Νίκος Γκρ33κ
No thi is not a mysql issue becaus ei have this line above for storing and 
retrieval form database.

con = pymysql.connect( db = 'metrites', host = 'localhost', user = 'me', passwd 
= 'somepass', init_command='SET NAMES UTF8' )
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 7:26 AM, Νίκος Γκρ33κ nikos.gr...@gmail.com wrote:
 No thi is not a mysql issue becaus ei have this line above for storing and 
 retrieval form database.

 con = pymysql.connect( db = 'metrites', host = 'localhost', user = 'me', 
 passwd = 'somepass', init_command='SET NAMES UTF8' )

Research MySQL and UTF-8, then see how your command is actually
flawed. Then research ESR and asking questions the smart way, and see
how your post is also flawed.

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


Re: Future standard GUI library

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 5:41 AM, Michael Torrie torr...@gmail.com wrote:
 Chuckle.  Simple CRUD, eh.  Almost all apps involve database CRUD
 interactions.  And often in highly complex ways using business logic.

Right. Sturgeon's Law of Applications.

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


Re: Solving the problem of mutual recursion

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 5:35 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 I'm pretty sure that CPython uses the GIL regardless of platform.  And
 yes you can have multiple OS-level threads, but because of the GIL
 only one will actually be running at a time.  Other possibilities
 include:

6) It's spinning in a function that has released the GIL. Python
threads can certainly execute concurrently; they just can't be
manipulating Python objects. Most of the I/O functions will release
the GIL before doing a potentially-blocking operation, and some
CPU-heavy functions can do the same (I'm given to understand that
numpy does this) - just depends on having a long job that involves no
refcounted objects.

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


Re: Cutting a deck of cards

2013-05-26 Thread Mark Lawrence

On 26/05/2013 19:16, Carlos Nepomuceno wrote:



Date: Sun, 26 May 2013 10:52:14 -0700
Subject: Cutting a deck of cards
From: rvinc...@gmail.com
To: python-list@python.org

Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie

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



list(range(13 * 4 * decks)) == range(13 * 4 * decks)

;)  



Wrong if you're using Python 3 :(

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: I want to know how to implement concurrent threads in Python

2013-05-26 Thread Mark Lawrence

On 26/05/2013 22:27, Andrew Berg wrote:

On 2013.05.26 16:21, Daniel Gagliardi wrote:

shutup bitch! i do know python cannot concurrent threads. want a workaround

You're a charming fellow. I'm sure everyone will flock to help you.



So How to win friends and influence people had two authors.

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Mark Lawrence

On 26/05/2013 22:26, Νίκος Γκρ33κ wrote:

No thi is not a mysql issue becaus ei have this line above for storing and 
retrieval form database.

con = pymysql.connect( db = 'metrites', host = 'localhost', user = 'me', passwd 
= 'somepass', init_command='SET NAMES UTF8' )



No wonder the Greek economy is so screwed up.

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


RE: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Carlos Nepomuceno

 To: python-list@python.org
 From: breamore...@yahoo.co.uk
[...]
 No wonder the Greek economy is so screwed up.

 --
 If you're using GoogleCrap™ please read this
 http://wiki.python.org/moin/GoogleGroupsPython.

 Mark Lawrence

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


Re: I want to know how to implement concurrent threads in Python

2013-05-26 Thread Mark Lawrence

On 26/05/2013 20:10, Daniel Gagliardi wrote:

I want to know how to implement concurrent threads in Python



google, bing, duckduckgo, yahoo...

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 To: python-list@python.org
 From: breamore...@yahoo.co.uk
[...]
 Wrong if you're using Python 3 :(

 --
 If you're using GoogleCrap™ please read this
 http://wiki.python.org/moin/GoogleGroupsPython.

 Mark Lawrence


Thanks guys! I've been delaying my dive into Python 3 (because I don't need it 
for now) but I'd like to run some code just to learn how different it is from 
Python 2 and even other Python flavors.

So, I'd like to know if it's possible to have multiple Python installations on 
the same machine (Windows 7 in my particular case) without messing one with 
each other. What care must I take not to mess up with them?

I've just found this[1] awesome service, but ridiculously it's PHP powered!!! 
lol Come on!!!

Why there aren't more Python powered websites available? What's the catch?


[1] http://www.compileonline.com/execute_python3_online.php 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:
 Thanks guys! I've been delaying my dive into Python 3 (because I don't need 
 it for now) but I'd like to run some code just to learn how different it is 
 from Python 2 and even other Python flavors.

 So, I'd like to know if it's possible to have multiple Python installations 
 on the same machine (Windows 7 in my particular case) without messing one 
 with each other. What care must I take not to mess up with them?

Easy. Just grab the standard installer and hit it. You'll get two
separate directories (or more; I have \Python26, \Python27, \Python32,
\Python33 on this box), and you can run whichever you want. The one
thing to take care of is .py associations; I haven't actually done it
(on here, all I actually do is IDLE, pretty much), but as of 3.3, you
should be able to use a Unix-style shebang to indicate which Python
you want to invoke.

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


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 8:21 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 26/05/2013 22:26, Νίκος Γκρ33κ wrote:

 No thi is not a mysql issue becaus ei have this line above for storing and
 retrieval form database.

 con = pymysql.connect( db = 'metrites', host = 'localhost', user = 'me',
 passwd = 'somepass', init_command='SET NAMES UTF8' )


 No wonder the Greek economy is so screwed up.

Do you think the Greek economy would be improved by Python coming with
PostgreSQL bindings? That'd push a lot of people onto a better
database engine than MySQL.

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


Re: serialize a class to XML and back

2013-05-26 Thread Irmen de Jong
On 26-5-2013 22:48, Roy Smith wrote:

 The advantage of pickle over json is that pickle can serialize many 
 types of objects that json can't.  The other side of the coin is that 
 pickle is python-specific, so if you think you'll ever need to read your 
 data from other languages, pickle is right out.

That is not entirely true :)  I've written a pickle implementation for Java and 
.NET
that is almost feature complete; it is part of 
http://pythonhosted.org/Pyro4/pyrolite.html

Still, pickle may not be the best choice here.

Cheers
Irmen

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


Re: Encodign issue in Python 3.3.1 (once again)

2013-05-26 Thread Mark Lawrence

On 26/05/2013 23:32, Chris Angelico wrote:

On Mon, May 27, 2013 at 8:21 AM, Mark Lawrence breamore...@yahoo.co.uk wrote:

On 26/05/2013 22:26, Νίκος Γκρ33κ wrote:


No thi is not a mysql issue becaus ei have this line above for storing and
retrieval form database.

con = pymysql.connect( db = 'metrites', host = 'localhost', user = 'me',
passwd = 'somepass', init_command='SET NAMES UTF8' )



No wonder the Greek economy is so screwed up.


Do you think the Greek economy would be improved by Python coming with
PostgreSQL bindings? That'd push a lot of people onto a better
database engine than MySQL.

ChrisA



Even the best economies would be improved by Python coming with 
PostgreSQL bindings, but if and only if the user knew how to use them :)


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 Date: Mon, 27 May 2013 08:42:56 +1000
 Subject: Re: Cutting a deck of cards
 From: ros...@gmail.com
[...]
 Easy. Just grab the standard installer and hit it. You'll get two
 separate directories (or more; I have \Python26, \Python27, \Python32,
 \Python33 on this box), and you can run whichever you want. The one
 thing to take care of is .py associations; I haven't actually done it
 (on here, all I actually do is IDLE, pretty much), but as of 3.3, you
 should be able to use a Unix-style shebang to indicate which Python
 you want to invoke.

 ChrisA

I'm not even using shebangs in Windows because I thought it wouldn't make any 
difference. I'm used to run scripts like python filename.py from the command 
line. No problem!

So, Python 3.3 will honor if I insert #!C:\Python27\python.exe? if I install 
it after Python 2.7? Cool!!!   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Mark Lawrence

On 26/05/2013 23:42, Chris Angelico wrote:

On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:

Thanks guys! I've been delaying my dive into Python 3 (because I don't need it 
for now) but I'd like to run some code just to learn how different it is from 
Python 2 and even other Python flavors.

So, I'd like to know if it's possible to have multiple Python installations on 
the same machine (Windows 7 in my particular case) without messing one with 
each other. What care must I take not to mess up with them?


Easy. Just grab the standard installer and hit it. You'll get two
separate directories (or more; I have \Python26, \Python27, \Python32,
\Python33 on this box), and you can run whichever you want. The one
thing to take care of is .py associations; I haven't actually done it
(on here, all I actually do is IDLE, pretty much), but as of 3.3, you
should be able to use a Unix-style shebang to indicate which Python
you want to invoke.

ChrisA



See this 
http://docs.python.org/3/whatsnew/3.3.html#pep-397-python-launcher-for-windows


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Python error codes and messages location

2013-05-26 Thread Carlos Nepomuceno
Where can I find all error codes and messages that Python throws (actual codes 
and messages from exceptions raised by stdlib)?

I've already found the module 'errno' and got a dictionary (errno.errorcode) 
and some system error messages (os.strerror(errno.ENAMETOOLONG)) but there's 
more I couldn't find.   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Piping processes works with 'shell = True' but not otherwise.

2013-05-26 Thread Luca Cerone
 Could you provide the *actual* commands you're using, rather than the generic 
 program1 and program2 placeholders? It's *very* common for people to get 
 the tokenization of a command line wrong (see the Note box in 
 http://docs.python.org/2/library/subprocess.html#subprocess.Popen for some 
 relevant advice).
 
Hi Chris, first of all thanks for the help. Unfortunately I can't provide the 
actual commands because are tools that are not publicly available.
I think I get the tokenization right, though.. the problem is not that the 
programs don't run.. it is just that sometimes I get that error..

Just to be clear I run the process like:

p = subprocess.Popen(['program1','--opt1','val1',...'--optn','valn'], ... the 
rest)

which I think is the right way to pass arguments (it works fine for other 
commands)..

 
 Could you provide the full  complete error message and exception traceback?
 
yes, as soon as I get to my work laptop..

 
 One obvious difference between the 2 approaches is that the shell doesn't 
 redirect the stderr streams of the programs, whereas you /are/ redirecting 
 the stderrs to stdout in the non-shell version of your code. But this is 
 unlikely to be causing the error you're currently seeing.
 
 
 You may also want to provide /dev/null as p1's stdin, out of an abundance of 
 caution.


I tried to redirect the output to /dev/null using the Popen argument:
'stdin = os.path.devnull' (having imported os of course)..
But this seemed to cause even more troubles...
 
 Lastly, you may want to consider using a wrapper library such as 
 http://plumbum.readthedocs.org/en/latest/ , which makes it easier to do 
 pipelining and other such fancy things with subprocesses, while still 
 avoiding the many perils of the shell.
 
 
Thanks, I didn't know this library, I'll give it a try.
Though I forgot to mention that I was using the subprocess module, because I 
want the code to be portable (even though for now if it works in Unix platform 
is OK).

Thanks a lot for your help,
Cheers,
Luca
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Piping processes works with 'shell = True' but not otherwise.

2013-05-26 Thread Carlos Nepomuceno
pipes usually consumes disk storage at '/tmp'. Are you sure you have enough 
room on that filesystem? Make sure no other processes are competing against for 
that space. Just my 50c because I don't know what's causing Errno 0. I don't 
even know what are the possible causes of such error. Good luck!


 Date: Sun, 26 May 2013 16:58:57 -0700
 Subject: Re: Piping processes works with 'shell = True' but not otherwise.
 From: luca.cer...@gmail.com
 To: python-list@python.org
[...]
 I tried to redirect the output to /dev/null using the Popen argument:
 'stdin = os.path.devnull' (having imported os of course)..
 But this seemed to cause even more troubles...

 Lastly, you may want to consider using a wrapper library such as 
 http://plumbum.readthedocs.org/en/latest/ , which makes it easier to do 
 pipelining and other such fancy things with subprocesses, while still 
 avoiding the many perils of the shell.


 Thanks, I didn't know this library, I'll give it a try.
 Though I forgot to mention that I was using the subprocess module, because I 
 want the code to be portable (even though for now if it works in Unix 
 platform is OK).

 Thanks a lot for your help,
 Cheers,
 Luca
 --
 http://mail.python.org/mailman/listinfo/python-list   
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: This mail never gets delivered. Any ideas why?

2013-05-26 Thread Cameron Simpson
On 26May2013 13:48, =?utf-8?B?zp3Or866zr/PgiDOk866z4EzM866?= 
nikos.gr...@gmail.com wrote:
| I'am receiving this now after some tries:
| 
| A problem occurred in a Python script. Here is the sequence of function calls 
leading up to the error, in the order they occurred.
| 
|  /home/nikos/public_html/cgi-bin/metrites.py in ()
| 139 else:
| 140 sp = subprocess.Popen(['mail', '-f', FROM, '-s', 
'Mail from Guest', 'supp...@superhost.gr'], stdin=subprocess.PIPE)
| =  141 sp.communicate( MESSAGE )
| 142 status = sp.wait()
| 143 if status:
| sp = subprocess.Popen object, sp.communicate = bound method 
Popen.communicate of subprocess.Popen object, MESSAGE = 
'kdsjfksdjkfjksdjfs\r\n\t'
|  /opt/python3/lib/python3.3/subprocess.py in 
communicate(self=subprocess.Popen object, input='kdsjfksdjkfjksdjfs\r\n\t', 
timeout=None)
| 901 if input:
| 902 try:
| =  903 self.stdin.write(input)

Well, you should probably be writing to sp.stdin, not sys.stdin.

| 904 except IOError as e:
| 905 if e.errno != errno.EPIPE and e.errno != 
errno.EINVAL:
| self = subprocess.Popen object, self.stdin = _io.BufferedWriter name=5, 
self.stdin.write = built-in method write of _io.BufferedWriter object, input 
= 'kdsjfksdjkfjksdjfs\r\n\t'
| TypeError: 'str' does not support the buffer interface 
|   args = ('str' does not support the buffer interface,) 
|   with_traceback = built-in method with_traceback of TypeError object

This is symptomatic of sys.stdin (well, whatever you're writing to)
being open in binary mode instead of text mode. And you're passing
a str. Try passing std.encode().

Cheers,
-- 
Cameron Simpson c...@zip.com.au

Yes, [congress is] petty and venal and selfish.  That's why they're called
_representatives_.  - Will Durst
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: This mail never gets delivered. Any ideas why?

2013-05-26 Thread Cameron Simpson
On 27May2013 10:22, I wrote:
| | =  903 self.stdin.write(input)
[...]
| | self = subprocess.Popen object, self.stdin = _io.BufferedWriter name=5, 
self.stdin.write = built-in method write of _io.BufferedWriter object, input 
= 'kdsjfksdjkfjksdjfs\r\n\t'
| | TypeError: 'str' does not support the buffer interface 
| |   args = ('str' does not support the buffer interface,) 
| |   with_traceback = built-in method with_traceback of TypeError object
| 
| This is symptomatic of sys.stdin (well, whatever you're writing to)
| being open in binary mode instead of text mode. And you're passing
| a str. Try passing std.encode().

Sorry, that should be input.encode().
-- 
Cameron Simpson c...@zip.com.au

PCs are like a submarine, it will work fine till you open Windows. - zollie101
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

2013-05-26 Thread Cameron Simpson
On 26May2013 17:45, Mark Lawrence breamore...@yahoo.co.uk wrote:
| On 26/05/2013 17:10, Νίκος Γκρ33κ wrote:
| Here is the live error log coming form apacher when i request the webpage 
form browser:
| 
| == /usr/local/apache/logs/error_log ==
| [Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] suexec failure: 
could not open log file
| [Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission 
denied
| [Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] fopen: Permission 
denied
| [Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of 
script headers: koukos.py
| [Sun May 26 19:07:41 2013] [error] [client 46.12.46.11] Premature end of 
script headers: koukos.py
| 
| what is that suexec?
| 
| What has this got to do with Python?

Little, and I've already explained what suexec is to him some weeks ago, off 
list.

Cheers,
-- 
Cameron Simpson c...@zip.com.au

The road less traveled is FASTER !!
- Luc Marcouiller, marco...@ireq.hydro.qc.ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: serialize a class to XML and back

2013-05-26 Thread Roy Smith
In article 51a28f42$0$15870$e4fe5...@news.xs4all.nl,
 Irmen de Jong irmen.nos...@xs4all.nl wrote:

 On 26-5-2013 22:48, Roy Smith wrote:
 
  The advantage of pickle over json is that pickle can serialize many 
  types of objects that json can't.  The other side of the coin is that 
  pickle is python-specific, so if you think you'll ever need to read your 
  data from other languages, pickle is right out.
 
 That is not entirely true :)  I've written a pickle implementation for Java 
 and .NET
 that is almost feature complete; it is part of 
 http://pythonhosted.org/Pyro4/pyrolite.html

Very cool

 Still, pickle may not be the best choice here.

Perhaps not, but lots of points for the awesomeness factor.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Short-circuit Logic

2013-05-26 Thread Steven D'Aprano
On Sun, 26 May 2013 16:22:26 -0400, Roy Smith wrote:

 In article mailman.2196.1369599562.3114.python-l...@python.org,
  Terry Jan Reedy tjre...@udel.edu wrote:
 
 On 5/26/2013 7:11 AM, Ahmed Abdulshafy wrote:
 
if not allow_zero and abs(x)  sys.float_info.epsilon:
   print(zero is not allowed)
 
 The reason for the order is to do the easy calculation first and the
 harder one only if the first passes.
 
 This is a particularly egregious case of premature optimization.  You're
 worried about how long it takes to execute abs(x)?  That's silly.

I don't think it's a matter of premature optimization so much as the 
general principle run code only if it needs to run. Hence, first you 
check the flag to decide whether or not you care whether x is near zero, 
and *only if you care* do you then check whether x is near zero.

# This is silly:
if x is near zero:
if we care:
handle near zero condition()

# This is better:
if we care:
if x is near zero
handle near zero condition()


Not only is this easier to understand because it matches how we do things 
in the real life, but it has the benefit that if the near zero 
condition ever changes to become much more expensive, you don't have to 
worry about reordering the tests because they're already in the right 
order.



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


Re: Python error codes and messages location

2013-05-26 Thread Steven D'Aprano
On Mon, 27 May 2013 02:13:54 +0300, Carlos Nepomuceno wrote:

 Where can I find all error codes and messages that Python throws (actual
 codes and messages from exceptions raised by stdlib)?

There is no list. It is subject to change from version to version, 
including point releases.

Many functions and methods document which exceptions they can be expected 
to raise, or at least the *usual* exceptions, but many more do not. And 
the error messages themselves are implementation details and are subject 
to change without notice, even if the exception type is a documented part 
of the API.

You can see a full list of built-in exception types in the docs:

http://docs.python.org/3/library/exceptions.html

but of course since they are classes, they can be subclassed, and in 
principle a function that raises (say) ValueError might sometimes raise a 
subclass of ValueError without documenting it.

So the actual answer to your question is:

Read the source code.


Sorry :-(


 I've already found the module 'errno' and got a dictionary
 (errno.errorcode) and some system error messages
 (os.strerror(errno.ENAMETOOLONG)) but there's more I couldn't find.

These are the standard C operating system and file system error codes, 
not Python exceptions.


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


  1   2   3   >