Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Dan Sommers

On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote:
>> Hi,
>>
>> I'm using bottledaemon to run a little REST service on a Pi that takes
>> input from other machines on the LAN and stores stuff in a database.
>> I have a cron job to call 'stop' and 'start' on it daily, just in case
>> of problems.
>>
>> Occasionally the oom-killer runs overnight and kills the process using
>> bottledaemon; when this happens (unlike properly stopping the daemon),
>> the pidfile and its lockfile are left on the filesystem, so the 'stop'
>> does nothing and the 'start' gets refusedq because the old pidfile and
>> lockfile are present.  At the moment, I eventually notice something
>> wrong with the output data, ssh into the Pi, and rm the two files then
>> call 'start' on the daemon again.
>>
>> Is there a recommended or good way to handle this situation
>> automatically?
>>
> Could you write a watchdog daemon that checks whether bottledaemon is
> running, and deletes those files if it isn't (or hasn't been for a 
while)?


What if the oom-killer kills the watchdog?

Whatever runs in response to the start command has to be smarter:  if
the pid and lock files exist, then check whether they refer to a
currently running bottledaemon.  If so, then all is well, and refuse to
start a redundant daemon.  If not, then remove the pid and lock files
and start the daemon.
--
https://mail.python.org/mailman/listinfo/python-list


Re: What Python related git pre-commit hooks are you using?

2018-11-18 Thread Albert-Jan Roskam



On 18 Nov 2018 20:33, Malcolm Greene  wrote:

>Curious to learn what Python related git >pre-commit hooks people are using? 
>What >hooks have you found useful and which >hooks have you tried

I use Python to reject large commits (pre-commit hook): 
http://code.activestate.com/recipes/578883-git-pre-commit-hook-to-reject-large-files-using-py/

I've also used hooks to trigger a Sphinx doc build, and for tox.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generators, generator expressions, and loops

2018-11-18 Thread David Neil

Steve,

On 17/11/18 03:52, Steve Keller wrote:

I have looked at generators, generator expressions, and iterators and
I try to get more familiar with these.

1. How would I loop over all (with no upper bound) integers or all
powers of two, for example?

In C it would be

for (int i = 0; ; i++) { ... }  or  for (int i = 1; ; i *= 2) { ... }

In Python, I could define a generator

 def powers():
 i = 1
while True:
yield(i)
i *= 2

 for i in powers():
 ...


Is there a fundamental error here? Is the attempt to start from C (or 
whatever) and reproduce C-code in Python?


Whilst it can be a useful early-learning path to translate "commands" 
from one language to another, in order to commence actual usage quickly; 
one should not try to use such kindergarten techniques to discuss 
philosophy! First, learn the new language's idioms - a combination of 
language-vocabulary and its underlying culture.


In this case, the comparison is between the for-command of a for-loop 
(C), with Python's for-in structure. Python's idiom is to loop over the 
contents of something: the characters within a string of characters, the 
elements of a list, etc.


The C languages (and many others) have an idiom which controls the 
repetition of a loop without regard to the data being processed, ie for 
index = start-value, end-value, incremental-amount. This works 
regardless of what the code is looping 'over', if indeed, anything.


In Python, we don't look at the "index", this is provided (ie "batteries 
included"). Python looks at an instance of a collection object 
(previously "sequence members") which is also an iterator (see your 
previous questions). The mention of an iterable within a for-in 
statement causes the production of an appropriate element-value at each 
loop of the construct. Whereas with C one uses the index to choose which 
item of data to consider during this iteration of the loop, eg 
array[index]. In C the 'subject' of the loop is the index (or "offset"). 
In Python it is the collection, and iteratively, its elements.


This idiom removes a significant proportion of C (etc) programming 
errors caused by the necessity to use "pointers" or indices, eg the 
famous "out by one" error. Whereas in C it is necessary to use a pointer 
to loop over the two choices, in Python we can immediately use, eg
for gender in [ "male", "female" ]: with no pointer and direct access to 
the label-values, cf (define genders_array earlier, and then for index = 
1, 2; this_loops_gender = genders_array( index ); use this_loops_gender.



To directly answer the narrow coding-question posed: in Python one 
achieves "counting loops" using a while-construct, eg

count = 0 #or start-value
while ( count < maximum ):
etc
count += 1
The set-up, condition, and increment corresponding directly with the 
descriptions of "start-value, end-value, and increment-amount" in C 
(etc). In the case of "infinite loops: a common Python idiom is:

while True:
etc
with attendant start/increment code. In which case you enjoy all of the 
benefits of a generator (eg no need to generate (and store) all of the 
index values before looping commences) but without the abstraction in 
the example code - simplicity before complexity!



Python also offers a second-level answer in the Python Standard Library. 
The basic concepts of an iterator and/or the underlying technologies are 
made available in "itertools" - just as you will find with many other 
facilities within and around the language. There are a couple of 
specific edge-cases (a deliberate, never-ending loop) within that 
library. Enjoy!



Is it a valid approach to first solve a problem by 'thinking in C' and 
only then trying to translate that 'solution' into Python? This approach 
is where Star Wars' concept behind Yoda-speak comes from: some languages 
sequence the words in a sentence quite differently from the preferred 
subject-verb-object order of English:

Jack hits the ball.
Jack the ball hits.
The ball hit (by) Jack.

IMHO Python is NOT a 'better version of C' - for any definition of 
"better", and regardless of anyone's enthusiastic preferences. There are 
situations where it would be 'better' to use one in preference to the 
other. Both ways! To write in Python, use Pythonic thinking, Python 
constructs (one author talks of "Python's beautiful heart"), and the 
idioms of Python; to realise its power!


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


Re: What Python related git pre-commit hooks are you using?

2018-11-18 Thread Chris Angelico
On Mon, Nov 19, 2018 at 6:34 AM Malcolm Greene  wrote:
>
> Curious to learn what Python related git pre-commit hooks people are
> using? What hooks have you found useful and which hooks have you tried
> and abandoned? Appreciate any suggestions for those new to this process.
> Background: Window, macOS, and Linux dev environments, PyCharm professional 
> edition IDE, 64-bit Python 3.6, private Github repos. Considering black 
> (standardize formatting), pylamas (multiple static code tests) and possibly a 
> hook into our pytest test runner.
> Thanks!

Here are a few that I've written and actively use.

This hook isn't written in Python, but I use it with my Python projects:
https://github.com/Rosuav/shed/blob/master/githook.pike
Whenever you make a commit that affects only a single file, it
automatically prepopulates the message with a tag, based on previous
commits affecting that file.

This one is written in Python, but is less for Python projects and
more for my git-managed config directories (like my /etc on most
computers):
https://github.com/Rosuav/shed/blob/master/git-watch
Once configured, it notifies me any time there are uncommitted
changes. For a typical source code repo, that's not particularly
likely, but when the files can be edited by other programs (or by
running system updates), it's good to be told.

Another one written in Python, but not a hook per se:
https://github.com/Rosuav/shed/blob/master/git-triangle
Triangle cloning is a variant of git clone designed for a pull-request model.

And this one is just a convenient tool.
https://github.com/Rosuav/shed/blob/master/git-ignore
Type "git ignore __pycache__" after you notice that you committed a
bunch of pyc files. Adds the line to .gitignore and then removes (from
the repo, but not your disk) every file that ought to be ignored.

Feel free to snag any parts you like, or to use them as inspiration.
The code is all MIT-licensed so have fun.

I'm also interested to see what tools other people use! Thanks for
starting this discussion.

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


What Python related git pre-commit hooks are you using?

2018-11-18 Thread Malcolm Greene
Curious to learn what Python related git pre-commit hooks people are
using? What hooks have you found useful and which hooks have you tried
and abandoned? Appreciate any suggestions for those new to this process.
Background: Window, macOS, and Linux dev environments, PyCharm professional 
edition IDE, 64-bit Python 3.6, private Github repos. Considering black 
(standardize formatting), pylamas (multiple static code tests) and possibly a 
hook into our pytest test runner.
Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in parsing the string output from the command using "subprocess"

2018-11-18 Thread srinivasan
Thanks a lot for your quick responses

I tried to fix the issue as below, I verified in my desktop ubuntu
environment, but tomorrow once I can verify on my embedded target, please
let me know if you foresee any issues with the below fix?

def wifi_disconnect(self, timeout=10):
"""
Connect to Access point using SSID and PW.

:param ssid: SSID of the ACCESS POINT.
:param pw: password for connecting to the access point.
:return: command output as True or False.
"""

cmd = "nmcli -t -f TYPE,UUID con"
res = self._helper.execute_cmd_output_string(cmd)
print(res)
lines = res.split("\n")
print(lines)

for line in lines:
parts = line.split(":")
print(parts)
print(parts[0])
if (parts[0] == "802-11-wireless"):
print("--")
print("nmcli connection delete uuid " + parts[1])
cmd = "nmcli connection delete uuid '%s'" % parts[1]
for i in range(timeout // 2):
exit_code = self._helper.execute_cmd_return_code(cmd)
print(exit_code)
time.sleep(1)
print "%d seconds have passed" % i
if exit_code == 0:
return True

return False


On Mon, Nov 19, 2018 at 12:50 AM MRAB  wrote:

> On 2018-11-18 14:59, srinivasan wrote:
> > Dear Python Experts Team,
> >
> > As am newbie to python and learning python, working on embedded linux
> > platform, my intention is to delete all the SSID's before connecting my
> > Wi-Fi module to specific SSID., I am trying to parse command output using
> > the "subprocess"  with wrapper "execute_cmd_output_string" written on
> > it described
> > as below,  using the nmcli commands "*nmcli -t -f TYPE,UUID con" and
> "**"nmcli
> > connection delete uuid ".*
> >
> > Could you please help me, what could be the bug in the below method "*def
> > wifi_disconnect_reconnect(self, ssid, pw):"  *using the method
> > "execute_cmd_output_string" (in-turn uses "subprocess") which is failing
> to
> > give correct output of., UUID's  for *"nmcli connection delete uuid "*  ?
> >
> > But which works fine with "commands.getstatusoutput" (res =
> > commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want
> to
> > include "commands.getstatusoutput" which costs me for including one more
> > python module in my rootfs
> >
> > Typical output for "nmcli -t -f TYPE,UUID con"
> >
> > ~$ nmcli -t -f TYPE,UUID con
> > 802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2
> > 802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877
> > 802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d
> > 802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837
> > 802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303
> > 802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c
> > 802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6
> > 802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128
> > 802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6
> > 802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5
> > 802-11-wireless:9f764fff-6288-49c4-9412-902e89230136
> > 802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc
> > ~$
> >
> > *Python Code Snipeet:*
> > *--*
> > *def wifi_disconnect_reconnect(self, ssid, pw):*
> > *"""*
> > *Connect to Access point using SSID and PW.*
> >
> > *:param ssid: SSID of the ACCESS POINT.*
> > *:param pw: password for connecting to the access point.*
> > *:return: command output as True or False.*
> > *"""*
> >
> > *cmd = "nmcli -t -f TYPE,UUID con"*
> > *res = self._helper.execute_cmd_output_string(cmd)*
> > *print(res)*
> > *lines = res[1].split('\n') > I suspect
> the
> > issue might be here*
> > *print(lines)*
> >
> > *for line in lines:*
> > *parts = line.split(":")*
> > *print(parts)*
> > *print(parts[1])*
> > *if (parts[0] == "802-11-wireless"):*
> > *print("nmcli connection delete uuid "+ parts[1])*
> > *os.system("nmcli connection delete uuid "+ parts[1])*
> >
> > *cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)*
> > *exit_code = self._helper.execute_cmd_return_code(cmd)*
> >
> > *return True if exit_code == 0 else False*
> >
> >
> >  def execute_cmd_output_string(self, cmd, enable_shell=False):
> >  """
> >  Execute a command and return its output as a string.
> >
> >  :param cmd: abs path of the command with arguments
> >  :param enable_shell : force the cmd to be run as shell
> script
> >  :return: a string.
> >  """
> >
> >  try:
> >  result = subprocess.check_output(split(cmd),
> >   stderr=subpro

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread MRAB

On 2018-11-18 17:50, Adam Funk wrote:

Hi,

I'm using bottledaemon to run a little REST service on a Pi that takes
input from other machines on the LAN and stores stuff in a database.
I have a cron job to call 'stop' and 'start' on it daily, just in case
of problems.

Occasionally the oom-killer runs overnight and kills the process using
bottledaemon; when this happens (unlike properly stopping the daemon),
the pidfile and its lockfile are left on the filesystem, so the 'stop'
does nothing and the 'start' gets refusedq because the old pidfile and
lockfile are present.  At the moment, I eventually notice something
wrong with the output data, ssh into the Pi, and rm the two files then
call 'start' on the daemon again.

Is there a recommended or good way to handle this situation
automatically?

Could you write a watchdog daemon that checks whether bottledaemon is 
running, and deletes those files if it isn't (or hasn't been for a while)?

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


Re: Issue in parsing the string output from the command using "subprocess"

2018-11-18 Thread MRAB

On 2018-11-18 14:59, srinivasan wrote:

Dear Python Experts Team,

As am newbie to python and learning python, working on embedded linux
platform, my intention is to delete all the SSID's before connecting my
Wi-Fi module to specific SSID., I am trying to parse command output using
the "subprocess"  with wrapper "execute_cmd_output_string" written on
it described
as below,  using the nmcli commands "*nmcli -t -f TYPE,UUID con" and "**"nmcli
connection delete uuid ".*

Could you please help me, what could be the bug in the below method "*def
wifi_disconnect_reconnect(self, ssid, pw):"  *using the method
"execute_cmd_output_string" (in-turn uses "subprocess") which is failing to
give correct output of., UUID's  for *"nmcli connection delete uuid "*  ?

But which works fine with "commands.getstatusoutput" (res =
commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want to
include "commands.getstatusoutput" which costs me for including one more
python module in my rootfs

Typical output for "nmcli -t -f TYPE,UUID con"

~$ nmcli -t -f TYPE,UUID con
802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2
802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877
802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d
802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837
802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303
802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c
802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6
802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128
802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6
802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5
802-11-wireless:9f764fff-6288-49c4-9412-902e89230136
802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc
~$

*Python Code Snipeet:*
*--*
*def wifi_disconnect_reconnect(self, ssid, pw):*
*"""*
*Connect to Access point using SSID and PW.*

*:param ssid: SSID of the ACCESS POINT.*
*:param pw: password for connecting to the access point.*
*:return: command output as True or False.*
*"""*

*cmd = "nmcli -t -f TYPE,UUID con"*
*res = self._helper.execute_cmd_output_string(cmd)*
*print(res)*
*lines = res[1].split('\n') > I suspect the
issue might be here*
*print(lines)*

*for line in lines:*
*parts = line.split(":")*
*print(parts)*
*print(parts[1])*
*if (parts[0] == "802-11-wireless"):*
*print("nmcli connection delete uuid "+ parts[1])*
*os.system("nmcli connection delete uuid "+ parts[1])*

*cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)*
*exit_code = self._helper.execute_cmd_return_code(cmd)*

*return True if exit_code == 0 else False*


 def execute_cmd_output_string(self, cmd, enable_shell=False):
 """
 Execute a command and return its output as a string.

 :param cmd: abs path of the command with arguments
 :param enable_shell : force the cmd to be run as shell script
 :return: a string.
 """

 try:
 result = subprocess.check_output(split(cmd),
  stderr=subprocess.STDOUT,
  shell=enable_shell)

 except subprocess.CalledProcessError as e:
 s = """While executing '{}' something went wrong.
 Return code == '{}'
 Return output:\n'{}'
 """.format(cmd, e.returncode, e.output, shell=enable_shell)
 raise AssertionError(s)

 return result.strip().decode("utf-8")


if __name__ == "__main__":
 m = wifi()
 print("disconnect and reconnect")
 print(m.wifi_disconnect_reconnect("NaWiFi", "abcds"))


*Errors:*
---
Traceback (most recent call last):
802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2
802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837
802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303
   File
"/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py",
line 153, in 
802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c
 print(m.wifi_connect("NI WiFi", "T.f.o.s.1996!"))
802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6
802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128
   File
"/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py",
line 77, in wifi_connect
802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6
 print(parts[1])
802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5
*IndexError: list index out of range*
802-11-wireless:9f764fff-6288-49c4-9412-902e89230136
802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc
[u'0']
[u'0']


[snip]
execute_cmd_output_string returns a string, so 'res' will be a string.

For example, res == u'802-11-wireless:3f5011d4-5681-4

Re: Reading 'scientific' csv using Pandas?

2018-11-18 Thread Martin Schöön
Den 2018-11-18 skrev Shakti Kumar :
> On Sun, 18 Nov 2018 at 18:18, Martin Schöön  wrote:
>>
>> Now I hit a bump in the road when some of the data is not in plain
>> decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation.
>>
>
> Martin, I believe this should be done by pandas itself while reading
> the csv file,
> I took an example in scientific notation and checked this out,
>
> my sample.csv file is,
> col1,col2
> 1.1,0
> 10.24e-05,1
> 9.492e-10,2
>
That was a quick answer!

My pandas is up to date.

In your example you use the US convention of using "." for decimals
and "," to separate data. This works perfect for me too.

However, my data files use European conventions: decimal "," and TAB
to separate data:

col1col2
1,1 0
10,24e-05   1
9,492e-10   2

I use 

EUData = pd.read_csv('file.csv', skiprows=1, sep='\t',
decimal=',', engine='python')

to read from such files. This works so so. 'Common floats' (3,1415 etc)
works just fine but 'scientific' stuff (1,6023e23) does not work.

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


bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Adam Funk
Hi,

I'm using bottledaemon to run a little REST service on a Pi that takes
input from other machines on the LAN and stores stuff in a database.
I have a cron job to call 'stop' and 'start' on it daily, just in case
of problems.

Occasionally the oom-killer runs overnight and kills the process using
bottledaemon; when this happens (unlike properly stopping the daemon),
the pidfile and its lockfile are left on the filesystem, so the 'stop'
does nothing and the 'start' gets refusedq because the old pidfile and
lockfile are present.  At the moment, I eventually notice something
wrong with the output data, ssh into the Pi, and rm the two files then
call 'start' on the daemon again.

Is there a recommended or good way to handle this situation
automatically?

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


Issue in parsing the string output from the command using "subprocess"

2018-11-18 Thread srinivasan
Dear Python Experts Team,

As am newbie to python and learning python, working on embedded linux
platform, my intention is to delete all the SSID's before connecting my
Wi-Fi module to specific SSID., I am trying to parse command output using
the "subprocess"  with wrapper "execute_cmd_output_string" written on
it described
as below,  using the nmcli commands "*nmcli -t -f TYPE,UUID con" and "**"nmcli
connection delete uuid ".*

Could you please help me, what could be the bug in the below method "*def
wifi_disconnect_reconnect(self, ssid, pw):"  *using the method
"execute_cmd_output_string" (in-turn uses "subprocess") which is failing to
give correct output of., UUID's  for *"nmcli connection delete uuid "*  ?

But which works fine with "commands.getstatusoutput" (res =
commands.getstatusoutput("nmcli -t -f TYPE,UUID con")), but I dont want to
include "commands.getstatusoutput" which costs me for including one more
python module in my rootfs

Typical output for "nmcli -t -f TYPE,UUID con"

~$ nmcli -t -f TYPE,UUID con
802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2
802-11-wireless:bfb93be0-740d-426e-b215-0fdc2f652877
802-11-wireless:69b60cf4-65aa-442b-a54c-fb82905adb0d
802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837
802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303
802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c
802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6
802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128
802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6
802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5
802-11-wireless:9f764fff-6288-49c4-9412-902e89230136
802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc
~$

*Python Code Snipeet:*
*--*
*def wifi_disconnect_reconnect(self, ssid, pw):*
*"""*
*Connect to Access point using SSID and PW.*

*:param ssid: SSID of the ACCESS POINT.*
*:param pw: password for connecting to the access point.*
*:return: command output as True or False.*
*"""*

*cmd = "nmcli -t -f TYPE,UUID con"*
*res = self._helper.execute_cmd_output_string(cmd)*
*print(res)*
*lines = res[1].split('\n') > I suspect the
issue might be here*
*print(lines)*

*for line in lines:*
*parts = line.split(":")*
*print(parts)*
*print(parts[1])*
*if (parts[0] == "802-11-wireless"):*
*print("nmcli connection delete uuid "+ parts[1])*
*os.system("nmcli connection delete uuid "+ parts[1])*

*cmd = "nmcli device wifi connect '%s' password %s" % (ssid, pw)*
*exit_code = self._helper.execute_cmd_return_code(cmd)*

*return True if exit_code == 0 else False*


def execute_cmd_output_string(self, cmd, enable_shell=False):
"""
Execute a command and return its output as a string.

:param cmd: abs path of the command with arguments
:param enable_shell : force the cmd to be run as shell script
:return: a string.
"""

try:
result = subprocess.check_output(split(cmd),
 stderr=subprocess.STDOUT,
 shell=enable_shell)

except subprocess.CalledProcessError as e:
s = """While executing '{}' something went wrong.
Return code == '{}'
Return output:\n'{}'
""".format(cmd, e.returncode, e.output, shell=enable_shell)
raise AssertionError(s)

return result.strip().decode("utf-8")


if __name__ == "__main__":
m = wifi()
print("disconnect and reconnect")
print(m.wifi_disconnect_reconnect("NaWiFi", "abcds"))


*Errors:*
---
Traceback (most recent call last):
802-11-wireless:3f5011d4-5681-4fed-8dea-95dee790e9e2
802-11-wireless:dc2a15ec-d3da-491e-9c8f-cb054f375837
802-11-wireless:5164e7f2-4489-462e-b093-76bc51bf1303
  File
"/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py",
line 153, in 
802-11-wireless:d462e8c4-fac7-42f2-8f9a-6846f52d4e8c
print(m.wifi_connect("NI WiFi", "T.f.o.s.1996!"))
802-11-wireless:e5020744-5c9c-453c-92ec-7a854fc893e6
802-11-wireless:eed3358e-8635-471d-b7e9-5c2973a05128
  File
"/home/srinivasan/Downloads/qa_wifi_nov15_after_incorporating_thilo_comments_zip/qa/test_library/wifi.py",
line 77, in wifi_connect
802-11-wireless:ceea6707-a929-4941-9047-a75e061914b6
print(parts[1])
802-11-wireless:dd6b9c83-db7b-42b9-99c0-14a04f6f35f5
*IndexError: list index out of range*
802-11-wireless:9f764fff-6288-49c4-9412-902e89230136
802-11-wireless:72c627cd-77a3-4d16-bb2c-058040d8e4fc
[u'0']
[u'0']

Process finished with exit code 1
But when I execute the below the command using the python module
"commands". I am able to successfully parse the multi line string output
and extarct the UUID's from

Re: Reading 'scientific' csv using Pandas?

2018-11-18 Thread Shakti Kumar
On Sun, 18 Nov 2018 at 18:18, Martin Schöön  wrote:
>
> I am in this project where I try to get an overview of a bunch of
> computer generated (finite element program) data. I have it stored in a
> number of csv files.
>
> Reading the data into spreadsheet programs works fine but is very labour
> intensive so I am working with Pandas in Jupyter notebooks which I find
> much more efficient.
>
> Now I hit a bump in the road when some of the data is not in plain
> decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation.
>

Martin, I believe this should be done by pandas itself while reading
the csv file,
I took an example in scientific notation and checked this out,

my sample.csv file is,
col1,col2
1.1,0
10.24e-05,1
9.492e-10,2

and then I execute,
In [29]: a= pd.read_csv('sample.csv')
In [30]: a.values
Out [30]:
array([[1.100e+00, 0.000e+00],
   [1.024e-04, 1.000e+00],
   [9.492e-10, 2.000e+00]])
In [31]: a.values[1][0]
Out[31]: 0.0001024
As you can see, pandas has converted scientific notation to float,
even the data type of these values is numpy.float64

What best I can guess is a problem with your pandas version, there
were some updates with the 0.17.x coming in, maybe give a shot
upgrading your pandas with,
pip install --upgrade pandas
or in case you’re using anaconda then,
conda update pandas

> [snipped for brevity]
> /Martin
> --
> https://mail.python.org/mailman/listinfo/python-list

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


Reading 'scientific' csv using Pandas?

2018-11-18 Thread Martin Schöön
I am in this project where I try to get an overview of a bunch of
computer generated (finite element program) data. I have it stored in a
number of csv files.

Reading the data into spreadsheet programs works fine but is very labour
intensive so I am working with Pandas in Jupyter notebooks which I find
much more efficient.

Now I hit a bump in the road when some of the data is not in plain
decimal notation (xxx,xx) but in 'scientific' (xx,xxxe-xx) notation.

I use read.csv and I read its documentation and poke around for
information on this but so far I have failed. Either I have found it
already but I don't understand or I ask the wrong question to the search
engines.

My experience of Pandas is limited and I would appreciate some guidance.

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