Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-25 Thread dieter
RAH  writes:

> I experienced an incomprehensible behavior (I've spent already many hours on 
> this subject): the `file.write('string')` provides an error in run mode and 
> not when interpreted at the console.

Maybe, I can explain the behavior: the interactive interpreter uses magic
to determine the console's encoding and automatically uses this
for console output. No such magic in non-interactive interpreter use.
Therefore, you can get "UnicodeEncoding" problems in non-interactive use
which you do not see in interactive use.

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


Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-25 Thread Chris Angelico
On Wed, Aug 26, 2015 at 7:19 AM, RAH  wrote:
> rb = request_body.decode()  # string

I'd recommend avoiding this operation in Python 2. As of Python 3,
omitting the encoding means "UTF-8", but in Python 2 it means "use the
default encoding", and that often causes problems in scripts that run
in various background environments. Instead, explicitly say what
encoding you're using:

rb = request_body.decode("UTF-8")

Conversely, if you're using Python 3 for this, the default encoding is
coming from this line:

> h = open('logdict', 'a')

Again, if you want this to be a text file with a specific encoding, say so:

h = open('logdict', 'a', encoding='UTF-8')

Give that a try and see if your problems disappear. If not, this
should at least poke them with a pointy stick.

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


Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-25 Thread Chris Kaynor
On Tue, Aug 25, 2015 at 2:19 PM, RAH  wrote:
> Dear All,
>
> I experienced an incomprehensible behavior (I've spent already many hours on 
> this subject): the `file.write('string')` provides an error in run mode and 
> not when interpreted at the console. The string must contain non-ASCII 
> characters. If all ASCII, there is no error.
>
> The following example shows what I can see. I must overlook something because 
> I cannot think Python makes a difference between interpreted and run modes 
> and yet ... Can someone please check that subject.
>
> Thank you in advance.
> René
>
> Code extract from WSGI application (reply.py)
> =
>
> request_body = environ['wsgi.input'].read(request_body_size)# bytes
> rb = request_body.decode()  # string
> d = parse_qs(rb)# dict
>
> f = open('logbytes', 'ab')
> g = open('logstr', 'a')
> h = open('logdict', 'a')
>
> f.write(request_body)
> g.write(str(type(request_body)) + '\t' + str(type(rb)) + '\t' + 
> str(type(d)) + '\n')
> h.write(str(d) + '\n')  <--- line 28 of the application
>
> h.close()
> g.close()
> f.close()
>
>
> Tail of Apache2 error.log
> =
>
> [Tue Aug 25 20:24:04.657933 2015] [wsgi:error] [pid 3677:tid 3029764928] 
> [remote 192.168.1.5:27575]   File "reply.py", line 28, in application
> [Tue Aug 25 20:24:04.658001 2015] [wsgi:error] [pid 3677:tid 3029764928] 
> [remote 192.168.1.5:27575] h.write(str(d) + '\\n')
> [Tue Aug 25 20:24:04.658201 2015] [wsgi:error] [pid 3677:tid 3029764928] 
> [remote 192.168.1.5:27575] UnicodeEncodeError: 'ascii' codec can't encode 
> character '\\xc7' in position 15: ordinal not in range(128)
>

What version of Python is Apache2 using? From the looks of the error,
it is probably using some version of Python2, in which case you'll
need to manually encode the string and pick an encoding for the file
(via an encoding argument to the open function). I'd recommend using
UTF-8.

You can log out the value of sys.version to find out the version number.


> Trying similar code within the Python interpreter
> =
>
> rse@Alibaba:~/test$ python
> Python 3.4.0 (default, Jun 19 2015, 14:18:46)
> [GCC 4.8.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 di = {'userName': ['Ça va !']}<--- A dictionary
 str(di)
> "{'userName': ['Ça va !']}"   <--- and its string representation
 type(str(di))
><--- Is a string indeed
 fi = open('essai', 'a')
 fi.write(str(di) + '\n')
> 26  <--- It works well
 fi.close()


In this run, you are using Python 3.4, which defaults to UTF-8.
-- 
https://mail.python.org/mailman/listinfo/python-list


file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-25 Thread RAH
Dear All,

I experienced an incomprehensible behavior (I've spent already many hours on 
this subject): the `file.write('string')` provides an error in run mode and not 
when interpreted at the console. The string must contain non-ASCII characters. 
If all ASCII, there is no error.

The following example shows what I can see. I must overlook something because I 
cannot think Python makes a difference between interpreted and run modes and 
yet ... Can someone please check that subject.

Thank you in advance.
René

Code extract from WSGI application (reply.py)
=

request_body = environ['wsgi.input'].read(request_body_size)# bytes
rb = request_body.decode()  # string
d = parse_qs(rb)# dict

f = open('logbytes', 'ab')
g = open('logstr', 'a')
h = open('logdict', 'a')

f.write(request_body)
g.write(str(type(request_body)) + '\t' + str(type(rb)) + '\t' + 
str(type(d)) + '\n')
h.write(str(d) + '\n')  <--- line 28 of the application

h.close()
g.close()
f.close()


Tail of Apache2 error.log
=

[Tue Aug 25 20:24:04.657933 2015] [wsgi:error] [pid 3677:tid 3029764928] 
[remote 192.168.1.5:27575]   File "reply.py", line 28, in application
[Tue Aug 25 20:24:04.658001 2015] [wsgi:error] [pid 3677:tid 3029764928] 
[remote 192.168.1.5:27575] h.write(str(d) + '\\n')
[Tue Aug 25 20:24:04.658201 2015] [wsgi:error] [pid 3677:tid 3029764928] 
[remote 192.168.1.5:27575] UnicodeEncodeError: 'ascii' codec can't encode 
character '\\xc7' in position 15: ordinal not in range(128)


Checking what has been logged
=

rse@Alibaba:~/test$ cat logbytes
userName=Ça va !   <--- this was indeed the input (notice the
french C + cedilla)
Unicode U+00C7ALT-0199UTF-8 C387
Reading the logbytes file one can verify
that Ç is indeed represented by the 2 bytes
\xC3 and \x87
rse@Alibaba:~/test$ cat logstr

rse@Alibaba:~/test$ cat logdict
rse@Alibaba:~/test$ <--- Obviously empty because of error


Trying similar code within the Python interpreter
=

rse@Alibaba:~/test$ python
Python 3.4.0 (default, Jun 19 2015, 14:18:46)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> di = {'userName': ['Ça va !']}<--- A dictionary
>>> str(di)
"{'userName': ['Ça va !']}"   <--- and its string representation
>>> type(str(di))
   <--- Is a string indeed
>>> fi = open('essai', 'a')
>>> fi.write(str(di) + '\n')
26  <--- It works well
>>> fi.close()
>>>


Checking what has been written
==

rse@Alibaba:~/test$ cat essai
{'userName': ['Ça va !']}   <--- The result is correct
rse@Alibaba:~/test$


No error if all ASCII
=

If the input is `userName=Rene` for instance then there is no error and the
`logdict' does indeed then contain the text of the dictionary
`{'userName': ['Rene']}`

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


[RELEASED] Python 3.5.0rc2 is now available

2015-08-25 Thread Larry Hastings



On behalf of the Python development community and the Python 3.5 release 
team, I'm relieved to announce the availability of Python 3.5.0rc2, also 
known as Python 3.5.0 Release Candidate 2.


Python 3.5 has now entered "feature freeze".  By default new features 
may no longer be added to Python 3.5.


This is a preview release, and its use is not recommended for production 
settings.



You can find Python 3.5.0rc2 here:

https://www.python.org/downloads/release/python-350rc2/

Windows and Mac users: please read the important platform-specific 
"Notes on this release" section near the end of that page.



Happy hacking,


//arry/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeCheck vs IsInstance in C API

2015-08-25 Thread random832
On Tue, Aug 25, 2015, at 12:56, Terry Reedy wrote:
> Huh??  I fail to see the point of this buggy code.
...
> The extra marginal '>' quote makes it look like this buggy code was 
> posted by Andrew, but it comes from random832.

Actually, it comes from one of the links I posted right above it. It
was, apparently, the recommended way to do this in python up to 1.4,
before isinstance existed.

It only worked with [old-style, goes without saying] instance and class
objects and not, say, ints, but AFAICT isinstance in 1.5 didn't support
anything else either. Since these couldn't be subclassed you could
simply add "if type(cl) is types.TypeType: return type(ob) is cl" to the
top.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [ANN] Python TreeTagger wrapper updated to 2.2.1

2015-08-25 Thread Laurent Pointal
Laurent Pointal wrote:

> It is available on PyPI:

… incomplete URL…

Here: https://pypi.python.org/pypi/treetaggerwrapper/


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


[ANN] Python TreeTagger wrapper updated to 2.2.1

2015-08-25 Thread Laurent Pointal
Hello,

for natural language processing, treetaggerwrapper, the Python wrapper for 
language independant part-of-speech statistical tagger TreeTagger from
H.Schmid is now available in version 2.2.1.

It is available on PyPI: 

https://pypi.python.org/pypi

And the doc is on Read the Docs:

http://treetaggerwrapper.readthedocs.org/

The source has been globally reworked, some modifications make it partially 
incompatible with 1.0 module. It should be more easy to use (tries to 
autodetect TreeTagger installation directory). It now works with Python2 
and Python3 with same source. 
I also added a treetaggerpoll module for use in a multiprocessing
context.

For important (and incompatible) modifications, see
http://treetaggerwrapper.readthedocs.org/en/latest/#important-modifications-notes
 

A+
Laurent Pointal 

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


Re: TypeCheck vs IsInstance in C API

2015-08-25 Thread Terry Reedy

On 8/25/2015 10:32 AM, random...@fastmail.us wrote:

On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote:

[question snipped]


And, now, your moment of zen:


Huh??  I fail to see the point of this buggy code.


def isa(ob, cl):
   try:
   raise ob
   except cl:
   return 1
   else: return 0


The extra marginal '>' quote makes it look like this buggy code was 
posted by Andrew, but it comes from random832.  In 3.x, both ob and cl 
must be exceptions and isa(1, int) cannot work. In 2.7, ob must be an 
exception or old-style class (not documented that I see).


>>> raise 1

Traceback (most recent call last):
  File "", line 1, in 
raise 1
TypeError: exceptions must be old-style classes or derived from 
BaseException, not int


Hence, isa(1, int) raises TypeError instead of returning 1. If 'else' is 
changed to 'except', it returns 0 instead of 1.


--
Terry Jan Reedy

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


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
Ian Kelly writes:
> On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro wrote:
>> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote:
>>>
>>> When I try it today, round brackets also work, both in 2.6.6 and
>>> 3.4.0 - no idea what version it was where they failed or if I'm
>>> imagining the whole thing.
>>
>> You are imagining the whole thing. Either that, or you had some other
>> problem with your tuple unpacking which kept it from working. That
>> has been a part of the language as far back as I can remember. I
>> started using Python around the 1.0 timeframe.
>
> My guess is that Jussi was trying to unpack a sequence of a single
> element like this:
>
> (a) = some_sequence
[snip]

It wasn't that. It was a known number of tab-separated fields that I
wanted to name individually, like this:

ID, FORM, LEMMA, POS, MOR, FEATS, \
HEAD, REL, DEPS, MISC \
= line.split('\t')

That's from actual code but not necessarily from the place where I first
tried and failed to use parentheses. It didn't occur to me to try square
brackets, so I got in the habit of using backslashes as above. (That
script is dated in January 2015. The something that happened happened
some months before that. But it may have been a hallucination.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
Skip Montanaro  writes:

> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote:
>
>> When I try it today, round brackets also work, both in 2.6.6 and
>> 3.4.0 - no idea what version it was where they failed or if I'm
>> imagining the whole thing.
>
> You are imagining the whole thing. Either that, or you had some other
> problem with your tuple unpacking which kept it from working. That has
> been a part of the language as far back as I can remember. I started
> using Python around the 1.0 timeframe.

At least they work now, and clearly are intended to work. But I just
checked and I have scripts with backslash-terminated lines where I'm
sure I wanted to use those brackets. Could it have been some sort of
temporary regression? Well, never mind :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Ian Kelly
On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro
 wrote:
>
> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen
>  wrote:
>>
>> When I try it today, round brackets
>> also work, both in 2.6.6 and 3.4.0 - no idea what version it was where
>> they failed or if I'm imagining the whole thing.
>
>
> You are imagining the whole thing. Either that, or you had some other
> problem with your tuple unpacking which kept it from working. That has been
> a part of the language as far back as I can remember. I started using Python
> around the 1.0 timeframe.

My guess is that Jussi was trying to unpack a sequence of a single
element like this:

(a) = some_sequence

With the result that a is assigned the whole sequence instead of the
one element, because (a) does not denote a tuple, but merely an
individual parenthesized expression. Any of these would work in its
place:

(a,) = some_sequence
a, = some_sequence
[a] = some_sequence
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Skip Montanaro
On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen <
harvested.address@is.invalid> wrote:

> When I try it today, round brackets
> also work, both in 2.6.6 and 3.4.0 - no idea what version it was where
> they failed or if I'm imagining the whole thing.
>

You are imagining the whole thing. Either that, or you had some other
problem with your tuple unpacking which kept it from working. That has been
a part of the language as far back as I can remember. I started using
Python around the 1.0 timeframe.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
"ast" writes:

 [a,b,c,d] = 1,2,3,4
 a
> 1
 b
> 2
 c
> 3
 d
> 4
>
> I have never seen this syntax before. Is it documented.
> Is there a name for that ?

I remember being unhappy when a similar assignment with round brackets
turned out to be invalid syntax. Then I learned (in this newsgroup) that
square brackets would work, and so they did, and then I was happy again,
though it felt a bit inconsistent. When I try it today, round brackets
also work, both in 2.6.6 and 3.4.0 - no idea what version it was where
they failed or if I'm imagining the whole thing.

The page that Joel Goldstick cited claims that Guido van Rossum himself
has called the left side of a statement like "w,x,y,z = t3" (no brackets
on that page) "the list of variables" (but their link to the evidence is
dead).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast


"Joel Goldstick"  a écrit dans le message de 
news:mailman.27.1440515128.11709.python-l...@python.org...

On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall  wrote:



On Tue, Aug 25, 2015 at 9:16 AM, ast  wrote:




The original example is one I haven't seen in the wild.


I found it using matplotlib

import numpy as np
import matplotlib.pyplot as plt

f, (ax1, ax2) = plt.subplots(2, 1, sharex=True)




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


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast


"ast"  a écrit dans le message de 
news:55dc853c$0$3083$426a7...@news.free.fr...


"Joel Goldstick"  a écrit dans le message de 
news:mailman.23.1440513059.11709.python-l...@python.org...

On Tue, Aug 25, 2015 at 10:16 AM, ast  wrote:

[a,b,c,d] = 1,2,3,4
a


1


b


2


c


3


d


4

I have never seen this syntax before. Is it documented.
Is there a name for that ?

thx
--
https://mail.python.org/mailman/listinfo/python-list


its called list unpacking or packing (?)

the right side is considered a tuple because of the commas

a = 1,2,3
a

(1, 2, 3)

a[1]

2





http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm


--
Joel Goldstick
http://joelgoldstick.com


Yes you are right, it is related to tuple unpacking
Here are some useful examples I found.
http://svn.python.org/projects/python/branches/pep-0384/Lib/test/test_unpack_ex.py


Unpack in list

   >>> [a, *b, c] = range(5)
   >>> a == 0 and b == [1, 2, 3] and c == 4
   True 


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


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast


"Joel Goldstick"  a écrit dans le message de 
news:mailman.23.1440513059.11709.python-l...@python.org...

On Tue, Aug 25, 2015 at 10:16 AM, ast  wrote:

[a,b,c,d] = 1,2,3,4
a


1


b


2


c


3


d


4

I have never seen this syntax before. Is it documented.
Is there a name for that ?

thx
--
https://mail.python.org/mailman/listinfo/python-list


its called list unpacking or packing (?)

the right side is considered a tuple because of the commas

a = 1,2,3
a

(1, 2, 3)

a[1]

2





http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm


--
Joel Goldstick
http://joelgoldstick.com


Yes you are right, it is related to tuple unpacking
Here are some useful examples I found.
http://svn.python.org/projects/python/branches/pep-0384/Lib/test/test_unpack_ex.py 


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


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Joel Goldstick
On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall  wrote:
>
>
> On Tue, Aug 25, 2015 at 9:16 AM, ast  wrote:
>
> [a,b,c,d] = 1,2,3,4
> a
>>
>> 1
>
> b
>>
>> 2
>
> c
>>
>> 3
>
> d
>>
>> 4
>>
>> I have never seen this syntax before. Is it documented.
>> Is there a name for that ?
>>
>> thx
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> That's called "sequence unpacking"
>
> Cody
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

The original example is one I haven't seen in the wild.  One nifty use
of this feature is to exchange values like this:

a, b = b, a

it saves the use of a temporary name
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jean-Michel Pichavant
- Original Message -
> From: "ast" 
> To: python-list@python.org
> Sent: Tuesday, 25 August, 2015 4:16:17 PM
> Subject: [a,b,c,d] = 1,2,3,4
> 
> >>> [a,b,c,d] = 1,2,3,4
> >>> a
> 1
> >>> b
> 2
> >>> c
> 3
> >>> d
> 4
> 
> I have never seen this syntax before. Is it documented.
> Is there a name for that ?
> 
> thx

You probably have already seen something like:

a,b,c,d = 1,2,3,4

which is the same code than yours with the list replaced by a tuple.

Moreover:
https://docs.python.org/2/tutorial/datastructures.html

"""
x, y, z = t
This is called, appropriately enough, sequence unpacking and works for any 
sequence on the right-hand side. Sequence unpacking requires the list of 
variables on the left to have the same number of elements as the length of the 
sequence. Note that multiple assignment is really just a combination of tuple 
packing and sequence unpacking.
"""

It's slightly confusing because it mentions a "list of variable" and then a 
"tuple packing" while the example uses a tuple.
Fortunately, lists and tuples can be used in both cases.

JM


-- IMPORTANT NOTICE: 

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


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Cody Piersall
On Tue, Aug 25, 2015 at 9:16 AM, ast  wrote:

> [a,b,c,d] = 1,2,3,4
 a

>>> 1
>
>> b

>>> 2
>
>> c

>>> 3
>
>> d

>>> 4
>
> I have never seen this syntax before. Is it documented.
> Is there a name for that ?
>
> thx
> --
> https://mail.python.org/mailman/listinfo/python-list
>

That's called "sequence unpacking"

Cody
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeCheck vs IsInstance in C API

2015-08-25 Thread random832
On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote:
> Hi.
> 
> I know this thread is ancient, but I would like to know the answer
> as well
> ( https://mail.python.org/pipermail/python-list/2006-May/413542.html).

Of course, the answer in 2015 is actually very different from the
answer in 2006, since we didn't have either Python 3 or abstract
classes back then.

The IsInstance (and IsSubclass) function documentation mentions that
they use the methods __instancecheck__ [and __subclasscheck__],
presumably to support abstract classes.

The actual implementation of TypeCheck is a macro:
PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
#define PyObject_TypeCheck(ob, tp) \
(Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))

PyType_IsSubtype (in typeobject.c) only appears to deal with the
real types, not any abstract class methods.

So it looks like PyObject_TypeCheck/PyType_IsSubtype was originally
introduced to check for real types (and not old style classes), and
continued in that niche as IsInstance/IsSubclass were repurposed to
deal with PEP 3119 ABC logic.

Incidentally, this made me wonder what was done before
PyObject_IsInstance was added in 2.1. In 2.0, substantially the same
code exists inside builtin_isinstance.

Stuff I found researching this:
http://comments.gmane.org/gmane.comp.python.cython.devel/2928
https://groups.google.com/forum/#!topic/comp.lang.python/z594gnaBhwY
https://groups.google.com/forum/#!topic/comp.lang.python/ywqzu3JD6Nw

And, now, your moment of zen:
> def isa(ob, cl):
>   try:
>   raise ob
>   except cl:
>   return 1
>   else: return 0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Joel Goldstick
On Tue, Aug 25, 2015 at 10:16 AM, ast  wrote:
 [a,b,c,d] = 1,2,3,4
 a
>
> 1

 b
>
> 2

 c
>
> 3

 d
>
> 4
>
> I have never seen this syntax before. Is it documented.
> Is there a name for that ?
>
> thx
> --
> https://mail.python.org/mailman/listinfo/python-list

its called list unpacking or packing (?)

the right side is considered a tuple because of the commas
>>> a = 1,2,3
>>> a
(1, 2, 3)
>>> a[1]
2
>>>


http://www.developer.com/lang/other/article.php/630101/Learn-to-Program-using-Python-Unpacking-Tuples.htm


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


[a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast

[a,b,c,d] = 1,2,3,4
a

1

b

2

c

3

d

4

I have never seen this syntax before. Is it documented.
Is there a name for that ?

thx
--
https://mail.python.org/mailman/listinfo/python-list


RE: Logging to a file from a C-extension

2015-08-25 Thread AllanPfalzgraf
Stefan,

You have understood my question.  I'm new to Python.  Could I use a Cython 
solution to get suggestions on just how to go about this in the C extension?  
Otherwise could you suggest which C-API functions I should be looking at?

Thanks,
Al

-Original Message-
From: Stefan Behnel [mailto:stefan...@behnel.de] 
Sent: Wednesday, August 19, 2015 2:51 PM
Subject: Re: Logging to a file from a C-extension

Al Pfalzgraf schrieb am 18.08.2015 um 15:07:
> If a logging file is opened at the level of a Python application, how 
> would the log file name be communicated to a C-extension so that 
> logging from the extension would be sent to the same log file?

Writing to the file directly (as was suggested) may not be a good idea as it 
would bypass the log filtering and formatting. Instead, I'd suggest sending 
output to a normal Python Logger object instead.

This is obviously trivial in Cython (where you can just implement it in Python 
code), but you can do the same in C with just the usual C-API overhead.

Stefan


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


Pyitect V2 support for 2.6+ and big chagnes

2015-08-25 Thread ryexander
A while back I posted my plugin framework module asking for feedback

I only got one person to respond but that just fine, they gave me plenty to 
think on. I'm back to showcase my improvements.

https://github.com/Ryex/pyitect

The biggest change in V2 is that Python versions 2.6 and up are supported with 
no loss of functionality. for some reason I blanked the existence of imp I know 
about it but forgot for around a year, it's weird. Regardless, Python 3.3 and 
lower uses imp and python 3.4 and up uses importlib.

The second biggest change is that the magic module PyitectConsumes is no longer 
used for import time component loading. one of the feedback's was that this was 
just too much magic going on with the import machinery.
Instead, pyitect has a empty sub-module pyitect.imports . this module is 
populated with components during import of a plugin module so insted of

from PyitectConsumes import foo

you use

from pyitect.imports import foo

the difference may seem semantic but the difference is that where as 
PyitectConsumes just magically existed during import pyitect.imports always 
exists but is empty unless a plugin module is getting imported


In pyitect that is a difference between import-time and run-time component 
fetching. for former makes components declared in the configuration file of the 
plugin available while the plugin's module is still being loaded. The latter is 
invoked on a plugin system instance via it's load method. Plugins MAY need to 
use run-time component acquisition in V1 this was possible but author of the 
system needed to make the plugin system instance available to the author. V2 
makes this much easier by letting the instance hangout in the pyitect module 
build_system, get_system, and destroy_system all work with a global instance of 
the pyitect.System class.

in V1 version postfixes was a system to provide different types of the same 
component. their use however was a bit arcane. In V2 the functionality of 
post-fixes is instead accomplished with component subtypes.

if a component is names with a doted notations ie. "compa.sub1.sub2"
each part represents a subtype of the part before it. so a "a.b.c" is also a 
"a.b" and an "a" type component. if a component type "a" is requested a "a.b" 
may be returned if an "a" is not available.

all this behavior can of course be modified. 

I've also written up sphinx docs this time 
http://pyitect.readthedocs.org/en/latest/

I would like more feedback if anyone has the time avalible to look at it.

Thanks ~
Benjamin "Ryex" Powers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best strategy for testing class and subclasses in pytest?

2015-08-25 Thread Jean-Michel Pichavant
> From: "C.D. Reimer" 
> Greetings,
> 
> I'm writing a chess engine to learn about Python classes and
> inheritance, and using pytest for the unit test. 
[snip]
> I tried to create a separate class and/or module to import the common
> tests for each class and subclass. My attempts often ended in failure
> with the "RuntimeError: super(): no arguments" message. I couldn't
> find
> a working example on the Internet on how to do that. The pytest
> documentation is all over the place.
> 
> Is there a way to reuse tests in pytest?
> 
> Or should I test everything in the class and test only the
> implemented
> functionality in the subclasses?
> 
> Thank you,
> 
> Chris R.

I've played a little bit with pytest, I was interested in trying since it 
claims to add less boilerplate than unittest.
I've created 2 classes, Piece and Queen, both have the 'isPiece' and 'name' 
property (for the sake of demo).

If you execute the code (python 2.7) with pytest, you'll see that the TestQueen 
class actually execute 2 tests, one inherited from its base test class 
TestPiece.
So in the end, I'd say that you may put all common tests in TestPiece, and each 
specific implementation into TestQueen.


import pytest

class Piece(object):
@property
def isPiece(self): #for the sake of demo
return True
@property
def name(self):
raise NotImplementedError # Piece is a sort of abstract class

class Queen(Piece):
@property
def name(self):
return 'Queen'

class TestPiece(object):
cls = Piece
def test_isPiece(self):
assert self.cls().isPiece
def test_name(self):
with pytest.raises(NotImplementedError):
assert self.cls().name

class TestQueen(TestPiece):
cls = Queen
def test_name(self):
assert self.cls().name == 'Queen'


py.test test.py
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
4 passed in 0.01 seconds


-- IMPORTANT NOTICE: 

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


Re: required help with python code.

2015-08-25 Thread Peter Otten
Srinivas, Jostna wrote:

> I am trying to write a python code to create tableau data extract using
> tableau API.
> 
> In the process I am facing following error.
> 
> Please help me to fix. I tried a lot but couldn't get over net. Its
> critical requirement and we need your help.

Posting a picture turns quoting into typing; this is not a polite way to 
ask. In the future please post text only.

In your screenshot you use the ibm_db.fetch_both() method twice, once as

row = ibm_db.fetch_both(result)
while row:
print row["FSC_YR"]
row = ibm_db.fetch_both(result)

which seems to work, and once as

for i in ibm_db.fetch_both(result):
...

which doesn't. Assuming everything else is correct replacing the for loop 
with a while loop similar to that in step 1 should help.


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


Re: required help with python code.

2015-08-25 Thread Chris Angelico
On Tue, Aug 25, 2015 at 6:20 PM, Srinivas, Jostna
 wrote:
>
> In the process I am facing following error.
>
> Please help me to fix. I tried a lot but couldn’t get over net. Its critical 
> requirement and we need your help.
>

Please do two things to help us to help you:

1) Make a simple file that has as little code as possible, but still
demonstrates the problem. I can't see all of your code, and I have no
idea what you're importing, what else your code's doing, etc.

2) Once you've done that, copy and paste the code and the traceback as
text. Thank you for posting the error and part of the code, but the
screenshot makes it a lot harder to work with, and as mentioned, we
don't have all of the code.

Ideally, code that we can test and run on our own systems would be a
big help, but by the sound of things, you're using a DB2 back end, so
we may well not be able to use that. But if you're using the standard
Python databasing API, we can quite possibly run your code against
PostgreSQL or SQLite3 or some other database.

Thanks!

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


Re: required help with python code.

2015-08-25 Thread Ben Finney
"Srinivas, Jostna"  writes:

> I am trying to write a python code to create tableau data extract
> using tableau API.

What is that? Does it have a website? Does it have its own community of
users and developers?

Your questions about Python are welcome here, and we'll help if we can.
That said, if the thing you're using has its own specific community, you
should also try the forums of that community to get more specific help.

> In the process I am facing following error.

Please don't post attachments, they don't propagate correctly across
this forum.

Instead make a Short, Self-contained, Complete, Correct Example
http://sscce.org/> that we can also execute to see the behaviour.

If it's not Short, you need to contrive a short example that *only*
demonstrates the problem.

If it's not Self-contained and Complete and Correct for demonstrating
the behaviour, you need to refine it until that's the case. Otherwise we
can't see the behaviour you're seeing, which is necessary to understand
what the problem is.

> Please help me to fix. I tried a lot but couldn't get over net. Its
> critical requirement and we need your help.

We can't be held to whatever critical requirements you have; but I
sympathise with your position. Please help us help you, by making a
SSCCE that we can run to see the behaviour.

-- 
 \“Good judgement comes from experience. Experience comes from |
  `\  bad judgement.” —Frederick P. Brooks |
_o__)  |
Ben Finney

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


required help with python code.

2015-08-25 Thread Srinivas, Jostna
Hi,

I am trying to write a python code to create tableau data extract using tableau 
API.

In the process I am facing following error.

Please help me to fix. I tried a lot but couldn't get over net. Its critical 
requirement and we need your help.

[cid:image001.png@01D0DC37.285DEAE0]

r

Regards,
Jostna Srinivas | Staples Enterprise Reporting | m. +91.984.017.8090 | 
jostna.srini...@staples.com


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


TypeCheck vs IsInstance in C API

2015-08-25 Thread Andrew Wang
Hi.

I know this thread is ancient, but I would like to know the answer as well (
https://mail.python.org/pipermail/python-list/2006-May/413542.html).

Thanks.
Andrew
-- 
https://mail.python.org/mailman/listinfo/python-list