Re: Ide or code editor confusion

2016-08-04 Thread Lawrence D’Oliveiro
On Friday, July 22, 2016 at 2:38:10 AM UTC+12, Chris Angelico wrote:
> On Fri, Jul 22, 2016 at 12:22 AM,  sigmaphine1914 wrote:
>> Beginning Python: using Python 2.6 and Python 3.1. By James Payne
>>
>> Part II.
> 
> Ugh, that's extremely old now.

That’s why I’ve come to the conclusion it’s a waste of time buying books on 
computing topics. They start to reek of decay while they’re still on the shelf.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Float

2016-08-04 Thread Lawrence D’Oliveiro
On Sunday, July 31, 2016 at 3:21:09 PM UTC+12, Rustom Mody wrote:
> In writing Tex he went out of his way to implement his own fixed point
> system and avoid using the builtin hardware floating point
> https://en.wikipedia.org/wiki/TeX#Development
> 
> To the extent its feasible it’s advisable to follow the example of Knuth
> [No not writing your own system, but avoiding when/if possible]

This is why IEEE-854 was developed, and why Python has the Decimal type 
.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging (was Re: Why not allow empty code blocks?)

2016-08-04 Thread BartC

On 04/08/2016 04:23, Steven D'Aprano wrote:

On Wed, 3 Aug 2016 08:16 pm, BartC wrote:



So the idea that remembering 'repeat N' is a cognitive burden, and the
myriad string operations for example are not, is ridiculous.


Who says it isn't a cognitive burden? Of course it is.

The difference is that most of the string methods carry their own weight in
usefulness versus burden, and "repeat N" doesn't (according to the core
developers). You have weighed "repeat N" high on the usefulness side and


OK, let's look at some string features.

First, you have string.ascii_uppercase, which is just 
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".


Is that really so indispensable that it has to be built-in to the 
language? Is it that much of a hardship to assign it once and for all to 
some variable?


And 'string.ascii_uppercase' is not that much more concise than just 
writing out the alphabet! In the case of "0123456789", the constant name 
is longer.


Now you have string str.lower, str.upper, and str.swapcase. Clearly one 
of those first two is redundant, as you can implement str.upper by 
writing str.lower().swapcase() for example.


Then these miss a trick by not having an optional length parameter, so 
that you can operate on the first N characters.


Then you can dispense with str.capitalise by writing str.upper(1). (Or 
str.lower().upper(1) if the current case is unknown.)


(And what about str.reverse()? (The comments here about the readability 
of Python code, and who is entitled to express an opinion about it, are 
amusing: 
http://stackoverflow.com/questions/931092/reverse-a-string-in-python))



Compare all that (and I'm sure there's tons more) with, for example, 
just leaving out the 'i in' in 'for range(N):')


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


Re: Debugging (was Re: Why not allow empty code blocks?)

2016-08-04 Thread Chris Angelico
On Thu, Aug 4, 2016 at 7:13 PM, BartC  wrote:
> On 04/08/2016 04:23, Steven D'Aprano wrote:
>>
>> On Wed, 3 Aug 2016 08:16 pm, BartC wrote:
>
>
>>> So the idea that remembering 'repeat N' is a cognitive burden, and the
>>> myriad string operations for example are not, is ridiculous.
>>
>>
>> Who says it isn't a cognitive burden? Of course it is.
>>
>> The difference is that most of the string methods carry their own weight
>> in
>> usefulness versus burden, and "repeat N" doesn't (according to the core
>> developers). You have weighed "repeat N" high on the usefulness side and
>
>
> OK, let's look at some string features.

Be careful: you're looking at two different things here (the 'string'
module, and methods/attributes on the 'str' type).

> First, you have string.ascii_uppercase, which is just
> "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
>
> Is that really so indispensable that it has to be built-in to the language?
> Is it that much of a hardship to assign it once and for all to some
> variable?

Once and for all? You mean like in a module?

> Now you have string str.lower, str.upper, and str.swapcase. Clearly one of
> those first two is redundant, as you can implement str.upper by writing
> str.lower().swapcase() for example.

"Clearly" only if you're thinking ASCII. You can't actually fudge this
either direction:

>>> s = "\u1e9e"
>>> s.lower().swapcase(), s.upper()
('SS', 'ẞ')
>>> s = "\u00df"
>>> s.upper().swapcase(), s.lower()
('ss', 'ß')

> Then these miss a trick by not having an optional length parameter, so that
> you can operate on the first N characters.
>
> Then you can dispense with str.capitalise by writing str.upper(1). (Or
> str.lower().upper(1) if the current case is unknown.)

You have to use the longer form for true equivalence, and then you run
into the same problem as above.

> (And what about str.reverse()? (The comments here about the readability of
> Python code, and who is entitled to express an opinion about it, are
> amusing:
> http://stackoverflow.com/questions/931092/reverse-a-string-in-python))

Slice it backwards. No need for a method, any more than there is need
of a str.charAt() method to get individual characters.

> Compare all that (and I'm sure there's tons more) with, for example, just
> leaving out the 'i in' in 'for range(N):')

If you want to push for a shorter syntax for simple repeat loops, this
has far better chances of landing than "repeat N" has - "for
" is simply an extension of "for  in " that
discards rather than binding. No new keywords introduced, no
fundamentally new looping structure, just the exact same thing as an
existing 'for' loop. The difference between "for thing in collection"
and "for collection" would then be:

# for thing in collection
_it = iter(collection)
while "moar stuff":
try: thing = next(_it)
except StopIteration: break
# loop body goes here

# for collection
_it = iter(collection)
while "moar stuff":
try: next(_it)
except StopIteration: break
# loop body goes here

That wouldn't be a bad thing, IMO. Whether it's worth the various
costs I still don't know, but its costs would be *way* lower than
adding a new keyword to the language, adding a new control flow form,
etc. Less magic. Just the removal of a name binding.

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


Re: Debugging (was Re: Why not allow empty code blocks?)

2016-08-04 Thread Steven D'Aprano
On Thursday 04 August 2016 19:13, BartC wrote:

> On 04/08/2016 04:23, Steven D'Aprano wrote:
>> On Wed, 3 Aug 2016 08:16 pm, BartC wrote:
> 
>>> So the idea that remembering 'repeat N' is a cognitive burden, and the
>>> myriad string operations for example are not, is ridiculous.
>>
>> Who says it isn't a cognitive burden? Of course it is.
>>
>> The difference is that most of the string methods carry their own weight in
>> usefulness versus burden, and "repeat N" doesn't (according to the core
>> developers). You have weighed "repeat N" high on the usefulness side and
> 
> OK, let's look at some string features.
> 
> First, you have string.ascii_uppercase, which is just
> "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
> 
> Is that really so indispensable that it has to be built-in to the
> language? Is it that much of a hardship to assign it once and for all to
> some variable?


/facepalm

It *is* assigned once and for all to some variable. It's a variable in the 
"string" module.

It is neither a built-in value (like None, True or False) nor a language 
feature.


> And 'string.ascii_uppercase' is not that much more concise than just
> writing out the alphabet! In the case of "0123456789", the constant name
> is longer.

The reason for giving constant values a fixed name is not to save keystrokes, 
but to have a consistent, readily understandable, self-descriptive name.

If you say:

from string import digits


that's only 26 keystrokes, including a newline. Compared to:

digits = '1234567890'

which is 22 keystrokes. So it costs you four keystrokes over defining it 
yourself. Big deal.


> Now you have string str.lower, str.upper, and str.swapcase. Clearly one
> of those first two is redundant, as you can implement str.upper by
> writing str.lower().swapcase() for example.

I've already suggested that swapcase() is not very useful, and that it still 
exists only for backwards compatibility. But are you serious about suggesting 
that Python should drop str.upper() in favour of having the user write 
str.lower().swapcase()?

At least put a wink or a smiley there, so we know you aren't a total idiot.


> Then these miss a trick by not having an optional length parameter, so
> that you can operate on the first N characters.

That's actually a nice feature. I might request it. It's too late for Python 
3.6, but maybe 3.7. It would have to take a start and end position, but that's 
actually quite clever.


> Then you can dispense with str.capitalise by writing str.upper(1). (Or
> str.lower().upper(1) if the current case is unknown.)

Backwards compatibility would require it stays even if it became redundant.


> (And what about str.reverse()? 

What about it? The canonical way to spell "reverse a string" is with a slice:

mystring[::-1]


> (The comments here about the readability
> of Python code, and who is entitled to express an opinion about it, are
> amusing:
> http://stackoverflow.com/questions/931092/reverse-a-string-in-python))

Ah, well, Stackoverflow. What did you expect?



-- 
Steve

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


Use pip to install non-python?

2016-08-04 Thread Tennis Smith


I have several utility scripts I want to install in /usr/local/bin.  Some are 
python, some are simple bash scripts.  Can I use pip to install them?  If so, 
can anyone point me to some examples? 

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


Re: Use pip to install non-python?

2016-08-04 Thread Jon Ribbens
On 2016-08-04, Tennis Smith  wrote:
> I have several utility scripts I want to install in /usr/local/bin.
> Some are python, some are simple bash scripts.  Can I use pip to
> install them?  If so, can anyone point me to some examples? 

By the looks of it*, you should be able to do this:

setup(

scripts=[
"scripts/bash1",
"scripts/bash2",
"scripts/bash3",
],
console_scripts=[
"foo=package.module:func1",
"bar=package.module.func2",
"baz=package.module.func3",
],
)

The first list is the list of bash scripts, which will just be copied
into the right place, and the second list is the Python functions you
want calling, and pip will automagically generate the appropriate
script to call your code when the command is executed.

* Barely documented at https://packaging.python.org/distributing/#scripts
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Error message

2016-08-04 Thread GBANE FETIGUE
Hi, 
I am running a python script to run some CURL commands, and return the response 
which is the applicationId and the versionId. I was able to do it. Now the 
versionId value supposed to be used on the second CURL as a value of the 
applications key which is an array. but it doesn't work.I 'll post the error 
after running the command as well as the script. It seems like I have an error 
somewhere because the curl works manually if i run. 

ec2-user@ip-172-31-21-77 playbooks]$ python mmc-uploader.py
  % Total% Received % Xferd  Average Speed   TimeTime Time  Current
 Dload  Upload   Total   SpentLeft  Speed
100  23180   119  100  2199496   9173 --:--:-- --:--:-- --:--:--  9200
Your applicationId is: local$fc9277b0-a5b1-4602-8730-714ab7472744
Your versionId is: local$423da1c8-c4e1-47af-9395-57300f839670
  % Total% Received % Xferd  Average Speed   TimeTime Time  Current
 Dload  Upload   Total   SpentLeft  Speed
100  1259  100  1091  100   168   100k  15868 --:--:-- --:--:-- --:--:--  106k
Final responseApache Tomcat/8.0.26 - Error 
reportH1 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
 H2 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
 H3 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
 BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} 
B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P 
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
 {color : black;}A.name {color : black;}.line {height: 1px; background-color: 
#525D76; border: none;} HTTP Status 415 - type Status reportmessage 
description The server refused this request because the 
request entity is in a format not supported by the reque
 sted resource for the requested method.Apache 
Tomcat/8.0.26
Seems the named id  already exists!

That's the script : 

from subprocess import check_output, STDOUT
import json

response = check_output(["curl", "--basic", "-u", "admin:admin", "-F", 
"file=@/var/lib/jenkins/workspace/Demo-Ci-cd-automation/playbooks/ms3-simple-hello-world-app-1.0.0-SNAPSHOT.zip",
 "-F", "name=ms3-simple-hello-world-app", "-F", "version=1.0.0", "--header", 
"\"Content-Type: multipart/form-data\"", 
"http://52.73.56.141:8080/mmc-console-3.6.2/api/repository";])


try:
parsed_response = json.loads(response)
print "Your applicationId is: " + parsed_response[u'applicationId']
version_id = parsed_response[u'versionId']
print "Your versionId is: " + version_id
except:
print 'Seems the named application already exists!'
print 'Seems the named versionId already exists!'

response = check_output(["curl", "--basic", "-u", "admin:admin", "-d", 
"'{\"name\" : \"ms3-simple-hello-world-app\" , \"servers\": [ 
\"local$d50bdc24-ff04-4327-9284-7bb708e21c25\" ], \"applications\": [ \"" + 
version_id +  "\"]}'", "--header", "\'Content-Type: application/json\'", 
"http://52.73.56.141:8080/mmc-console-3.6.2/api/deployments";])

print 'Final response' + response

try:
  parsed_response = json.loads(response)
  deployid  = parsed_response[u'id']
  print "Your deployid is: " + deployid
except:
print 'Seems the named id  already exists!'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Error message

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 1:31 AM, GBANE FETIGUE  wrote:
> try:
> parsed_response = json.loads(response)
> print "Your applicationId is: " + parsed_response[u'applicationId']
> version_id = parsed_response[u'versionId']
> print "Your versionId is: " + version_id
> except:
> print 'Seems the named application already exists!'
> print 'Seems the named versionId already exists!'
>

This is a very bad idea. You're catching every possible exception and
printing out the same message for all of them. And then continuing
blithely on. Instead, catch ONLY the exceptions you really expect to
be seeing (I'm guessing KeyError here). If anything else goes wrong,
let the exception bubble up.

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


Re: Python Error message

2016-08-04 Thread Steven D'Aprano
On Fri, 5 Aug 2016 01:31 am, GBANE FETIGUE wrote:

> try:
>   parsed_response = json.loads(response)
>   deployid  = parsed_response[u'id']
>   print "Your deployid is: " + deployid
> except:
> print 'Seems the named id  already exists!'


I'm not going to try to debug your code blindfolded with my hands tied
behind my back. Get rid of those "try...except" blocks so that you can see
what error is *actually* happening.

As you have it now, an error happens, somewhere. You don't know where the
error is, or what it is, but Python generates a nice exception showing all
the detail you need to debug.

But you catch that exception, throw it away, and then print a lie.

It is **not true** that the named ID already exists. That is not what the
error is, so why does your script tell a lie?

The output from the server might give you a clue:

"The server refused this request because the request entity is in a format
not supported by the requested resource for the requested method."


Never[1] use a bare "try...except". It is the worst thing you can do to a
Python script, making it almost impossible to debug.

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/

Fix that problem first, get rid of the "try...except" and lying print
messages, and then either the bug will be obvious, or we can debug further.






[1] There are exceptions to this rule, for experts. But if you need to ask
what they are, you're not ready to know.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Python Error message

2016-08-04 Thread Igor Korot
Steven,

On Thu, Aug 4, 2016 at 11:56 AM, Steven D'Aprano
 wrote:
> On Fri, 5 Aug 2016 01:31 am, GBANE FETIGUE wrote:
>
>> try:
>>   parsed_response = json.loads(response)
>>   deployid  = parsed_response[u'id']
>>   print "Your deployid is: " + deployid
>> except:
>> print 'Seems the named id  already exists!'
>
>
> I'm not going to try to debug your code blindfolded with my hands tied
> behind my back. Get rid of those "try...except" blocks so that you can see
> what error is *actually* happening.
>
> As you have it now, an error happens, somewhere. You don't know where the
> error is, or what it is, but Python generates a nice exception showing all
> the detail you need to debug.
>
> But you catch that exception, throw it away, and then print a lie.
>
> It is **not true** that the named ID already exists. That is not what the
> error is, so why does your script tell a lie?
>
> The output from the server might give you a clue:
>
> "The server refused this request because the request entity is in a format
> not supported by the requested resource for the requested method."
>
>
> Never[1] use a bare "try...except". It is the worst thing you can do to a
> Python script, making it almost impossible to debug.
>
> https://realpython.com/blog/python/the-most-diabolical-python-antipattern/
>
> Fix that problem first, get rid of the "try...except" and lying print
> messages, and then either the bug will be obvious, or we can debug further.
>
>
>
>
>
>
> [1] There are exceptions to this rule, for experts. But if you need to ask
> what they are, you're not ready to know

But even the experts will never write such a code - you never know what happens
in a month. Server might throw some new exception, you may move on to
a different project,
etc, etc. ;-)

Thank you.

>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Error message

2016-08-04 Thread MRAB

On 2016-08-04 16:31, GBANE FETIGUE wrote:

Hi,
I am running a python script to run some CURL commands, and return the response 
which is the applicationId and the versionId. I was able to do it. Now the 
versionId value supposed to be used on the second CURL as a value of the 
applications key which is an array. but it doesn't work.I 'll post the error 
after running the command as well as the script. It seems like I have an error 
somewhere because the curl works manually if i run.


What do you put on the command line when you do it manually?


ec2-user@ip-172-31-21-77 playbooks]$ python mmc-uploader.py
  % Total% Received % Xferd  Average Speed   TimeTime Time  Current
 Dload  Upload   Total   SpentLeft  Speed
100  23180   119  100  2199496   9173 --:--:-- --:--:-- --:--:--  9200
Your applicationId is: local$fc9277b0-a5b1-4602-8730-714ab7472744
Your versionId is: local$423da1c8-c4e1-47af-9395-57300f839670
  % Total% Received % Xferd  Average Speed   TimeTime Time  Current
 Dload  Upload   Total   SpentLeft  Speed
100  1259  100  1091  100   168   100k  15868 --:--:-- --:--:-- --:--:--  106k
Final responseApache Tomcat/8.0.26 - Error reportH1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY 
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name 
{color : black;}.line {height: 1px; background-color: #525D76; border: none;} HTTP Status 415 - type Status 
reportmessage description The server refused this request because the request entity is in a format not supported by the req

ue

 sted resource for the requested method.Apache 
Tomcat/8.0.26
Seems the named id  already exists!

That's the script :

from subprocess import check_output, STDOUT
import json

response = check_output(["curl", "--basic", "-u", "admin:admin", "-F", 
"file=@/var/lib/jenkins/workspace/Demo-Ci-cd-automation/playbooks/ms3-simple-hello-world-app-1.0.0-SNAPSHOT.zip", "-F", "name=ms3-simple-hello-world-app", "-F", 
"version=1.0.0", "--header", "\"Content-Type: multipart/form-data\"", "http://52.73.56.141:8080/mmc-console-3.6.2/api/repository";])


try:
parsed_response = json.loads(response)
print "Your applicationId is: " + parsed_response[u'applicationId']
version_id = parsed_response[u'versionId']
print "Your versionId is: " + version_id


Don't use a bare except because it'll catch _ANY_ exception, including 
NameError, which could happen if you accidentally misspell a name.



except:
print 'Seems the named application already exists!'
print 'Seems the named versionId already exists!'

This look likes it passes curl some JSON wrapped in "'", so curl won't 
see something like this:


{"key": "value"}

(a dict), it'll see something like this:

'{"key": "value"}'

(a string delimited by '...') which isn't valid JSON.


response = check_output(["curl", "--basic", "-u", "admin:admin", "-d", "'{\"name\" : \"ms3-simple-hello-world-app\" , \"servers\": [ 
\"local$d50bdc24-ff04-4327-9284-7bb708e21c25\" ], \"applications\": [ \"" + version_id +  "\"]}'", "--header", "\'Content-Type: application/json\'", 
"http://52.73.56.141:8080/mmc-console-3.6.2/api/deployments";])

print 'Final response' + response

try:
  parsed_response = json.loads(response)
  deployid  = parsed_response[u'id']
  print "Your deployid is: " + deployid


Another bare except!


except:
print 'Seems the named id  already exists!'


'check_output' and related functions/methods will do the quoting for you.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Error message

2016-08-04 Thread MRAB

On 2016-08-04 17:09, Igor Korot wrote:

Steven,

On Thu, Aug 4, 2016 at 11:56 AM, Steven D'Aprano
 wrote:

On Fri, 5 Aug 2016 01:31 am, GBANE FETIGUE wrote:


try:
  parsed_response = json.loads(response)
  deployid  = parsed_response[u'id']
  print "Your deployid is: " + deployid
except:
print 'Seems the named id  already exists!'



I'm not going to try to debug your code blindfolded with my hands tied
behind my back. Get rid of those "try...except" blocks so that you can see
what error is *actually* happening.

As you have it now, an error happens, somewhere. You don't know where the
error is, or what it is, but Python generates a nice exception showing all
the detail you need to debug.

But you catch that exception, throw it away, and then print a lie.

It is **not true** that the named ID already exists. That is not what the
error is, so why does your script tell a lie?

The output from the server might give you a clue:

"The server refused this request because the request entity is in a format
not supported by the requested resource for the requested method."


Never[1] use a bare "try...except". It is the worst thing you can do to a
Python script, making it almost impossible to debug.

https://realpython.com/blog/python/the-most-diabolical-python-antipattern/

Fix that problem first, get rid of the "try...except" and lying print
messages, and then either the bug will be obvious, or we can debug further.






[1] There are exceptions to this rule, for experts. But if you need to ask
what they are, you're not ready to know


But even the experts will never write such a code - you never know what happens
in a month. Server might throw some new exception, you may move on to
a different project,
etc, etc. ;-)

In those rare occasions when you do write a bare except, you'd re-raise 
the exception afterwards:


try:
...
except:
print("'tis but a scratch!")
raise


Thank you.



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


Re: Python Error message

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 2:09 AM, Igor Korot  wrote:
>> [1] There are exceptions to this rule, for experts. But if you need to ask
>> what they are, you're not ready to know
>
> But even the experts will never write such a code - you never know what 
> happens
> in a month. Server might throw some new exception, you may move on to
> a different project,
> etc, etc. ;-)

Yes, in those situations you don't write a bare except :) As Steven
said, there ARE legit uses; most of them fall under the description
"boundary location".

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


Tracing memory in production django process with systemtap

2016-08-04 Thread Lei G
Hi all,

  Recently I met some python memory problems with Django and uwsgi, and found 
to find exactly which part is causing the problem, so I went to use systemtap 
to tracing the problem, and here are some problems that I met:

  It seems python needs to patch some 'probes' into the source code, but the 
patch for python version like 2.x ~ 3.x is not in the main python branch,

  If someone has used it, I want to know whether they are safe in the 
production? 

  patch list: https://www.jcea.es/artic/python_dtrace.htm
  bug list: http://bugs.python.org/issue13405
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tracing memory in production django process with systemtap

2016-08-04 Thread Lei G
在 2016年8月5日星期五 UTC+8上午1:41:04,Lei G写道:
> Hi all,
> 
>   Recently I met some python memory problems with Django and uwsgi, and found 
> to find exactly which part is causing the problem, so I went to use systemtap 
> to tracing the problem, and here are some problems that I met:
> 
>   It seems python needs to patch some 'probes' into the source code, but the 
> patch for python version like 2.x ~ 3.x is not in the main python branch,
> 
>   If someone has used it, I want to know whether they are safe in the 
> production? 
> 
>   patch list: https://www.jcea.es/artic/python_dtrace.htm
>   bug list: http://bugs.python.org/issue13405

Or some advice to do this debugging on ubuntu + systemtap + python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ide or code editor confusion

2016-08-04 Thread Michael Torrie
On 08/04/2016 01:23 AM, Lawrence D’Oliveiro wrote:
> On Friday, July 22, 2016 at 2:38:10 AM UTC+12, Chris Angelico wrote:
>> On Fri, Jul 22, 2016 at 12:22 AM,  sigmaphine1914 wrote:
>>> Beginning Python: using Python 2.6 and Python 3.1. By James Payne
>>>
>>> Part II.
>>
>> Ugh, that's extremely old now.
> 
> That’s why I’ve come to the conclusion it’s a waste of time buying books on 
> computing topics. They start to reek of decay while they’re still on the 
> shelf.

Except for old Unix books!  I've got an old book on sed and awk that
will likely be in date for years to come!  There's also an old book on
vi, another on regular expression.  So some things are invaluable
references.  Moving targets like Python, that's another story of course!

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


Re: Debugging (was Re: Why not allow empty code blocks?)

2016-08-04 Thread Terry Reedy

Making repeat a keyword would have such an extremely high cost
that it is out of the question and not a sane proposal.
To start with, it is used in two major, widely used APIs.

itertools.repeat + 50 uses in other itertools and tests
 + all the imports and and uses of repeat()
 in code all over the world.

timeit command line option
timeit.timeit(..., repeat=3) parameter name
timeit.repeat() function  + tests
 + all the scripts (some in other languages) using 'repeat'
 as a command line option and all the python code using
 the parameter or function.

There are other C-coded public APIs that use repeat.  One in xml.etree 
was revealed by the grep hit for the Python-coded test.


Other places in the *Python-coded* stdlib that would break.

distutils\fancy_getopt.py: 141: self.repeat = {}
lib2to3\fixes\fix_operator.py: 8: operator.repeat(obj, n) ...
lib2to3\patcomp.py: 105: repeat = None
lib2to3\patcomp.py: 139: def compile_basic(self, nodes, repeat=None):
lib2to3\tests\test_fixers.py: 4494: b = "operator.repeat(x, n)"
test\test_faulthandler.py: 533: repeat = {repeat}
test\test_faulthandler.py: 539: def func(timeout, repeat, ...
test\test_xml_etree.py: 1784:  for dumper, loader in 
product(self.modules, repeat=2):

typing.py: 373:   def repeat(x: T, n: int) -> Sequence[T]:

--
Terry Jan Reedy

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


Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
I'm processing a lot of dirty CSV files and would like to track the bad
codes that are raising UnicodeErrors. I'm struggling how to figure out
what the exact codes are so I can track them, them remove them, and then
repeat the decoding process for the current line until the line has been
fully decoded so I can pass this line on to the CSV reader. At a high
level it seems that I need to wrap the decoding of a line until it
passes with out any errors. Any suggestions appreciated.

Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ide or code editor confusion

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 4:36 AM, Michael Torrie  wrote:
> On 08/04/2016 01:23 AM, Lawrence D’Oliveiro wrote:
>> On Friday, July 22, 2016 at 2:38:10 AM UTC+12, Chris Angelico wrote:
>>> On Fri, Jul 22, 2016 at 12:22 AM,  sigmaphine1914 wrote:
 Beginning Python: using Python 2.6 and Python 3.1. By James Payne

 Part II.
>>>
>>> Ugh, that's extremely old now.
>>
>> That’s why I’ve come to the conclusion it’s a waste of time buying books on 
>> computing topics. They start to reek of decay while they’re still on the 
>> shelf.
>
> Except for old Unix books!  I've got an old book on sed and awk that
> will likely be in date for years to come!  There's also an old book on
> vi, another on regular expression.  So some things are invaluable
> references.  Moving targets like Python, that's another story of course!

Anything that focuses on specifics will get out of date, but the
generalities don't. Here in the 2010s, I'm passing on to my students
design advice (eg relational database schemas, laying out program
code) that I learned from my father in the 1990s, and which he learned
in the 1970s, and which probably have been passed down since the
invention of programming, back in about 4004 BC. So there's often
*something* you can learn from an old book - but I still wouldn't
recommend a novice start out by picking up something that starts with
the proper way to install hard drive platters in an IBM System/360,
even if it does have a lot of sage wisdom in it :)

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


Re: Debugging (was Re: Why not allow empty code blocks?)

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 4:37 AM, Terry Reedy  wrote:
> Making repeat a keyword would have such an extremely high cost
> that it is out of the question and not a sane proposal.
> To start with, it is used in two major, widely used APIs.
>
> itertools.repeat + 50 uses in other itertools and tests
> timeit.repeat() function  + tests

Ooh, time to break out the thesaurus!

rerun, rehash, reiterate [1], replicate, reproduce, recount, reprise,
retread, relive, vamp_till_ready

I'm sure we can come up with something!

ChrisA

[1] included mainly to troll the people who want some definition of "reiterable"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 4:47 AM, Malcolm Greene  wrote:
> I'm processing a lot of dirty CSV files and would like to track the bad
> codes that are raising UnicodeErrors. I'm struggling how to figure out
> what the exact codes are so I can track them, them remove them, and then
> repeat the decoding process for the current line until the line has been
> fully decoded so I can pass this line on to the CSV reader. At a high
> level it seems that I need to wrap the decoding of a line until it
> passes with out any errors. Any suggestions appreciated.

Remove them? Not sure what you mean, exactly; but would an
errors="backslashreplace" decode do the job? Something like (assuming
you use Python 3):

def read_dirty_file(fn):
with open(fn, encoding="utf-8", errors="backslashreplace") as f:
for row in csv.DictReader(f):
process(row)

You'll get Unicode text, but any bytes that don't make sense in UTF-8
will be represented as eg \x80, with an actual backslash. Or use
errors="replace" to hide them all behind U+FFFD, or other forms of
error handling. That'll get done at a higher level than the CSV
reader, like you suggest.

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


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
Hi Chris,

Thanks for your suggestions. I would like to capture the specific bad
codes *before* they get replaced. So if a line of text has 10 bad codes
(each one raising UnicodeError), I would like to track each exception's
bad code but still return a valid decode line when finished. 

My goal is to count the total number of UnicodeExceptions within a file
(as a data quality metric) and track the frequency of specific bad
code's (via a collections.counter dict) to see if there's a pattern that
can be traced to bad upstream process.

Malcolm


Remove them? Not sure what you mean, exactly; but would an
errors="backslashreplace" decode do the job? Something like (assuming
you use Python 3):

def read_dirty_file(fn):
with open(fn, encoding="utf-8", errors="backslashreplace") as f:
for row in csv.DictReader(f):
process(row)

You'll get Unicode text, but any bytes that don't make sense in UTF-8
will be represented as eg \x80, with an actual backslash. Or use
errors="replace" to hide them all behind U+FFFD, or other forms of
error handling. That'll get done at a higher level than the CSV
reader, like you suggest.

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


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread MRAB

On 2016-08-04 20:22, Malcolm Greene wrote:

Hi Chris,

Thanks for your suggestions. I would like to capture the specific bad
codes *before* they get replaced. So if a line of text has 10 bad codes
(each one raising UnicodeError), I would like to track each exception's
bad code but still return a valid decode line when finished.

My goal is to count the total number of UnicodeExceptions within a file
(as a data quality metric) and track the frequency of specific bad
code's (via a collections.counter dict) to see if there's a pattern that
can be traced to bad upstream process.


You could catch the UnicodeDecodeError exception and look at its attributes:

try:
b'\x80'.decode('utf-8')
except UnicodeDecodeError as e:
print('Failed to decode')
print('e.start is', e.start)
print('e.end is', e.end)
else:
print('Decoded successfully')


It prints:

Failed to decode
e.start is 0
e.end is 1


Malcolm


Remove them? Not sure what you mean, exactly; but would an
errors="backslashreplace" decode do the job? Something like (assuming
you use Python 3):

def read_dirty_file(fn):
with open(fn, encoding="utf-8", errors="backslashreplace") as f:
for row in csv.DictReader(f):
process(row)

You'll get Unicode text, but any bytes that don't make sense in UTF-8
will be represented as eg \x80, with an actual backslash. Or use
errors="replace" to hide them all behind U+FFFD, or other forms of
error handling. That'll get done at a higher level than the CSV
reader, like you suggest.




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


Re: Python Error message

2016-08-04 Thread Terry Reedy

On 8/4/2016 12:19 PM, MRAB wrote:


In those rare occasions when you do write a bare except,


A bare "except:" is never needed and in my opinion, and that of others, 
one should never write one (except possibly for experimentation). Be 
explicit and write "except BaseException:" or "except Exception:", 
whichever one is the actual intent.


> you'd re-raise the exception afterwards:

As a general rule, this is wrong, just as this rule is wrong for other 
exception blocks.



try:
...
except:
print("'tis but a scratch!")
raise


This is right when one wants to do something *in addition to* the normal 
handling, such as log errors to a file, but is wrong when wants to do 
something *instead of* allowing the normal handling.


An example of the latter is when one writes code in Python to execute 
'other' code.  (IDLE is one example.  It both executes user statements 
and evals user expressions.)  One needs "except BaseException:"  to 
isolate the interpreter from exceptions raised in the interpreted code. 
(It would be wrong for IDLE to stop because a user submitted code that 
raises, whether intentionally or accidentally)  A 'raise' that throws 
the exception into the interpreter is likely the worst thing to do.


--
Terry Jan Reedy

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


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Random832
On Thu, Aug 4, 2016, at 15:22, Malcolm Greene wrote:
> Hi Chris,
> 
> Thanks for your suggestions. I would like to capture the specific bad
> codes *before* they get replaced. So if a line of text has 10 bad codes
> (each one raising UnicodeError), I would like to track each exception's
> bad code but still return a valid decode line when finished. 

Look into writing your own error handler - there's enough information
provided to do this.

https://docs.python.org/3/library/codecs.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Error message

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 5:36 AM, Terry Reedy  wrote:
> An example of the latter is when one writes code in Python to execute
> 'other' code.  (IDLE is one example.  It both executes user statements and
> evals user expressions.)  One needs "except BaseException:"  to isolate the
> interpreter from exceptions raised in the interpreted code. (It would be
> wrong for IDLE to stop because a user submitted code that raises, whether
> intentionally or accidentally)  A 'raise' that throws the exception into the
> interpreter is likely the worst thing to do.

This is a classic example of a "boundary location". Another extremely
common example is a web server: if an exception bubbles out of a
request handler function, the outer wrapper code should catch that,
log it, and send a 500 back to the client.

But none of this is what the OP is doing.

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


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 5:22 AM, Malcolm Greene  wrote:
> Thanks for your suggestions. I would like to capture the specific bad
> codes *before* they get replaced. So if a line of text has 10 bad codes
> (each one raising UnicodeError), I would like to track each exception's
> bad code but still return a valid decode line when finished.
>

Interesting. Sounds to me like the simplest option is to open the file
as binary, split it on b"\n", and decode line by line before giving it
to the csv module. The csv.reader "csvfile" argument doesn't actually
have to be a file - it can be anything that yields lines. So you can
put a generator in between, like this:

def decode(binary):
for line in binary:
try:
yield line.decode("utf-8")
except UnicodeDecodeError:
log_stats()

def read_dirty_file(fn):
with open(fn, "rb") as f:
for row in csv.DictReader(decode(f)):
process(row)

Or what Random said, which is also viable.

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


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Michael Selik
On Thu, Aug 4, 2016 at 3:24 PM Malcolm Greene  wrote:

> Hi Chris,
>
> Thanks for your suggestions. I would like to capture the specific bad
> codes *before* they get replaced. So if a line of text has 10 bad codes
> (each one raising UnicodeError), I would like to track each exception's
> bad code but still return a valid decode line when finished.
>
> My goal is to count the total number of UnicodeExceptions within a file
> (as a data quality metric) and track the frequency of specific bad
> code's (via a collections.counter dict) to see if there's a pattern that
> can be traced to bad upstream process.
>

Give this a shot (below). It seems to do what you want.


import csv
from collections import Counter
from io import BytesIO

def _cleanline(line, counts=Counter()):
try:
return line.decode()
except UnicodeDecodeError as e:
counts[line[e.start:e.end]] += 1
return line[:e.start].decode() + _cleanline(line[e.end:], counts)

def cleanlines(fp):
'''
convert data to text; track decoding errors
``fp`` is an open file-like iterable of lines'
'''
cleanlines.errors = Counter()
for line in fp:
yield _cleanline(line, cleanlines.errors)

f = BytesIO(b'''\
this,is line,one
line two,has junk,\xffin it
so does,\xfa\xffline,three
''')

for row in csv.reader(cleanlines(f)):
print(row)

print(cleanlines.errors.most_common())
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
Wow!!! A huge thank you to all who replied to this thread!

Chris: You gave me some ideas I will apply in the future.

MRAB: Thanks for exposing me to the extended attributes of the UnicodeError 
object (e.start, e.end, e.object).

Mike: Cool example! I like how _cleanlines() recursively calls itself to keep 
cleaning up a line after an error is handled. Your code solved the mystery of 
how to recover from a UnicodeError and keep decoding.

Random832: Your suggestion to write a custom codecs handler was great. Sample 
below for future readers reviewing this thread.

# simple codecs custom error handler
import codecs

def custom_unicode_error_handler(e):
 bad_bytes = e.object[e.start:e.end]
 print( 'Bad bytes: ' + bad_bytes.hex())
 return ('', e.end)

codecs.register_error('custom_unicode_error_handler',
custom_unicode_error_handler)

Malcolm

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


Win32 API in pywin32

2016-08-04 Thread jj0gen0info
According to Python.org Mark Hammond has an Add-on (pywin32) that supports 
Win32 and COM.

Does anyone know if the Add-on covers all Win32 API functions, and if not is 
there a list of the subset of Win32 API functions it does include?

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


Re: can't add variables to instances of built-in classes

2016-08-04 Thread Lawrence D’Oliveiro
On Thursday, August 4, 2016 at 3:07:17 PM UTC+12, Chris Angelico wrote:
> On Thu, Aug 4, 2016 at 12:34 PM, Lawrence D’Oliveiro wrote:
>> On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote:
>>
>>> Using __slots__ basically takes your object down to the level of a
>>> Java one.
>>
>> Is Java like a bogeyman you use to scare people with if they don’t write
>> Python code the way you like it?
> 
> LOL! Not really; it's just that Java's objects are way less featured
> than Python's.

Using Java as an example of how it can keep you out of trouble where Python 
won’t is fine; using it as a stick to commit personal attacks on people is not.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Win32 API in pywin32

2016-08-04 Thread Lawrence D’Oliveiro
On Friday, August 5, 2016 at 11:50:28 AM UTC+12, [email protected] wrote:
> According to Python.org Mark Hammond has an Add-on (pywin32) that supports
> Win32 and COM.

Are people still using Win32? I thought Windows went 64-bit years ago.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: make an object read only

2016-08-04 Thread Lawrence D’Oliveiro
On Wednesday, August 3, 2016 at 3:13:01 AM UTC+12, Robin Becker wrote:
> A reportlab user found he was doing the wrong thing by calling
> canvas.save repeatedly, our documentation says you should not use Canvas
> objects after the save method has been used. The user had mixed results :(

As GvR has said: “we’re all consenting adults here”.

In other words, we”re capable of coping with the consequences of our actions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Win32 API in pywin32

2016-08-04 Thread Igor Korot
Hi,

On Thu, Aug 4, 2016 at 4:57 PM, Lawrence D’Oliveiro
 wrote:
> On Friday, August 5, 2016 at 11:50:28 AM UTC+12, [email protected] wrote:
>> According to Python.org Mark Hammond has an Add-on (pywin32) that supports
>> Win32 and COM.
>
> Are people still using Win32? I thought Windows went 64-bit years ago.

This is the question about Win API calls

Thank you.

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


Re: Win32 API in pywin32

2016-08-04 Thread iMath
On Friday, August 5, 2016 at 7:50:28 AM UTC+8, [email protected] wrote:
> According to Python.org Mark Hammond has an Add-on (pywin32) that supports 
> Win32 and COM.
> 
> Does anyone know if the Add-on covers all Win32 API functions, and if not is 
> there a list of the subset of Win32 API functions it does include?
> 
> J.

According to my experience , pywin32 doesn't  covers all Win32 API functions 
but most of them , so for these not supported functions, you could resort to 
ctypes
,and  there seems no list of the subset of Win32 API functions it does include.

You can contact with the developers of pywin32 using the mailing list  
[email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


get a certain request url during Loading a web page

2016-08-04 Thread iMath
During Loading this web page(http://www.iqiyi.com/v_19rrkkri8k.html) , the 
browser makes many requests,now I need a certain request url (e.g.starts with 
'http://cache.video.qiyi.com/vms?') during the Loading process ,and the request 
is made on condition that the adobe flash player plugin for NPAPI is enabled , 
so any way to get the url via python ?

P.S. Better to show some code, I am new to this area.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Win32 API in pywin32

2016-08-04 Thread eryk sun
On Fri, Aug 5, 2016 at 12:25 AM, iMath  wrote:
> On Friday, August 5, 2016 at 7:50:28 AM UTC+8, [email protected] wrote:
>> According to Python.org Mark Hammond has an Add-on (pywin32) that supports 
>> Win32 and COM.
>>
>> Does anyone know if the Add-on covers all Win32 API functions, and if not is 
>> there a list of the subset of Win32 API functions it does include?
>>
>> J.
>
> According to my experience , pywin32 doesn't  covers all Win32 API functions 
> but most of them , so for these not supported functions, you could resort to 
> ctypes
> ,and  there seems no list of the subset of Win32 API functions it does 
> include.
>
> You can contact with the developers of pywin32 using the mailing list  
> [email protected]

Currently I just search with a filter of "site:activestate.com"
because they have the PyWin32 docs online.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime vs Arrow vs Pendulum vs Delorean vs udatetime

2016-08-04 Thread Steven D'Aprano
On Fri, 5 Aug 2016 08:41 am, [email protected] wrote:

> I hereby ask that only people who know and use Python reply, not the
> theoretical idiots who could not fight their way out of a wet paper bag. 

So it's only people who are theoretically idiots that are prohibited from
replying? Actual, proven idiots are permitted to reply.

Awesome! Looking forward to the posts from actual idiots, and people who can
fight their way out of wet paper bags.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Win32 API in pywin32

2016-08-04 Thread Lawrence D’Oliveiro
On Friday, August 5, 2016 at 12:06:23 PM UTC+12, Igor Korot wrote:
> 
> On Thu, Aug 4, 2016 at 4:57 PM, Lawrence D’Oliveiro wrote:
>> On Friday, August 5, 2016 at 11:50:28 AM UTC+12, [email protected] wrote:
>>> According to Python.org Mark Hammond has an Add-on (pywin32) that
>>> supports Win32 and COM.
>>
>> Are people still using Win32? I thought Windows went 64-bit years ago.
> 
> This is the question about Win API calls
> 
> Thank you.

This is a Python group.

You’re welcome.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tcl/Tk for Python 3.6.0a3 on Os X 10.9.5

2016-08-04 Thread Lawrence D’Oliveiro
On Tuesday, August 2, 2016 at 8:21:57 PM UTC+12, Valeria Munoz wrote:
> 
> I have downloaded Python 3.6.0a3 on a Mac 10.9.5 and realized that I also
> need to download an Active Tcl for it.

Python should already come with Tk . 
Tcl is an entirely separate language from Python. While it is where Tk 
originated, you don’t need it to use Tk with Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Is Activestate's Python recipes broken?

2016-08-04 Thread Steven D'Aprano
Log in to Activestate:

https://code.activestate.com/recipes/langs/python/new/

and click "Add a Recipe". I get 


Forbidden

You don't have permission to access /recipes/add/ on this server.
Apache Server at code.activestate.com Port 443



Broken for everyone, or just for me?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


RE: Issue with ctypes and callback functions

2016-08-04 Thread Bill Somerville
-Original Message-
From: eryk sun [mailto:[email protected]] 

from_param is a hook method for a type that's set in a function pointer's 
argtypes. It gets called to convert an argument when the function pointer is 
called from Python. The return value can be a ctypes instance, an object with a 
hard-coded conversion (e.g. a string or integer), or an object that defines an 
_as_parameter_ attribute.

Only ctypes types are supported in callbacks, which unfortunately isn't 
documented clearly. Specifically, the class dict needs to be an extended C 
storage dict (i.e. StgDictObject), either to look up the getfunc of a simple 
type or to ensure that instantiating a non-simple type returns a ctypes 
instance (i.e. CDataObject) with a known size.
The relevant code in _CallPythonObject is as follows (when stripped of 
declarations and error handling):

cnv = PySequence_GetItem(converters, i);
dict = PyType_stgdict(cnv);
if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) {
v = dict->getfunc(*pArgs, dict->size);
PyTuple_SET_ITEM(arglist, i, v);
} else if (dict) {
obj = (CDataObject *)PyObject_CallFunctionObjArgs(cnv, NULL);
memcpy(obj->b_ptr, *pArgs, dict->size);
PyTuple_SET_ITEM(arglist, i, (PyObject *)obj);
} else {
PyErr_SetString(PyExc_TypeError,
"cannot build parameter");

I don't have much experience with SWIG. Does it provide some means to 
instantiate a wrapped type from an address? If it does, then you can use a void 
pointer as the callback parameter.

Hi Eryk,

Thanks for looking at this. I had got as far as looking at the code above and 
guessed that only ctypes types were supported. This does seem like a bit of a 
functionality gap that cannot be solved easily by users of ctypes. It would 
appear to be fairly easy to define a protocol for objects that can be 
instantiated from ctypes arguments before passing to Python callables, i.e. 
some requirement for a class method factory that takes a ctypes type as a 
parameter and returns a Python object. This would seem to be a natural 
complement to from_param()/_as_parameter_ for the C/C++ to Python direction of 
function calls.

I had started with an implementation that converted a c_void_p value and 
instantiated the required SWIG Python wrapper. This is not too difficult as 
SWIG allows its types to be extended in both the C/C++ world and the Python 
world. The result is only a one liner for each callback parameter but it is 
still ugly as the writer of the callback has to know what type the argument is 
and remember to call the "constructor" before accessing the attributes of the 
object.

My requirement is to wrap an API for testers and customers to write simple test 
cases and any ugliness in the test cases is undesirable given that the users 
will probably not be Python experts and maybe not even developers.

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


Re: Tcl/Tk for Python 3.6.0a3 on Os X 10.9.5

2016-08-04 Thread Zachary Ware
On Thu, Aug 4, 2016 at 8:25 PM, Lawrence D’Oliveiro
 wrote:
> On Tuesday, August 2, 2016 at 8:21:57 PM UTC+12, Valeria Munoz wrote:
>>
>> I have downloaded Python 3.6.0a3 on a Mac 10.9.5 and realized that I also
>> need to download an Active Tcl for it.
>
> Python should already come with Tk 
> . Tcl is an entirely separate 
> language from Python. While it is where Tk originated, you don’t need it to 
> use Tk with Python.

This is very inaccurate.  From the first line of the second paragraph
at your link, "The tkinter package is a thin object-oriented layer on
top of Tcl/Tk."

Tk is very closely tied to Tcl (in fact a significant fraction of Tk
is implemented in Tcl), and a Tcl interpreter (of the exact same
version) is required to use Tk.  Python's tkinter package dynamically
links to libtcl and libtk to embed a Tcl interpreter, and all GUI
interactions are handled by Tcl calling Python callbacks.

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


Re: Is Activestate's Python recipes broken?

2016-08-04 Thread Jason Friedman
>
> Log in to Activestate:
>
> https://code.activestate.com/recipes/langs/python/new/
>
> and click "Add a Recipe". I get
>
>
> Forbidden
>
> You don't have permission to access /recipes/add/ on this server.
> Apache Server at code.activestate.com Port 443
>
>
>
> Broken for everyone, or just for me?
>

Broken for me, too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Win32 API in pywin32

2016-08-04 Thread jj0gen0info
Thanks for the info iMath, I will try to contact the developers as you've 
suggested.
-- 
https://mail.python.org/mailman/listinfo/python-list


Installing Python 2.7 for all users on SLES 11

2016-08-04 Thread Bo Stone
I installed Python 2.7 on SLES 11 box that previously was running Python 2.6. 
To do so I used a script described in this post 
(http://stackoverflow.com/a/11371726/135946) and run it as a root user. 
Everything went well but when it was done I discovered few issues:

1. No symbolic links were created and no path updated so I had to manually 
update the path to link to the new installation bin directory /opt/python2.7/bin
2. Everything runs good until I switch from root to the normal user at which 
point Python shell runs but some modules I installed such as PyYAML are 
missing. Again, these are OK when I run Python as root
3. As a regular user I'm not able to run pip, easy_install and wheel. For pip I 
get "ImportError: No module named pkg_resources"

This question is also posted to Stackoverflow here: 
http://stackoverflow.com/q/38749809/135946

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