setuptools setup.py commands are unintuitive and undiscoverable (--help-commands should replace --help)

2018-04-27 Thread jimbo1qaz
Frequently I have encountered projects packaged using setuptools, with a
setup.py. To find out how to install it, I usually turned to Stack Overflow
(https://stackoverflow.com/a/1472014) which doesn't explain what options
exist or do.

Surprisingly, neither "setup.py" nor "setup.py --help" doesn't provide a
list of options either, instead telling you how to show various metadata
options which are not useful to end users of the software project, trying
to build/install it.

Instead, to show a list of useful actions a user can perform, you need to
use "setup.py --help-commands", which I only discovered several years after
starting to use Python. Why isn't this command enabled by default (called
without arguments, or with --help).

https://imgur.com/a/HF4Iw6D
-- 
https://mail.python.org/mailman/listinfo/python-list


How to add values from test steps in pytest excel report

2018-04-27 Thread Sum
Hi,

I am using python 2.7 and pytest version 3.2.1
I am using pytest excel plugin to run the pytest and generate test report
in excel format.

Step to install pytest excel : pip install pytest-excel

I am running my pytest test using below :

py.test --excelreport=report.xls e_test.py

Output Test report excel format :

SUITE NAME  TEST NAME   DESCRIPTION RESULT  DURATIONMESSAGE FILE
NAME   MARKERSTestSumFlow test_step1  PASSED  15.24737811
e_test.py

My query is that I want to display the values from my corresponding test
steps in pytest.
e.g. if my test step is following, then how do I display the output of
test_step1 "newNum" in the excel report.

def test_step1(fNum, sNum):
newNum = fNum - sNum
print newNum


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


Question about Decimal and rounding

2018-04-27 Thread Frank Millman

Hi all

I have an object which represents a Decimal type.

It can receive input from various sources. It has to round the value to a 
particular scale factor before storing it. The scale factor can vary, so it 
has to be looked up every time, which is a slight overhead. I thought I 
could speed it up a bit by checking first to see if the value has any 
decimal places. If not, I can skip the scaling routine.


This is how I do it -

   s = str(value)
   if '.' in s:
   int_portion, dec_portion = s.split('.')
   is_integer = (int(int_portion) == value)
   else:
   is_integer = True

It assumes that the value is in the form iii.ddd or just iii. Today I found 
the following value -


   -1.4210854715202004e-14

which does not match my assumption.

It happens to work, but I don't understand enough about the notation to know 
if this is reliable, or if there are any corner cases where my test would 
fail.


I suspect that my test is a case of premature optimisation, and that I might 
as well just scale the value every time. Still, I would be interested to 
know if this could be a problem, or if there is a better way to do what I 
want.


Thinking aloud, maybe this is a better test -

   is_integer = (value == value.quantize(0))

Thanks

Frank Millman


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


Re: setuptools setup.py commands are unintuitive and undiscoverable (--help-commands should replace --help)

2018-04-27 Thread Thomas Jollans
On 27/04/18 06:06, jimbo1qaz wrote:
> Frequently I have encountered projects packaged using setuptools, with a
> setup.py. To find out how to install it, I usually turned to Stack Overflow
> (https://stackoverflow.com/a/1472014) which doesn't explain what options
> exist or do.
> 
> Surprisingly, neither "setup.py" nor "setup.py --help" doesn't provide a
> list of options either, instead telling you how to show various metadata
> options which are not useful to end users of the software project, trying
> to build/install it.
> 
> Instead, to show a list of useful actions a user can perform, you need to
> use "setup.py --help-commands", which I only discovered several years after
> starting to use Python. Why isn't this command enabled by default (called
> without arguments, or with --help).
> 
> https://imgur.com/a/HF4Iw6D
> 

Sure, setuptools has a lot of weird historical quirks, but the help
message? That looks fine to me. It *starts* by telling you about
setup.py install and setup.py build. The only command most users will
ever need is listed clearly in the *third* line of the --help message.
How do you get any more discoverable than that?

There are other specialised commands, but those are mostly useful for
maintainers and some sysadmins. (and --help-commands is referenced in
the *first* line of the --help message)

Most of the time, you should just be installing things with pip anyway.
Most packages are on the PyPI, and even where they're not, pip can
install directly from source tarballs and git repositories.

-- Thomas

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


Re: Question about Decimal and rounding

2018-04-27 Thread Thomas Jollans
On 27/04/18 10:21, Frank Millman wrote:
> Hi all
> 
> I have an object which represents a Decimal type.
> 
> It can receive input from various sources. It has to round the value to
> a particular scale factor before storing it. The scale factor can vary,
> so it has to be looked up every time, which is a slight overhead. I
> thought I could speed it up a bit by checking first to see if the value
> has any decimal places. If not, I can skip the scaling routine.
> 
> This is how I do it -
> 
>    s = str(value)
>    if '.' in s:
>    int_portion, dec_portion = s.split('.')
>    is_integer = (int(int_portion) == value)
>    else:
>    is_integer = True
> 
> It assumes that the value is in the form iii.ddd or just iii. Today I
> found the following value -
> 
>    -1.4210854715202004e-14
> 
> which does not match my assumption.
> 
> It happens to work, but I don't understand enough about the notation to
> know if this is reliable, or if there are any corner cases where my test
> would fail.

This is not reliable. Decimal is happy to give you integers in
scientific notation if this is needed to keep track of the number of
significant digits.

>>> str(Decimal('13.89e2'))
'1389'
>>> str(Decimal('13.89e3'))
'1.389E+4'
>>> Decimal('13.89e3') == 13890
True

It appears to me that the "obvious" way to check whether a Decimal
number is an integer is simply:

>>> d1 = Decimal('1.1')
>>> d2 = Decimal('3')
>>> int(d1) == d1
False
>>> int(d2) == d2
True


Final thoughts:
 * Beware of spending too much time on premature optimisations that you
might not need.
 * Are you *absolutely* sure that you can *always* skip your rounding
step for all integers? There's *no* risk of this optimisation ruining
some future dataset?

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


Re: Question about Decimal and rounding

2018-04-27 Thread Frank Millman
"Thomas Jollans"  wrote in message 
news:19223891-2006-d496-bdfe-32776834e...@tjol.eu...



On 27/04/18 10:21, Frank Millman wrote:

> I have an object which represents a Decimal type.
>
> It can receive input from various sources. It has to round the value to
> a particular scale factor before storing it. The scale factor can vary,
> so it has to be looked up every time, which is a slight overhead. I
> thought I could speed it up a bit by checking first to see if the value
> has any decimal places. If not, I can skip the scaling routine.
>
> This is how I do it -
>
>s = str(value)
>if '.' in s:
>int_portion, dec_portion = s.split('.')
>is_integer = (int(int_portion) == value)
>else:
>is_integer = True
>
> It assumes that the value is in the form iii.ddd or just iii. Today I
> found the following value -
>
>-1.4210854715202004e-14
>
> which does not match my assumption.
>
> It happens to work, but I don't understand enough about the notation to
> know if this is reliable, or if there are any corner cases where my test
> would fail.

This is not reliable. Decimal is happy to give you integers in
scientific notation if this is needed to keep track of the number of
significant digits.

>>> str(Decimal('13.89e2'))
'1389'
>>> str(Decimal('13.89e3'))
'1.389E+4'
>>> Decimal('13.89e3') == 13890
True

It appears to me that the "obvious" way to check whether a Decimal
number is an integer is simply:

>>> d1 = Decimal('1.1')
>>> d2 = Decimal('3')
>>> int(d1) == d1
False
>>> int(d2) == d2
True



Thanks, Thomas - makes perfect sense.

I have been burned before by -


int('1.1')

Traceback (most recent call last):
 File "", line 1, in 
ValueError: invalid literal for int() with base 10: '1.1'

so I did not think of trying -


int(Decimal('1.1'))

1

but it works just fine.

Frank


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


Fwd: Reporting Documentation Bug in Documentation » The Python Tutorial »6.Modules

2018-04-27 Thread VijithNambiar
Hi
I think there is a bug in the section https://docs.python.org/3/
tutorial/modules.html#more-on-modules
where the outputs of the statements below is given as wrong as it is
starting with a '0'

>>> import fibo as fib>>> fib.fib(500)0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

>>> import fibo as fib>>> fib.fib(500)0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
-- 
https://mail.python.org/mailman/listinfo/python-list


Passing all pandas DataFrame columns to function as separate parameters

2018-04-27 Thread zljubisic
Hi,

I have pandas DataFrame with several columns. I have to pass all columns as 
separate parameter to a function. 

Something like this if I have 4 columns.

f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 2], 
df_piv.iloc[:, 3])

As number of columns varies, how to do it in the most efficient way?

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


Re: Passing all pandas DataFrame columns to function as separate parameters

2018-04-27 Thread Thomas Jollans
On 27/04/18 15:50, zljubi...@gmail.com wrote:
> Hi,
> 
> I have pandas DataFrame with several columns. I have to pass all columns as 
> separate parameter to a function. 
> 
> Something like this if I have 4 columns.
> 
> f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 
> 2], df_piv.iloc[:, 3])
> 
> As number of columns varies, how to do it in the most efficient way?

You could get the DataFrame as a 2d array (df.values) and work from there:

  func(*df.values.T)

Of course, this is completely unreadable, and it has another problem: if
your columns have different types, this will cast some or all of your
columns to a different type.

It's probably clearer if you start with the column labels:

  func(*(df.loc[:,col] for col in df.columns))

or use df.items():

  func(*(values for col, values in df.items()))



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


Understanding pdb result

2018-04-27 Thread Rich Shepard

  Running python3-3.6.5 and wxPython-4.0.1 on Slackware-14.2.

  The module begins this way:

#!/usr/bin/env python3

import sys, os
import pdb
import wx

  When pdb is invoked and I step through the code I get these results:

$ python3 -m pdb openEDMS.py

/home/rshepard/development/openEDMS/openEDMS.py(8)()

-> """
(Pdb) s

/home/rshepard/development/openEDMS/openEDMS.py(10)()

-> import sys, os
(Pdb) s

/home/rshepard/development/openEDMS/openEDMS.py(11)()

-> import pdb
(Pdb) 

/home/rshepard/development/openEDMS/openEDMS.py(12)()

-> import wx
(Pdb) --Call--

(966)_find_and_load()

(Pdb)

  My web search suggests that I need to import importlib, but doing so does
not change the results.

  Please pass me a pointer to a resource that teaches me how to avoid this
error.

TIA,

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


Re: Understanding pdb result

2018-04-27 Thread Steven D'Aprano
On Fri, 27 Apr 2018 10:34:27 -0700, Rich Shepard wrote:

> Running python3-3.6.5 and wxPython-4.0.1 on Slackware-14.2.
> 
>The module begins this way:
> 
> #!/usr/bin/env python3
> 
> import sys, os
> import pdb
> import wx

[...]
>Please pass me a pointer to a resource that teaches me how to avoid
>this error.

What error are you referring to?

Why are you using pdb in the first place?

If you're getting an error, the first thing to do is read the traceback. 
If you're getting a traceback, tell us what it is. Don't paraphrase it, 
copy and paste it.

If you're not getting a traceback, please explain why you think you need 
to use pdb and what error you think you are getting, because I have no 
clue.


-- 
Steve

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


I need help with this python regex

2018-04-27 Thread Ed Manning
Here is the source code.


import re


log = open("csg.txt", "r") # Opens a file call session.txt
regex = re.compile(r'policy id \d+') # search for the policy ID
regex1 = re.compile(r'log count \d+') # search for the policy ID

for match in log:
x = regex.findall(match)
y = regex1.findall(match)

q = x + y
print(q)
 

The problem I am having i when it print out ti looks like this


L'Policy ID 243"|
[]
[]
[]
[]
[]
[]
[]
[]
{'log count 777,"]



How so I fix the code sone that it does not print empty []






Here so to the test file 


 get policy id 243
name:"csg to wes" (id 243), zone csg -> fwc,action Permit, status "enabled"
10 sources: "206.221.59.229", "206.221.59.246/32", "csg_205.144.151.107/32", 
"csg_205.144.151.177/32", "csg_205.144.151.24/32", "csg_205.144.152.50/32", 
"csg_205.144.153.55/32", "csg_206.221.59.244/32", "csg_206.221.59.250/32", 
"csg_206.221.61.29/32"
19 destinations: "MIP(204.235.119.135)", "MIP(204.235.119.136)", 
"MIP(204.235.119.243)", "MIP(204.235.119.34)", "MIP(204.235.119.39)", 
"MIP(204.235.119.40)", "MIP(204.235.119.41)", "MIP(204.235.119.42)", 
"MIP(204.235.119.43)", "MIP(204.235.119.44)", "MIP(204.235.119.45)", 
"MIP(204.235.119.46)", "MIP(204.235.119.47)", "MIP(204.235.119.50)", 
"MIP(204.235.119.51)", "MIP(204.235.119.52)", "MIP(204.235.119.79)", 
"MIP(204.235.119.82)", "MIP(204.235.119.83)"
1 service: "ANY"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 0001, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 777, alert no, counter yes(79) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/79
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression se
 get policy id 602
name:"ID 36129" (id 602), zone csg -> fwc,action Permit, status "enabled"
src "csg_205.144.151.107/32", dst "MIP(204.235.119.191)", serv "ANY"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 0001, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 0, alert no, counter yes(80) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/80
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression set
csg-vx-fw-n-12:csg-vx-fw-n-01(M)-> get policy id 420
name:"ID 12637" (id 420), zone csg -> fwc,action Permit, status "enabled"
1 source: "csg_204.235.119.78/32"
1 destination: "eg_csg"
6 services: "PING", "tcp_30001-30100", "tcp_6051-6055", "tcp_7041-7091", 
"TELNET", "TRACEROUTE"
Rules on this VPN policy: 0
nat off, Web filtering : disabled
vpn unknown vpn, policy flag 0001, session backup: on
traffic shaping off, scheduler n/a, serv flag 00
log close, log count 0, alert no, counter yes(81) byte rate(sec/min) 0/0
total octets 0, counter(session/packet/octet) 0/0/81
priority 7, diffserv marking Off
tadapter: state off, gbw/mbw 0/0 policing (no)
No Authentication
No User, User Group or Group expression set
-- 
https://mail.python.org/mailman/listinfo/python-list