Re: "help( pi )"

2017-11-22 Thread Cameron Simpson

On 22Nov2017 18:47, Greg Ewing  wrote:

Cameron Simpson wrote:
one could change  implementations such that applying a docstring to 
an object _removed_ it from  the magic-shared-singleton pool,


That's not sufficient, though. Consider:

  BUFFER_SIZE = 256
  BUFFER_SIZE.__doc__ = "Size of the buffer"

  TWO_TO_THE_EIGHT = 256
  TWO_TO_THE_EIGHT.__doc__ = "My favourite power of two"

Before the code is even run, the compiler may have merged the
two occurences of the integer literal 256 into one entry in
co_consts. By the time the docstrings are assigned, it's too
late to decide that they really needed to be different objects.

So, an int with a docstring needs to be explicitly created as
a separate object to begin with, one way or another.


Ah.

Even without that it felt a little racy to me anyway.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: General Purpose Pipeline library?

2017-11-22 Thread Friedrich Rentsch



On 11/21/2017 03:26 PM, Jason wrote:

On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote:

a pipeline can be described as a sequence of functions that are applied to an 
input with each subsequent function getting the output of the preceding 
function:

out = f6(f5(f4(f3(f2(f1(in))

However this isn't very readable and does not support conditionals.

Tensorflow has tensor-focused pipepines:
 fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1')
 fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, 
scope='fc2')
 out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out')

I have some code which allows me to mimic this, but with an implied parameter.

def executePipeline(steps, collection_funcs = [map, filter, reduce]):
results = None
for step in steps:
func = step[0]
params = step[1]
if func in collection_funcs:
print func, params[0]
results = func(functools.partial(params[0], 
*params[1:]), results)
else:
print func
if results is None:
results = func(*params)
else:
results = func(*(params+(results,)))
return results

executePipeline( [
(read_rows, (in_file,)),
(map, (lower_row, field)),
(stash_rows, ('stashed_file', )),
(map, (lemmatize_row, field)),
(vectorize_rows, (field, min_count,)),
(evaluate_rows, (weights, None)),
(recombine_rows, ('stashed_file', )),
(write_rows, (out_file,))
]
)

Which gets me close, but I can't control where rows gets passed in. In the 
above code, it is always the last parameter.

I feel like I'm reinventing a wheel here.  I was wondering if there's already 
something that exists?

Why do I want this? Because I'm tired of writing code that is locked away in a 
bespoke function. I'd  have an army of functions all slightly different in 
functionality. I require flexibility in defining pipelines, and I don't want a 
custom pipeline to require any low-level coding. I just want to feed a sequence 
of functions to a script and have it process it. A middle ground between the 
shell | operator and bespoke python code. Sure, I could write many binaries 
bound by shell, but there are some things done far easier in python because of 
its extensive libraries and it can exist throughout the execution of the 
pipeline whereas any temporary persistence  has to be though environment 
variables or files.

Well after examining your feedback, it looks like Grapevine has 99% of the 
concepts that I wanted to invent, even if the | operator seems a bit clunky. I 
personally prefer the affluent interface convention. But this should work.

Kamaelia could also work, but it seems a little bit more grandiose.


Thanks everyone who chimed in!


This looks very much like I what I have been working on of late: a 
generic processing paradigm based on chainable building blocks. I call 
them Workshops, because the base class can be thought of as a workshop 
that takes some raw material, processes it and delivers the product (to 
the next in line). Your example might look something like this:


    >>> import workshops as WS

    >>> Vectorizer = WS.Chain (
            WS.File_Reader (),        # WS provides
            WS.Map (lower_row),   # WS provides (wrapped builtin)
            Row_Stasher (),           # You provide
            WS.Map (lemmatize_row),   # WS provides. Name for addressed 
Directions sending.

        Row_Vectorizer (),        # Yours
        Row_Evaluator (),     # Yours
            Row_Recombiner (),
        WS.File_Writer (),
            _name = 'Vectorizer'
        )

    Parameters are process-control settings that travel through a 
subscription-based mailing system separate from the payload pipe.


    >>> Vectorizer.post (min_count = ...,  ) # Set all parameters that 
control the entire run.
    >>> Vectorizer.post ("File_Writer", file_name = 
'output_file_name')    # Addressed, not meant for File_Reader


    Run

    >>> Vectorizer ('input_file_name')    # File Writer returns 0 if 
the Chain completes successfully.

    0

    If you would provide a list of your functions (input, output, 
parameters) I'd be happy to show a functioning solution. Writing a Shop 
follows a simple standard pattern: Naming the subscriptions, if any, and 
writing a single method that reads the subscribed parameters, if any, 
then takes payload, processes it and returns the product.


    I intend to share the system, provided there's an interest. I'd 
have to tidy i

Re: General Purpose Pipeline library?

2017-11-22 Thread Friedrich Rentsch



On 11/21/2017 03:26 PM, Jason wrote:

On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote:

a pipeline can be described as a sequence of functions that are applied to an 
input with each subsequent function getting the output of the preceding 
function:

out = f6(f5(f4(f3(f2(f1(in))

However this isn't very readable and does not support conditionals.

Tensorflow has tensor-focused pipepines:
 fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, scope='fc1')
 fc2 = layers.fully_connected(fc1, 256, activation_fn=tf.nn.relu, 
scope='fc2')
 out = layers.fully_connected(fc2, 10, activation_fn=None, scope='out')

I have some code which allows me to mimic this, but with an implied parameter.

def executePipeline(steps, collection_funcs = [map, filter, reduce]):
results = None
for step in steps:
func = step[0]
params = step[1]
if func in collection_funcs:
print func, params[0]
results = func(functools.partial(params[0], 
*params[1:]), results)
else:
print func
if results is None:
results = func(*params)
else:
results = func(*(params+(results,)))
return results

executePipeline( [
(read_rows, (in_file,)),
(map, (lower_row, field)),
(stash_rows, ('stashed_file', )),
(map, (lemmatize_row, field)),
(vectorize_rows, (field, min_count,)),
(evaluate_rows, (weights, None)),
(recombine_rows, ('stashed_file', )),
(write_rows, (out_file,))
]
)

Which gets me close, but I can't control where rows gets passed in. In the 
above code, it is always the last parameter.

I feel like I'm reinventing a wheel here.  I was wondering if there's already 
something that exists?

Why do I want this? Because I'm tired of writing code that is locked away in a 
bespoke function. I'd  have an army of functions all slightly different in 
functionality. I require flexibility in defining pipelines, and I don't want a 
custom pipeline to require any low-level coding. I just want to feed a sequence 
of functions to a script and have it process it. A middle ground between the 
shell | operator and bespoke python code. Sure, I could write many binaries 
bound by shell, but there are some things done far easier in python because of 
its extensive libraries and it can exist throughout the execution of the 
pipeline whereas any temporary persistence  has to be though environment 
variables or files.

Well after examining your feedback, it looks like Grapevine has 99% of the 
concepts that I wanted to invent, even if the | operator seems a bit clunky. I 
personally prefer the affluent interface convention. But this should work.

Kamaelia could also work, but it seems a little bit more grandiose.


Thanks everyone who chimed in!


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


Re: General Purpose Pipeline library?

2017-11-22 Thread Friedrich Rentsch



On 11/22/2017 10:54 AM, Friedrich Rentsch wrote:



On 11/21/2017 03:26 PM, Jason wrote:

On Monday, November 20, 2017 at 10:49:01 AM UTC-5, Jason wrote:
a pipeline can be described as a sequence of functions that are 
applied to an input with each subsequent function getting the output 
of the preceding function:


out = f6(f5(f4(f3(f2(f1(in))

However this isn't very readable and does not support conditionals.

Tensorflow has tensor-focused pipepines:
 fc1 = layers.fully_connected(x, 256, activation_fn=tf.nn.relu, 
scope='fc1')
 fc2 = layers.fully_connected(fc1, 256, 
activation_fn=tf.nn.relu, scope='fc2')
 out = layers.fully_connected(fc2, 10, activation_fn=None, 
scope='out')


I have some code which allows me to mimic this, but with an implied 
parameter.


def executePipeline(steps, collection_funcs = [map, filter, reduce]):
results = None
for step in steps:
    func = step[0]
    params = step[1]
    if func in collection_funcs:
    print func, params[0]
    results = func(functools.partial(params[0], 
*params[1:]), results)

    else:
    print func
    if results is None:
    results = func(*params)
    else:
    results = func(*(params+(results,)))
return results

executePipeline( [
    (read_rows, (in_file,)),
    (map, (lower_row, field)),
    (stash_rows, ('stashed_file', )),
    (map, (lemmatize_row, field)),
    (vectorize_rows, (field, min_count,)),
    (evaluate_rows, (weights, None)),
    (recombine_rows, ('stashed_file', )),
    (write_rows, (out_file,))
    ]
)

Which gets me close, but I can't control where rows gets passed in. 
In the above code, it is always the last parameter.


I feel like I'm reinventing a wheel here.  I was wondering if 
there's already something that exists?
Why do I want this? Because I'm tired of writing code that is locked 
away in a bespoke function. I'd  have an army of functions all 
slightly different in functionality. I require flexibility in 
defining pipelines, and I don't want a custom pipeline to require any 
low-level coding. I just want to feed a sequence of functions to a 
script and have it process it. A middle ground between the shell | 
operator and bespoke python code. Sure, I could write many binaries 
bound by shell, but there are some things done far easier in python 
because of its extensive libraries and it can exist throughout the 
execution of the pipeline whereas any temporary persistence  has to 
be though environment variables or files.


Well after examining your feedback, it looks like Grapevine has 99% 
of the concepts that I wanted to invent, even if the | operator seems 
a bit clunky. I personally prefer the affluent interface convention. 
But this should work.


Kamaelia could also work, but it seems a little bit more grandiose.


Thanks everyone who chimed in!


This looks very much like I what I have been working on of late: a 
generic processing paradigm based on chainable building blocks. I call 
them Workshops, because the base class can be thought of as a workshop 
that takes some raw material, processes it and delivers the product 
(to the next in line). Your example might look something like this:


    >>> import workshops as WS

    >>> Vectorizer = WS.Chain (
            WS.File_Reader (),        # WS provides
            WS.Map (lower_row),   # WS provides (wrapped builtin)
            Row_Stasher (),           # You provide
            WS.Map (lemmatize_row),   # WS provides
        Row_Vectorizer (),        # Yours
        Row_Evaluator (),     # Yours
            Row_Recombiner (),
        WS.File_Writer (),
            _name = 'Vectorizer'
        )

    Parameters are process-control settings that travel through a 
subscription-based mailing system separate from the payload pipe.


    >>> Vectorizer.post (min_count = ...,  ) # Set all parameters that 
control the entire run.
    >>> Vectorizer.post ("File_Writer", file_name = 
'output_file_name')    # Addressed, not meant for File_Reader


    Run

    >>> Vectorizer ('input_file_name')    # File Writer returns 0 if 
the Chain completes successfully.

    0

    If you would provide a list of your functions (input, output, 
parameters) I'd be happy to show a functioning solution. Writing a 
Shop follows a simple standard pattern: Naming the subscriptions, if 
any, and writing a single method that reads the subscribed parameters, 
if any, then takes payload, processes it and returns the product.


    I intend to share the system, provided there's an interest. I'd 
have to tidy it up quite a bit, though, before daring to release it.


    There's a lot more to it . . .

Frederic

I'm sorry, I made a mistake with the "From" item. My address is 
obviously not "python-list". It is "[email protected]".


Frederic

--
https://ma

Re: Student can't get if elif final statement to print for discussion post for python

2017-11-22 Thread Rick Johnson
Richard Damon wrote:
> Cheri Castro wrote:
> > I've tried several variations but haven't been able to
> > figure out why my final if elif statement won't print. I
> > tried using return, I tried using 1's and 0's rather than
> > yes and no. Not sure what the issue is. Please, help.
> >
> >
> > #This function will print how many yes answers the user has and a message
> > def correctAnswers(job, house, yard, time):
> >  if correctAnswers == 'yes':
> >  print ("Congratulations! You should get a puppy!")
> >  else:
> >  return "I'm sorry, you shouldn't get a puppy."
> 
> Why does one path print and the other return, those are
> different actions.

A valid point. My guess is that the OP may have wanted to
explicitly exit the look on this branch (instead of allowing
it fall off the end of the function) perhaps because some of
the code is missing from example or perhaps because some
code may be added in the future as an extension of the if
clause. Setting up such a conditional structure such as this
allows the intent to be clear. And any incidental code that
supports the if clause can be handles after flow falls off
the end of the conditional, and returns to the function
body. But who knows...

However, i'm more concerned that this code unapologetically
discriminate against those who'd rather have a kitten! :-(

I want a *KITTEN*!

And a safe space!

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


Re: How to add months to a date (datetime object)?

2017-11-22 Thread abiodun . ogunmolu
How about this...

from dateutil.relativedelta import relativedelta
myDate = datetime.date.today() + relativedelta(months=3)

On Sunday, March 15, 2009 at 5:28:24 PM UTC, [email protected] wrote:
> I have a date in the form of a datetime object and I want to add (for
> example) three months to it.  At the moment I can't see any very
> obvious way of doing this.  I need something like:-
> 
> myDate = datetime.date.today()
> inc = datetime.timedelta(months=3)
> myDate += inc
> 
> but, of course, timedelta doesn't know about months. I had a look at
> the calendar object but that didn't seem to help much.
> 
> -- 
> Chris Green

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


Finding the module object in Python 3 C extensions

2017-11-22 Thread Jon Ribbens
In Python 2, a C extension module's global state was stored in
global variables. This obviously means the state is trivially
accessible to all code in the module.

In Python 3, you are supposed to store the global state in an
allocated memory area instead. For functions defined directly
under the module, it is still trivial to find the state, because
a pointer to the module object is passed as the first parameter
to the function, so you just call PyModule_GetState(self).

However, suppose your module defines a new type, and you define
methods on that type. How do those methods get access to the
module object so that they can access the module state?

Unfortunately neither PEP3121 nor the "Porting Extension Modules
to Python 3" documentation seem to have thought to mention this
presumably extremely common situation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: pip3 file in Scripts folder is missing

2017-11-22 Thread pavan kopparthi
Hi,

Installed Python 3.6.3 Amd64 in Windows 10 OS. But pip3 file in Scripts
folder is missing. Scripts folder is empty.

-- 
Reg,
Pavan Kumar K
Mob: +91 8801401789 <088014%2001789>


Virus-free.
www.avg.com

<#m_-7513067775123038273_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>



-- 
Reg,
Pavan Kumar K
Mob: +91 8801401789
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to Generate dynamic HTML Report using Python

2017-11-22 Thread Rick Johnson
Chris Angelico wrote:
> Gregory Ewing
> > 
> > It looks like I'm going to have to filter Mr. Ram's posts
> > out of my usenet feed as well, lest I accidentally show
> > one of his URIs as a link on my screen.
> 
> Or, just ignore his copyright altogether, and let him prove
> its defensibility in court. Can you actually enforce that
> EVERY usenet server carry out your wishes? 

Although it's quite possible that what Stefan is doing here
_might_ be in accordance with the _letter_ of copyright law --
OTOH -- this "forced distribution" that Stefan is engageing
in, would seem to violate the _spirit_ of copyright law.

For instance, if we consider that copyright law was created
to protect intellectual property (IP), and furthermore, we
consider that copyrighted material is typically made
_available_ to the public[1] by IP owners, but not _forced_
on the public by IP owners, then we realize that what Stefan
is doing is the latter case.

So, by intentionally injecting this "licensed IP" into
public discourse, Stefan is indeed violating the spirit of
copyright law, and in fact, is using copyright law in a very
irresponsible, and arguably very rude, manner. It would seem
logical to me that Stefan's behavior should be judged as
unethical[2] and would therefore undermine the contract
between IP owners and the "doe-eyed consumers" of that IP,
rendering it null and void.

But history has proven that law is neither just nor logical.
So whether a court would agree with my interpretation is yet
to be determined. Of course, as is the case with tax
advisers, every court seems to have it's own unique
interpretation of the law. Which would lead me to the
troubling conclusion that our Western legal systems are
poorly designed, corrupt, or both.


[1] IOW, the public consumes this IP or uses this IP _fully_
_knowing_ beforehand that they are bound by a license
agreement. Which is not the cause here! Plus there are the
issues that Chris brings up concerning automated
dissemination.

[2] As forcing people to consume your product simply so you
can weild IP rights over them is a violation of individual
liberty recognized by every western democracy i know of, or
at least every definition of individual liberty that i am
aware of.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reading text in pdf, some working sample code

2017-11-22 Thread Jon Ribbens
On 2017-11-21, Daniel Gross  wrote:
> I am new to python and jumped right into trying to read out (english) text
> from PDF files.

That's not a trivial task. However I just released pycpdf, which might
help you out. Check out https://github.com/jribbens/pycpdf which shows
an example of extracting text from PDFs. It may or may not cope with
the particular PDFs you have, as there's quite a lot of variety within
the format.

Example:

pdf = pycpdf.PDF(open("file.pdf", "rb").read())
if pdf.info and pdf.info.get('Title'):
print('Title:', pdf.info['Title'])
for pageno, page in enumerate(pdf.pages):
print('Page', pageno + 1)
print(page.text)
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: DIPY 0.13.0

2017-11-22 Thread Eleftherios Garyfallidis
Hello all,

We are happy to announce a new public release of DIPY. This is mostly a
maintenance release with extra fixes, speedups and minor changes of
dependencies.

*DIPY 0.13 (Tuesday, 24 October 2017)*

This release received contributions from 13 developers (the full release
notes are at: http://nipy.org/dipy/release0.13.html)

*Highlights of this release include:*

- Faster Local PCA implementation.
- Fixed different issues with OpenMP and Windows / OSX.
- Replacement of cvxopt module by cvxpy.
- Replacement of Pytables module by h5py.
- Updated API to support latest numpy version (1.14).
- New user interfaces for visualization.
- Large documentation update.

To upgrade, run the following command in your terminal:

*pip install --upgrade dipy*

or

*conda install -c conda-forge dipy*


For any questions go to http://dipy.org, or send an e-mail to
[email protected]

We also have an instant messaging service and chat room available at
https://gitter.im/nipy/dipy

Expect mad features in release 0.14 (Jan 2018)!!!

On behalf of the DIPY developers,
Eleftherios Garyfallidis, Ariel Rokem, Serge Koudoro
http://dipy.org/developers.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reading text in pdf, some working sample code

2017-11-22 Thread Bob van der Poel
On Wed, Nov 22, 2017 at 5:39 PM, Jon Ribbens 
wrote:

> On 2017-11-21, Daniel Gross  wrote:
> > I am new to python and jumped right into trying to read out (english)
> text
> > from PDF files.
>
> That's not a trivial task. However I just released pycpdf, which might
> help you out. Check out https://github.com/jribbens/pycpdf which shows
> an example of extracting text from PDFs. It may or may not cope with
> the particular PDFs you have, as there's quite a lot of variety within
> the format.
>
> Example:
>
> pdf = pycpdf.PDF(open("file.pdf", "rb").read())
> if pdf.info and pdf.info.get('Title'):
> print('Title:', pdf.info['Title'])
> for pageno, page in enumerate(pdf.pages):
> print('Page', pageno + 1)
> print(page.text)
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Sorry if I'm late to this party, but I use pdf2txt for this. Works just
fine. It has options for different encodings, page range, etc. On Linux
just "apt install python-pdfminer" to install.



-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list