Re: ssl proxy server

2013-05-15 Thread Zachary Ware
On Wed, May 15, 2013 at 1:58 PM, Chris “Kwpolska” Warrick
 wrote:
> On Tue, May 14, 2013 at 9:14 PM, Skip Montanaro  wrote:
>> I haven't touched the SpamBayes setup for the usenet-to-mail gateway
>> in a long while.  For whatever reason, this message was either held
>> and then approved by the current list moderator(s), or (more likely)
>> slipped through unscathed.  No filter is perfect.
>>
>> Skip
>
> A filter on this guy altogether would be.  He sent 24 messages there
> since February 25.  All of them spam.
>

You can always set your own filter.  I had been somewhat confused by
this thread until I realized the initial message had been killed by a
filter I set up a while back.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I just wrote my first Python program a guessing game and it exits with an error I get this.

2013-06-05 Thread Zachary Ware
On Wed, Jun 5, 2013 at 10:14 AM, Armando Montes De Oca
 wrote:
> On Wednesday, June 5, 2013 10:40:52 AM UTC-4, Armando Montes De Oca wrote:
>> Traceback (most recent call last):
>>
>>   File "Guessing_Game.py", line 32, in 
>>
>> input (enter)
>>
>>   File "", line 0
>>
>> ^
>>
>> SyntaxError: unexpected EOF while parsing
>>
>> --
>>
>> (program exited with code: 1)
>>
>> This is the only place a string is used:
>>
>> else:
>>
>>   print "Sorry you loose the game."
>>
>>   computernum = str(computernum)
>>
>>   print " The computers number was!"+ computernum
>>
>>   input (enter)
>>
>>   sys.exit(0)
>> Yes I did declare and enter value it is:
>  enter = "Please Press Enter To Continue..."
>> Thank You,

Hi Armando,

There are a few problems with your question.  To be able to help you,
we really need to know your Python version, what OS you are using, how
you are running your script, and at what point you get the error in
question.  Also, just a snippet of code from the middle of the script
is useless to us, we need to see a complete, runnable program that
shows your problem.

In this particular case, though, I can deduce a few things and, I
believe, answer your question.

First, your Python version.  Judging by your use of 'print' as a
statement rather than a function, it looks like you're using Python 2,
probably 2.7.  This is a big factor in your problem.

Second, when you get your error.  I'm betting it's after you see
"Please Press Enter To Continue..." and have pressed 'enter'.

Now the kicker: I can reproduce your problem with the following
complete program:

# error_test.py
input('Press enter')
# end of error_test.py

The problem here is that you are using 'input()' in Python 2.  In
Python 2, 'input()' is equivalent to 'eval(raw_input())', which means
that anything you give to 'input' will be evaluated in the current
scope, and this is a HUGE security hole.  It can also cause serious
issues, such as you are having with your program: when you press enter
at the prompt, you pass '' (the empty string) to eval, which sees EOF
before it can actually evaluate anything, and so it raises a
SyntaxError.  The simple fix here is to replace every occurance of
'input(' with 'raw_input(', or to make a step towards Python 3
compatibility, add this to the top of your program:

try:
input = raw_input
except NameError:
pass

Hope this helps,

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


Re: I just wrote my first Python program a guessing game and it exits with an error I get this.

2013-06-05 Thread Zachary Ware
On Wed, Jun 5, 2013 at 10:35 AM, Armando Montes De Oca
 wrote:
> Thank You now the program exits with:
> (program exited with code: 0)
> Press return to continue
>
>
> Is there a way to get the line (program exited with code: 0) to say something
>
> like: "The game will end now"
>
> Press return to contine

To whom are you replying?  Please quote what (and who) you are
replying to to provide context.

As for how to change that line, it depends on how you're running the script.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Questions on "import" and "datetime"

2013-06-10 Thread Zachary Ware
On Mon, Jun 10, 2013 at 10:37 AM, Yunfei Dai  wrote:
> Hi all,

Hi Yunfei,

>
> I have some questions on "import":
>
> 1."from datetime import datetime" works well. But I am confused why "import 
> datetime.datetime" leads to importerror. "from xlrd import open_workbook" 
> could be replaced by "from xlrd.open_workbook" without any problem.

I assume you mean "import xlrd.open_workbook" here, as "from
xlrd.open_workbook" would be a SyntaxError :)

> The only difference here is that if "from xlrd import open_workbook" is used 
> we do not have to write "xlrd.open_workbook" in the following code but just 
> "open_workbook". So my understanding of the difference is "from...import..." 
> shortens the code (just like "using namespace std" in C++) but maybe leads to 
> name clash.

"from ... import ..." imports an object from a module and assigns it
to a local name that is the same as the name in the other module.  In
other words, the following two examples do the same thing:

from foo import bar

import foo;bar = foo.bar

If foo.bar happens to be a module (module 'bar' in package 'foo'), you
could also do this:

import foo.bar as bar

...and that restriction is where your problem lies.

> But what is the problem of datetime?

I'm not familiar with xlrd, but I believe the difference between
xlrd.open_workbook and datetime.datetime would be that
xlrd.open_workbook is a module in a package, while datetime.datetime
is a class in a module.  'from ... import ...' can import any object
from the target module/package, and assign it to a local name.
'import ...' on the other hand can only import a module (you'll notice
the ImportError you get when you try 'import datetime.datetime' is 'No
module named datetime'.  This particular example is a bit confusing
due to there being a class in a module of the same name, but try
'import datetime.date' for a clearer message.

> 2.I am also comfused that "datetime.datetime" is a function but whithin 
> "datetime.datetime" there are lots of other functions. So what is the type of 
> "datetime.datetime" on earth? is it a function, or a class or a 
> folder(library) here?

datetime.datetime is actually a type of type 'type' (as can be seen
with 'import datetime;type(datetime.datetime)').  In Python 2, this
means it is a new-style class (meaning it is a subclass of 'object').
In Python 3, it's just a class (since there are no longer old-style
classes).

> Thanks very much in advance! Very looking forward to your answers.
>
> Best,
> Yunfei
>

I hope I have actually answered your question and not just muddied
things further for you.  You can of course ask again if I've made
things worse :)

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


Re: Timsort in Cpython

2013-06-15 Thread Zachary Ware
On Sat, Jun 15, 2013 at 2:44 PM,   wrote:
> I'm currently trying to make sense of Python's Timsort function. From the 
> wikipedia page I was told the algorithm is located somewhere here: 
> http://hg.python.org/cpython/file/default/Objects/listobject.c
>
> So of all the functions in there, could somebody point to me which one is 
> timsort?
>
> Thanks, if anyone can help.
> Alphonse23

Actually, it looks to me like it's several of them, but the main
function is here:
http://hg.python.org/cpython/file/default/Objects/listobject.c#l1902.

HTH,

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


Re: Question regarding building Python Windows installer

2013-07-15 Thread Zachary Ware
On Mon, Jul 15, 2013 at 8:11 AM, Mcadams, Philip W
 wrote:
> I’m attempting to create a Python 64-bit Windows Installer.  Following the
> instructions here: http://docs.python.org/2/distutils/builtdist.html I’m to
> navigate to my Python folder and user command:
>
>
>
> python setup.py build --plat-name=win-amd64 bdist_wininst
>
>
>
> I get error: COMPILED_WTH_PYDEBUG = (‘—with-pydebug’ in
> sysconfig.get_config_var(“CONFIG_ARGS”))
>
> TypeError: argument of type ‘NoneType’ is not iterable
>
>
>
> I also have tried:
>
>
>
> setup.py build --plat-name=win-amd64 bdist_wininst
>
>
>
> and get error:
>
>
>
> File “setup.py”, line 263
>
> Print “%-*s %-*s %-*s” % (longest, e, longet, f,
>
>
>
> SyntaxError: invalid syntax
>
>
>
> I followed the instructions here: http://docs.python.org/devguide/setup.html
> to create a PC build for Windows which allows me to run a Python prompt.
> Now I need to create a Windows Installer to install this Python on a Windows
> Server 2008 R2 box.
>
>
>
> To explain why I’m attempting to do this instead of just using the Windows
> Installer provided by Python:
>
>
>
> I needed to modify a _ssl.c file in the Python source code to deal a
> Mercurial that I’m trying to resolve.
>
>
>
> Any help on why I’m hitting these errors would be appreciated.
>
>
>
> Thank you.
>
>

Most of your problem is that setup.py is just for the extension
modules of the standard library, not the interpreter and all.  The
rest of your problem is that setup.py is really just not
Windows-friendly, relying on some Makefile vars and Modules/Setup.

Do you really need to install it?  If you're still in the testing
phase, would it be enough to just copy the source tree (with compiled
interpreter) to the box you need it on?  You can still use Mercurial
with it, just stick the hg modules somewhere on PYTHONPATH.

If you really do need an installer, I would suggest trying out
Tools/buildbot/buildmsi.bat and see if you can get it to work for you.
 I will warn you, buildmsi.bat is not well maintained and it may take
quite a bit of effort to make it work.

HTH,

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


Re: Is this a bug?

2013-07-15 Thread Zachary Ware
On Mon, Jul 15, 2013 at 10:50 AM, Jack Bates  wrote:
> Hello,
>
> Is the following code supposed to be an UnboundLocalError?
> Currently it assigns the value 'bar' to the attribute baz.foo
>
>foo = 'bar'
>class baz:
>   foo = foo

No bug.  It's not an error because of differences in the way classes
and functions compile.

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


Re: Question regarding building Python Windows installer

2013-07-15 Thread Zachary Ware
On Mon, Jul 15, 2013 at 1:02 PM, Mcadams, Philip W
 wrote:
> Thanks for the reply Zachery. We have decided to just use another solution. 
> Out of curiosity though I wanted to clarification on your statement:
>
> just stick the hg modules somewhere on PYTHONPATH.
>
> Are you saying that I would just map hg modules i.e.: 
> C:\Users\pwmcadam\Downloads\Python-2.7.4\Python-2.7.4\Modules to my 
> environment variables in Windows.
>
> Wasn't exactly following your comment.
>

Did I understand correctly that in your initial message you said you
needed an installer to try to resolve a Mercurial issue?  If not,
ignore that whole sentence of mine :)

Otherwise, I meant that you can just copy the mercurial and hgext
directories from \Lib\site-packages to \Lib\site-packages,
which would add that dir to the start of sys.path.  I did somewhat
misuse 'PYTHONPATH' in my earlier message.

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


Re: Question regarding building Python Windows installer

2013-07-15 Thread Zachary Ware
(Side note: Please avoid top-posting in future.  Bottom-posting keeps
context more clearly)

On Mon, Jul 15, 2013 at 2:27 PM, Mcadams, Philip W
 wrote:
> Yes.  My goal was to create the installer to put the modified python on my 
> Mercurial server.  So I could have effectively copied over the  with your compiled interpreter\Lib\site-packages to the  dir>\Lib\site-packages on the server?  What I was trying to resolve was the 
> issue with large Mercurial pushes.  I instead am using the IIS Crypto tool to 
> resolve the issue.  I'd found a link that stated that modification to the 
> _ssl.c module in Python could also fix the issue but that the python source 
> would to be recompiled.  Since we are going with IISCrypto the Python change 
> is no longer needed.  But out curiosity, and in case I ran into a situation 
> where did indeed need to make a fix to Python I've wondered what's the best 
> way to do that.  Hopefully this gives you a little insight on what I'm trying 
> to do.  Thanks for your replies.
>

Hmmm, not quite.  \Lib\site-packages would be empty.  I meant the other way
around, copying the installed site-packages dir into the source tree
to use mercurial from the source tree.  I think you'd also have to
copy hg and hg.bat from \Scripts as well, though.  You
might have been able to get away with just copying the newly compiled
_ssl.pyd from your source tree to \DLLs, but I can't
guarantee that.

I think the solution you've gone for is a much better solution in the
long run, though.  Building your own Python (on Windows) should
probably be a last resort.

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


Re: Why can't I define a variable like "miles_driven" with an underscore in Python 3.4.3 ?

2016-08-10 Thread Zachary Ware
On Wed, Aug 10, 2016 at 12:39 PM, Cai Gengyang  wrote:
> I managed to get this piece of code to work :
>
 print("This program calculates mpg.")
> This program calculates mpg.
 milesdriven = input("Enter miles driven:")
> Enter miles driven: 50
 milesdriven = float(milesdriven)
 gallonsused = input("Enter gallons used:")
> Enter gallons used: 100
 gallonsused = float(gallonsused)
 gallonsused = float(gallonsused)
 mpg = milesdriven / gallonsused
 print("Miles per gallon:", mpg)
> Miles per gallon: 0.5
 print("This program calculates mpg.")
> This program calculates mpg.
 milesdriven = input("Enter miles driven:")
> Enter miles driven: 100
 milesdriven = float(milesdriven)
 gallonsused = input("Enter gallons used:")
> Enter gallons used: 500
 gallonsused = float(gallonsused)
 mpg = milesdriven / gallonsused
 print("Miles per gallon:", mpg)
> Miles per gallon: 0.2
>
> But, why can't i define a variable like "miles_driven" with an underscore in 
> my Python Shell ? When I try to define it , the underscore doesn't appear at 
> all and instead I get this result :
> "miles driven" , with no underscore appearing even though I have already 
> typed "_" between "miles" and "driven" ?

Are you using IDLE on OSX?  Try changing your font or bumping up the
size (or switch to 3.5.2, which has better defaults).

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


Re: collect2: ld returned 1 exit status when building from source

2016-09-10 Thread Zachary Ware
On Sep 10, 2016 09:56, "Steve D'Aprano"  wrote:
>
> I'm trying to build from source using:
>
> ./configure --with-pydebug && make -s -j2
>
>
> At first the output is okay, then I get a whole heap of similar errors:
>
> Python/dtrace_stubs.o: In function `PyDTrace_LINE':
> /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple
> definition of `PyDTrace_LINE'
>
Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:25:
> first defined here
> Python/dtrace_stubs.o: In function `PyDTrace_FUNCTION_ENTRY':
> /home/steve/python/python-dev/cpython/Include/pydtrace.h:26: multiple
> definition of `PyDTrace_FUNCTION_ENTRY'
>
Python/ceval.o:/home/steve/python/python-dev/cpython/Include/pydtrace.h:26:
> first defined here
>
> [ ... many, many, many more PyDTrace_* multiple definitions ... ]
>
> collect2: ld returned 1 exit status
> make: *** [Programs/_freeze_importlib] Error 1
>
>
> Any suggestions for fixing this?

Try make distclean, then configure and build again.  If that fails, try
another make distclean, then configure, do 'make touch', then build again.

--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Copying a compiled Python from one system to another

2016-10-01 Thread Zachary Ware
On Oct 1, 2016 06:25, "Steve D'Aprano"  wrote:
>
> Long story short: I have no working systems capable of compiling the
latest
> Python 3.6, and no time to upgrade my usual machines to something which
> will work.

Since you're working on a pure-Python module (statistics), I'd recommend
updating to the latest changeset that will build, and work from there. I
don't know of any changes that would make it impossible for you to update
to the last working changeset, build, update to 3.6 tip, and develop and
test your statistics changes without rebuilding. You may have some test
failures, just run the full test suite after update to determine which
failures are not due to your development.

Otherwise, I'd suggest compiling your own GCC, but I haven't tried that
myself without the aid of Gentoo's package manager.

--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pip error on installing Python 3.5

2016-10-11 Thread Zachary Ware
On Tue, Oct 11, 2016 at 7:07 PM, Steve D'Aprano
 wrote:
> I've just installed Python 3.5 from the source tarball and received an
> unexpected error related to pip. On Linux, as a regular user (except for
> the last line):
>
>
> wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
> tar xvf Python-3.5.2.tgz
> cd Python-3.5.2
> ./configure
> make
> sudo make altinstall
>
>
> There were no obvious errors until the end:
>
> The directory '/home/steve/.cache/pip/http' or its parent directory is not
> owned by the current user and the cache has been disabled. Please check the
> permissions and owner of that directory. If executing pip with sudo, you
> may want sudo's -H flag.
>
> Ignoring indexes: https://pypi.python.org/simple
>
> The directory '/home/steve/.cache/pip' or its parent directory is not owned
> by the current user and caching wheels has been disabled. check the
> permissions and owner of that directory. If executing pip with sudo, you
> may want sudo's -H flag.
>
>
>
> Can anyone explain what is going on, why I should care, and how I should fix
> it?

Those aren't errors, and pip should be perfectly usable.  The message
about `/home/steve/.cache/pip` is just because pip is being run via
sudo; pip's cache dir is based on $HOME, which is still set to
`/home/steve` and pip doesn't want to screw up its cache for the
`steve` user.  The "Ignoring indexes" message is due to ensurepip
explicitly disabling pulling from PyPI when installing pip and
setuptools.

The messages about the cache do look a bit unnecessarily scary, it
might be nice if they didn't appear when pip is run by ensurepip.  I'm
not sure what removing the message for that particular case might
entail, but it might be worth opening an issue for it.

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


Re: System-wide module path

2016-10-24 Thread Zachary Ware
On Mon, Oct 24, 2016 at 6:49 PM, Rob Gaddi
 wrote:
> On a Linux (Ubuntu) system, with no concerns for Python < 3.4, how do I
>   a) Add a directory to the system-wide (rather than per-user) module
> path?

This is the trickier part.  There are a couple of ways to do it, but
which is better is a matter of some debate (at least in my head).  The
first option is to stick a `.pth` file in the regular site-packages
directory that points to /usr/highland/lib/python3.4/site-packages.
Another option is to set PYTHONPATH; this is one of the very few
exceptions to the rule that you never want to permanently set
PYTHONPATH.  The main differences between the two options are which
end of sys.path the directory is added to, and whether it's added when
the -S interpreter option is used (say, by system utilities).  The
`.pth` option is cleaner and safer, but `.pth` files just feel icky.

>   b) Tell pip that I would like to install a given module to there.

Use the --prefix option: `pip install --prefix /usr/highland/
alembic`.  This tells pip to install the package(s) as though Python
was installed at /usr/highland/, so libraries go in
/usr/highland/lib/python3.4/site-packages and executable stubs go in
/usr/highland/bin/.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows switch between python 2 and 3

2016-10-27 Thread Zachary Ware
On Thu, Oct 27, 2016 at 10:11 AM, Daiyue Weng  wrote:
> Hi, I installed Python 2.7 and Python 3.5 64 bit versions on Win 10. Under
>
> C:\Python35
>
> C:\Python27
>
> Both have been set in environment variable Path.
>
> When I type python in cmd, it only gives me python 2.7, I am wondering how
> to switch between 2 and 3 in command prompt.

Along with Python 3.5, the Python Launcher for Windows (py.exe) was
installed in C:\Windows, unless you unchecked it.  You can choose
which interpreter you want to run by an argument to py.exe; for Python
2.7, use `py -2.7`; for Python 3.5, use `py -3.5`.  There are also
shortcuts for "latest Python 2" and "latest Python 3", `py -2` and `py
-3` respectively.  Calling `py` on its own will default to matching
`py -2`, but settings can be changed in C:\Windows\py.ini.  See
https://docs.python.org/using/windows.html#launcher for more details.

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


Re: Asyncio -- delayed calculation

2016-11-28 Thread Zachary Ware
On Mon, Nov 28, 2016 at 6:48 AM, Steve D'Aprano
 wrote:
> What am I doing wrong?

Give yourself a bit more to debug with, since you're going to want to
do something with the result your expensive calculation anyway:

import asyncio

class Counter:
def __init__(self, i):
self.count = 10
self.i = i

async def count_down(self):
print(self, self.i, "starting")
while self.count > 0:
# simulate a computation
await asyncio.sleep(0.5)
self.count -= 1
print(self, self.i, "completed")
return self.i + self.count

async def main():
pool = [Counter(i) for i in range(5)]
results = []
for obj in pool:
results.append(obj.count_down())
return results

loop = asyncio.get_event_loop()
print(loop.run_until_complete(main()))


This gives you:

[, , , , ]
asynctest.py:25: RuntimeWarning: coroutine 'Counter.count_down' was
never awaited
  print(loop.run_until_complete(main()))

Ok, so let's fix that by adding an 'await' on line 21 (it's reported
at line 25 because that's when the unawaited coroutines are gc'd):

results.append(await obj.count_down())

Running that gives:

<__main__.Counter object at 0x10203f978> 0 starting
<__main__.Counter object at 0x10203f978> 0 completed
<__main__.Counter object at 0x1025af710> 1 starting
<__main__.Counter object at 0x1025af710> 1 completed
<__main__.Counter object at 0x1025b60b8> 2 starting
<__main__.Counter object at 0x1025b60b8> 2 completed
<__main__.Counter object at 0x1025b60f0> 3 starting
<__main__.Counter object at 0x1025b60f0> 3 completed
<__main__.Counter object at 0x1025b6128> 4 starting
<__main__.Counter object at 0x1025b6128> 4 completed
[0, 1, 2, 3, 4]

Still not right, only one count_down is run at a time.  But that's
because we're using a synchronous for loop to await our results and
populate the results list.  Naively, I tried an 'async for', but
that's trying to be asynchronous in the wrong place:

Traceback (most recent call last):
  File "asynctest.py", line 25, in 
print(loop.run_until_complete(main()))
  File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in
run_until_complete
return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
  File "asynctest.py", line 20, in main
async for obj in pool:
TypeError: 'async for' requires an object with __aiter__ method, got list

So instead, checking the docs suggests using asyncio.gather for
parallel execution of tasks, which takes a variable number of
'coros_or_futures'.  On the first attempt, we saw that we had
accidentally created a list of "coroutine objects", so lets go back
and use that:

--- asynctest.py.orig 2016-11-28 21:03:04.0 -0600
+++ asynctest.py 2016-11-28 21:03:35.0 -0600
@@ -16,9 +16,10 @@

 async def main():
 pool = [Counter(i) for i in range(5)]
-results = []
+coros = []
 for obj in pool:
-results.append(await obj.count_down())
+coros.append(obj.count_down())
+results = asyncio.gather(*coros)
 return results

 loop = asyncio.get_event_loop()

Output:

<__main__.Counter object at 0x1026b6160> 4 starting
<__main__.Counter object at 0x10213f978> 0 starting
<__main__.Counter object at 0x1026b6128> 3 starting
<__main__.Counter object at 0x1026af748> 1 starting
<__main__.Counter object at 0x1026b60f0> 2 starting
<_GatheringFuture pending>

Now we've started everything asynchronously, but it exited way too
fast and never completed anything.  But instead of a list of results,
we got a _GatheringFuture at the end of everything.  So let's await
that:

results = await asyncio.gather(*coros)

And now we get:

<__main__.Counter object at 0x101eb6160> 4 starting
<__main__.Counter object at 0x10063f978> 0 starting
<__main__.Counter object at 0x101eb6128> 3 starting
<__main__.Counter object at 0x101eaf748> 1 starting
<__main__.Counter object at 0x101eb60f0> 2 starting
<__main__.Counter object at 0x101eb6160> 4 completed
<__main__.Counter object at 0x10063f978> 0 completed
<__main__.Counter object at 0x101eb6128> 3 completed
<__main__.Counter object at 0x101eaf748> 1 completed
<__main__.Counter object at 0x101eb60f0> 2 completed
[0, 1, 2, 3, 4]


And there we have it.  Our final script is:

import asyncio

class Counter:
def __init__(self, i):
self.count = 10
self.i = i

async def count_down(self):
print(self, self.i, "starting")
while self.count > 0:
# simulate a computation
await asyncio.sleep(0.5)
self.count -= 1
print(self, self.i, "completed")
return self.i + self.count

async def main():
pool = [Counter(i) for i in range(5)]
coros = []
for obj in pool:
coros.append(obj.count_down())
results = await asyncio.gather(*coros)
return results

loop = asyncio.get

Re: Can json.dumps create multiple lines

2016-12-01 Thread Zachary Ware
On Thu, Dec 1, 2016 at 10:30 AM, Cecil Westerhof  wrote:
> I would prefer when it would generate:
> '[
>  "An array",
>  "with several strings",
>  "as a demo"
>  ]'
>
> Is this possible, or do I have to code this myself?

https://docs.python.org/3/library/json.html?highlight=indent#json.dump

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.dumps(["An array", "with several strings", "as a demo"])
'["An array", "with several strings", "as a demo"]'
>>> print(_)
["An array", "with several strings", "as a demo"]
>>> json.dumps(["An array", "with several strings", "as a demo"], indent=0)
'[\n"An array",\n"with several strings",\n"as a demo"\n]'
>>> print(_)
[
"An array",
"with several strings",
"as a demo"
]

I've also seen something about JSON support in SQLite, you may want to
look into that.

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


Re: Pyscripter Issues

2016-03-31 Thread Zachary Ware
On Thursday, March 31, 2016, Simon Martin  wrote:
>
> Hi
>
> I have been having issues trying to run python 3.5.1 and pyscripter 2.6. 
> Giving the error message that it cannot initialize python.
>
> I have tried to re-install multiple versions of both python and pyscripter to 
> no avail. Any advice?

Use PyCharm.

Less bluntly, I used to be a heavy PyScripter user, but after it took
forever for PyScripter to support Python 3.4 (I wasn't even sure if it
did yet, but it apparently does as of a year ago, added one year after
3.4 was released), I moved on.  PyScripter also has the big
disadvantage of being strictly single-platform, unlike Python itself,
so if you were to try to develop on another platform you would have to
learn a new IDE/editor anyway. I have found PyCharm to be very nice,
and very consistent cross-platform--I use it regularly on OSX and
Windows, and have also used it on Linux. I'm also becoming rather
partial to vim, which is also nicely cross-platform: if you have Git
on Windows, you have vim available already.  Vim does have a somewhat
steeper learning curve, though.

Looking a bit deeper into what your problem might actually be,
PyScripter does not support Python 3.5.  Support for each new Python
version has to be added explicitly, and it has not been done for 3.5.
If you still want to use PyScripter, you should use the latest release
of Python 3.4.  Keep in mind that you must match use 32-bit Python
with 32-bit PyScripter, and 64-bit Python with 64-bit PyScripter, you
cannot mix and match.

But seriously, you'll be much happier with PyCharm.

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


Re: Slice equivalent to dict.get

2016-03-31 Thread Zachary Ware
On Thu, Mar 31, 2016 at 12:51 PM, Terry Reedy  wrote:
> On 3/31/2016 11:24 AM, Peter Otten wrote:
>> try...except to the rescue:
>>
> def get(seq, index, default=None):
>>
>> ... try: return seq[index]
>> ... except IndexError: return default
>
>
> Replace IndexError with (IndexError, KeyError) and the functions works with
> any subscriptable that raises either exception.

Or use the superclass of both of those, LookupError, and also catch
anything that uses that more generic name as well.

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


Re: Launcher for 64 bits doesnt work

2016-04-04 Thread Zachary Ware
Hi Gustaf,

On Mon, Apr 4, 2016 at 9:38 PM, Gustaf Nilsson
 wrote:
> Hi!
>
> The only 3.5.1 versio that works for me is the 32 bits version, will it be
> a problem to use the 32 bits version for 64 bits computer?

>From your mention of a 'launcher' I'm assuming you're on Windows.
It's perfectly fine to use 32-bit Python on 64-bit Windows.  However,
how exactly does the launcher for the 64-bit version not work?  What
happens?  What did you expect to happen that didn't?  What error
message do you get?  It's entirely possible that your version of
Windows is in fact 32-bit, even though the computer itself has a
64-bit processor.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How are you supposed to define subclasses in C?

2016-04-21 Thread Zachary Ware
On Thu, Apr 21, 2016 at 11:35 AM, Random832  wrote:
> I was trying to write a proof of concept on including descriptors (e.g.
> a "sys.recursionlimit" instead of set/get methods) in the sys module,
> and couldn't figure out how to "properly" define a type using
> PyType_FromSpecWithBases. Everything I tried just segfaulted. I ended up
> just calling PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type, ...)
> but I assume there's a better way to do it. I couldn't find any examples
> or tutorial.

Have a look at https://hg.python.org/cpython/file/default/Modules/xxsubtype.c

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


Re: Python(x,y) 64 bit

2016-04-27 Thread Zachary Ware
Hi Pierre,

On Wed, Apr 27, 2016 at 6:23 AM, Pierre  wrote:
> Hello,
>
> I installed Python(x,y) 64 bit version and ran it using a library that 
> requires Python 64 bit.
> I got an error which indicated that I am using Python 32 bit.
>
> So, is the python used by Python(x,y) 64 bit, using Python 64 or 32 bit?

You can check by doing `python -c "import sys;print(sys.maxsize ==
2**63-1)"`.  You'll get True for 64-bit, False for 32-bit.  There's a
possibility that you've gotten a misleading error message, though.
What version of Python(x,y) are you using, and what library?

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


Re: Slight problems with python in Windows

2016-05-06 Thread Zachary Ware
Hi Peter,

On Fri, May 6, 2016 at 6:22 AM, Peter Toye  wrote:
> I'm trying to install Python under Windows 7 so that I can use git-review and 
> have found a few niggling issues.
>
> 1) Apparently (according to the git-review pages) pip has a problem with 
> directories with spaces in their names. Python's default installation 
> directory is under Program Files. I agree that this is a pip issue rather 
> than a Python one, but maybe a warning message would help?

I don't believe this is true anymore, I've successfully used pip with
3.5 installed in Program Files, and also just now in a test venv named
"test venv".  Do note that with installation in Program Files, you get
the benefits of the install directory being writable only to
administrators, but also the drawbacks: only administrators can use
pip to install to the global site-packages.  You can use either 'pip
--user', or create a venv in a directory writable to you and use it.
Also note that you can't use "pip.exe" to upgrade pip itself since it
can't overwrite "pip.exe" while it's in use; use 'python -m pip'
instead.

> 2) According to the Programs and Files section of the Windows Control Panel, 
> installing Python also installs something called the Python Launcher. When I 
> try to remove this (so I can reinstall Python in a better directory) is comes 
> up with an error message:

The Python Launcher is a very handy tool called 'py.exe' which makes
it much easier to use more than one version of Python on a Windows
machine.  In an all users install, py.exe is installed to C:\Windows
and is thus always available on PATH, so you can invoke Python 3.5 by
calling 'py -3.5' without having to adjust your PATH.  The error
message is odd, though, would you mind trying to reproduce it and
opening a bug at bugs.python.org?

> Error opening installation log file.  Verify that the specified log file 
> location exists and is writable.
>
> After reinstalling I now have 2 copies of the launcher I hope it doesn't 
> give me any problems.

It shouldn't.  The launcher only installs 2 files, py.exe and pyw.exe
(counterpart to pythonw.exe), both in C:\Windows.

> 3) After uninstalling Python the installation directory is still there with a 
> few files in it (possibly connected with the previous issue). Can I just 
> delete it?

Yes, that should be fine.  I would guess it's still there due to pip
artifacts in Lib\ and Scripts\.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create development Python environment on Linux.

2016-05-16 Thread Zachary Ware
On Mon, May 16, 2016 at 6:22 AM,   wrote:
> I have a Linux system (Mint 17.3 based in Ubuntu 14.04) on which I wish to do 
> some Python development. The system has Python 2.7.6 installed already (there 
> is a Python 3 installation too but I won't be needing to use that to start 
> with).

Not what you asked for, but I would encourage you to look into whether
it's possible for you to use Python 3 instead of Python 2 for what
you're doing.  If it's possible, starting with Python 3 will save you
several headaches in the future.

> [...]
> 1. I am unsure which of these technologies is most suitable for my needs. 
> Virtualenv sounds like what I need, but two things give me pause for thought. 
> First I came across this github issue
>
> https://github.com/pypa/virtualenv/pull/697
>
> ...which highlights what seem like severe issues in the vitualenv 
> implementation and proposes to rewrite the whole library. This raises two 
> questions.
>
>i) Is this rewrite complete?
>ii) Is 'legacy' virtualenv or virtualenv-rewrite now the recommended 
> library?

virtualenv is a bit of a hack, by necessity.  Python 2 doesn't truly
support virtualenv, so virtualenv has to make do with what it has
available.  That said, it has worked well for my needs and for many
others.

(The real solution is Python 3.3+'s venv module :))

> The second thing that gives me pause for thought is the remark in this article
>
> http://python-packaging-user-guide.readthedocs.io/en/latest/install_requirements_linux/#installing-pip-setuptools-wheel-with-linux-package-managers
>
> ...where it says
>
> 'Recent Debian/Ubuntu versions have modified pip to use the “User Scheme” by 
> default, which is a significant behavior change that can be surprising to 
> some users.'
>
> These concerns caused me to try and research more in the area of user 
> installs and package installation, which leads me to my next two issues.

The real issue here is mixing the use of the OS package manager with
the use of pip.  If you only install python packages using the OS
package manager (e.g., `apt-get install python-requests`) or only with
pip (e.g., `pip install requests`), you'll probably be fine.  If you
try to use both, though, you may wind up in a weird situation.

> 2. User install site.py behaviour confusing.
>
> The first thing I wanted to work out was whether 'user install' was indeed 
> enabled by default on my system as described in the article above. Here is 
> the documentation for site.py
>
> https://docs.python.org/2/library/site.html
>
> This is the documenation for 2.7.11 while I only have 2.7.6. I don't see a 
> link to documentation for 2.7.6 and I dont know whether this version 
> disparity is significant or not.

It shouldn't be, but here's the 2.7.6 documentation anyway:
https://docs.python.org/release/2.7.6/library/site.html

> However, the documentation starts by saying that this module is loaded by 
> default. That being so I would expect sys.prefix to be /usr/local.

Why do you expect that?  sys.prefix is baked in at compile time of the
python interpreter, and refers to where Python is installed on the
system.  `/usr/local` is the default prefix for custom builds, but
most Linux distributions install Python under `/usr`.  That the site
module is loaded by default just means that particular locations
outside of the standard library path are automatically added to
sys.path (the list of directories where Python will look when you try
to import something).  Compare the output of `python -c "import
pprint,sys;pprint.pprint(sys.path)"` with and without the -S and -s
options.

> If I fire up Python import sys and dump sys.prefix it outputs /usr.
> If I dump site.USER_BASE I get 'name 'site' is not defined'.

Even though site is imported by default by the interpreter, it doesn't
bind the name 'site' anywhere in the default namespace.  If you want
to use the contents of the site module, you still need to import site
yourself (this second import simply looks up 'site' in the sys.modules
dict and returns the module it finds there).

> If I import site and dump site.USER_BASE I get '/home//.local'.
>
> This confuses the hell out of me. Two documentary sources suggest this 
> behaviour should be enabled by default, yet it doesn't seem to be, I don't 
> know why, and I don't know how to enable it, or even whether I should.
>
> Can anyone either explain why I'm seeing what I'm seeing here, or point the 
> in the direction to some documentation that can.

Hopefully I've cleared things up a bit above.  Please ask again if
it's still murky!

> 3. Installers
>
> My system Python installation doesn't appear to have either easy_install nor 
> pip nor virtualenv installed. This leaves me with what seems like a circular 
> problem.
>
> I'm pretty sure I need pip, but there are (at least) two ways to get it.
>i) apt-get pip
>ii) or download and run get-pip.py.
>
> I've come across various credible warnings of the dangers of using apt-get 
> and pip to

Re: How to create development Python environment on Linux.

2016-05-17 Thread Zachary Ware
On Mon, May 16, 2016 at 4:28 PM,   wrote:
> Thanks Zach, that's a big help. The only reason I want to get a Python 2.7 
> environment working first is because I'll be working on third party code and 
> that's the platform it uses. For any new projects I would use Python 3.

Fair enough :)

> After considering your guidance I think what I will do is install virtualenv 
> using apt-get and then use that to create a dev environment. Is it ok to run 
> get-pip.py in a virtual environment?

Sounds like a plan.  get-pip.py should work fine in a venv, but first
check to see if pip is already there, as Michael mentioned.

> I won't worry about using the latest version of 2.7 for now, since it's only 
> one or two third party open source projects I'll use 2.7 for and they don't 
> need a more recent version.
>
> There are a couple of other things I'm not quite clear on, such as where it 
> would be best to create my new virtual environment (I'm tempted to put it in 
> /usr/local if that means it can be used by all user accounts on my machine), 
> and how I can can control which Python environment is used by the various 
> system and user programs that depend on them, but I expect I can find that 
> information on the web, though I'll make another post here if I do get stuck.

The thing about virtual environments is that you can create as many as
you want wherever you want, and they're all independent of each other.
All you need to do is have a way to consistently recreate the same
environment, which is usually easiest to do with a 'requirements.txt'
file with all of your dependencies' versions pinned.  Then recreating
the venv is as simple as `virtualenv --python=some_python
/path/to/venv && /path/to/venv/bin/pip install -r
/path/to/requirements.txt`.  Then you can do your development wherever
you want and install into somewhere in `/usr/local` when you deploy.
For example, one project I work on creates a venv in
`/usr/local/lib/project_name/`, then creates links to the entry point
scripts (that actually live in `/usr/local/lib/project_name/bin/`) in
`/usr/local/bin/`.

As for controlling which environment is used: all system scripts/apps
should specify some version-specific flavor of /usr/bin/python in
their shebang--if they don't it's an OS bug and should be filed as
such.  For your stuff, the path of least headache is probably to
create a venv for each one, and specify the path to the venv's python
in shebang lines.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for / while else doesn't make sense

2016-05-20 Thread Zachary Ware
On Fri, May 20, 2016 at 3:09 AM, Erik  wrote:
> On 20/05/16 00:51, Gregory Ewing wrote:
>>
>> It's not so bad with "else" because you need to look back
>> to find out what condition the "else" refers to anyway.
>
>
> With my tongue only slightly in my cheek, if it was desirable to
> "fix"/clarify this syntax then I would suggest adding some optional
> (existing) trailing keywords to 'else' in this context that spells it out:
>
> for item in seq:
> if foo(item):
> break
> else if not break:
> nomatch()

With tongue firmly cheeked, you can always use the special `:#` operator:

   for item in seq:
   if foo(item):
   break
   else:# if no break:
   nomatch()

This has the benefit that you can use whatever syntax you like after
the `:#`, and use it in any version of Python you want.

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


Re: Format a timedelta object

2016-05-25 Thread Zachary Ware
On Thu, May 26, 2016 at 12:16 AM, Steven D'Aprano
 wrote:
> I have a timedelta object, and I want to display it in a nice human-readable
> format like 03:45:17 for "three hours, forty five minutes, 17 seconds".
>
> Is there a standard way to do this?

   >>> timedelta(100)
   datetime.timedelta(100)
   >>> str(timedelta(seconds=100))
   '0:01:40'
   >>> str(timedelta(hours=100))
   '4 days, 4:00:00'

(I recently spent *way* too long trying to figure out how to properly
format the thing before being reminded that a plain str call gives
exactly what I was after.)

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


Re: Format a timedelta object

2016-05-27 Thread Zachary Ware
On Fri, May 27, 2016 at 11:21 AM, Steven D'Aprano  wrote:
> On Thu, 26 May 2016 03:28 pm, Zachary Ware wrote:
>> On Thu, May 26, 2016 at 12:16 AM, Steven D'Aprano
>>  wrote:
>>> I have a timedelta object, and I want to display it in a nice
>>> human-readable format like 03:45:17 for "three hours, forty five minutes,
>>> 17 seconds".
>>
>>>>> str(timedelta(seconds=100))
>>'0:01:40'
>
> Thanks Zach. Unfortunately, the format is not quite how I want it, so I
> guess I'll have to extract the H:M:S fields manually from the seconds.

What's missing the mark, no leading 0 on the hour, or the extra 0 hour
specification?

Yes, unfortunately it looks like manual extraction is your only option
for that.  I'd support an RFE for a strftime-like __format__ method on
timedelta that only supported certain %-codes, though.  I haven't
checked to see if there's already an open issue.

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


Re: best text editor for programming Python on a Mac

2016-06-17 Thread Zachary Ware
On Jun 17, 2016 6:56 PM, "Chris via Python-list" 
wrote:
>
> I have been trying to write a simple Hello World script on my Mac at work
with TextEdit.

TextEdit is not just a simple text editor, it defaults to rich text mode.
You can either attempt to get TextEdit out of rich text mode and into plain
text mode, or use a different editor, like nano or vim (I'm pretty sure
both are available by default).

--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Setting up Python WinXP

2016-06-22 Thread Zachary Ware
Hi Michael,

On Wed, Jun 22, 2016 at 11:41 AM, Michael Smolen <8smo...@tds.net> wrote:
> Folks:
> I can't wait to start programming with Python.

Welcome to Python!

> However, I am having difficulty installing on my XP operating system.

This unsolicited advice is rather beside the point, but I would highly
recommend moving away from XP if you have any say in the matter.
Linux Mint (or other distro of your choice) is easy to install and
use, is free in whatever sense of the word you'd like to use, and will
be much more secure than XP, which is no longer supported by Microsoft
(this is why it's not supported by Python 3.5+, either).  An upgrade
to a newer version of Windows is also a good idea, but more costly.

> I downloaded Python-3.4.5ci

I'm not sure what you mean by 3.4.5ci; do you mean 3.4.5rc1?  3.4.5rc1
is pre-release software; 3.4.5 will be released in a week or so.
However, it won't include binary installers for Windows since Python
3.4 is now in security-fix-only mode.

> as that seems like the version that will run on my operating system. The 
> latest version will not as per mention on the website. I downloaded the 
> compacted version  (*.tar), converted it to a *.tgz and extracted the 
> software into a folder Python-3.4.5ci. That subdirectory contains numerous 
> files (11) and 13 subdirectories. The README file states that "On Windows, 
> see PCbuild/readme.txt.". That link was not found.
>
> So, I am clueless on what I need to do to successfully install Python3.4 on 
> my computer. Any advice would be greatly appreciated.

If you're stuck with XP, stick with Python 3.4.4, and download the
installer from here:
https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [tkinter] widget size adjustment

2016-06-22 Thread Zachary Ware
On Wed, Jun 22, 2016 at 4:05 PM, Christian Gollwitzer  wrote:
> BTW, the Tkinter wrapper is a bit clumsy for this option. In the original
> Tk, the sticky option is just a string. You can still pass that and do
>
> sticky='nsew'
>
> instead of the clumsy
>
> sticky=Tkinter.N+Tkinter.S+Tkinter.E+Tkinter.W

There are constants in tkinter for this: NSEW, NS, NE, NW, SE, SW, and EW.

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


Re: Question on compiling on linux

2016-06-24 Thread Zachary Ware
On Fri, Jun 24, 2016 at 1:35 PM, Steven Truppe  wrote:
> So back to my first question now that you saw everything worked fine, but
> there is no python.so file, did i miss something when using ./configure ?

Try `./configure --enable-shared`.

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


Re: Question on compiling on linux

2016-06-24 Thread Zachary Ware
On Fri, Jun 24, 2016 at 2:28 PM, Steven Truppe  wrote:
> That gives me many .so files but no python*.so* file :(

Where are you finding these many .so files?  There should be
libpython3.5m.so in the root of the source tree (alongside `python`).

By the way, I'm not sure how you're accessing the list/newsgroup, but
your quoting seems to be messed up somehow -- my message, which I'm
assuming the above was in reply to, was nowhere to be found in your
message.  Also, as a minor matter of netiquette, we prefer new content
to follow a quote of what the new message is in reply to, as I've done
in this message.

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


Re: Question on compiling on linux

2016-06-26 Thread Zachary Ware
On Saturday, June 25, 2016, Steven Truppe  wrote:
>
> i hope this email works like you expected!

Not quite, but closer.  You've quoted me properly, but you added your
reply above the quote, so-called "top-posting".

A: Because you have to read things in reverse order.
Q: Why?
A: Top-posting.
Q: What's one of the most annoying common email practices?

But that's all rather beside the point :)

> I found the libpython3.so, i don't know why i was not able to see it,

Note that libpython3.so is very different from libpython3.5m.so:
libpython3.so is the interface to the PEP 384 stable ABI.  It does not
include the full interpreter, and is in fact just a shim that
redirects to libpython3.5m.so.  It's only really useful for building
extension modules and using the resulting binary with multiple
versions of Python.

> thank you very much to everyone wo helped me!

I'm glad we've been able to clear things up a bit!

> No my last question(s) is how can i create debug/release builds ?

Pass '--with-pydebug' to ./configure to get a debug build.  On Linux,
the difference between a debug and release build is just the
definition of debug-related macros (Py_DEBUG, _DEBUG, NDEBUG) and the
optimization level.  On Windows, another big difference in a debug
build is that it is linked against the debug CRT.  There is no such
thing on Linux, so you likely won't need a debug version of Python
just to debug your embedding app the way you would on Windows.

Hope this helps,
--
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __all__ attribute: bug and proposal

2016-06-27 Thread Zachary Ware
On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico  wrote:
> If you're primarily worried about classes and functions, here's a neat
> trick you can use:
>
> __all__ = []
> def all(thing):
> __all__.append(thing.__name__)
> return thing

Barry Warsaw has written a nice decorator called 'public' that can be
installed from PyPI as 'atpublic'[0].  It was proposed for inclusion
as a builtin in 3.6 [1], but a less-than-enthusiastic response at the
2016 Language Summit has put that off indefinitely.  I, for one, would
like to see it happen anyway [2], and public support may make it
possible.

The '@public' decorator works like so:

"""
# spam.py

@public
def spam():
return ' '.join(['spam']*10)

@public
def eggs():
return 'bacon'

public(HAM=4)
assert HAM == 4

assert sorted(__all__) == sorted(['spam', 'eggs', 'HAM'])
"""

This strikes me as being a cleaner approach than what the OP
suggested, easier to use than Chris' simple decorator, and a nice way
to bring an end to outdated __all__ lists (which is a problem
currently plaguing the standard library, and probably many other
libraries).

[0] https://pypi.python.org/pypi/atpublic
[1] https://bugs.python.org/issue26632
[2] https://bugs.python.org/issue26632#msg267305

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


Re: Meta decorator with parameters, defined in explicit functions

2016-06-27 Thread Zachary Ware
On Tue, Jun 28, 2016 at 12:02 AM, Ben Finney  wrote:
> Howdy all,
>
> I want an explicit replacement for a common decorator idiom.
>
> There is a clever one-line decorator that has been copy-pasted without
> explanation in many code bases for many years::
>
> decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda 
> func: decorator(func, *args, **kwargs)
>
> My problem with this is precisely that it is clever: it explains nothing
> about what it does, has many moving parts that are not named, it is
> non-obvious and lacks expressiveness.
>
> Even the widely-cited ActiveState recipe by Peter Hunt from 2005
> http://code.activestate.com/recipes/465427-simple-decorator-with-arguments/>
> gives no clue as to what this is doing internally nor what the names of
> its parts should be.
>
> I would like to see a more Pythonic, more explicit and expressive
> replacement with its component parts easily understood.

Try this on for size:

'''
import functools

def decorator_with_args(decorator):
"""
Meta-decorator for decorators that take arguments.

Usage:

   @decorator_with_args
   def some_decorator(func, foo, bar=None)
   if foo:
   func.bar = bar
   return func

   @some_decorator(True, bar='quux')
   def some_decorated_function(some_arg)
   return some_arg

   assert some_decorated_function.bar == 'quux'

Returns a function that takes arguments which are to be
passed to the decorator along with the function to be
decorated.

This allows you to just write your decorator as taking
the arguments you want, without having to write a decorator
factory that creates and returns a decorator.
"""

@functools.wraps(decorator)
def factory(*args, **kwargs):
"""Generic decorator factory.

Returns a decorator that calls the original decorator
with the function to be decorated and all arguments
passed to this factory.
"""

def decorator_wrapper(func):
"""Thin wrapper around the real decorator."""
return decorator(func, *args, **kwargs)
return decorator_wrapper
return factory
'''

I make no guarantees about this; this is completely untested and is
based solely upon how the original translated in my mind.  If I
misunderstood how the original works, this is worse than useless :).
Also, I'm not sure how close I got on the "easily understood" part.
It's certainly more explanatory than the original, but it's not the
simplest of concepts anyway: a function that takes a function and
returns a function that takes arbitrary arguments and returns a
function that takes a function and returns the result of calling the
originally passed function with arguments consisting of the passed
function and the aforementioned arbitrary arguments has too many
layers of indirection to keep in mind at once!

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


Re: "for/while ... break(by any means) ... else" make sense?

2016-06-29 Thread Zachary Ware
On Wed, Jun 29, 2016 at 11:12 PM, Steven D'Aprano  wrote:
> On Thu, 30 Jun 2016 11:28 am, Chris Angelico wrote:
>
>> On Thu, Jun 30, 2016 at 10:27 AM, Steven D'Aprano 
>> wrote:
>>> Following os.abort(), the interpreter exits in the hardest, quickest
>>> manner possible.
>>
>> os.kill(os.getpid(), 9)
>>
>> Now THAT is the hardest way to abort. You ain't comin' back from this one!
>
> The docs say it will abort in the hardest way possible, by dumping core or
> equivalent. I *think* I recall seeing os.abort() actually segfault at some
> point, but I can't replicate that now.
>
> I tried to find the actual implementation of os.abort(), but I couldn't work
> out where it was or what it does. Can somebody enlighten me?

Right here: 
https://hg.python.org/cpython/file/default/Modules/posixmodule.c#l10528

Here's the entire implementation of os.abort:
{
abort();
/*NOTREACHED*/
Py_FatalError("abort() called from Python code didn't abort!");
return NULL;
}

abort(3) is a standard C function, see the manpage.  If execution
somehow makes it past the abort() call, Python does its best to make
sure it really doesn't by calling Py_FatalError, which dumps a scary
message to stderr along with any traceback it can get its hands on,
then calls abort() again.  I tried setting a signal handler for
SIGABRT (I tried `signal.signal(signal.SIGABRT, print)`), but it
didn't trigger a Py_FatalError call on OSX or Linux.

On Windows, abort() causes the "some.exe has stopped working" dialog
to pop up and "search for solutions".  Similarly, the Crash Reporter
pops up on OSX.

-- 
Zach
-- 
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: Running Python from the source repo

2016-08-08 Thread Zachary Ware
On Sun, Aug 7, 2016 at 9:11 PM, Steven D'Aprano
 wrote:
> I have cloned the Python source repo, and build CPython, as described here:
>
> https://docs.python.org/devguide/
>
>
> Now a little bit later, I want to update the repo, so I run:
>
> hg fetch

According to the hg docs [1], you should probably avoid 'hg fetch'.
Use 'hg pull -u' (or 'hg pull && hg update') instead.

> to get and apply any changes. How do I know if I need to rebuild Python? I
> don't want to have to rebuild after every fetch, because that's quite time
> consuming (I estimate about five minutes on my machine, just long enough to
> be a distraction but not long enough to get into something else). Plus the
> time to run the tests (significantly longer).
>
> What do others do?

I generally assume that if I'm testing a patch, I'm going to need to
rebuild regardless of what the patch actually touches.  I often wait
until the patch is applied before I do the rebuild, or if I'm manually
testing a bug I go ahead and do the rebuild immediately.  Most make
targets (including 'test') will go ahead make sure the build is up to
date without your input.  Usually the slowest part of a rebuild is
rerunning ./configure, which 'make' will do for you if it determines
that it should.  You can speed up ./configure by passing it the
'--config-cache' (or '-C') option.  If you're on a multi-core machine,
also remember to pass '-j' to make to speed up
building, and also to regrtest (which you can do with 'make test
TESTOPTS=-j9') to speed up testing.

[1]https://www.mercurial-scm.org/wiki/FetchExtension

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


Re: Running Python from the source repo

2016-08-08 Thread Zachary Ware
On Mon, Aug 8, 2016 at 2:25 PM, Terry Reedy  wrote:
> Last January, I wrote a batch file to build all three versions with the
> 'optional' extensions.  I started rebuilding more often after this.
>
> 36\pcbuild\build.bat -e -d
> 35\pcbuild\build.bat -e -d
> 27\pcbuild\build.bat -e -d
>
> Thanks for making this possible.  It initially worked, but now it stops
> after the first command, even without errors.  Has a flag been changed to
> treat warnings as errors?  How can I change the .bat to wrap each command
> with the equivalent of try: except: pass?

I'm not sure why that would have stopped working, but the way to use a
.bat from a .bat is to 'call' it:

call 36\PCbuild\build.bat -e -d

.bat scripts don't care about the exit codes of what they run, errors
must be explicitly checked and 'exit' called if you want the script to
die early.  Try this for an unconditional build on all three branches,
with a report at the end if any of them failed:

call 36\PCbuild\build.bat -e -d
set rc36=%ERRORLEVEL%

call 35\PCbuild\build.bat -e -d
set rc35=%ERRORLEVEL%

call 27\PCbuild\build.bat -e -d
set rc27=%ERRORLEVEL%

@if %rc36% NEQ 0 (
echo 3.6 build failed, rc: %rc36%
)
@if %rc35% NEQ 0 (
echo 3.5 build failed, rc: %rc35%
)
@if %rc27% NEQ 0 (
echo 2.7 build failed, rc: %rc27%
)


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


Re: Running Python from the source repo

2016-08-09 Thread Zachary Ware
On Tue, Aug 9, 2016 at 2:55 AM, Terry Reedy  wrote:
> This works great.  Might there be any way to collect together
> the warning messages?  There were perhaps 100 for the changes in
> the last few weeks.  (People on non-windows seems to routinely write code
> that msc does not like.)

Glad it works!  Collecting warning messages is less simple, you'd
probably get the best results from writing a Python script to drive
the build.bats and do what you want with the output.  You can also
pass '-v' to build.bat to get more verbose output, which includes a
summary of warnings and errors at the end of each build.

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


Re: To whoever hacked into my Database

2013-11-13 Thread Zachary Ware
On Wed, Nov 13, 2013 at 12:27 PM, superchromix  wrote:
>
>
> hi all,
>
> I've been thinking about learning Python for scientific programming.. but all 
> of these flame war type posts make the user community look pretty lame.  How 
> did all of these nice packages get written when most of the user interaction 
> is  this??
>
> Can anyone tell me, is there another newsgroup where the discussion is more 
> on python programming?

Please don't judge the whole community by this thread, I promise we're
not all bad!  The majority of the traffic on this list is of a useful
sort, and you can learn fairly quickly the addresses that are best
ignored, blocked, or otherwise passed over.  For myself using Gmail, I
have a filter set up to mark particular threads that I don't want to
be notified about and mute them after the first few mails come in.  I
didn't see your message initially because it was part of a muted
thread, I only saw it at all because the thread spilled over the 100
message mark into a "new" thread in Gmail with one of the replies to
your message.

Also, if you have a specific question about how to do something in
Python you can try the tutor list (tu...@python.org) which is much
more focused, much lower traffic, and has several very knowledgeable
Pythonistas listening in.

Give us a chance, and I don't think we'll let you down :)

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


Re: Running python's own unit tests?

2013-11-14 Thread Zachary Ware
On Thu, Nov 14, 2013 at 1:12 PM, Russell E. Owen  wrote:
> I'm building python from source and trying to figure out how to test the
> result. I must be overlooking something obvious, but I looked through
> the documentation and source and tried some google searches (which turn
> up plenty about writing unit tests in python, but nothing about testing
> a python distribution).
>
> Any hints?

`python -m test -uall` will test everything (where 'python' invokes
the interpreter you built, which may be "python_d.exe" on Windows if
you built in Debug mode, or "python.exe" on OSX).  If you're testing
2.7, '-m test' needs to be '-m test.regrtest'.

For any further detail, check Tim's link to the devguide, specifically
the chapter on running tests.

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


Re: request for guidance

2013-12-13 Thread Zachary Ware
On Thu, Dec 12, 2013 at 11:15 PM, jennifer stone
 wrote:
> greetings
> I am a novice who is really interested in contributing to Python projects.
> How and where do I begin?
> thanking you in anticipation

If you're interested in contributing to Python itself, you can consult
the Python devguide [1] for suggestions on how to get started.  I
would also recommend the core-mentorship mailing list[2][3], which is
a private (archives are only available to members) list where you can
ask any questions you may have.

Welcome! :)

-- 
Zach

[1] http://docs.python.org/devguide/index.html
[2] List info: http://mail.python.org/mailman/listinfo/core-mentorship
[3] Homepage: http://pythonmentors.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: buggy python interpretter or am I missing something here?

2014-01-26 Thread Zachary Ware
On Mon, Jan 27, 2014 at 12:02 AM, me  wrote:
> On Mon, 27 Jan 2014 00:36:20 -0500, Dave Angel wrote:
>
>> sys.exit() raises an exception,  and you're deliberately eating
>>  that exception.
>>
>
> I can buy that sys.exit (may) be throwing an exception...My point of
> contention isn't that I may be throwing one, but why would a subsequent
> "raise" in the except: clause cause the point of program execution to
> jump back up to the sys.exit(0) and then function correctly.

You've missed the point here.  sys.exit() *does* raise an exception:
SystemExit, a subclass of BaseException.  In fact, you can implement
sys.exit in pure Python like so:

def exit(status):
raise SystemExit(status)

Your bare 'except:' catches that SystemExit along with any other
possible exception; the bare 'raise' in the except clause just
re-raises the same SystemExit, which then does what you meant for it
to do in the first place.

Exception classes form a hierarchy, with BaseException being the base
(obviously :)), "except:" is really just shorthand for "except
BaseException:", and is very rarely a good idea.  Deriving from
BaseException are SystemExit, KeyboardInterrupt, and Exception.
SystemExit is the exception raised by sys.exit(), which if left
unhandled, the interpreter takes as a sign to shut down gracefully.
KeyboardInterrupt is raised by Ctrl+C, or (more accurately, if I'm not
mistaken) by sending SIGINT to the process.  Exception is the base
class for all other exceptions, such as TypeError, ValueError,
OSError, etc., and is what you actually want to catch if you really
don't care what exception is raised but want to handle it (though in
most cases, you either should care, or should at least report what the
exception was, preferably with a traceback...which is easiest to do by
not trying to catch the exception at all).

I would suggest skimming through the Python tutorial and/or language
reference if you haven't before, there's a lot of good information in
there that will make your life with Python much easier.

And, please take this positively, but from your posted code it's
fairly apparent that Python is not your native tongue :).  For
instance, you don't need the backslashes in your defaultparams
assignment; the parser knows it needs to keep looking on subsequent
lines when it hasn't found the closing '}' yet.  Also, you can iterate
over a (sys.argv) in a for loop, replacing 'l', 'idx', and the while
loop; something like

for arg in a:
if arg == '-h':
print help # help being defined elsewhere...
elif arg == '-hh':
# no really, print help
print 'help'

And the big one, argument parsing is a solved problem in Python.
Check out the argparse module in the standard library (or if you're
using an older version of Python, try either optparse or getopt.  It's
really a thrice-solved problem ;)).

I hope I've been of some help,

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


Re: buggy python interpretter or am I missing something here?

2014-01-26 Thread Zachary Ware
On Mon, Jan 27, 2014 at 12:46 AM, me  wrote:
>
> In any case, thanks for the answers guys.  I'm satisfied that the except:
> syntax yields undefined behavior, and in my mind it shouldn't be
> syntactically allowed then.

It's not undefined, though; it is explicitly defined.  See my other
message, and here are a couple other places to skim through:
http://docs.python.org/2/tutorial/errors.html and
http://docs.python.org/2/library/exceptions.html

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


Re: buggy python interpretter or am I missing something here?

2014-01-27 Thread Zachary Ware
On Mon, Jan 27, 2014 at 1:17 AM, me  wrote:
> It's the intendation specific requirements that throw me.  I haven't seen
> such a hork since RPG. ;^)

Best I can tell, the only thing RPG and Python have in common is the
fact that they're "programming languages", though I'm being a little
generous to RPG there.  I'll note that RPG (IV) is the only language
I've ever been formally trained in, unfortunately.  I've mostly
forgotten it though, so that's a plus :)

Python's significant indentation is really quite nice and intuitive.
The basic rule of thumb is if a line ends in a colon, the next line
needs to be indented one more level.  If you're continuing the same
logical block, keep the same indention level.  When a logical block is
finished (whether by a raise, continue, break, or return statement, or
just by "falling off the end" of the block), indent the next line one
level less.  Parentheses () (and brackets [] and braces {}) create
what amounts to a 'virtual line', \n characters are basically ignored
until the closing parenthesis is found (as long as they aren't in a
non-triple-quoted string literal).

As long as you don't try to mix tabs and spaces for your indentation
(either is fine on its own, but spaces are generally preferred), it's
very straightforward and allows you to better see the flow of the
program with no question as to whether there is anything hidden within
a block.  I've been using C more in the past two weeks than I really
expected to all this year, and have been bitten more than once by
missing braces.  Indenting intentionally is just a much cleaner,
clearer way to do things (in my opinion, of course).

>> Also, you can iterate over a (sys.argv) in a for
>> loop, replacing 'l', 'idx', and the while loop; something like
>>
>> for arg in a:
>> if arg == '-h':
>> print help # help being defined elsewhere...
>> elif arg == '-hh':
>> # no really, print help
>> print 'help'
>
> Understood, except that some parameters take multiple elements...thus why
> I manually reference the indexes.

Try this on for size, then:

a_iter = iter(a)
for arg in a_iter:
print('current', arg)
if arg == '-#':
print('next', next(a_iter))

> Yup.  Every language and platform has multiple arg parsing libraries.
> Didn't feel like taking the time to research any since most of my python
> ramblings are usually pyQT4 bindings to QT4 gui and postgresql apps.

As with most modules in the standard library, I would bet you can get
started using argparse in probably 15 minutes or less.  The online
documentation of the language and standard library is already quite
good, and there is constant effort going into improving it.  You might
also want to play around with the 'help()' function in the interactive
interpreter, it may have answered your original question without ever
having had to ask here:

>>> help(sys.exit)
Help on built-in function exit in module sys:

exit(...)
exit([status])

Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).

> Pointing out that sys.exit() raises a low level exception was the point I
> was missing.  Thx!

You're welcome, I'm glad I could help :)


As a general reply to the 'attitude' portion of this thread: "mutual
respect" is the name of the game here.  If you show respect (whether
you've already received it or not), you're likely to receive respect.
If not, don't be surprised by heated responses.  This applies equally
to everyone, I'm not pointing fingers at anyone in particular.

Regards,

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


Re: end quote help for a newbie

2014-01-30 Thread Zachary Ware
On Thu, Jan 30, 2014 at 7:26 AM, Peter Clark  wrote:
> There is probably an easy solution to this – but I have not found it.
>
> Trying to terminate a literal in a print statement (from the tutorial).
>
> The literal should be enclosed in double quotes “ “
>
> the initial double quote seems to be OK (if I use a different character it
> flags it) but the ending is flagged as invalid syntax.  I have tried
> changing my keyboard from UK to USA, without any effect, and tried adding a
> space after the final double quote,

Which version of Python are you using?  Make sure you're using the
same version of interpreter and tutorial.  'print' was one of the big
changes between Python 2 and Python 3 (in Python 2 it was a statement,
while in Python 3 it is a function), so a tutorial written with Python
2 in mind will have some issues if you're using Python 3.

If you've already checked that, try copying and pasting your entire
interpreter session into a reply here, and we'll be more able to
figure out what's going on.

Hope this helps,

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


Re: end quote help for a newbie

2014-01-30 Thread Zachary Ware
Please reply to the list, rather than to me directly.  You can use
"Reply to List" if you have that option, or "Reply to All" to make
sure you include the list.

On Thu, Jan 30, 2014 at 8:52 AM, Peter Clark  wrote:
> I do not know how to dump the screen - it will not let me select anything
> with the mouse cursor, so here is my (typed in) reproduction:

Since it looks like you're probably using Windows Command Prompt, you
can right click anywhere in that window, click "Mark", and highlight a
rectangle containing what you want and hit the Enter key.  Note that
it doesn't go by lines, only the rectangle you highlight will be
copied! (Yes, it is horribly annoying :)

Thank you for taking the time to type it all out!

> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40)  [MSC v.1600 32
> bit (In
> tel) on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> print "xyz"
>  File "(stdin)", line 1
> print "xyz"
>^
> SyntaxError: invalid syntax

This right here confirms what I thought: you're using Python 3 with a
Python 2 tutorial.  'print' in Python 3 is a function just like
'input' or 'open', so you have to use it like this instead:

   >>> print("xyz")
   xyz



>>>> print '''xyz"  . . .'''
>  File "(stdin)", line 1
> print '''xyz'''
>  ^
> SyntaxError: invalid syntax
>>>> print '''xyz"  . . .''(note - not appearing on
>>>> screen - this is 2 single quotes)
> ... '''
> File "(stdin)", line 2
> '''
>  ^
> SyntaxError: invalid syntax
>>>>
>
> I do not see anywhere a definition of which version the tutorial relates to,
> but I downloaded it from the Python site on 19th January 2014.

The Python website provides docs for every current version of Python,
and the community is currently in the midst of a very long transition
from version 2.7 to 3.x, so both versions are considered "current".
In fact, most links to the Python documentation will link to the 2.7
version to maintain compatibility.  Here's a link to the Python 3
version of the tutorial, which should work much better for you!
http://docs.python.org/3/tutorial/

You can also find the docs in your Python installation: find Python
3.3 in your start menu, and choose "Python Manuals".  This will open
the same docs as are found online, in standard Windows help file
format.  Click the "Tutorial" link on the first page of that, and you
should have the right tutorial to work from.

Hope this helps, and welcome to Python!

--

Zach

>
> peter.
>
> On Thursday, 30 January 2014, 16:13, Zachary Ware
>  wrote:
>
> On Thu, Jan 30, 2014 at 7:26 AM, Peter Clark  wrote:
>
>> There is probably an easy solution to this – but I have not found it.
>>
>> Trying to terminate a literal in a print statement (from the tutorial).
>>
>> The literal should be enclosed in double quotes “ “
>>
>> the initial double quote seems to be OK (if I use a different character it
>> flags it) but the ending is flagged as invalid syntax.  I have tried
>> changing my keyboard from UK to USA, without any effect, and tried adding
>> a
>> space after the final double quote,
>
>
> Which version of Python are you using?  Make sure you're using the
> same version of interpreter and tutorial.  'print' was one of the big
> changes between Python 2 and Python 3 (in Python 2 it was a statement,
> while in Python 3 it is a function), so a tutorial written with Python
> 2 in mind will have some issues if you're using Python 3.
>
> If you've already checked that, try copying and pasting your entire
> interpreter session into a reply here, and we'll be more able to
> figure out what's going on.
>
> Hope this helps,
>
> --
> Zach
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems compiling Python 3.4 on Ubuntu

2014-02-03 Thread Zachary Ware
On Mon, Feb 3, 2014 at 12:48 PM, Chris Angelico  wrote:
> On Tue, Feb 4, 2014 at 2:50 AM, Christian Heimes  wrote:
>> On 03.02.2014 16:14, Ram Rachum wrote:
>>> Worked! Thanks Ervin!
>>
>>$ sudo apt-get build-dep python3.3
>>
>> will install everything you need to compile Python 3.4 on Debian and
>> Ubuntu. Good luck! :)
>
> Technically that gets everything you need to compile Python 3.3...
> wasn't there one more library needed for 3.4? It's still an excellent
> way to get nearly everything, though.

I think you're thinking of 3.2 -> 3.3.  3.3 added the lzma module,
which requires lzma-dev.  I think 3.4 has the same requirements as
3.3.

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


Re: Latest Python 3.4 in the source repo is broken?

2014-02-04 Thread Zachary Ware
On Tue, Feb 4, 2014 at 9:45 AM, Steven D'Aprano
 wrote:
> Before I bother Python-Dev with this, can anyone else confirm that
> building Python 3.4 from source using the latest version in the source
> repository fails?
>
> # Get the source code
> hg clone http://hg.python.org/cpython
>
> # Build Python (on Unix, sorry Windows and Mac people, you're on your own)
> ./configure --with-pydebug && make -j2
>
>
>
> I get the following errors:
>
> libpython3.4dm.a(pythonrun.o): In function `_Py_InitializeEx_Private':
> /home/steve/python/cpython/Python/pythonrun.c:459: undefined reference to
> `_PyTraceMalloc_Init'
> libpython3.4dm.a(pythonrun.o): In function `Py_Finalize':
> /home/steve/python/cpython/Python/pythonrun.c:648: undefined reference to
> `_PyTraceMalloc_Fini'
> collect2: ld returned 1 exit status
> make: *** [Modules/_testembed] Error 1

The buildbots[1] don't seem to agree, and it builds fine for me on
Windows.  In order of destructiveness, try these:

   make
  Without -j2, see if there's a race somewhere.
   make distclean
  Clear out nearly all generated files.
   hg purge --all
  Clear out everything that's not checked in (this
  includes untracked and ignored files). You may
  need to enable the purge extension,
  `hg --config extensions.purge= purge --all`
  And I would suggest checking the output of
  `hg purge --all -p` before you do it to make sure
  you're not obliterating anything you want to keep.
   hg up null && hg purge --all && hg up default
  Rebuild the repository from scratch (without a full clone).

[1] http://buildbot.python.org/all/waterfall?category=3.x.stable

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


Re: Latest Python 3.4 in the source repo is broken?

2014-02-04 Thread Zachary Ware
On Tue, Feb 4, 2014 at 10:49 AM, Chris Angelico  wrote:
> Are there any buildbots that configure --with-pydebug? This could be a
> debug-only issue.

Only all of them :).  As far as I know, the only 'bot that does a
non-debug build is the "x86 Gentoo Non-Debug" bot.

> That said, though, I just did a build without -j2 (on Linux - Debian
> Wheezy amd64) and it worked fine. Doing another one with -j2 didn't
> show up any errors either, but if it is a -j problem, then as Zachary
> says, it could be a race.
>
> What commit hash were you building from? It might have been broken and
> then fixed shortly, and you got into that tiny window.

There was a brief issue this morning, but it was in typeobject.c, not
_testembed.  See http://hg.python.org/cpython/rev/655d7a55c165

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


Re: Metaprogramming question

2014-02-11 Thread Zachary Ware
On Tue, Feb 11, 2014 at 12:13 PM, Travis Griggs  wrote:
> So here’s my basic question. Is there anyway to programatically query that 
> information in python code?
>
> inspect.signature(datetime.datetime.now)
>
> just gives a ValueError. inspect must only be good for the python code that I 
> write, in python. Is there another way to dig out what the interpreter knows 
> there?

Fixing that issue is in the works.  Argument Clinic[1][2] has been
added for Python 3.4 which, once all C functions have been converted,
will provide signature information for all builtins (functions written
in C).  If you try out the Python 3.4 RC1[3], you can try
inspect.signature(datetime.datetime.now) again and get the information
you expect: that's one of the (unfortunately relatively few) builtins
that is already converted.

Aside from the Argument Clinic effort, builtin functions are pretty
much black boxes to Python--hence why we're trying to fix it!

-- 
Zach

[1] http://docs.python.org/3.4/howto/clinic.html
[2] http://hg.python.org/cpython/file/default/Tools/clinic/clinic.py
[3] http://python.org/download/releases/3.4.0/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Futex hang when running event loop on a separated thread

2015-11-24 Thread Zachary Ware
On Tue, Nov 24, 2015 at 9:46 AM, Marc Aymerich  wrote:
> if __name__ == '__main__':
> loop_container = {}
> handler = threading.Thread(target=run_loop, args=(loop_container, ))
> handler.start()
> try:
> time.sleep(1)
> finally:
> loop_container['loop'].stop()

loop.stop() must be called from the thread running the loop.  You can
do this by doing
`loop_container['loop'].call_soon_threadsafe(loop_container['loop'].stop)`
from the main thread (untested).

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Futex hang when running event loop on a separated thread

2015-11-24 Thread Zachary Ware
On Tue, Nov 24, 2015 at 12:37 PM, Marc Aymerich  wrote:
> still it appears to work only if the main thread is in the foreground
> (as of calling Thread() with deamon=True), I don't get why it behaves
> differently :( maybe it is waiting for other stuff, but no idea how to
> confirm this with strace of other means.. i always see the same
> 'futex(0x7f9a7c10, FUTEX_WAIT_PRIVATE, 0, NULL'

What's your exact version of Python?  asyncio is still evolving
rapidly, and may behave differently between patch releases (say,
between 3.4.1 and 3.4.3).

I have tried out your reproducer with my fix, and I can't provoke a
hang using Python 3.4.3 on either OSX or Ubuntu Trusty.  Can you give
some more specific directions to reproduce?

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


Re: Futex hang when running event loop on a separated thread

2015-11-25 Thread Zachary Ware
On Wed, Nov 25, 2015 at 8:10 AM, Marc Aymerich  wrote:
> problem solved !
> Just found out that threads should be started by fuse.init() in order
> to run when fuse is backgrounded.

Glad you found it; I would not have, not being a pyfuse user :)

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


Re: Help needed with compiling python

2015-11-25 Thread Zachary Ware
On Wed, Nov 25, 2015 at 2:23 PM, Cecil Westerhof  wrote:
> I wanted to install python myself. I started with 2.7.10. If that
> works I also will install 3.5.0.
>
> I did:
> ./configure --prefix=/usr
> make
> make altinstall
>
> I have:
> /usr/bin/python2.7
>
> But when I execute this, I get:
> Could not find platform dependent libraries 
> Consider setting $PYTHONHOME to [:]
> Python 2.7.10 (default, Nov 25 2015, 20:58:29)
> [GCC 4.8.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> Traceback (most recent call last):
>   File "/etc/pythonstart", line 7, in 
> import readline
> ImportError: No module named readline
>
> What do I need to do to get it working?

First off, I strongly suggest not using --prefix=/usr.  Stick with
--prefix=/usr/local (the default) to avoid overwriting the system
Python, which may differ from a source build (and, in fact,
overwriting your system Python may be what's causing some of your
problems; those first two lines are worrying).

Secondly, there are several optional modules that are not compiled
unless particular libraries are found to link against, including
readline.  You'll need the readline development package (probably
readline-dev or readline-devel, depending on your distribution).  You
can quickly pull in the dependencies for all optional modules by doing
something like the following for an apt-based system: `apt-get
build-dep python3`.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-25 Thread Zachary Ware
On Wed, Nov 25, 2015 at 3:52 PM, Cecil Westerhof  wrote:
> My system python was all-ready damaged: that is why I wanted to build
> myself.

Then you should try to repair the system Python install via the system
package manager.  It's not worth the hassle to try to replace it; it
almost certainly won't work for some strange corner case that won't
bite you until 3 months from now.  It's perfectly OK to have a second
Python install in /usr/local, even of the same version as the system
Python.

> It is an openSUSE system. I installed the readline with:
> zypper install readline-devel
>
> The strange thing is that it does mot compile anymore now. I get:
> Python build finished, but the necessary bits to build these modules were not 
> found:
> _bsddb _tkinter   bsddb185
> dbmdl gdbm
> imageopsunaudiodev
> To find the necessary bits, look in setup.py in detect_modules() for the 
> module's name.

Before you installed readline-devel, readline would have been listed
there as well.  It's ok to have modules listed there if you don't need
those particular modules.  Most of those are actually deprecated, and
have been removed from Python 3.  Of those that remain, _tkinter
requires tcl-devel and tk-devel; dbm and gdbm require similarly named
development packages (I have no experience with using dbm/gdbm).

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


Re: Help needed with compiling python

2015-11-26 Thread Zachary Ware
On Thu, Nov 26, 2015 at 3:39 PM, Cecil Westerhof  wrote:
> On Thursday 26 Nov 2015 12:07 CET, Dave Farrance wrote:
>> zypper in -f 
>>
>> So you'll want to try package names like "python" and "python2.7".
>
> Sadly that also only installs only libraries and no applications.

Try "python-base".  (See `zypper wp /usr/bin/python`).

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


Re: Question about code writing '% i, callback'

2015-11-30 Thread Zachary Ware
On Mon, Nov 30, 2015 at 10:44 AM, fl  wrote:
> The content inside parenthesis in last line is strange to me.
>
> "button %s" % i, callback

https://docs.python.org/library/stdtypes.html#printf-style-string-formatting

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


Re: Question about code writing '% i, callback'

2015-11-30 Thread Zachary Ware
On Mon, Nov 30, 2015 at 10:53 AM, Zachary Ware
 wrote:
> On Mon, Nov 30, 2015 at 10:44 AM, fl  wrote:
>> The content inside parenthesis in last line is strange to me.
>>
>> "button %s" % i, callback
>
> https://docs.python.org/library/stdtypes.html#printf-style-string-formatting

Sorry, should have tested that link before sending.  That should be either

https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting

or

https://docs.python.org/2/library/stdtypes.html#string-formatting-operations

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


Re: Frozen apps (py2exe, cx_freeze) built with Python 3.5

2015-12-04 Thread Zachary Ware
On Fri, Dec 4, 2015 at 10:37 AM, Ian Kelly  wrote:
> On Fri, Dec 4, 2015 at 10:21 AM, d...@forestfield.co.uk
>  wrote:
>> Python 3.5 will not run under Windows XP, but what about applications 
>> created using py2exe or cx_freeze under Windows 7, 8 or 10, is there any 
>> knowledge of whether they will run under XP?
>
> I wouldn't expect them to. Those bundlers are just packaging up the
> Python binary, so they should have all the same problems.

I'll confirm that expectation.

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


Re: Problem in pip

2015-12-04 Thread Zachary Ware
On Fri, Dec 4, 2015 at 12:02 PM, Ali Zarkesh  wrote:
> My pip can't download or upgrade anything
> I use python 3.5 (win 32) and my pip version is 7.1.2.
> The error message is this:
>
> Exception:
> Traceback (most recent call last):
> ...
> PermissionError: [Errno 13] Permission denied: 'c:\program files\python
> 3.5\Lib\site-packages\PyWin32.chm'
>
> What do I do?

It looks like you're trying to install in the global environment,
which requires administrative privileges.  You'll either need to do
the above from an Administrative Command Prompt or create a virtual
environment (py -3.5 -m venv ) and try it using the pip from the venv.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter

2015-12-09 Thread Zachary Ware
On Dec 9, 2015 3:36 AM, "Chris Harwood"  wrote:
>
> Hi,
>
> Python » 3.5.0 Documentation » The Python Standard Library » 25.
Graphical User Interfaces with Tk » states that "You can check that tkinter
is properly installed on your system by running python -m tkinter from the
command line; this should open a window demonstrating a simple Tk
interface."
>
> Having recently installed Python 3.5.0 I find that python -m tkinter
produces:
> 'python' is not recognised as an  internal or external command, operable
program or batch file.
>
> Can you help, please?

Try "py -3.5 -m tkinter" instead.  On Windows, you have tkinter unless you
deselected it when you installed Python.

For future reference, it's very helpful to provide your OS and OS version
when asking questions like this; I'm just assuming you're on Windows since
that's the default "that's not on PATH" message.

Hope this helps,
--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python 351x64

2015-12-11 Thread Zachary Ware
On Fri, Dec 11, 2015 at 10:30 AM, Jay Hamm  wrote:
> Hi
>
> I was trying to use your windows version of python 3.5.1 x64.
>
> It has a conflict with a notepad++ plugin NppFTP giving 
> api-ms-win-crt-runtime-I1-1-0.dll error on start up.
>
> This seems pretty well documented on the web. The work around is to delete 
> the plugin and reinstall since it borks the install.

api-ms-win-crt-runtime-I1-1-0.dll is part of the Universal CRT; I
don't see what the relation between Python and Notepad++ is.  This
sounds like an issue with Notepad++/NppFTP, not Python.

> Since about every other admin I've ever known uses notepad++, you might want 
> to fix this.
>
> Also your installer fails to set the permissions correctly:
>
> H:\>py -m pip install requests
> Collecting requests
>   Downloading requests-2.8.1-py2.py3-none-any.whl (497kB)
> 100% || 499kB 875kB/s
> Installing collected packages: requests
> Exception:
> Traceback (most recent call last):
>   File "C:\Program Files\Python35\lib\site-packages\pip\basecommand.py", line 
> 211, in mainstatus = self.run(options, args)
>   File "C:\Program Files\Python35\lib\site-packages\pip\commands\install.py", 
> line 311, in runroot=options.root_path,
>   File "C:\Program Files\Python35\lib\site-packages\pip\req\req_set.py", line 
> 646, in install**kwargs
>   File "C:\Program Files\Python35\lib\site-packages\pip\req\req_install.py", 
> line 803, in installself.move_wheel_files(self.source_dir, root=root)
>   File "C:\Program Files\Python35\lib\site-packages\pip\req\req_install.py", 
> line 998, in move_wheel_filesisolated=self.isolated,
>   File "C:\Program Files\Python35\lib\site-packages\pip\wheel.py", line 339, 
> in move_wheel_filesclobber(source, lib_dir, True)
>   File "C:\Program Files\Python35\lib\site-packages\pip\wheel.py", line 310, 
> in clobberensure_dir(destdir)
>   File "C:\Program Files\Python35\lib\site-packages\pip\utils\__init__.py", 
> line 71, in ensure_diros.makedirs(path)
>   File "C:\Program Files\Python35\lib\os.py", line 241, in makedirs
> mkdir(name, mode) PermissionError: [WinError 5] Access is denied: 
> 'C:\\Program Files\\Python35\\Lib\\site-packages\\requests'
>
> Once I gave myself control it started working.

The point of installing in C:\Program Files\ is that non-admin users
can't write there.  If you want a package installed in the global
site-packages, do it as an administrator or install Python somewhere
else (like C:\Python35\ as previous versions did, but be aware of the
security implications).  Otherwise, create a local venv (`py -3.5 -m
venv path\to\venv`), install your packages there, and use it.

> This is pretty shoddy for released software.

That seems uncalled for.

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


Re: python 351x64

2015-12-11 Thread Zachary Ware
On Fri, Dec 11, 2015 at 11:53 AM, Jay Hamm  wrote:
> It is an issue that borks your install. That seems like your issue which 
> involves notepad++. You might want to talk with them about it or more likely 
> since they've not fixed it in a while - develop a work around or at least a 
> message that pops up and asks if they want it fixed so the install succeeds.

Could you describe the steps you took, the results you got, and the
result you expected?  It's not clear from your description what is
broken by what, and not at all clear that there is any interaction
whatsoever between Python and Notepad++.  Also, we're not in the habit
of including workarounds for bugs in software that may or may not be
installed on some fraction of systems of one particular platform.

> Likewise if you have an option to install for all uses, then it should work 
> without further intervention.

"Install for all users" means "make it readable by all users" rather
than "make it writable by all users."  As I stated previously, install
your package as an administrator if you need it in the global site
packages, or use a virtual environment that you have write access to
as a non-admin.  Or install Python elsewhere (which could be as simple
as choosing "install for just me").  Or adjust the permissions you
want adjusted yourself, as you apparently did.  The installer cannot
do everything for everyone, so it does what we believe to be best for
most use cases and errs on the side of security.

> As for unfair, is this production software or is it a toy? If it is a toy, I 
> withdraw my comment.

It seems to me there is even less call for that.  Civility breeds
civility, incivility breeds contempt.

Python is a volunteer-driven open source project, available to you at
no cost and with free community support.  If there is a bug to fix,
we're happy to fix it, but at bare minimum we need clear steps to
reproduce the problem.  Being open source, you're also more than
welcome to provide a patch that fixes your issues.

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


Re: Should stdlib files contain 'narrow non breaking space' U+202F?

2015-12-18 Thread Zachary Ware
On Fri, Dec 18, 2015 at 1:43 AM, Chris Angelico  wrote:
> On Fri, Dec 18, 2015 at 6:12 PM, Serhiy Storchaka  wrote:
>> Agreed. Please open an issue.
>>
>> Using non-ASCII apostrophes and like in docstrings may be considered a bug.
>
> http://bugs.python.org/issue25899
>
> Also noticed this. Is this a markup error?
>
> Lib/urllib/request.py:190:
> Note that *None& may be returned if no handler handles the request (though
> the default installed global OpenerDirector uses UnknownHandler to ensure
> this never happens).

The '&' is a typo; it should have been '*'.

> It looks fine on the web:
> https://docs.python.org/3/library/urllib.request.html

Because what's on the web has no relation to the docstring :)

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


Re: v3.5.1 - msi download

2015-12-21 Thread Zachary Ware
On Mon, Dec 21, 2015 at 6:49 AM, Mark Lawrence  wrote:
> On 19/12/2015 17:45, Renato Emanuel Dysangco wrote:
>>
>> hello
>>
>> is an **.msi* version of your *Python 3.5.1 (32 bit)* in the pipeline
>> soon?
>>
>> thanks for your time
>>
>
> msi files are not being made available for 3.5.

Correction: there is no longer a single MSI for everything.  However,
each individual component (e.g. the interpreter, the standard library,
the standard library test suite, Tcl/Tk and IDLE, etc...) is packaged
as an MSI, and all can be downloaded by running the installer as
`.exe /layout some/path/to/hold/the/MSIs`.  The .exe
installer itself also takes many useful command line options, see
https://docs.python.org/3.5/using/windows.html.

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


Re: object() can't have attributes

2015-12-23 Thread Zachary Ware
On Dec 23, 2015 7:00 AM, "Chris Angelico"  wrote:
> On Wed, Dec 23, 2015 at 11:46 PM, Neal Becker  wrote:
> > Sometimes I want to collect attributes on an object.  Usually I would make
> > an empty class for this.  But it seems unnecessarily verbose to do this.  So
> > I thought, why not just use an Object?  But no, an instance of Object
> > apparantly can't have an attribute.  Is this intentional?
>
> Yes; there are other uses of object() that benefit from being
> extremely compact. You can use types.SimpleNamespace for this job, or
> you can create the empty class as you're describing. (Chances are you
> can give the class a meaningful name anyway.)

Its more that if you give object() an instance dict, all objects
inheriting from object (i.e., all of them) must have an instance dict,
which would make __slots__ and its benefits impossible.

Another cross-version option:

   >>> bag = type("AttrBag", (), {})()
   >>> bag.spam = 2
   >>> bag.spam
   2

You can even sneak in keyword arguments like SimpleNamespace supports
by passing them in the namespace dict (the third argument):

   >>> bag = type("AttrBag", (), dict(spam=3))()
   >>> bag.spam
   3

Of course, using this you lose easy access to the 'AttrBag' class, but
in most cases you shouldn't need it.  If you do, just make it a
regular class as has been suggested, or save off a reference to the
class before instantiating.

No comments on how ugly this is, though :)

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


Re: Problem Running tkinter gui Code

2015-12-27 Thread Zachary Ware
On Sat, Dec 26, 2015 at 10:59 PM, brian.moreira
 wrote:
> I trying to run a simple code that opens a Tkinter window with text in it, on 
> my windows 8  machine using Python 3.4.3

Hi Brian,

Details are important, and there are several missing from your
question that make any advice just guesswork.  Please show us a simple
code example that doesn't work ("import tkinter;tkinter.Tk()" should
be enough to either run successfully or throw an exception in this
case), and how you're trying to run it that doesn't work.  With that
extra information, we should be able to figure out what's going on.
I've given a couple of guesses below anyway.

> I used to ge: “ImportError: no tkinter module exists”

That is not the phrasing that is actually used in Python; it is better
to copy and paste tracebacks than to retype them from memory.  I
realize that's not an option when the traceback is no longer
available, but that also means that the traceback is irrelevant to the
current issue.  My guess is that either your own code produced that
exception, or you were trying to import 'Tkinter' rather than
'tkinter' (the name changed from Python 2 to Python 3; many online
examples may still refer to 'Tkinter').

> But now it opens a windows Wizard screen that prompts me to Modify, Repair, 
> or Uninstall Python.

That sounds like you're trying to run the installer rather than the
interpreter.  Without knowing how you're trying to run it, I can't
guess as to how that might be.

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


Re: We will be moving to GitHub

2016-01-01 Thread Zachary Ware
On Jan 1, 2016 1:47 PM, "Chris Angelico"  wrote:
>
> On Sat, Jan 2, 2016 at 6:39 AM, Mark Lawrence 
wrote:
> > Please see
> > https://mail.python.org/pipermail/core-workflow/2016-January/000345.html
> >
> > This should encourage developers at all levels to help out, such that
the
> > list of open issues on the bug tracker falls drastically.
>
> How does that interact with the still-Draft status of PEP 481? The
> email seems to mainly be saying "not GitLab", but until PEP 481 is
> accepted, I'm not certain that GitHub is accepted either.
>
> It's not entirely clear whether that message is an acceptance of PEP 481
or not.

I've lost track of the pep numbers, but Brett's decision is final; the
canonical CPython repository will be moving to GitHub in the near future.
Note that we will *not* be using the GitHub issue tracker or wiki, just the
hosting and review/pull request system. There are still several details to
be worked out, though.

--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: We will be moving to GitHub

2016-01-01 Thread Zachary Ware
On Jan 1, 2016 2:35 PM, "Paul Rubin"  wrote:
>
> Zachary Ware  writes:
> > ... the canonical CPython repository will be moving to GitHub in the
> > near future.  Note that we will *not* be using the GitHub issue
> > tracker or wiki, just the hosting and review/pull request system.
>
> Will everyone wanting to submit patches be required to use a Github
> account?  Or will it be enough to put the patch in an outside repo and
> link to it in the Python issue tracker?  I'm glad that (it sounds like)
> no Github account will be needed to submit bug reports.

Correct, no GitHub account will be required for interactions on the
bugs.python.org tracker, and a patch can move all the way through to commit
entirely on the b.p.o tracker (just as currently).

--
Zach
(On a phone)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: We will be moving to GitHub

2016-01-01 Thread Zachary Ware
On Fri, Jan 1, 2016 at 2:03 PM,   wrote:
> Is there a summary document that discusses the options examined and why
> others did not meet the requirements? I am -NOT- trying to dredge up
> arguments about the choice. I am guessing that there have been some.

Easiest would be to look through the archives of the core-workflow
mailing list: https://mail.python.org/pipermail/core-workflow/

> If this fact-based decision was based solely on the fact that the BDFL
> prefers GitHub, please just say so. It is clear that git is a capable tool.

There were three reasons given in Brett's decision message:

   1. No major distinguishing features between GitHub or GitLab

Note that GitHub and GitLab were the only proposals under
consideration; nobody else stepped up to champion any other solution.

   2. Familiarity amongst core devs -- and external contributors -- with GitHub
   3. Guido prefers GitHub

Guido repeatedly stated that his preference should not be taken into
account.  I believe Brett gave it little weight, but obviously it was
in his mind.

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


Re: ignoring or replacing white lines in a diff

2016-01-14 Thread Zachary Ware
On Thu, Jan 14, 2016 at 2:22 PM, Adriaan Renting  wrote:
> Any suggestions?

Instead of trying to make diff behave through subprocess, have a look
at Python's difflib: https://docs.python.org/3/library/difflib.html

In particular, I think `difflib.ndiff(first_list_of_strings,
second_list_of_strings, linejunk=difflib.IS_LINE_JUNK)` might be what
you're looking for (you may not even need to specify linejunk).

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


Re: Installing on linux - missing devel packages

2016-01-21 Thread Zachary Ware
On Thu, Jan 21, 2016 at 1:18 AM, Frank Millman  wrote:
> Hi all
>
> Fedora 22 comes standard with Python 3.4.2. I want to install 3.5.1.
>
> It is easy enough to download the source and run ./configure;make;make
> altinstall. But then I find that I cannot import gzip because zlib-devel is
> missing. I fix that, then I find that sqlite-devel is missing.
>
> Is there an easy way to find out all the missing components, so that when
> the installation is complete I can be sure I have the entire standard lib?

Other answers have given you the proper way to quickly get all the
build dependencies.  In order to see what modules you won't have
available, look at the output near the end of the 'make' command (it's
very quickly buried by `make altinstall`, so be sure to do those as
separate commands :)).  Most of the extension modules are built by
setup.py, which gives a report at the end of its run about which
modules it couldn't find dependencies for, which modules couldn't be
built, and which modules built but couldn't be imported.

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


Re: Python Calculator

2016-02-01 Thread Zachary Ware
Hi Ryan,

On Mon, Feb 1, 2016 at 1:30 PM, Ryan Young  wrote:
> I am new to Python but have known Java for a few years now. With python, so
> far, so good! I created a simple calculator to calculate the total cost of
> a meal. My variables were tip tax total and order. I am confused about how
> to put in a new 'order' because when i reset the order variable to a
> different number it still calculates the original value. I have sent you a
> picture to help you understand my problem. Thank you so much!

Your picture didn't come through.  This is a text-based mailing list
gated to a Usenet group, many participants wouldn't receive an
attached picture no matter how you tried to do it.  Instead, just copy
and paste the code you're running and the exact output you get into
the body of a message, making sure that the formatting (especially
indentation, which is significant in Python) is kept by your email
client.  The simplest step towards ensuring good formatting is to send
your message in plain text mode (rather than HTML).

With your code in hand, I'm sure someone here will be able to explain
what's going on :)

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


Re: snmpset

2016-02-05 Thread Zachary Ware
On Fri, Feb 5, 2016 at 9:16 AM, Matt  wrote:
> How do I do the equivalent of this in Python?
>
> snmpset -v 2c -c $community $ip .1.3.1.1.4.1.1.1.1.1.1.1.0 s test
>
> and
>
> snmpset -v 2c -c $community $ip .1.3.1.1.4.1.1.1.1.1.1.1.0 i 123
>
> and
>
> snmpbulkget -v2c -c $community -m ALL $ip .1.3.1.1.4.1.1.1.1.1.1.1.1
>
> and
>
> snmpget -v2c -c $community -m ALL $ip .1.3.1.1.4.1.1.1.1.1.1.1.2

I have had success with pysnmp (http://pysnmp.sourceforge.net/).  It
is far from a shining example of a Pythonic API and I don't envy you
if you should need to subclass something to change its behavior, but
it is effective.

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


Re: snmpset

2016-02-05 Thread Zachary Ware
On Fri, Feb 5, 2016 at 11:12 AM, Joel Goldstick
 wrote:
> On Fri, Feb 5, 2016 at 11:10 AM, Zachary Ware > wrote:
>> I have had success with pysnmp (http://pysnmp.sourceforge.net/).  It
>
> That page 404s for me

Hmm, it works for me (just tried again).  Even Gmail's automatic
linkification didn't kill it.

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


Re: snmpset

2016-02-05 Thread Zachary Ware
On Fri, Feb 5, 2016 at 11:14 AM, Joel Goldstick
 wrote:
> On Fri, Feb 5, 2016 at 12:12 PM, Joel Goldstick 
> wrote:
>> That page 404s for me.
>>
>
> Pardon me, looks like sourceforge is down

Ah, I guess caching fooled me when I rechecked.

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


Re: AIX build and (potentially missing modules

2016-03-19 Thread Zachary Ware
On Thu, Mar 17, 2016 at 6:02 PM, Michael Felt  wrote:
> I have been packaging python for AIX - and wanting minimal dependancies I
> have been ignoring the final messages from make.
>
> Personally, I do not see any real harm in the missing *audio "bits", but how
> terrible are the other missing "bits" for normal python programs?
>
> Many thanks for feedback!
>
> ...
> building dbm using ndbm
> INFO: Can't locate Tcl/Tk libs and/or headers
>
> Python build finished, but the necessary bits to build these modules were
> not found:
> _bsddb _curses_panel  _sqlite3
> _tkinter   bsddb185   dl
> gdbm   imageoplinuxaudiodev
> ossaudiodevreadline   spwd
> sunaudiodev

None of the above are absolutely necessary, unless you need them
(obviously :)).  Not having readline does make using the REPL rather
annoying, though.

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


Re: Python

2016-03-24 Thread Zachary Ware
On Thu, Mar 24, 2016 at 11:21 AM, Niyoo *Unkown*
 wrote:
> The reason I uninstalled Python was because it was 32 bit not 64 bit and I
> couldn't find the 64 bit version.

Have a look at this page: https://www.python.org/downloads/windows/

The 64 bit versions are the "x86_64" ones.

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


Re: Problem With Embedded Icon and Python 3.4

2016-03-24 Thread Zachary Ware
On Fri, Mar 25, 2016 at 12:10 AM, Wildman via Python-list
 wrote:
> I have a program that I have been trying to rewrite so it will
> run on Python 2.7 and 3.4.  It has been a pain to say the least.
> Thank $DIETY for aliases.  Anyway, I got it all working except
> for one thing.  The program has an embedded icon.  It is displayed
> in the window's titlebar.  The icon is a 16x16 png that has been
> base64 encoded using a Linux utility called memencoder.  The code
> below works perfectly with Python 2.7.  The icon data is complete
> for anyone that wants to try to run this code:
>
> encoded_icon = """\
[...]
> I tried converting the icon string to a byte variable like this:
>
> encoded_icon = bytes("""\
> iVBORw0KGgoNSUhEUgAAABAQCAMoLQ9TBGdBTUEAALGPC/xhBQAAACBj
> (...)
> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""")
>
>
> That give me a different error:
>
> Traceback (most recent call last):
>   File "./myprogram.py", line 269, in 
> ZGlmeQAyMDE2LTAzLTIxVDE1OjE5OjI3LTA1OjAwe2m2vwBJRU5ErkJggg==""")
> TypeError: string argument without an encoding
>
> I'm not sure what that means.  I looks like it wants the string
> to be encoded but it already is.

The bytes constructor in Python 3 requires you to provide an encoding
(utf-8, ascii, latin-1, koi8, etc) when passing in a string, otherwise
it doesn't know what bytes you want and refuses to guess.  You could
fix this by adding `encoding='ascii'` to the bytes() call–but I'm not
certain that that would work in 2.7, and there's a much easier method,
noted later.

> And why the reference to only
> the last line of the string?

Because the traceback would be huge if it included the entire function
call, and there's no need to.  You can find the error from just that
line.  It would be arguably more useful to show the first line, but
that's more difficult to do.

> I am at a loss here.  Any help would be greatly appreciated.

What you need here is a bytes literal, which is accomplished by
prepending a 'b' to the string literal.   Your `encoded_icon = """\`
just needs to become `encoded_icon = b"""\`.  See here [1] for more
information.

-- 
Zach

[1] 
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Zachary Ware
On Fri, Mar 25, 2016 at 3:24 PM, Ray Cote
 wrote:
> Hello:
>
> I’m trying to perform an synchronous task while using asyncio.
> I understand the solution is to use run_in_executor.
> I’m not clear on how to add this into an already running event loop.
>
> I’ve found lots of examples showing how to set up a loop and run this, but
> I’m blocked in regards to doing this when the loop is already established.
>
>
> Example code:
>
> def blocking_func(param1):
> # call the blocking call here.
> return results
>
> async def process_request():
> loop = asyncio.get_event_loop()
> block = loop.run_in_executor(None, blocking_func, “hello”)
> results = await loop.run_until_complete(asyncio.gather(*[block, ])
>
> The above code says “loop already running.” because we’re already in an
> async ask that has been awaited. What is the proper method of adding in
> this new synchronous task?

I'm assuming you're doing `await process_request()` elsewhere, which
is what's producing your error: you're trying to start the loop within
a coroutine running on that loop.  loop.run_in_executor() returns a
Future just like any other coroutine, so process_request just needs
this:

   async def process_request():
   loop = asyncio.get_event_loop()
   results = await loop.run_in_executor(None, blocking_func, 'hello')

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


Re: Adding run_in_executor task to already existing loop.

2016-03-25 Thread Zachary Ware
On Fri, Mar 25, 2016 at 3:56 PM, Marko Rauhamaa  wrote:
> Ray Cote :
>
>> I’m trying to perform an synchronous task while using asyncio.
>
> You seem to want to do something you shouldn't be doing. Asyncio does
> not tolerate synchronous/blocking calls. You will need to move those in
> separate threads or processes if you can't turn them into asynchronous
> tasks.

That's exactly what run_in_executor does.

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Tue, Oct 28, 2014 at 10:22 PM, Rustom Mody  wrote:
> How to see that list and range are both sequences?
> Or more generally how to to introspectively discover (ie not by reading 
> docs!!)
> the abstract base classes -- eg sequence, iterable etc -- for an arbitrary
> object?

# Python 2/3 compatible.  Combine with pprint for nice interactive output
try:
from collections import abc
except ImportError:
import collections as abc

def get_abc_map(cls):
   return {n: issubclass(cls, getattr(abc, n)) for n in dir(abc) if
n[0].isupper()}

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Tue, Oct 28, 2014 at 11:16 PM, Zachary Ware
 wrote:
> def get_abc_map(cls):
>return {n: issubclass(cls, getattr(abc, n)) for n in dir(abc) if
> n[0].isupper()}

Of course, Gmail decided to wrap my long line for me.  In case it's
not obvious, that should be a single line.

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Tue, Oct 28, 2014 at 11:40 PM, Rustom Mody  wrote:
> On Wednesday, October 29, 2014 9:53:46 AM UTC+5:30, Zachary Ware wrote:
>> On Tue, Oct 28, 2014 at 11:16 PM, Zachary Ware wrote:
>> > def get_abc_map(cls):
>> >return {n: issubclass(cls, getattr(abc, n)) for n in dir(abc) if
>> > n[0].isupper()}
>>
>> Of course, Gmail decided to wrap my long line for me.  In case it's
>> not obvious, that should be a single line.
>
> Thanks
>
> Wrapping -- no problem.
> But the isupper looks like black-magic :-)
>
> And removing the ' ... if n[0].isupper()'
> breaks the code

It's a terrible hack for 2/3 compatibility; in 3 I'd do "if not
n.startswith('__')" since the Python 3 collections.abc module only
contains ABCs (and the standard dunder names).  Python 2 has all the
ABCs mixed into the toplevel collections namespace with some other
non-ABCs, but it happens that all the ABCs are capitalized, while the
non-ABCs are not.  The ABCs are imported into collections from
_abcoll, but _abcoll also some uncapitalized non-ABCs as well.

For somewhat greyer magic, do 'from abc import ABCMeta' and filter the
collections<.abc> namespace with isinstance(obj, ABCMeta).  I just
used the above because it's short and sweet and keeps the name handy
:)

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Wed, Oct 29, 2014 at 12:15 AM, Rustom Mody  wrote:
> Maybe nicer to filter out the false's with a filter-false thus??
>
> def ff(d): return [n for n in d if d[n]]

Sure.  Or, combining things:

try:
from collections import abc
except ImportError:
import collections as abc
from abc import ABCMeta

abcs = [o for o in vars(abc).values() if isinstance(o, ABCMeta)]

def get_abcs(cls):
return [abc for abc in abcs if issubclass(cls, abc)]

def get_abc_names(cls):
return [abc.__name__ for abc in get_abcs(cls)]



Of course, that's 3 (progressively shorter) loops to get the names of
the ABCs of a class compared to 1 (fairly short in the first place)
loop for a map of relationships to all available ABCs, but optimizing
such a toy as this would just be an exercise in futility :)

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Wed, Oct 29, 2014 at 12:27 AM, Ben Finney  wrote:
> Zachary Ware  writes:
>
>> Of course, Gmail decided to wrap my long line for me. In case it's not
>> obvious, that should be a single line.
>
> Right, GMail is a poor choice for composing messages. You might get
> better results installing a proper mail client, and communicating via
> IMAP.

Noted, but it works fine 99% of the time for me.  I'm not really
interested in trying to get a proper mail client set up on 5 different
devices and 4 different platforms with settings shared between all
just to avoid inconvenient line-wrapping (that I can avoid just by
sticking to 80 column lines in the first place :).

Although if you have a suggestion for that kind of setup, I'm all ears.

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


Re: What for -- for? (was A bug?)

2014-10-28 Thread Zachary Ware
On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody  wrote:
> On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
>> Of course, that's 3 (progressively shorter) loops to get the names of
>> the ABCs of a class compared to 1 (fairly short in the first place)
>> loop for a map of relationships to all available ABCs, but optimizing
>> such a toy as this would just be an exercise in futility :)
>
> Not so.
>
> The charm of introspection is that the introspection
> itself can be introspected.
> For that to be convincing there needs to be a good combo
> of clarity and succinctness.  In particular why not reduce
> the two functions to one?
>
> def get_abc_names(cls):
> return [abc.__name__ for abc in abcs if issubclass(cls,abc)]

Well, it depends on what you actually want, the spec has been a bit fuzzy ;)

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


Re: set environmental variable from python

2014-10-30 Thread Zachary Ware
On Thursday, October 30, 2014, Artur Bercik  wrote:

> Dear Dave Angel
>
> Thanks for your answer.
>
> I am using Python 2.7
>
> I want to set it permanently.
> I have to set several variables so it would be easier if I could set them
> from Python.
>

Depending on how "permanently" you mean, about your only solutions would be
"os.system('setx <...>')" or manually manipulating the registry with the
_winreg module.

Hope this helps,
--
Zach


-- 
Sent from Gmail Mobile
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: set environmental variable from python

2014-10-30 Thread Zachary Ware
On Thu, Oct 30, 2014 at 9:40 PM, Artur Bercik  wrote:
> could you please elaborate 'setx <...>'?

>From a Command Prompt, do 'help setx' for details on how to use setx.

Rustom's suggestion of using regedit is going to be far easier than
using _winreg (which probably shouldn't even be considered as an
option).  Using `os.system('setx ...')` is going to be the easiest way
to do things if you have to calculate the values of your variables,
but if you just have a bunch of values that you're going to have to
key in anyway, just use setx directly (or in a batch script).

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


Re: Classes

2014-10-31 Thread Zachary Ware
On Fri, Oct 31, 2014 at 12:31 PM, Seymore4Head
 wrote:
> I run across this page frequently.  To me, this is examples.  While
> examples can be quite useful, I don't call this a tutorial.  I have
> found the answer to my question by searching this page several times,
> but the biggest problem with this page is that you can't copy and
> paste the examples into IDLE.

Sure you can, just click the little '>>>' button in the upper right of
the example box.

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


Re: set environmental variable from python

2014-10-31 Thread Zachary Ware
On Fri, Oct 31, 2014 at 1:11 PM, Dennis Lee Bieber
 wrote:
> On Thu, 30 Oct 2014 22:00:33 -0500, Zachary Ware
>  declaimed the following:
> >From a Command Prompt, do 'help setx' for details on how to use setx.
>
> Really? 
>
> C:\Users\Wulfraed\Documents>help setx
> This command is not supported by the help utility.  Try "setx /?".

Oops, should have tried it before posting.  It at least tells you how
to get what I meant to give, though ;)

> OTOH: I didn't know about this command before -- and setting user 
> level
> environment variables on Win7 wasn't working for me...

I came across it after becoming very frustrated with having to jump
through all the hoops to find the environment variable GUI at one
point.

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


Re: Infinitely nested containers

2014-11-21 Thread Zachary Ware
On Fri, Nov 21, 2014 at 12:37 PM, Ian Kelly  wrote:
> Here's a nice crash. I thought this might similarly produce a
> recursion depth error, but no, it's a seg fault!
>
> $ cat test.py
> import itertools
>
> l = []
> it = itertools.chain.from_iterable(l)
> l.append(it)
> next(it)
> $ python3 test.py
> Segmentation fault (core dumped)

Would you mind submitting a bug report for that?  Any segfault
produced by pure Python code must be fixed.

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


Re: Proposed new conditional operator: "or else"

2014-12-02 Thread Zachary Ware
On Tue, Dec 2, 2014 at 11:18 AM, Roy Smith  wrote:
> Wouldn’t it be neat to write:
>
>foo == 42 or else
>
> and have that be an synonym for:
>
> assert foo == 42
>
> :-)

Never going to happen, but I like it!  Perhaps raise IntimidationError
instead of AssertionError when it fails?

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


Re: Python re.search simple question

2014-12-07 Thread Zachary Ware
On Mon, Dec 8, 2014 at 12:52 AM, Ganesh Pal  wrote:
> Hi Folks ,
>
> This  might seem to be very trivial question but iam breaking my head over
> it for a while .
>
>  My understanding is that re.search should search for the match anywhere in
> the string .
>
>
> why is re.search failing in the below case  ??
>
 pattern
> 'Token-based migrations cannot be mixed with level-based: [prev 0 , now 1]'

Your pattern here contains a character class ([enoprvw 01,]).  You'll
need to escape the '[' character to make it literal.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition

2014-12-13 Thread Zachary Ware
On Sat, Dec 13, 2014 at 9:51 AM, Grant Edwards  wrote:
> On 2014-12-10, Bruno Cauet  wrote:
>
>> Nathaniel, I'm not sure about that: even if the code is 2- and 3-compatible
>> you'll pick one runtime.
>
> Why do you say that?
>
> I have both installed.  I use both.  Sometimes it depends on which
> OS/distro I'm running, sometimes other reasons prevail.

Just to give another anecdote, I wrote myself a little tool last night
for visualizing healthcare scenarios to help my family decide which
insurance plan to choose this year.  I didn't realize until I added
'subTest's to the tests and mistakenly invoked them as "python -m
test" instead of "python3 -m test" that I'd accidentally written it to
be 2/3 compatible!  I took the subTest back out, and tests pass with
both interpreters.

-- 
Zach

(If such a tool could be useful to anyone, I can post it on
BitBucket/GitHub.  Its support for all possibilities is far from
complete, but it helped us a bit.  Also, I make no guarantees that you
won't want to gouge your eyes out reading the code, but that
*shouldn't* happen ;)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console rejects an object reference, having made an object with that reference as its name in previous line

2014-12-14 Thread Zachary Ware
On Sun, Dec 14, 2014 at 11:38 PM, Michael Torrie  wrote:
> Guess the future import is only to make not having parens and error.

Python 2.7.8+ (default, Nov  2 2014, 00:32:19) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print(1, 2)
(1, 2)
>>> from __future__ import print_function
>>> print(1, 2)
1 2

Also, without the future import you can't use the 'sep', 'end', and
'file' keyword arguments.

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


Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-14 Thread Zachary Ware
On Mon, Dec 15, 2014 at 1:29 AM, Ben Finney  wrote:
> How can I get that ‘__import__’ call, complete with its ‘fromlist’
> parameter, working correctly under both Python 2 and Python 3, keeping
> the ‘unicode_literals’ setting?

How about "str('bar')"?

> If some kind of kludge is needed to make it work between versions, is
> this a bug which should be fixed so “use Unicode for text” remains
> applicable advice?

Fixed in which version?  The problem is that Python 2 mixes the
notions of strings and bytestrings, and the solution is Python 3.

I believe six also has a "give me a native string" function to help with this.

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


  1   2   3   >