benchmarking in general and using xheap

2016-02-19 Thread Sven R. Kunze

Hi everybody,

I've finally had the time to do the benchmarks and here you go: 
http://srkunze.blogspot.com/2016/02/the-xheap-benchmark.html


The benchmark compares heapq, Heap, OrderHeap, RemovalHeap and XHeap 
regarding their operation heapify, push and pop.


As expected wrapping results in some overhead. Most of the overhead 
consists of wrapper, super and descriptor calls. As with the current 
optimizations efforts, I expect this to be reduced even further. But 
even using current CPython 2.7 or 3.5, the overhead for simple heaps, 
heaps with a custom orders or heaps with removal can be considered 
affordable given the maintenance benefits.


@srinivas
The current removal implementation uses a index-tracking approach with 
quite some overhead for other operations. I am not sure if that is 
remediable with a mark-and-sweep approach but given the time I will 
definitely look into it for another benchmark post now that I have build 
the infrastructure for it.


@all benchmark friends
Not sure how you do your benchmarks, but I am somewhat dissatisfied with 
the current approach. I started out using unittests as they integrated 
nicely with my current toolchain and I could write actual code. Then I 
threw anything away and used timeit as suggested here 
https://mail.python.org/pipermail/python-list/2016-January/702571.html 
and grew my own set of tools around it to produce readable results; 
writing code as strings. :-/


And from what I know, there is no official infrastructure (tools, 
classes, ... such as there is for unittests) around timeit to 
encapsulate benchmarks, choosing a baseline, calculate ratios etc (and 
write code instead of strings).


Does somebody have an idea here?

Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-19 Thread Ethan Furman

On 02/02/2016 07:26 PM, Rick Johnson wrote:

a bunch of garbage.

*sigh*

Time to update my procmail filters...

Anyone know one for deleting all responses to a troll post?

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


Re: [TIP] testfixtures 4.8.0 Released!

2016-02-19 Thread Chris Withers

On 18/02/2016 22:35, Mark Lawrence wrote:

On 18/02/2016 22:27, Chris Withers wrote:

Hi All,

I'm pleased to announce the release of testfixtures 4.9.0 featuring the
following:



4.8.0 or 4.9.0, that is the question, or should it be just how good is 
your version control? :)


Gah, I really need to automate the release emails to stop stupidity like 
that :-S


It's 4.9.0...

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


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-19 Thread Jon Ribbens
On 2016-02-19, Ethan Furman  wrote:
> On 02/02/2016 07:26 PM, Rick Johnson wrote:
>
> a bunch of garbage.
>
> *sigh*
>
> Time to update my procmail filters...
>
> Anyone know one for deleting all responses to a troll post?

Well for this particular imbecile, just blocking posts without any
lower-case letters in the Subject line would apparently help...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Steven D'Aprano
On Fri, 19 Feb 2016 01:14 pm, BartC wrote:

> On 19/02/2016 00:30, Steven D'Aprano wrote:
[...]
>> "Then don't do that. What if you pass the source code through a system
>> that strips out braces?"
> 
> Python doesn't use braces, so that's not a problem!


mydict = {23: 'twenty-three', 17: 'seventeen'}
myset = {1, 2, 4, 8}

:-)



-- 
Steven

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


Re: extending PATH on Windows?

2016-02-19 Thread Ulli Horlacher
pyotr filipivich  wrote:

> >   Windows (especially 7) search function is highly crippled. There is
> >some command sequence that will open it up to looking at other file types
> >and locations.
> >
> >http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-search-does-not-find-files-that-it/61b88d5e-7df7-4427-8a2e-82b801a4a746?auth=1
> 
> 
> Thanks.  I've found it "simpler" to just open a command prompt, and
> use DOS.

How can one search for files with DOS?

-- 
Ullrich Horlacher  Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlac...@tik.uni-stuttgart.de
Universitaet Stuttgart Tel:++49-711-68565868
Allmandring 30aFax:++49-711-682357
70550 Stuttgart (Germany)  WWW:http://www.tik.uni-stuttgart.de/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-19 Thread Chris Angelico
On Fri, Feb 19, 2016 at 9:42 PM, Ulli Horlacher
 wrote:
> pyotr filipivich  wrote:
>
>> >   Windows (especially 7) search function is highly crippled. There is
>> >some command sequence that will open it up to looking at other file types
>> >and locations.
>> >
>> >http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-search-does-not-find-files-that-it/61b88d5e-7df7-4427-8a2e-82b801a4a746?auth=1
>>
>>
>> Thanks.  I've found it "simpler" to just open a command prompt, and
>> use DOS.
>
> How can one search for files with DOS?

dir /s /b \*add2path.*

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread wrong . address . 1
On Thursday, 18 February 2016 21:31:20 UTC+2, Tim Chase  wrote:
> On 2016-02-18 07:33, wrong.addres...@gmail.com wrote:
> > Another question I have is regarding reading numerical data from
> > text files. Is it necessary to read one character at a time, or can
> > one read like in Fortran and Basic (something like Input #5, X1,
> > X2, X3)?
> 
> A lot of my work is extracting data from text files.  If it's
> CSV-format data, Python's "csv" module in the standard library offers
> some nice tools for doing this.
> 
> If the numbers are in plain-text, but at fixed column-offsets, I
> usually create a mapping of slices to make it easier to work with.
> If this is the case and you want some example code, I can dig some up.
> 
> Finally, if the data is actually binary, Python's "struct" module
> (also in the standard library) makes it a lot easier to work with such
> data.
> 
> -tkc

Thanks. The data I will often have to read from text files could read like

2 12.657823 0.1823467E-04 114 0
3 4 5 9 11
"Lower"
278.15

Is it straightforward to read this, or does one have to read one character at a 
time and then figure out what the numbers are?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread wrong . address . 1
On Friday, 19 February 2016 03:06:58 UTC+2, Steven D'Aprano  wrote:
> On Fri, 19 Feb 2016 02:35 am, wrong.addres...@gmail.com wrote:
> 
> > I am almost eager to do this but want to be sure that I know the pitfalls
> > in using Python for my purposes. Thanks for your encouraging response.
> 
> Honestly "wrong.address.1", the ONLY pitfall you need to be aware of is to
> beware of trying to write VB code using Python's interpreter. Python has
> it's own way of doing things, and if you insist on doing them "just like
> VB" you will end up with horrible, slow, inefficient, unusable code. 

This I am aware of. And it is not a problem.

> That's
> not to say that VB is worse, or Python is worse, just that they are
> different. You don't use a hammer the same was a screwdriver.
> 
> Python is a 20+ year old language used by millions of professionals all over
> the world for everything from quick scripting, scientific computing, web
> applications, long-running server applications, and everything in between.
> The answer to every one of your questions "Can Python do X?" will be one
> of:
> 
> (1) Yes it can.
> 
> (2) No, but instead it will do Y which gives you the same result.
> 
> 
> I'll be frank, to come here and ask a bunch of questions like:
> 
> "Is it necessary to read one character at a time...?"
> 
> is a little bit rude. I don't want to discourage you from asking questions,
> but think about *how* you ask them. What you're doing is a little bit like
> going to a car dealer, looking at the cars, then asking a bunch of
> questions:

No, I first saw this trouble in VB.net. Later I found there was an input 
command which allowed me to read numbers in varying formats more or less like 
in Fortran or Basic. I really hope Python has decent ways of reading numeric 
data which may not follow regular formats.

> 
> "So... does this car have a reverse gear or can it only go forward? Do the
> doors open for entry, or do I have to squeeze through the windows? Can I
> use the radio while driving, or is there only enough power for one at a
> time?"
> 
> In most programming communities, if you start asking questions like that,
> you can expect to be ignored or abused. Good thing we're a friendly
> bunch :-)

I hope it was not rude. At least I did not mean to be. 

> 
> 
> Instead, a good question is:
> 
> "How do I read a bunch of numbers from a text file?"
> 
> 
> I'll show you, not only how to read a bunch of numbers, but how to write
> them first.
> 
> Of course there are a million different ways you can do this, and for
> serious use you will probably want to use something like a CSV (Comma
> Separated Values) file like Excel produces, but for a quick idea of how
> Python works, let's write some numbers to a file, one per line. Comments
> start with # and have no effect. Remember that indentation is meaningful:
> you must use the same number of spaces as shown in my code.
> 
> Copy and paste this code into the Python interpreter:
> 
> 
> 
> # = cut =
> 
> # Define some numbers.
> numbers = [1, 45, 38, 99, 1002, 83025, 234, 55, 273, 2]
> # Open a file for writing.
> with open("myfile.txt", "w") as f:
> # Write each number to the file, one per line.
> for number in numbers:
> print("Writing %d to the file." % number)
> f.write(str(number) + "\n")
> 
> # = cut =
> 
> 
> 
> And that's done. Five lines of code, ignoring comments. Now let's read them
> back and see if they're the same:
> 
> 
> # = cut =
> 
> # Prepare a list to hold the numbers.
> data = []
> # Open a file for reading.
> with open("myfile.txt", "r") as f:
> # Read each line.
> for line in f:
> value = line.strip()  # Get rid of trailing newline.
> print("Read %s from the file." % value)
> data.append(int(value))
> 

I have not yet learnt any Python so I do not understand almost anything. 
Besides, I will have to read data given to me by people, which may not come in 
nice formats like CSV, or pre-written by Python.

> # Confirm the numbers read in are the same as those written out.
> if data != numbers:
> print("mismatch in values")
> 
> # Print the sorted values.
> print(sorted(data))
> 
> # = cut =
> 
> 
> 
> Does this help?
> 

Yes. Thanks for your response. I am clear about that I will have to think in a 
different way and not try to convert VB to Python line by line.

> 
> 
> -- 
> Steven

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Mark Lawrence

On 19/02/2016 10:47, wrong.addres...@gmail.com wrote:


2 12.657823 0.1823467E-04 114 0
3 4 5 9 11
"Lower"
278.15

Is it straightforward to read this, or does one have to read one character at a 
time and then figure out what the numbers are?



One character at a time in a high level language like Python, please. 
See http://nedbatchelder.com/text/python-parsers.html for a list of 
parsers that can do all sorts for you.  Or the stdlib re module 
https://docs.python.org/3/library/re.html.  Or a likely replacement for 
the re module https://pypi.python.org/pypi/regex.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Tony van der Hoff

On 19/02/16 11:23, Mark Lawrence wrote:

On 19/02/2016 10:47, wrong.addres...@gmail.com wrote:


2 12.657823 0.1823467E-04 114 0
3 4 5 9 11
"Lower"
278.15

Is it straightforward to read this, or does one have to read one
character at a time and then figure out what the numbers are?



One character at a time in a high level language like Python, please.
See http://nedbatchelder.com/text/python-parsers.html for a list of
parsers that can do all sorts for you.  Or the stdlib re module
https://docs.python.org/3/library/re.html.  Or a likely replacement for
the re module https://pypi.python.org/pypi/regex.


Am I alone in thinking that this wrongaddress character is trolling?

How much effort can it be to just install python, and try out these 
simple things *before* asking trivia here?


--
Tony van der Hoff| mailto:t...@vanderhoff.org
Buckinghamshire, England |
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python keyword args can be any string

2016-02-19 Thread Rustom Mody
On Thursday, February 18, 2016 at 11:12:45 AM UTC+5:30, Steven D'Aprano wrote:
> Today I learned that **kwargs style keyword arguments can be any string:
> 
> 
> py> def test(**kw):
> ... print(kw)
> ... 
> py> kwargs = {'abc-def': 42, '': 23, '---': 999, '123': 17}
> py> test(**kwargs)
> {'': 23, '123': 17, '---': 999, 'abc-def': 42}
> 

Hoo boy!
Namespaces are a honking great idea though sometimes the honk is too loud

> 
> Bug or feature?

Dunno...
I dont like it
-- 
https://mail.python.org/mailman/listinfo/python-list


Compilation of Python 3.5.1 fails on Solaris 8 sparc

2016-02-19 Thread bthk55
When I try to compile the python from source on Solaris 8. I getting the 
following error


"""

Modules/_localemodule.o: In function PyIntl_gettext': 
Modules/_localemodule.o(.text+0xb60): undefined reference to libintl_gettext' 
Modules/_localemodule.o: In function PyIntl_dgettext': 
Modules/_localemodule.o(.text+0xba8): undefined reference to libintl_dgettext' 
Modules/_localemodule.o: In function PyIntl_dcgettext': 
Modules/_localemodule.o(.text+0xbf8): undefined reference to libintl_dcgettext' 
Modules/_localemodule.o: In function PyIntl_textdomain': 
Modules/_localemodule.o(.text+0xc38): undefined reference to 
libintl_textdomain' Modules/_localemodule.o: In function 
PyIntl_bindtextdomain': Modules/_localemodule.o(.text+0xcec): undefined 
reference to libintl_bindtextdomain' Modules/_localemodule.o: In function 
PyIntl_bind_textdomain_codeset': Modules/_localemodule.o(.text+0xde0): 
undefined reference to libintl_bind_textdomain_codeset' collect2: ld returned 1 
exit status make: *** [Programs/_freeze_importlib] Error 1


"""



 CPPFLAGS="-I/usr/local/include"
 export CPPFLAGS
 LD_OPTIONS='-L/usr/local/lib -R/usr/local/lib'
 export LD_OPTIONS
 LDFLAGS='-L/usr/local/lib -R/usr/local/lib'
 export LDFLAGS
 CC=/usr/local/bin/gcc OPT="-O2" ./configure  
--prefix=/opt/soe/local/Python-3.5.1
-- 
https://mail.python.org/mailman/listinfo/python-list


Compilation of Python 3.5.1 fails on Solaris 8 sparc

2016-02-19 Thread bthk55
When I try to compile the python from source on Solaris 8. I getting the 
following error 



"""

Modules/_localemodule.o: In function PyIntl_gettext': 
Modules/_localemodule.o(.text+0xb60): undefined reference to libintl_gettext' 
Modules/_localemodule.o: In function PyIntl_dgettext': 
Modules/_localemodule.o(.text+0xba8): undefined reference to libintl_dgettext' 
Modules/_localemodule.o: In function PyIntl_dcgettext': 
Modules/_localemodule.o(.text+0xbf8): undefined reference to libintl_dcgettext' 
Modules/_localemodule.o: In function PyIntl_textdomain': 
Modules/_localemodule.o(.text+0xc38): undefined reference to 
libintl_textdomain' Modules/_localemodule.o: In function 
PyIntl_bindtextdomain': Modules/_localemodule.o(.text+0xcec): undefined 
reference to libintl_bindtextdomain' Modules/_localemodule.o: In function 
PyIntl_bind_textdomain_codeset': Modules/_localemodule.o(.text+0xde0): 
undefined reference to libintl_bind_textdomain_codeset' collect2: ld returned 1 
exit status make: *** [Programs/_freeze_importlib] Error 1


"""



The steps that I followed :

CPPFLAGS="-I/usr/local/include"
 export CPPFLAGS
 LD_OPTIONS='-L/usr/local/lib -R/usr/local/lib'
 export LD_OPTIONS
 LDFLAGS='-L/usr/local/lib -R/usr/local/lib'
 export LDFLAGS
 CC=/usr/local/bin/gcc OPT="-O2" ./configure  
--prefix=/opt/soe/local/Python-3.5.1

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


ANN: eGenix PyRun - One file Python Runtime 2.1.2

2016-02-19 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

 eGenix PyRun - One file Python Runtime

Version 2.1.2


 An easy-to-use single file relocatable Python run-time -
   available for Linux, Mac OS X and Unix platforms,
 with support for Python 2.6, 2.7 and
   **also for Python 3.4**.


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-PyRun-2.1.2-GA.html



INTRODUCTION

eGenix PyRun is our open source, one file, no installation version of
Python, making the distribution of a Python interpreter to run based
scripts and applications to Unix based systems as simple as copying a
single file.

eGenix PyRun's executable only needs 11MB for Python 2 and 13MB for
Python 3, but still supports most Python application and scripts - and
it can be compressed to just 3-4MB using upx, if needed.

Compared to a regular Python installation of typically 100MB on disk,
eGenix PyRun is ideal for applications and scripts that need to be
distributed to several target machines, client installations or
customers.

It makes "installing" Python on a Unix based system as simple as
copying a single file.

eGenix has been using eGenix PyRun internally in the mxODBC Connect
Server product since 2008 with great success and decided to make it
available as a stand-alone open-source product.

We provide both the source archive to build your own eGenix PyRun, as
well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32-
and 64-bit versions. The binaries can be downloaded manually, or you
can let our automatic install script install-pyrun take care of the
installation: ./install-pyrun dir and you're done.

Please see the product page for more details:

http://www.egenix.com/products/python/PyRun/



NEWS

This patch level release of eGenix PyRun 2.1 comes with the following
enhancements:

Enhancements / Changes
--

 * Upgraded eGenix PyRun to work with and use Python 2.7.11 per
   default.

   Python 2.7.11 now uses computed gotos in the interpreter loop,
   adding some more performance. In addition, the vulnerable SSLv3
   protocol was switched off in the defaults of the ssl module.

 * Upgraded eGenix PyRun to work with and use Python 3.4.4 for the
   Python 3 version.

 * Added an explicit --libpath configure setting to work a problem
   with some 64-bit platforms defaulting to lib64/. The new setting
   forces the libs to always go into a lib/ directory.


install-pyrun Quick Install Enhancements
-

eGenix PyRun includes a shell script called install-pyrun, which
greatly simplifies installation of PyRun. It works much like the
virtualenv shell script used for creating new virtual environments
(except that there's nothing virtual about PyRun environments).

https://downloads.egenix.com/python/install-pyrun

With the script, an eGenix PyRun installation is as simple as running:

./install-pyrun targetdir

This will automatically detect the platform, download and install the
right pyrun version into targetdir.

We have updated this script since the last release:

 * Updated install-pyrun to default to eGenix PyRun 2.1.2 and its
   feature set.

For a complete list of changes, please see the eGenix PyRun Changelog:

http://www.egenix.com/products/python/PyRun/changelog.html



LICENSE

eGenix PyRun is distributed under the eGenix.com Public License 1.1.0
which is an Open Source license similar to the Python license. You can
use eGenix PyRun in both commercial and non-commercial settings
without fee or charge.

Please see our license page for more details:

http://www.egenix.com/products/python/PyRun/license.html

The package comes with full source code.



DOWNLOADS

The download archives and instructions for installing eGenix PyRun can
be found at:

http://www.egenix.com/products/python/PyRun/

As always, we are providing pre-built binaries for all common
platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac
OS X 32/64-bit. Source code archives are available for installation on
other platforms, such as Solaris, AIX, HP-UX, etc.

___

SUPPORT

Commercial support for this product is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.



MORE INFORMATION

For more information about eGenix PyRun, licensing and download
instructions, please visit ou

Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread wrong . address . 1
On Friday, 19 February 2016 13:24:46 UTC+2, Mark Lawrence  wrote:
> On 19/02/2016 10:47, wrong.addres...@gmail.com wrote:
> >
> > 2 12.657823 0.1823467E-04 114 0
> > 3 4 5 9 11
> > "Lower"
> > 278.15
> >
> > Is it straightforward to read this, or does one have to read one character 
> > at a time and then figure out what the numbers are?
> >
> 
> One character at a time in a high level language like Python, please. 

That is what VB.net seems designed for. I know nothing about Python, and have 
to decide soon, so I am asking these *very stupid* questions.

> See http://nedbatchelder.com/text/python-parsers.html for a list of 
> parsers that can do all sorts for you.  Or the stdlib re module 

I am an engineer, and do not understand most of the terminology used there. And 
do I need something fancy to read a line of numbers? Should it not be built 
into the language?

The new languages are not designed by engineers or for engineers, so it is 
likely that what we take for granted may not be easy in Python. It was 
different when there was no such thing called "computer science" in the 1960s.

> https://docs.python.org/3/library/re.html.  Or a likely replacement for 
> the re module https://pypi.python.org/pypi/regex.
> 

Thanks.

> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Tim Chase
On 2016-02-19 02:47, wrong.addres...@gmail.com wrote:
> 2 12.657823 0.1823467E-04 114 0
> 3 4 5 9 11
> "Lower"
> 278.15
> 
> Is it straightforward to read this, or does one have to read one
> character at a time and then figure out what the numbers are? -- 

It's easy to read.  What you do with that mess of data is the complex
part.  They come in as byte-strings, but you'd have to convert them
to the corresponding formats:

  from shlex import shlex
  USE_LEX = True # False
  with open('data.txt') as f:
for i, line in enumerate(f, 1):
  if USE_LEX:
bits = shlex(line)
  else:
bits = line.split()
  for j, bit in enumerate(bits, 1):
if bit.isdigit():
  result = int(bit)
  t = "an int"
elif '"' in bit:
  result = bit
  t = "a string"
else:
  result = float(bit)
  t = "a float"
print("On line %i I think that item %i %r is %s: %r" % (
  i,
  j,
  bit,
  t,
  result,
  ))

The USE_LEX controls whether the example code uses string-splitting
on white-space, or uses the built-in "shlex" module to parse for
quoted strings that might contain a space.  The naive way of
string-splitting will be faster, but choke on string-data containing
spaces.

You'd have to make up your own heuristics for determining what type
each data "bit" is, parsing it out (with int(), float() or whatever),
but the above gives you some rough ideas with at least one known
bug/edge-case.  But we can't do *all* the work for you ;-)

-tkc




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


Re: extending PATH on Windows?

2016-02-19 Thread Gisle Vanem
Dennis Lee Bieber wrote:

>>> How can one search for files with DOS?
>>
>> dir /s /b \*add2path.*
>>
>> ChrisA
>
>   Or move to PowerShell...
>
> Windows PowerShell
> Copyright (C) 2009 Microsoft Corporation. All rights reserved.
>
> PS C:\Users\Wulfraed\Documents> Get-ChildItem -Path c:\ -Filter *add2path*
> -Name -Recurse

Clumsy IMHO. Try:
c:\> envtool --path *ipython*

Matches in %PATH:
  12 Feb 2015 - 17:16:12: f:\ProgramFiler\Python27\Scripts\ipython-script.py
  12 Feb 2015 - 17:16:12: f:\ProgramFiler\Python27\Scripts\ipython.exe
  12 Feb 2015 - 17:16:12: 
f:\ProgramFiler\Python27\Scripts\ipython.exe.manifest
  12 Feb 2015 - 17:16:12: 
f:\ProgramFiler\Python27\Scripts\ipython2-script.py
  12 Feb 2015 - 17:16:12: f:\ProgramFiler\Python27\Scripts\ipython2.exe
  12 Feb 2015 - 17:16:12: 
f:\ProgramFiler\Python27\Scripts\ipython2.exe.manifest
  08 Feb 2015 - 12:48:56: 
f:\ProgramFiler\Python27\Scripts\ipython_win_post_install.py
7 matches found for "*ipython*".

---

Or find a spec on *all partitions* using Everything Search engine:
c:\> envtool --evry *ipython*
Matches from EveryThing:
...
133 matches found for "*ipython*".

---

Or for Python-path searches:
c:\> envtool --python *ipython*
Matches in "f:\ProgramFiler\Python27\python.exe" sys.path[]:
  23 Jan 2016 - 13:50:30: 
f:\ProgramFiler\Python27\lib\site-packages\ipython-2.1.0-py2.7.egg\IPython\
  23 Jan 2016 - 13:50:26: 
f:\ProgramFiler\Python27\lib\site-packages\IPython\
  23 Jan 2016 - 13:50:30: 
f:\ProgramFiler\Python27\lib\site-packages\ipython-2.1.0-py2.7.egg\
3 matches found for "*ipython*".

-

My envtool is at https://github.com/gvanem/EnvTool
EveryThing is at http://voidtools.com/

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Peter Otten
Tim Chase wrote:

> On 2016-02-19 02:47, wrong.addres...@gmail.com wrote:
>> 2 12.657823 0.1823467E-04 114 0
>> 3 4 5 9 11
>> "Lower"
>> 278.15
>> 
>> Is it straightforward to read this, or does one have to read one
>> character at a time and then figure out what the numbers are? --
> 
> It's easy to read.  What you do with that mess of data is the complex
> part.  They come in as byte-strings, but you'd have to convert them
> to the corresponding formats:
> 
>   from shlex import shlex
>   USE_LEX = True # False
>   with open('data.txt') as f:
> for i, line in enumerate(f, 1):
>   if USE_LEX:
> bits = shlex(line)
>   else:
> bits = line.split()
>   for j, bit in enumerate(bits, 1):
> if bit.isdigit():
>   result = int(bit)
>   t = "an int"
> elif '"' in bit:
>   result = bit
>   t = "a string"
> else:
>   result = float(bit)
>   t = "a float"
> print("On line %i I think that item %i %r is %s: %r" % (
>   i,
>   j,
>   bit,
>   t,
>   result,
>   ))
> 
> The USE_LEX controls whether the example code uses string-splitting
> on white-space, or uses the built-in "shlex" module to parse for
> quoted strings that might contain a space.  The naive way of
> string-splitting will be faster, but choke on string-data containing
> spaces.
> 
> You'd have to make up your own heuristics for determining what type
> each data "bit" is, parsing it out (with int(), float() or whatever),
> but the above gives you some rough ideas with at least one known
> bug/edge-case.  

Or just tell the parser what to expect:

$ cat read_data_shlex2.py
import shlex

CONVERTERS = {
"i": int,
"f": float,
"s": str
}


def parse_line(types, line=None, file=None):
if line is None:
line = file.readline()
values = shlex.split(line)
if len(values) != len(types):
raise ValueError("Too few/many values %r <-- %r" % (types, values))
return tuple(CONVERTERS[t](v) for t, v in zip(types, values))


with open("data.txt") as f:
print(parse_line("iffii", file=f))
print(parse_line("i", file=f))
print(parse_line("s", file=f))
print(parse_line("fsi", file=f))
print(parse_line("ff", file=f))
$ cat data.txt
2 12.657823 0.1823467E-04 114 0
3 4 5 9 11
"Lower"
1.2 "foo \" bar \\ baz" 42
278.15
$ python3 read_data_shlex2.py 
(2, 12.657823, 1.823467e-05, 114, 0)
(3, 4, 5, 9, 11)
('Lower',)
(1.2, 'foo " bar \\ baz', 42)
Traceback (most recent call last):
  File "read_data_shlex2.py", line 24, in 
print(parse_line("ff", file=f))
  File "read_data_shlex2.py", line 15, in parse_line
raise ValueError("Too few/many values %r <-- %r" % (types, values))
ValueError: Too few/many values 'ff' <-- ['278.15']
$ 


But we can't do *all* the work for you ;-)

If this thread goes long enough eventually we will ;)

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


Re: Ohnoes significant whitespace (was: Considering migrating to Python from Visual Basic 6 for engineering applications)

2016-02-19 Thread Grant Edwards
On 2016-02-19, Ben Finney  wrote:

> So I am sympathetic to Python newcomers recoiling in horror from
> significant whitespace, *before* they try it. And because of that, we
> are burdened with forever needing to deal with that reaction and
> soothing it.

The first time I wrote Python (it was the only language I could find
that was free and for which I found understandable examples on how to
suck e-mail messages out of Outlook using DCOM -- which was the
problem to be solved), I had an initial aversion to the "significant
whitespace" concept.  That immediately vanished once I started working
on my first Python code.  That was Python 1.5.2 back in 1999.  Shortly
after that, I went to the trouble to add raw socket support to the
Python standard library "socket" module so that I could use Python for
some other tasks. :)

> Those people who claim to have tried Python and *still* complain
> about “significant whitespace”, I have no sympathy for.

I, on the other hand, do feel sorry for them because their brains are
evidently broken in some basic manner that can't help but cause them
suffering.

>  Python clearly does it right, and it's a huge boon to readability
> and reducing simple errors.

Indeed.

-- 
Grant Edwards   grant.b.edwardsYow! Used staples are good
  at   with SOY SAUCE!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Guido on python3 for beginners

2016-02-19 Thread Grant Edwards
On 2016-02-19, Steven D'Aprano  wrote:

> Pascal was easy to learn and powerful, but it made the mistake of not
> standardising on a few critical functions that production languages need,
> like strings. Nevertheless, for the first 10 or 15 years, Apple used a mix
> of Pascal and assembly to write not just the operating system but a whole
> lot of applications for the Macintosh. Anyone who says that Pascal is a toy
> language is just ignorant.

At one point, Pascal was quite popular for emedded systems
(e.g. microprocessor) development also.  One of my first projects out
of school back in the early 80's was working on cell-site radio
firmware (Zilog Z8000 uP).

There were a few small extensions to the standard langage to deal with
the fact it was low-level code running on bare metal, but it was quite
a nice language for writing stuff for small microprocessor-based
systems.  After you debugged everything, you could turn off
array-bounds-checking, and the extra overhead compared to something
like C vanished.

-- 
Grant Edwards   grant.b.edwardsYow! HAIR TONICS, please!!
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread BartC

On 17/02/2016 19:49, wrong.addres...@gmail.com wrote:


Could someone kindly tell me advantages and disadvantages of Python?


Something I don't think anyone has mentioned is that Python is 
case-sensitive.


So keywords, identifiers, library functions and so on have to be written 
just right. (For example the identifier "abcdef" can be written 64 
different ways, such as "aBCdEf", and they will all be different symbols.)


This is a complete pain if you're used to a language that ignores case 
(except in data). But pretty much every language now is the same, you 
can't do much about it, you just need to be aware of it.


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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Chris Angelico
On Sat, Feb 20, 2016 at 2:34 AM, BartC  wrote:
> On 17/02/2016 19:49, wrong.addres...@gmail.com wrote:
>
>> Could someone kindly tell me advantages and disadvantages of Python?
>
>
> Something I don't think anyone has mentioned is that Python is
> case-sensitive.
>
> So keywords, identifiers, library functions and so on have to be written
> just right. (For example the identifier "abcdef" can be written 64 different
> ways, such as "aBCdEf", and they will all be different symbols.)
>
> This is a complete pain if you're used to a language that ignores case
> (except in data). But pretty much every language now is the same, you can't
> do much about it, you just need to be aware of it.

Indeed. Most languages are case sensitive, because it's too risky to
do anything else. Python 3 allows you to use other scripts than the
basic Latin letters in the ASCII set:

>>> привет = "hello"

and of course you wouldn't expect that to collide with something
written in a completely different script. As far as the interpreter's
concerned, "P" and "p" are just as different as are "A", "Α", "А", and
so on.

Like with Fortran's peculiar freedom in whitespace, case insensitivity
in identifiers is an unwanted relic of a past age.

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Grant Edwards
On 2016-02-19, BartC  wrote:
> On 17/02/2016 19:49, wrong.addres...@gmail.com wrote:
>
>> Could someone kindly tell me advantages and disadvantages of Python?
>
> Something I don't think anyone has mentioned is that Python is 
> case-sensitive.

That's an _advantage_ not a disadvantage.

Anybody who writes code that depends on the assumption that FOOBAR
foobar and FooBar are identical deserves to have his keyboard explode
under his fingertips.

> So keywords, identifiers, library functions and so on have to be
> written just right.

IOW, you're expected to do things correctly rather that have the
compiler try to guess the intent of your inept typing.

[OK, I may be a bit touchy on this subject from dealing with code
written by people used to working on Windows where they assume that
file names are case insensitive, so therefore seem to feel the need to
spice up life by using a variety of spellings for the same damned
file.]

-- 
Grant Edwards   grant.b.edwardsYow! I would like to
  at   urinate in an OVULAR,
  gmail.comporcelain pool --
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Grant Edwards
On 2016-02-19, Chris Angelico  wrote:

> and of course you wouldn't expect that to collide with something
> written in a completely different script. As far as the interpreter's
> concerned, "P" and "p" are just as different as are "A", "Α", "А", and
> [...]

...and a, ã, á, ä, â, à, ą, å, æ, etc.

[Just wanted to see if I remembered how to do that...]

-- 
Grant Edwards   grant.b.edwardsYow! I like your SNOOPY
  at   POSTER!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird and sparese cgi:error

2016-02-19 Thread Φώντας Λαδοπρακόπουλος
#!/usr/bin/python3
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, re, os, sys, socket, time, datetime, locale, codecs, random, 
smtplib, subprocess, pymysql, geoip2.database
from datetime import datetime, timedelta
from http import cookies
===

[root@nexus cgi-bin]# /usr/bin/python3 
Python 3.3.2 (default, Aug 14 2014, 14:25:52) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
=

[root@nexus cgi-bin]# /usr/bin/python3 ./metrites.py 
Error in sys.excepthook:
ValueError: underlying buffer has been detached

Original exception was:
Traceback (most recent call last):
  File "/opt/rh/python33/root/usr/lib64/python3.3/os.py", line 673, in 
__getitem__
value = self._data[self.encodekey(key)]
KeyError: b'HTTP_USER_AGENT'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./metrites.py", line 22, in 
userinfo = os.environ['HTTP_USER_AGENT']
  File "/opt/rh/python33/root/usr/lib64/python3.3/os.py", line 676, in 
__getitem__
raise KeyError(key)
KeyError: 'HTTP_USER_AGENT'
[root@nexus cgi-bin]# 
===

everything is they should but still iam gettign that weird cgi:err error
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird and sparese cgi:error

2016-02-19 Thread Φώντας Λαδοπρακόπουλος
[root@nexus cgi-bin]# head -10 ./metrites.py 
#!/usr/bin/python3
# coding=utf-8

import cgitb; cgitb.enable()
import cgi, re, os, sys, socket, time, datetime, locale, codecs, random, 
smtplib, subprocess, pymysql, geoip2.database
from datetime import datetime, timedelta
from http import cookies


#needed line, script does *not* work without it
[root@nexus cgi-bin]# ^C
[root@nexus cgi-bin]# /usr/bin/python3 
Python 3.3.2 (default, Aug 14 2014, 14:25:52) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt
>>> 
KeyboardInterrupt
>>> quit()
[root@nexus cgi-bin]# 
[root@nexus cgi-bin]# /usr/bin/python3 ./metrites.py 
Error in sys.excepthook:
ValueError: underlying buffer has been detached

Original exception was:
Traceback (most recent call last):
  File "/opt/rh/python33/root/usr/lib64/python3.3/os.py", line 673, in 
__getitem__
value = self._data[self.encodekey(key)]
KeyError: b'HTTP_USER_AGENT'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./metrites.py", line 22, in 
userinfo = os.environ['HTTP_USER_AGENT']
  File "/opt/rh/python33/root/usr/lib64/python3.3/os.py", line 676, in 
__getitem__
raise KeyError(key)
KeyError: 'HTTP_USER_AGENT'
[root@nexus cgi-bin]# ^C
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread BartC

On 19/02/2016 15:59, Grant Edwards wrote:

On 2016-02-19, BartC  wrote:

On 17/02/2016 19:49, wrong.addres...@gmail.com wrote:


Could someone kindly tell me advantages and disadvantages of Python?


Something I don't think anyone has mentioned is that Python is
case-sensitive.


That's an _advantage_ not a disadvantage.

Anybody who writes code that depends on the assumption that FOOBAR
foobar and FooBar are identical deserves to have his keyboard explode
under his fingertips.


So keywords, identifiers, library functions and so on have to be
written just right.


IOW, you're expected to do things correctly


You mean pedantically.

In real life, names generally are not case sensitive. I can call myself 
bart or Bart or BART or any of the remaining 13 combinations, without 
anyone getting confused (but they might be puzzled as to why I'd choose 
to spell it bArT).


And in speech there is no distinction between case (so anyone using 
voice-to-text is going to have trouble with writing code).


Even in computing, many kinds of names are case-insensitive, emails and 
website names for example. I think even MS would struggle to register 
all the 32768 upper and lower case combinations of www dot microsoft dot 
com. It becomes nonsensical.


It's just a popular fad in programming languages, probably originating 
in C and/or Unix, and doing a good job of infesting everything else.



rather that have the
compiler try to guess the intent of your inept typing.


That's not being very helpful then. Do I type help, Help or HELP? Or 
would it be a better idea to recognise all of them, instead of 
stubbornly refusing to work until I get it exactly right?



[OK, I may be a bit touchy on this subject from dealing with code
written by people used to working on Windows where they assume that
file names are case insensitive, so therefore seem to feel the need to
spice up life by using a variety of spellings for the same damned
file.]


But they're all the same file?

If I had to give you the name of a file over the phone, wouldn't it make 
life much easier if I didn't have to describe, letter by letter, which 
was upper case and which was lower?


[Most of the code I write uses lower-case anyway, but I also like to 
write temporary or debugging code in upper-case. That won't work in a 
language like Python. But it's also a nuisance in remembering if it's 
tkinter or Tkinter. Or are there actually two different packages 
differing only in the case of one letter of their names?]


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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Chris Angelico
On Sat, Feb 20, 2016 at 3:32 AM, BartC  wrote:
> In real life, names generally are not case sensitive. I can call myself bart
> or Bart or BART or any of the remaining 13 combinations, without anyone
> getting confused (but they might be puzzled as to why I'd choose to spell it
> bArT).

There are other conflations, too. You might transliterate your name
into another script, or represent it using only sounds found in a
particular language, to introduce yourself in a completely different
culture. Would you expect a computer to recognize all those as
identical, too? Should the computer treat "Dad" and "John" as the same
variable, since my father's name happens to be John? (Or should it
treat them as distinct, because the _computer's_ father wasn't named
John?)

> And in speech there is no distinction between case (so anyone using
> voice-to-text is going to have trouble with writing code).

That's true of all sorts of other spoken parallels too, though. If
you're using speech-to-text to enter code, you will have to cope with
those, and it's no extra complexity to cope with mixed case.

> Even in computing, many kinds of names are case-insensitive, emails and
> website names for example. I think even MS would struggle to register all
> the 32768 upper and lower case combinations of www dot microsoft dot com. It
> becomes nonsensical.

DNS is a bit of a special case. It has a bizarre mess of ASCII-only
and full-Unicode naming, such that it really shouldn't be held up as a
model for programming language identifiers.

> It's just a popular fad in programming languages, probably originating in C
> and/or Unix, and doing a good job of infesting everything else.

Go ask a German how ß should be capitalized. Then ask if it's
identical to "ss", which also uppercases to "SS". Now, how do you feel
about that whole case sensitivity thing? And is "Ö" equivalent to "O"
or to "OE" or neither? (Answer: It depends on context.)

Everyone I've heard arguing in favour of programming language case
insensitivity has assumed ASCII-only (and English-only). It's 2016.
Time to stop making that assumption.

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


Re: extending PATH on Windows?

2016-02-19 Thread pyotr filipivich
Ulli Horlacher  on Fri, 19 Feb 2016
10:42:52 + (UTC) typed in comp.lang.python  the following:
>pyotr filipivich  wrote:
>
>> >   Windows (especially 7) search function is highly crippled. There is
>> >some command sequence that will open it up to looking at other file types
>> >and locations.
>> >
>> >http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-search-does-not-find-files-that-it/61b88d5e-7df7-4427-8a2e-82b801a4a746?auth=1
>> 
>> 
>> Thanks.  I've found it "simpler" to just open a command prompt, and
>> use DOS.
>
>How can one search for files with DOS?

cd %searchPathStart%
dir /s *.php
or variants.
-- 
pyotr filipivich
Next month's Panel: Graft - Boon or blessing?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Matt Wheeler
On 19 February 2016 at 14:58, Peter Otten <__pete...@web.de> wrote:
> Tim Chase wrote:
>> [a long thing]
>
> Or just tell the parser what to expect:
>
> [another long thing]

If you're sure all of the words on a line are going to be numbers then

>>> [float(x) for x in '2 12.657823 0.1823467E-04 114 0'.split()]
[2.0, 12.657823, 1.823467e-05, 114.0, 0.0]

This will of course break if anything on the line *doesn't* look like
a float, but rather than jumping straight into a giant engineering
exercise I'd probably start there.

I'm sure there was a recent thread about returning the best fit type
(i.e. int, if not then float, if not then str)?

-- 
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing data across callbacks in ThreadPoolExecutor

2016-02-19 Thread Joseph L. Casale
> It's still not clear to me specifically what you're trying to do. It
> would really help if you would describe the problem in more detail.
> Here's what I think you're trying to do:
> 
> 1) Submit a task to a ThreadPoolExecutor and get back a future.
> 
> 2) When the task is complete, submit another task that needs the
> result of the first task to do its work.
> 
> 3) When the chained task is complete, return the final result of the
> chained task back to whoever submitted the original task via the
> original task's future.
> 
> The problem arises in that the original task's future already
> completed when the original task did. The chained task sets its result
> in a different future that the submitter didn't know about.

Yes, I may have 2 or more tasks that depend on the previous.
They are each distinct tasks, or continuations, so they each want the result
of the previous task however each one can cancel the set.

The callback model doesn't apply, its based on the result of _one_ task.

What I need I are continuations, much like the .NET TPL.

def task_a():
return "a"

def task_b():
return "b"

def task_c():
return "c"

So I submit task_a, if it completes successfully, task_b runs on its result.
If task_b completes successfully, task_c runs on its result. They "look"
like callbacks, but they are continuations.

Task_b must be able to cancel the continuation of task_c  if it see's task_a
has failed.

Thanks for the continued help!
jlc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Grant Edwards
On 2016-02-19, BartC  wrote:
>
>> IOW, you're expected to do things correctly
>
> You mean pedantically.

:)

> In real life, names generally are not case sensitive. I can call
> myself bart or Bart or BART or any of the remaining 13 combinations,
> without anyone getting confused (but they might be puzzled as to why
> I'd choose to spell it bArT).

You probably answer to half-a-dozen others things as well.  Such
natural-language concepts just don't work in code.

> And in speech there is no distinction between case (so anyone using
> voice-to-text is going to have trouble with writing code).

That's a good point.

> Even in computing, many kinds of names are case-insensitive, emails and 
> website names for example. I think even MS would struggle to register 
> all the 32768 upper and lower case combinations of www dot microsoft dot 
> com. It becomes nonsensical.

True.

>> [OK, I may be a bit touchy on this subject from dealing with code
>> written by people used to working on Windows where they assume that
>> file names are case insensitive, so therefore seem to feel the need to
>> spice up life by using a variety of spellings for the same damned
>> file.]
>
> But they're all the same file?

Yes.  Sometimes three or four different spellings scattered over
multiple domains (Makefile, C source (e.g. #include directives), and
the filesystem).

-- 
Grant Edwards   grant.b.edwardsYow! I'd like some JUNK
  at   FOOD ... and then I want to
  gmail.combe ALONE --
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-19 Thread eryk sun
On Fri, Feb 19, 2016 at 4:48 AM, Chris Angelico  wrote:
> On Fri, Feb 19, 2016 at 9:42 PM, Ulli Horlacher
>  wrote:
>> pyotr filipivich  wrote:
>>
>>> >   Windows (especially 7) search function is highly crippled. There is
>>> >some command sequence that will open it up to looking at other file types
>>> >and locations.
>>> >
>>> >http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-search-does-not-find-files-that-it/61b88d5e-7df7-4427-8a2e-82b801a4a746?auth=1
>>>
>>>
>>> Thanks.  I've found it "simpler" to just open a command prompt, and
>>> use DOS.
>>
>> How can one search for files with DOS?
>
> dir /s /b \*add2path.*

This search is carried out by Windows NT instead of MS-DOS in almost
all cases nowadays:

Z:\Python\repo\2.7>dir /s /b Tools\Scripts\win_add?*.*
Breakpoint 0 hit
ntdll!NtQueryDirectoryFile:
7ffb`d9d138c0 4c8bd1  mov r10,rcx

0:000> dS poi(@rsp + a*8)
00df`bab1ff9a  "win_add><"*"

NT has normal (i.e. sane) * and ? wildcard matching, so WinAPI
FindFirstFile has to translate DOS wildcards to special values before
calling NtQueryDirectoryFile. See the file-system runtime library
function FsRtlIsNameInExpression [1]. Dot, question mark, and asterisk
may be mapped (depending on context in the string) to double quote and
the angle brackets, as shown in the above debugger output in which
'win_add?*.*' is passed to the system call as 'win_add><"*'.

DOS_DOT (")
Matches either a period or zero characters beyond the
name string.

DOS_QM (>)
Matches any single character or, upon encountering a
period or end of name string, advances the expression
to the end of the set of contiguous DOS_QMs.

DOS_STAR (<)
Matches zero or more characters until encountering
and matching the final . in the name.

[1]: https://msdn.microsoft.com/en-us/library/ff546850
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-19 Thread eryk sun
On Thu, Feb 18, 2016 at 10:55 AM, Ulli Horlacher
 wrote:
> Ulli Horlacher  wrote:
>
>> > but simpler still and more reliable to just call QueryValueEx.
>>
>> I find it more complicated.
>
> I have now (after long studying docs and examples)::
>
> def get_winreg(key,subkey):
>   try:
> rkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,key,0,winreg.KEY_READ)
> rvalue,rtype = winreg.QueryValueEx(rkey,subkey)
> winreg.CloseKey(rkey)
>   except WindowsError:
> rvalue,rtype = None,None
>   return rvalue

The 2nd parameter should be named "value_name", not "subkey".

A registry key is similar to an NTFS file-system node, and values are
similar to NTFS $DATA streams [1], but with different types of data
[2] other than just REG_BINARY, to make it easier to store structured
configuration data.

[1]: https://msdn.microsoft.com/en-us/library/aa364404
[2]: https://msdn.microsoft.com/en-us/library/ms724884
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exception handling for socket.error in Python 3.5/RStudio

2016-02-19 Thread shaunak . bangale
On Monday, February 8, 2016 at 1:05:08 AM UTC-7, shaunak...@gmail.com wrote:
> On Sunday, February 7, 2016 at 1:23:32 AM UTC-7, dieter wrote:
> > Shaunak Bangale  writes:
> > > ...
> > > while (count > 0):
> > > try :
> > > # read line from file:
> > > print(file.readline())
> > > # parse
> > > parse_json(file.readline())
> > > count = count - 1
> > > except socket.error as e:
> > > print('Connection fail', e)
> > > print(traceback.format_exc())
> > > ...
> > > Error:
> > > except socket.error as e:
> > >  ^
> > > SyntaxError: invalid syntax
> > 
> > Are you sure, that there is no invisible character at the end
> > of that line?
> > 
> > When I try code like the above (in PYthon 2.7), there is no
> > "SyntaxError":
> > 
> > >>> while(False):
> > ... try :
> > ... # read line from file:
> > ... print(file.readline())
> > ... # parse
> > ... parse_json(file.readline())
> > ... count = count - 1
> > ... except socket.error as e:
> > ... print('Connection fail', e)
> > ... print(traceback.format_exc())
> > ... 
> > >>> 
> > 
> > 
> > Another reason for your problem could be an older Python version.
> > The "as" construct as part of the "except" clause is a more recent
> > addition to Python.
> 
> Hi Dieter,
> 
> I typed that line again but didn't help. I am using Python 3.5.
-

Hi people, it finally worked. One problem was with the way modules were set up, 
so installed anacoda and using accessing it through PyCharm. It's working well 
now. Another problem was with the initiation command, had to renew the password 
and that's working too. I sincerely thank everyone here who tried to help me. 
:) 
Have a great weekend guys!

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread wrong . address . 1
On Friday, 19 February 2016 16:08:46 UTC+2, Tim Chase  wrote:
> On 2016-02-19 02:47, wrong.addres...@gmail.com wrote:
> > 2 12.657823 0.1823467E-04 114 0
> > 3 4 5 9 11
> > "Lower"
> > 278.15
> > 
> > Is it straightforward to read this, or does one have to read one
> > character at a time and then figure out what the numbers are? -- 
> 
> It's easy to read.  What you do with that mess of data is the complex
> part.  They come in as byte-strings, but you'd have to convert them
> to the corresponding formats:
> 
>   from shlex import shlex
>   USE_LEX = True # False
>   with open('data.txt') as f:
> for i, line in enumerate(f, 1):
>   if USE_LEX:
> bits = shlex(line)
>   else:
> bits = line.split()
>   for j, bit in enumerate(bits, 1):
> if bit.isdigit():
>   result = int(bit)
>   t = "an int"
> elif '"' in bit:
>   result = bit
>   t = "a string"
> else:
>   result = float(bit)
>   t = "a float"
> print("On line %i I think that item %i %r is %s: %r" % (
>   i,
>   j,
>   bit,
>   t,
>   result,
>   ))
> 

All this I could do with one Read or Input statement in Fortran and Basic.

> The USE_LEX controls whether the example code uses string-splitting
> on white-space, or uses the built-in "shlex" module to parse for
> quoted strings that might contain a space.  The naive way of
> string-splitting will be faster, but choke on string-data containing
> spaces.
> 
> You'd have to make up your own heuristics for determining what type
> each data "bit" is, parsing it out (with int(), float() or whatever),
> but the above gives you some rough ideas with at least one known
> bug/edge-case.  But we can't do *all* the work for you ;-)
> 
> -tkc

This is precisely reading one character at a time. If not exactly reading one 
character, it is effectively looking at each character to assemble the number. 
Not a good sign. I guess there might be libraries which will help read numbers 
better, but I would expect a good language to be able to handle this basic 
thing for engineers - to read numbers like Fortran and Basic do.

Still, if I have misunderstood something, I will be glad to be corrected. I 
would generally know that the first three numbers will be floating point, the 
next will be something and then the next will be something else, etc. Does that 
help or does one still have to look at each character and determine how to 
place it in a number?

Thanks for your patience. I don't want surprises later on, which is why I am 
asking very stupid questions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Processing multiple forms in a cgi script

2016-02-19 Thread Jeremy Leonard
I have a quick question regarding processing multiple forms. Most of my 
experience has been where there is just one form so the logic was pretty 
straight forward for me. My question revolves around how to handle multiple 
forms. I've seen that you can have an id for each form, but I'm unsure how to 
process that. Any info or a point/kick in the right direction would be 
appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Processing multiple forms in a cgi script

2016-02-19 Thread Jon Ribbens
On 2016-02-19, Jeremy Leonard  wrote:
> I have a quick question regarding processing multiple forms. Most of
> my experience has been where there is just one form so the logic was
> pretty straight forward for me. My question revolves around how to
> handle multiple forms. I've seen that you can have an id for each
> form, but I'm unsure how to process that. Any info or a point/kick
> in the right direction would be appreciated.

Only one form can be submitted at once. To identify in your code
which one it was, either make the "action" attribute for each form
point to different URLs, or put a unique "name" attribute on each
submit button, or put an  in each form with
a unique name/value.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Processing multiple forms in a cgi script

2016-02-19 Thread Grant Edwards
On 2016-02-19, Jon Ribbens  wrote:
> On 2016-02-19, Jeremy Leonard  wrote:
>
>> I have a quick question regarding processing multiple forms. Most
>> of my experience has been where there is just one form so the logic
>> was pretty straight forward for me. My question revolves around how
>> to handle multiple forms. I've seen that you can have an id for
>> each form, but I'm unsure how to process that. Any info or a
>> point/kick in the right direction would be appreciated.
>
> Only one form can be submitted at once.

Unless you do something rather obtuse like using Javascript to
serialize multiple HTML forms into separate JSON objects and then
combine those into a single JSON object and then submit that via an
AJAX call.  [You could use XML instead of JSON, but that'd be even
worse.]

I've no clue _why_ somebody would go to the trouble to do something
like that -- if you know how to stuff like that, then you probably
know better than to actually do it. ;)

If the data on some set of multiple forms is always going to be
submitted together, then just use a single form instead.

If you want to handle multiple different forms _one_at_a_time_ using a
single form handler, then just put a hidden input field on each form
that identifies which one it is.

-- 
Grant Edwards   grant.b.edwardsYow! Are you selling NYLON
  at   OIL WELLS??  If so, we can
  gmail.comuse TWO DOZEN!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Passing data across callbacks in ThreadPoolExecutor

2016-02-19 Thread Ian Kelly
On Fri, Feb 19, 2016 at 10:18 AM, Joseph L. Casale
 wrote:
>> It's still not clear to me specifically what you're trying to do. It
>> would really help if you would describe the problem in more detail.
>> Here's what I think you're trying to do:
>>
>> 1) Submit a task to a ThreadPoolExecutor and get back a future.
>>
>> 2) When the task is complete, submit another task that needs the
>> result of the first task to do its work.
>>
>> 3) When the chained task is complete, return the final result of the
>> chained task back to whoever submitted the original task via the
>> original task's future.
>>
>> The problem arises in that the original task's future already
>> completed when the original task did. The chained task sets its result
>> in a different future that the submitter didn't know about.
>
> Yes, I may have 2 or more tasks that depend on the previous.
> They are each distinct tasks, or continuations, so they each want the result
> of the previous task however each one can cancel the set.
>
> The callback model doesn't apply, its based on the result of _one_ task.
>
> What I need I are continuations, much like the .NET TPL.
>
> def task_a():
> return "a"
>
> def task_b():
> return "b"
>
> def task_c():
> return "c"
>
> So I submit task_a, if it completes successfully, task_b runs on its result.
> If task_b completes successfully, task_c runs on its result. They "look"
> like callbacks, but they are continuations.
>
> Task_b must be able to cancel the continuation of task_c  if it see's task_a
> has failed.

Thanks for the clarification. The first suggestion that I gave in my
initial reply will handle cancellations implicitly. If task_b() is
waiting on future_a.result() and task_a() raises an uncaught
exception, then future_a.result() will reraise the exception. If it
then propagates uncaught out of task_b() then future_b.result() will
again reraise the exception, and task_c() that is waiting on it will
reraise it as well.  See this in action below.

You might also be interested in the promise decorator described at
https://bloerg.net/2013/04/05/chaining-python-futures.html. It does
essentially the same as what I've described, but it abstracts it into
a decorator and allows the caller to determine which arguments to pass
as futures and which to pass as concrete values, instead of
hard-coding the resolution of futures of dependencies into the task
function itself.

In the course of digging that up, I also found this:
https://github.com/dvdotsenko/python-future-then which is brand-new
and looks promising, but I can't see how one would use it with a
ThreadPoolExecutor.


py> import concurrent.futures
py> def task_a():
... raise ValueError(42)
...
py> def task_b(future_a):
... return future_a.result()
...
py> def task_c(future_b):
... return future_b.result()
...
py> executor = concurrent.futures.ThreadPoolExecutor()
py> future_a = executor.submit(task_a)
py> future_b = executor.submit(task_b, future_a)
py> future_c = executor.submit(task_c, future_b)
py> future_c.result()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
398, in result
return self.__get_result()
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
357, in __get_result
raise self._exception
  File "/usr/local/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
  File "", line 2, in task_c
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
398, in result
return self.__get_result()
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
357, in __get_result
raise self._exception
  File "/usr/local/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
  File "", line 2, in task_b
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
398, in result
return self.__get_result()
  File "/usr/local/lib/python3.5/concurrent/futures/_base.py", line
357, in __get_result
raise self._exception
  File "/usr/local/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
  File "", line 2, in task_a
ValueError: 42
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird python 2.7 import thing

2016-02-19 Thread Dan Stromberg
On Thu, Feb 18, 2016 at 5:40 PM, Dan Stromberg  wrote:

>
> BTW, this is not a package I pip installed from pypi - it's an
> internal-only project.

I need to correct this: It's not installed from pypi.python.org, but
it probably is installed from our internal pypi server.

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


Re: Processing multiple forms in a cgi script

2016-02-19 Thread Jeremy Leonard
On Friday, February 19, 2016 at 1:18:41 PM UTC-5, Jon Ribbens wrote:
> On 2016-02-19, Jeremy Leonard wrote:
> > I have a quick question regarding processing multiple forms. Most of
> > my experience has been where there is just one form so the logic was
> > pretty straight forward for me. My question revolves around how to
> > handle multiple forms. I've seen that you can have an id for each
> > form, but I'm unsure how to process that. Any info or a point/kick
> > in the right direction would be appreciated.
> 
> Only one form can be submitted at once. To identify in your code
> which one it was, either make the "action" attribute for each form
> point to different URLs, or put a unique "name" attribute on each
> submit button, or put an  in each form with
> a unique name/value.

Thank you. That helps. The hidden input will be perfect.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extending PATH on Windows?

2016-02-19 Thread eryk sun
On Fri, Feb 19, 2016 at 8:18 AM, Gisle Vanem  wrote:
> Dennis Lee Bieber wrote:
>
 How can one search for files with DOS?
>>>
>>> dir /s /b \*add2path.*
>>>
>>> ChrisA
>>
>>   Or move to PowerShell...
>>
>> Windows PowerShell
>> Copyright (C) 2009 Microsoft Corporation. All rights reserved.
>>
>> PS C:\Users\Wulfraed\Documents> Get-ChildItem -Path c:\ -Filter *add2path*
>> -Name -Recurse
>
> Clumsy IMHO. Try:
> c:\> envtool --path *ipython*
>
> Matches in %PATH:

Your tool has special integration with Python's search paths, which is
cool. But for someone that wants some of these features without
installing another program and without learning PowerShell, where.exe
may suffice:

https://technet.microsoft.com/en-us/library/cc753148

Search PATH and the current directory:

C:\>where kd
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\kd.exe

Search an environment variable that may contain one or more directories:

C:\>set MYPATH=^
More? %SystemRoot%\System32;^
More? %SystemRoot%\System32\drivers

C:\>where $MYPATH:conhost*.*
C:\Windows\System32\conhost.exe
C:\Windows\System32\ConhostV1.dll
C:\Windows\System32\ConhostV2.dll

Search a list of directories:

C:\>where "%MYPATH%":con*.sys
C:\Windows\System32\drivers\condrv.sys

Recursively search a directory:

C:\>where /r "%LocalAppData%\Programs" python.exe
C:\Users\Administrator\AppData\Local\Programs\Python\
Python35-32\python.exe
-- 
https://mail.python.org/mailman/listinfo/python-list


downloading a CSV

2016-02-19 Thread noydb
Greetings All,

Python v 3.4, windows

I want to be able to download this CSV file and save to disk
>> http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv 

This (interacting with the web using python) is very new to me, so can anyone 
provide direction on how to go about doing this?  Is it involved?  Is there a 
good example out there that can illustrate the needs/mechanics/how-to?

Many thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: downloading a CSV

2016-02-19 Thread MRAB

On 2016-02-19 18:46, noydb wrote:

Greetings All,

Python v 3.4, windows

I want to be able to download this CSV file and save to disk

http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv


This (interacting with the web using python) is very new to me, so can anyone 
provide direction on how to go about doing this?  Is it involved?  Is there a 
good example out there that can illustrate the needs/mechanics/how-to?

Many thanks in advance!


Lookup "urlretrieve" in the help file.

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


Re: downloading a CSV

2016-02-19 Thread Grant Edwards
On 2016-02-19, noydb  wrote:
> Greetings All,
>
> Python v 3.4, windows
>
> I want to be able to download this CSV file and save to disk
>>> http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv 

Unless you really want to write a Python program, "wget" is a good solution:

http://gnuwin32.sourceforge.net/packages/wget.htm

Just do this on a command line:

 wget http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv


Curl is another good option:

https://curl.haxx.se/

Just do this at the command line:

 curl http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv > 
all_month.csv

-- 
Grant Edwards   grant.b.edwardsYow! I just had my entire
  at   INTESTINAL TRACT coated
  gmail.comwith TEFLON!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weird python 2.7 import thing

2016-02-19 Thread Dan Stromberg
On Fri, Feb 19, 2016 at 10:33 AM, Dan Stromberg  wrote:
> On Thu, Feb 18, 2016 at 5:40 PM, Dan Stromberg  wrote:
>
>>
>> BTW, this is not a package I pip installed from pypi - it's an
>> internal-only project.
>
> I need to correct this: It's not installed from pypi.python.org, but
> it probably is installed from our internal pypi server.
>
> Thanks!

I've taken this to Stackoverflow:
http://stackoverflow.com/questions/35512989/weird-cpython-2-7-import-traceback-not-an-importerror

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


Re: downloading a CSV

2016-02-19 Thread noydb
Thanks!  That was pretty easy.

import urllib.request
url = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv'
urllib.request.urlretrieve(url, csv_file)
csv_file = r"C:\Temp\earthquakeAll_last30days.csv"
urllib.request.urlretrieve(url, csv_file)

I do want to use python -- there's much more I need to do with the file after 
downloading.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: downloading a CSV

2016-02-19 Thread Joel Goldstick
On Fri, Feb 19, 2016 at 3:05 PM, noydb  wrote:

> Thanks!  That was pretty easy.
>
> import urllib.request
> url = '
> http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv'
> urllib.request.urlretrieve(url, csv_file)
> csv_file = r"C:\Temp\earthquakeAll_last30days.csv"
> urllib.request.urlretrieve(url, csv_file)
>
> I do want to use python -- there's much more I need to do with the file
> after downloading.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

You might look at the Requests library.  Its third party, but easier to
understand and use than urllib

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread BartC

On 19/02/2016 18:14, wrong.addres...@gmail.com wrote:

On Friday, 19 February 2016 16:08:46 UTC+2, Tim Chase  wrote:



All this I could do with one Read or Input statement in Fortran and Basic.


I agree with you completely. This stuff is far more complicated than it 
need be. And the fact that there a hundred possible ways of doing it 
doesn't help!


It seems modern languages don't like having i/o as part of the language 
but prefer to have function libraries deal with it. And it still seems 
to be largely DIY...


Although the approach used by Peter Otten doesn't seem too bad. Then you 
would end up writing something like this:


a,b,c,d,e = readline(f, "iffii")

with f being a file handle. You'd need to deal with tokens (in the 
implementation of readline), but not individual characters of each number.


(Remember that Fortran and VB6 are be statically typed, so the language 
knows what types to read into each of those variables. And the Fortran 
might have a 'format' to help out, unless they've got rid of those since 
1979...)


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


Re: How to properly override the default factory of defaultdict?

2016-02-19 Thread Ian Kelly
On Thu, Feb 18, 2016 at 10:41 AM, Herman  wrote:
> From: Ben Finney 
>>
>> you are using the inheritance hierarchy but thwarting it by not using
>> ‘super’. Instead::
>>
>> super().__init__(self, default_factory, *a, **kw)
>>
>> and::
>>
>> super().__getitem__(self, key)
>> --
>>  \   "Those who will not reason, are bigots, those who cannot, are |
>>   `\fools, and those who dare not, are slaves." —“Lord” George |
>> _o__)Gordon Noel Byron |
>> Ben Finney
>
> super does not work for defaultdict. I am using python 2.7. If I use
> super(defaultdict, self).__init__(default_factory, *a, **kw), I get the
> error:
>
> super(defaultdict, self).__init__(default_factory, *a, **kw)
> TypeError: 'function' object is not iterable

You're using it incorrectly. If your class is named
DefaultDictWithEnhancedFactory, then the super call would be:

super(DefaultDictWithEnhancedFactory, self).__init__(default_factory, *a, **kw)

You pass in the current class so that super can look up the next
class. If you pass defaultdict instead, super will think that it's
being called *by* defaultdict and call the __init__ method on its own
superclass, dict, which has a different signature.
defaultdict.__init__ is effectively skipped.

> Look like inheriting from defaultdict is easier. I don't even  have to
> override the constructor as suggested by Chris Angelico above. Thanks.

True, although there's a faint code smell as this technically violates
the Liskov Substitution Principle; the default_factory attribute on
defaultdict instances is expected to be a function of zero arguments,
not one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: downloading a CSV

2016-02-19 Thread Tim Chase
On 2016-02-19 10:46, noydb wrote:
> I want to be able to download this CSV file and save to disk
> >> http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv 

  from urllib.request import urlopen
  data = 
urlopen("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv";)

> This (interacting with the web using python) is very new to me, so
> can anyone provide direction on how to go about doing this?  Is it
> involved?  Is there a good example out there that can illustrate
> the needs/mechanics/how-to?

You can then either iterate over the incoming data and write it to a
file:

  with open('output.csv', 'wb') as output:
output.writelines(data)

or you can process it as it comes in:

  import csv
  r = csv.DictReader(line.decode('utf8') for line in data)
  for i, row in enumerate(r):
do_something(row)
if i == 0: print(repr(r))

{'rms': '', 'gap': '158.52', 'latitude': '38.3625', 'magType': 'ml',
'net': 'nn', 'horizontalError': '', 'status': 'automatic', 'depth':
'3', 'nst': '5', 'magError': '', 'magSource': 'nn', 'depthError': '',
'longitude': '-118.4693', 'updated': '2016-02-20T00:17:41.069Z',
'mag': '1.1', 'type': 'earthquake', 'time':
'2016-02-20T00:15:24.120Z', 'id': 'nn00532282', 'locationSource':
'nn', 'dmin': '0.128', 'magNst': '', 'place': '22km SE of Hawthorne,
Nevada'}



-tkc





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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Steven D'Aprano
On Sat, 20 Feb 2016 12:27 am, Dennis Lee Bieber wrote:


> Then the best suggestion I have would be to take a weekend and just
> read the language reference manual (it used to be about an 80-page PDF
> file, but has no doubt grown into some less handy dynamically linked
> HTML/"help" file). Then add the section of the library reference manual
> that discusses data types. And while in that manual, scan the table of
> contents -- you may find there are modules in the standard library that
> already do what you need.

Surely you should start with the tutorial, not the reference manual.



-- 
Steven

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


Re: How to properly override the default factory of defaultdict?

2016-02-19 Thread Chris Angelico
On Sat, Feb 20, 2016 at 11:24 AM, Ian Kelly  wrote:
>> Look like inheriting from defaultdict is easier. I don't even  have to
>> override the constructor as suggested by Chris Angelico above. Thanks.
>
> True, although there's a faint code smell as this technically violates
> the Liskov Substitution Principle; the default_factory attribute on
> defaultdict instances is expected to be a function of zero arguments,
> not one.

My suggestion was a minimal change against his own code, but really,
the right way to do it is to not subclass defaultdict at all - just
subclass dict and define __missing__. Then there's no violation of
LSP, and probably no super() call either.

And the correct way to use super() is with no arguments and Python 3.
Much less fiddling around, no repetition of the class name, and you're
not depending on a global name lookup that might fail:

Python 2.7:

>>> class Foo(object):
...  def method(self): print("Base method")
...
>>> class Bar(Foo):
...  def method(self):
...   super(Bar,self).method()
...   print("Derived method")
...
>>> b = Bar()
>>> del Bar
>>> b.method()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in method
NameError: global name 'Bar' is not defined

Python 3.6:
>>> class Foo(object):
...  def method(self): print("Base method")
...
>>> class Bar(Foo):
...  def method(self):
...   super().method()
...   print("Derived method")
...
>>> b = Bar()
>>> del Bar
>>> b.method()
Base method
Derived method

Yes, that's a little contrived. But imagine the mess if you use a
class decorator that returns a function, or accidentally reuse a name
at the interactive prompt, or something. Needing to look something up
just to find your own parent seems unnecessary.

(That said, though, we depend on a name lookup to perform a recursive
function call, and that's a lot more likely to be rebound than a
class. But the no-arg super is still better for the other reasons.)

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


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Steven D'Aprano
On Thu, 18 Feb 2016 09:08 am, Mark Lawrence wrote:

> Seeing there is a lot of interest in asyncio recently I figured people
> might be interested in this
> http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5


Thanks for the link, but I'm now no wiser than I was before :-(

Can somebody explain Brett's explanation?




-- 
Steven

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


Re: Guido on python3 for beginners

2016-02-19 Thread Steven D'Aprano
On Fri, 19 Feb 2016 02:39 pm, Rustom Mody wrote:

> Consider as hypothesis
> L1: Needs 4 weeks to master

A language that only takes 4 weeks to master, starting from zero programming
experience, clearly doesn't include much in the way of features.


> L2: Needs 4 years to manage (if you want to make it less hypothetical
> think C++)

Do you mean 4 years to *master*?

Generally speaking, it takes 10 years of experience to become a master of a
complex skill. You might learn all the syntax of C++ in 4 years, but that
doesn't mean you have mastered the language :-)


> Which would be more satisfying to a student?

To be satisfying, a language needs to have a shallow enough learning curve
that the student can make good progress right from the beginning, and
enough features that they can actually do interesting things. Here's a
language that a student can learn in about one minute, because it only has
two features:

Assignment:

LET x = 99

Printing:

print x


But you can't do anything interesting with this language, so it is not
satisfying. On the other hand, here's "Hello World" in another language,
one which is Turing complete so it can do anything Python or C can do:

(=<`#9]~6ZY32Vx/4Rs+0No-&Jk)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc

but the learning curve is steep enough that it will be frustrating rather
than interesting.

https://en.wikipedia.org/wiki/Malbolge




-- 
Steven

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread William Ray Wing

> On Feb 19, 2016, at 8:13 PM, Steven D'Aprano  wrote:
> 
> On Sat, 20 Feb 2016 12:27 am, Dennis Lee Bieber wrote:
> 
> 
>> Then the best suggestion I have would be to take a weekend and just
>> read the language reference manual (it used to be about an 80-page PDF
>> file, but has no doubt grown into some less handy dynamically linked
>> HTML/"help" file). Then add the section of the library reference manual
>> that discusses data types. And while in that manual, scan the table of
>> contents -- you may find there are modules in the standard library that
>> already do what you need.
> 
> Surely you should start with the tutorial, not the reference manual.
> 
> 
> 
> -- 
> Steven
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Plus +1.  The ref manual would be like learning English from a dictionary

Bill

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


Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-19 Thread Terry Reedy

On 2/18/2016 9:22 PM, Ethan Furman wrote:


Anyone know one for deleting all responses to a troll post?


Thunderbird has 'ignore thread' on its context menu.

--
Terry Jan Reedy

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


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Denis Akhiyarov
On Wednesday, February 17, 2016 at 1:49:44 PM UTC-6, wrong.a...@gmail.com wrote:
> I am mostly getting positive feedback for Python.
> 
> It seems Python is used more for web based applications. Is it equally fine 
> for creating stand-alone *.exe's? Can the same code be compiled to run on 
> Linux or Android or web-based?
> 
> Is it possible to create GUI elements with a good IDE? Can they be defined 
> like in Visual Basic with given sizes, fonts, visible/invisible, etc.?
> 
> Is it easy to do matrix operations in Python? Or do I need to write 
> subroutines like in Visual Basic?
> 
> Could someone kindly tell me advantages and disadvantages of Python? Or any 
> better options? I have like 40-50 VB Forms and may be around 2 lines of 
> code. It will be a task to learn a new language and translate/re-write that 
> code.
> 
> Thanks for your responses.

I'm surprised that no one mentioned this tool called vb2py. It looks outdated, 
but I actually used it successfully to convert vba code to python, once all 
dependencies were installed correctly :)

http://vb2py.sourceforge.net/

You can also understand how vb objects map to python objects.

vb2py has also minimal support for GUI conversion.

Someone has even forked it on github recently:

https://github.com/reingart/vb2py
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Rustom Mody
On Saturday, February 20, 2016 at 8:07:03 AM UTC+5:30, Steven D'Aprano wrote:
> On Thu, 18 Feb 2016 09:08 am, Mark Lawrence wrote:
> 
> > Seeing there is a lot of interest in asyncio recently I figured people
> > might be interested in this
> > http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5
> 
> 
> Thanks for the link, but I'm now no wiser than I was before :-(
> 
> Can somebody explain Brett's explanation?

Does "C++" light a bulb? 

Less snarkily looks like a series of bolt-ons after bolt-ons

IMHO Guido's (otherwise) uncannily sound intuitions have been wrong right from
2001 when he overloaded def for generators.
And after that its been slippery-slope down: reusing generator-yield (statement)
for coroutine-yield (expression)
Most recently choosing these async-await keywords instead of the more symmetric 
suggestions of Greg Ewing

PS. Will be off email/net for about a week
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Rustom Mody
On Saturday, February 20, 2016 at 10:55:02 AM UTC+5:30, Rustom Mody wrote:
> On Saturday, February 20, 2016 at 8:07:03 AM UTC+5:30, Steven D'Aprano wrote:
> > On Thu, 18 Feb 2016 09:08 am, Mark Lawrence wrote:
> > 
> > > Seeing there is a lot of interest in asyncio recently I figured people
> > > might be interested in this
> > > http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5
> > 
> > 
> > Thanks for the link, but I'm now no wiser than I was before :-(
> > 
> > Can somebody explain Brett's explanation?
> 
> Does "C++" light a bulb? 
> 
> Less snarkily looks like a series of bolt-ons after bolt-ons
> 
> IMHO Guido's (otherwise) uncannily sound intuitions have been wrong right from
> 2001 when he overloaded def for generators.
> And after that its been slippery-slope down: reusing generator-yield 
> (statement)
> for coroutine-yield (expression)
> Most recently choosing these async-await keywords instead of the more 
> symmetric 
> suggestions of Greg Ewing

Forgot the probably most important: Not merging stackless into CPython
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Paul Rubin
Rustom Mody  writes:
> Forgot the probably most important: Not merging stackless into CPython

I thought there was some serious technical obstacle to that.

Where can I find Greg Ewing's suggestions about Python coroutines?  The
async/await stuff seems ok on the surface.

I liked the Lua paper about coroutines:

  http://www.inf.puc-rio.br/~roberto/docs/corosblp.pdf

it has a fair amount of historical info, comparison of implementation
techniques, etc.

But frankly the stuff I'm seeing in this thread makes me sad for Python.
It's an impossible dream but it would be awesome to have Erlang-like
communicating microtasks in Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Christian Gollwitzer

Am 20.02.16 um 03:36 schrieb Steven D'Aprano:

On Thu, 18 Feb 2016 09:08 am, Mark Lawrence wrote:


Seeing there is a lot of interest in asyncio recently I figured people
might be interested in this
http://www.snarky.ca/how-the-heck-does-async-await-work-in-python-3-5



Thanks for the link, but I'm now no wiser than I was before :-(

Can somebody explain Brett's explanation?


If you have difficulties wit hthe overall concept, and if you are open 
to discussions in another language, take a look at this video:


https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines

MS has added coroutine support with very similar syntax to VC++ 
recently, and the developer tries to explain it to the "stackful" 
programmers.


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


Re: asyncio - run coroutine in the background

2016-02-19 Thread Paul Rubin
Marko Rauhamaa  writes:
> "Frank Millman" :
>> I would love to drive the database asynchronously, but of the three
>> databases I use, only psycopg2 seems to have asyncio support.
> Yes, asyncio is at its infancy. There needs to be a moratorium on
> blocking I/O.

Unfortunately there appears to be no way to open a file in Linux without
at least potentially blocking (slow disk or whatever).  You need
separate threads or processes to do the right thing.
-- 
https://mail.python.org/mailman/listinfo/python-list


[newbie] Problem with matplotlib

2016-02-19 Thread jenswaelkens
When I use either of the following commands I get an error for which I don't 
have a solution, could someone here help me further?
These are the commands:
import matplotlib.pyplot as plt

or

from matplotlib.pyplot import pyplot as plt

This is the error I get:
Traceback (most recent call last):
  File "/home/waelkens/matplotlibdemo.py", line 2, in 
from matplotlib.pyplot import pyplot as plt
  File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 27, in 

import matplotlib.colorbar
  File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 36, in 

import matplotlib.contour as contour
  File "/usr/lib/python2.7/dist-packages/matplotlib/contour.py", line 17, in 

import matplotlib.ticker as ticker
  File "/usr/lib/python2.7/dist-packages/matplotlib/ticker.py", line 152, in 

import decimal
  File "/usr/lib/python2.7/decimal.py", line 3744, in 
_numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'

thanks in advance
Jens
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Ian Kelly
On Fri, Feb 19, 2016 at 10:24 PM, Rustom Mody  wrote:
> Less snarkily looks like a series of bolt-ons after bolt-ons
>
> IMHO Guido's (otherwise) uncannily sound intuitions have been wrong right from
> 2001 when he overloaded def for generators.
> And after that its been slippery-slope down: reusing generator-yield 
> (statement)
> for coroutine-yield (expression)
> Most recently choosing these async-await keywords instead of the more 
> symmetric
> suggestions of Greg Ewing

Two out of three of those are fine. IMO generators should have
required a separate keyword to distinguish them from ordinary
functions, but it's a minor complaint and they're otherwise a great
addition to the language.

I do think it's pretty clear at this point though that PEP 342 was a
mistake. We should never have introduced generator-based coroutines;
it's an abstraction with too much leakage. It doesn't make sense that
generator-based coroutines implement the iterator protocol, because
there's no reason to ever try to iterate over them. It also doesn't
make sense to ever iterate over a Future, and yet asyncio Futures,
which aren't even coroutines, are nevertheless *forced* to be iterable
just because that's how coroutines work. Otherwise you couldn't "yield
from" a Future.

As another point that happens to be fresh in my mind, awaiting a
Future on which an exception gets set is supposed to propagate the
exception. I recently found that this breaks if the exception in
question happens to be StopIteration (granted not one that should
generally be allowed to propagate anyway, but that's a separate
discussion) for the simple reason that raising StopIteration in a
generator is equivalent to returning None. The awaiting coroutine thus
gets a non-exceptional result of None rather than the expected
exception. The irritating thing to me is that this even plagues PEP
492 coroutines using "await" rather than "yield from", because the two
are basically the same under the covers. The former gets an iterator
by calling __await__ instead of __iter__, but it's still implemented
using an iterator. If you look at the asyncio.Future implementation,
__await__ is actually just a synonym of the __iter__ method.

My hope is that someday we can get rid of PEP 342 coroutines entirely.
Then maybe we can get a coroutine implementation that's actually sane.
PEP 492 with async/await and non-iterable semantics is a step in the
right direction, but ultimately I think we also need an underlying
implementation that *isn't* fundamentally based on iteration.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Considering migrating to Python from Visual Basic 6 for engineering applications

2016-02-19 Thread Larry Hudson via Python-list

On 02/19/2016 10:14 AM, wrong.addres...@gmail.com wrote:
[snip]


This is precisely reading one character at a time. If not exactly reading one 
character, it is effectively looking at each character to assemble the number. 
Not a good sign. I guess there might be libraries which will help read numbers 
better, but I would expect a good language to be able to handle this basic 
thing for engineers - to read numbers like Fortran and Basic do.

Still, if I have misunderstood something, I will be glad to be corrected. I 
would generally know that the first three numbers will be floating point, the 
next will be something and then the next will be something else, etc. Does that 
help or does one still have to look at each character and determine how to 
place it in a number?

Thanks for your patience. I don't want surprises later on, which is why I am 
asking very stupid questions.

It absolutely does NOT require reading a character at a time!  You are reading the data from a 
text file, which means everything is a string.  These strings (or sub-strings) can represent 
integers, floats, dates, phone numbers or whatever.  Your example data implies a free-form 
style, where it is then necessary to determine the data type for each of these (sub)strings 
individually.  Of course, if your data has a defined fixed format, this is simplified -- but 
they are still initially strings that have to be converted.  String processing in Python is very 
powerful and versatile.


BTW, it does no good to continue to think strictly in BASIC techniques.  Python is a different 
language with a different approach to attacking problems.  If you try to write BASIC (or C or 
Java or ...) programs in Python syntax you'll just get bad programs.  Forget trying to find 
features in Python that are identical to the features of BASIC.  Python requires a different 
mind-set to use it properly -- just like any other language.


Here is a rather naive somewhat brute-force way to read your example data.  I'm using a Python 
list here to simulate the file reading.  (Actually, using read() instead of readline() will also 
give this list.)  Python lists are essentially the same as arrays in other languages, but much 
more powerful and versatile.  Two examples of the differences between arrays and lists are:  can 
use mixed data types, you are not restricted to all the same data type, and the size of lists 
are dynamic -- they grow or shrink as necessary.


Comments start with a #
Strings in Python can be delimited by single-quotes ('), double-quotes (") or triple-quotes (""" 
or ''').  Triple-quoted strings can be multi-line text.  The triple-quote here is used as what 
Python calls a docstring, which it saves internally for documenting your program.



#   Define a function to determine the data type a string represents
def chktyp(s):
"""Check string s for int, float or string.  Returns the data and a type 
code"""
try:
return int(s), 'int'  #  Try to convert to int, return it if 
successful
except ValueError:#  No, it's not an int
pass  #  Drop into float test
try:
return float(s), 'float'  #  Try to convert to float, return it if 
successful
except ValueError:#  No, it's not a float
return s, 'str'   #  It must be a string

#   Here is your (simulated) data as a list of strings
data = [
'2 12.657823 0.1823467E-04 114 0',
'3 4 5 9 11',
'"Lower"',#  Could be left simply as "Lower"
'278.15']

#   Process the data
for line in data: #  For each line of the data
dat = line.split()#  Make a list of the sub-strings in the line
for stng in dat:  #  For each substring
dt, tp = chktyp(stng) #  Get the data and the type
print('{} is a {}'.format(dt, tp))#  Print this data


Running this example gives this result:

2 is a int
12.657823 is a float
1.823467e-05 is a float
114 is a int
0 is a int
3 is a int
4 is a int
5 is a int
9 is a int
11 is a int
"Lower" is a str
278.15 is a float

I hope this gives you a slight hint about the Python way of doing things.  Yes, of course it's 
very different from BASIC, but if you can pick up on the Pythonic way of doing things I think 
you might at least find it useful.


 -=- Larry -=-

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