Type hinting

2019-04-08 Thread Joseph L. Casale
Hi,
Is it possible to associate combinations of types for a given signature, for 
example:

T = TypeVar('T', Foo, Bar, Baz)
S = TypeVar('S', FooState, BarState, BazState)

closure = 'populated dynamically'

def foo(factory: Callable[[List[T], str], None], state: S) -> List[T]:
results = []
factory(results, closure)
return results

When T is Foo, S must be FooState etc.

Is that possible with the current implementation?

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


Re: Getting file extensions [linux fs]

2019-04-08 Thread Paulo da Silva
Às 01:35 de 06/04/19, Pablo Lucena escreveu:
> Have you looked into eBPF?
I'll take a look at that. Thanks Pablo.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logging cf Reporting = Friday Filosofical Finking

2019-04-08 Thread DL Neil

Is logging an unpopular package?
Is extending its use, as described, 
interesting/inappropriate/illogical/downright-crazy?



On 5/04/19 8:34 AM, DL Neil wrote:
Is the logging module an ideal means to provide (printed) user reports, 
or is it a 'bad fit' and not designed/fit for such a purpose?



PSL's logging module (per discussion 'here' earlier this week) is often 
quietly avoided by 'the average Python programmer'. It is unwieldy, yet 
that is, in-part, a function of its power and flexibility. Its 
explanation in the Library docs requires multiple pages - and even after 
sending us first to the 'HowTo', still many people turn away (vaguely 
promising to 'come back later'). For the nit-picky amongst us: it 
dramatically fails PEP-8* (and we won't even mention higher numbers).


Once the framework is learned, its flexibility appreciated, and its 
strictures accepted; (IMHO) the library comes into its own. Over the 
years, the range of output options ("handlers") has grown and become 
ever more sophisticated. Simple text files are now supplemented by 
"rotating" mechanisms; simple socket transmissions have formalised into 
SMTP (email), HTTP, queues, and datagrams; and both MS-Win and *nix 
syslog mechanisms are covered. Similarly, the traditional formatting of 
messages with ToD-clock, technicalIDs, and error-level preceding the 
'real content', whilst still standard, can be completely replaced to 
suit the application and circumstance.


The received-wisdom of text books and tutorials is that Python trainees 
should 'evolve' from using quick-and-dirty debug-print functionality, to 
logging. This idea(l) promotes the virtue of providing a full 
information flow when it is vitally-needed, but not cluttering-up the 
display with excessive and extraneous data, when not - especially when 
GUIs are involved! (plus obviating that pesky-business of going-through 
ensuring every debug-print is deleted or commented-out, before delivery 
to 'live'!) However, there's always a lot to learn - too many toys, too 
little time!


Recently, I was building a little "batch job"# for an author-friend 
who'd lost control of his extensive and burgeoning library of files, 
back-ups, half-dead disks, archives... Being a 'good boy'& I was 
throwing all the debug/test/demo info out to a log-file. Without (my) 
thinking too much, all the useful listings ended-up in the same place. 
Oops! Rather than bringing them 'back' out to the screen (which, because 
he prefers to work from paper rather than the screen - "now you tell 
me". Sigh!) would also have meant capturing sys.stdout to grant the user 
his (late-expressed) desire; I established another logger and made minor 
mods to the code so that it would instead emit the 'useful' output 
there. Hence, an "output report".


I was chuckling at how my 'mistake' turned into a 'plus', because 
without a lot of work to 'fix' things, the user was given exactly what 
he wanted! ("oh, and it would be nice if you could send the file to me 
by email..." - they're always, um, never, (quite) satisfied...)



In the more general case, when at least some of an application's output 
goes to file (or similar), is it a 'smart move'% to use the logging 
library to collect more than behind-the-scenes debugging, or 
application/syslog-level data?



* but then, so do I!
# https://en.wikipedia.org/wiki/Batch_processing
& if you believe that, you'll believe anything!
% 
https://www.quora.com/What-is-meant-by-the-Mark-Twain-quote-To-a-man-with-a-hammer-everything-looks-like-a-nail 



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


Re: [Tutor] Questions

2019-04-08 Thread William Ray Wing via Python-list
Diana, I’m answering you via the Tutor list - please, the accepted protocol is 
to send all questions and answers to the list so answers can be seen by (and 
possibly help) others.

Having said that, I should have paid more attention to your original question, 
which is really going to require answers that are beyond the typical Tutor 
question level, so I’m also forwarding to the main Python list where you should 
be able to get pointers.

But let me ask, how much programming do you know? Python is a full-blown 
programming language, like Java or C.  Have you written programs before that, 
for example can accept a file name from a user, open that file, and read its 
contents?  If yes, then I apologize, and would point you at:


https://medium.freecodecamp.org/how-to-scrape-websites-with-python-and-beautifulsoup-5946935d93fe
 


https://towardsdatascience.com/how-to-web-scrape-with-python-in-4-minutes-bc49186a8460

https://realpython.com/python-web-scraping-practical-introduction/
or
https://docs.python-guide.org/scenarios/scrape/

The next steps would probably involve loading that scraped data into Pandas:


https://pandas.pydata.org/pandas-docs/stable/getting_started/tutorials.html


https://data36.com/pandas-tutorial-1-basics-reading-data-files-dataframes-data-selection/

https://www.tutorialspoint.com/python_pandas

On the other hand, if your answer to my question is: “no” - then you should 
take a look at any of the really vast
collection of web sites devoted to Python learning.  Note that Python was 
originally designed to be a language that would be easy for beginners to learn. 
 It still is - I’d claim it is about the easiest -

>>> print( "Hello world!" ) 
Hello world!

Those lines were lifted from Alan Gauld’s learn to program web site.

Let us know how we can help.

Bill


> On Apr 8, 2019, at 5:40 PM, Diana Katz  wrote:
> 
> Yes - data would need to be scraped from sec.gov  website. 
> I want to be able to pull up segment data from 10-Q filings of individual 
> companies by putting in a ticker (preferably in excel, but an be done 
> elsewhere).  Trying to figure out how to even start setting this up. 
> 
> Thank you!
> 
> On Sun, Apr 7, 2019 at 8:57 PM William Ray Wing  > wrote:
> 
> 
> > On Apr 5, 2019, at 8:01 PM, Diana Katz  > > wrote:
> > 
> > 1) Can you use python from excel? Or just export to excel?
> 
> Simple answer: no.  Python can read and write excel files through libraries:
> 
>  https://www.datacamp.com/community/tutorials/python-excel-tutorial 
>  
> 
> > 2) I am trying to see if there's a way using python to automate all of this
> > work that I need to do. I have to collect quarterly segment data for
> > hundreds of public companies and go back at least 12-16 quarters. We use an
> > aggregator like factset and they actually don't have this option available
> > in an automated way. So I'm trying to see if there's a way to build this.
> 
> We really need more information to be of any help.  Is the starting data 
> coming from a web site?
> Python scripts can interact with web sites, “scrape” data from them or read 
> data from files downloaded in response to the script's interaction with the 
> site. The python library Pandas (named by its originator in the financial 
> field where such data is referred to as “panel” data) is optimized for 
> manipulating spreadsheet-like tables of data (it includes a pivot operation).
> 
> > Basically, I get my data from sec.gov  and they have 
> > interactive data - they
> > even have the data in excel (though it's a messy file and hard to read). I
> > attached some of the steps and the data that i'd want to see.
> > Basically i'd want the excel to look like:
> > old to new quarters - going back 12 to 16 quarters (more if possible but
> > not if it will stop the project).
> > Columns: 3/31/2017, 6/30/2017, 9/30/17, 12/31/17, 3/313/2018...
> > Rows:
> > Sales for segment A
> > Sales for Segment b
> > Sales for SEgment C
> > …(for as many segments as they have)
> > 
> > Earnings for Segment A
> > .Earnings for Segment B
> > 
> > Depreciation for Segment A
> > Depreciation for Segment B
> > Depreciation for Segment C...
> > 
> > I included where I get the data in the attached document.
> 
> Since attachments can contain unknown contents, this list drops them.
> 
> Bill
> 
> > 
> > All the best,
> > 
> > Diana Katz
> > ___
> > Tutor maillist  -  tu...@python.org 
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor 
> > 
> 

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


"get_python_lib() :for pip install, data_files with get_python_lib() are copied with duplicate path name on ubuntu"

2019-04-08 Thread Saba Kauser
Hi there,

I have the following in setup.py :
from distutils.sysconfig import get_python_lib

data_files = [ (get_python_lib(), ['./README.md']),
(get_python_lib(), ['./LICENSE']),
 (get_python_lib(), ['./CHANGES']),
(get_python_lib(), ['./config.py.sample'])]


setup( name = PACKAGE,
version = VERSION,
license = LICENSE,
description = 'Python DBI driver for DB2 (LUW, zOS, i5) and IDS',
author = 'IBM Application Development Team',
.
.
data_files = data_files,
include_package_data = True,
cmdclass = cmd_class,
**extra
)
Can be seen at : 
https://github.com/ibmdb/python-ibmdb/blob/master/IBM_DB/ibm_db/setup.py#L286

On:
Distributor ID: Ubuntu
Description:Ubuntu 16.04.3 LTS
Release:16.04
Codename:   xenial

Pip install is copying files under a duplicate append of current site-package 
path. E.g:

/work/skauser/python_installations/python27/lib/python2.7/site-packages/work/skauser/python_installations/python27/lib/python2.7/site-packages/CHANGES

/work/skauser/python_installations/python27/lib/python2.7/site-packages/work/skauser/python_installations/python27/lib/python2.7/site-packages/LICENSE

/work/skauser/python_installations/python27/lib/python2.7/site-packages/work/skauser/python_installations/python27/lib/python2.7/site-packages/README.md

/work/skauser/python_installations/python27/lib/python2.7/site-packages/work/skauser/python_installations/python27/lib/python2.7/site-packages/config.py.sample

On other platforms, the files are correctly copied under 
/work/skauser/python_installations/python27/lib/python2.7/site-packages.
>From python command line on ubuntu, get_python_lib() returns the correct path:
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.sysconfig import get_python_lib
>>> get_python_lib()
'/work/skauser/python_installations/python27/lib/python2.7/site-packages'

I need to know why is the incorrect behavior while using pip.

Building the source as:
Python setup.py build
Python setup.py install
Copies the files correctly.

Any help is appreciated!
Thanks.

Saba Kauser
Db2 Connect development and support.

Rocket Software Development India Pvt Ltd
Karle Town Centre - SEZ,
HUB 1 building, 4th Floor (North West Wing),
100 ft. Kempapura road, adjacent to Nagawara lake,
Nagawara, Bangalore - 560 045
E: skau...@rocketsoftware.com
-



Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? 
Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: 
https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - 
http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy


This communication and any attachments may contain confidential information of 
Rocket Software, Inc. All unauthorized use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please notify Rocket 
Software immediately and destroy all copies of this communication. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list