[issue45497] Argparse: Refactor '%' interpolation to f-strings

2021-10-16 Thread Shivnaren Srinivasan


Shivnaren Srinivasan  added the comment:

Understood--thank you for the responses.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue45497>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45497] Argparse: Refactor '%' interpolation to f-strings

2021-10-16 Thread Shivnaren Srinivasan

New submission from Shivnaren Srinivasan :

I use `argparse` a lot, and I think it's great—going through the source code, I 
see all string interpolation is with the old printf `%` formatting.

AFAIK, f-strings are now the suggested method for interpolation (*after they 
were introduced, that is*).

Do we want to refactor the '%' instances to f-strings? Happy to submit a PR if 
so.

--
components: Library (Lib)
messages: 404108
nosy: rhettinger, shivnaren
priority: normal
severity: normal
status: open
title: Argparse: Refactor '%' interpolation to f-strings
type: enhancement
versions: Python 3.10, Python 3.11

___
Python tracker 
<https://bugs.python.org/issue45497>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45442] Update `Virtual Environment` tutorial

2021-10-16 Thread Shivnaren Srinivasan


Change by Shivnaren Srinivasan :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue45442>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45442] Update `Virtual Environment` tutorial

2021-10-15 Thread Shivnaren Srinivasan


Change by Shivnaren Srinivasan :


--
pull_requests: +27268
pull_request: https://github.com/python/cpython/pull/28981

___
Python tracker 
<https://bugs.python.org/issue45442>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45442] Update `Virtual Environment` tutorial

2021-10-12 Thread Shivnaren Srinivasan


Shivnaren Srinivasan  added the comment:

In the same vein, the specified script for windows is the old .bat file, though 
PowerShell is now the preferred shell (and for which a .ps1 script is generated 
in the venv directory).

We could make the .ps1 the default, and specify the .bat as an alternative?

--
type: enhancement -> 

___
Python tracker 
<https://bugs.python.org/issue45442>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45442] Update `Virtual Environment` tutorial

2021-10-12 Thread Shivnaren Srinivasan

New submission from Shivnaren Srinivasan :

Priority: Low

The Virtual Environment tutorial page 
(https://docs.python.org/3/tutorial/venv.html) doesn't specify how we can 
revert, or deactivate the `venv`.

This is quite a popular question on SO:
https://stackoverflow.com/questions/990754/how-to-leave-exit-deactivate-a-python-virtualenv

``deactivate`` worked for me—this could be added to the docs?

Happy to submit a PR.

--
assignee: docs@python
components: Documentation
messages: 403722
nosy: docs@python, shivnaren
priority: normal
severity: normal
status: open
title: Update `Virtual Environment` tutorial
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 
<https://bugs.python.org/issue45442>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26543] [EASY] imaplib noop Debug: bytes vs Unicode bug in debug mode

2020-04-23 Thread Sadhana Srinivasan


Change by Sadhana Srinivasan :


--
nosy: +rotuna
nosy_count: 9.0 -> 10.0
pull_requests: +19013
pull_request: https://github.com/python/cpython/pull/19693

___
Python tracker 
<https://bugs.python.org/issue26543>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23082] pathlib relative_to() can give confusing error message

2020-04-19 Thread Sadhana Srinivasan


Change by Sadhana Srinivasan :


--
keywords: +patch
pull_requests: +18945
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19611

___
Python tracker 
<https://bugs.python.org/issue23082>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23082] pathlib relative_to() can give confusing error message

2020-04-15 Thread Sadhana Srinivasan


Sadhana Srinivasan  added the comment:

I'll work on this. 

I tried to come up with a single error message but having two different error 
messages seems like a better idea to me. One for when the path isn't a subpath 
and one for when absolute and relative paths are mixed. Basically to explain 
this:

>>> Path("/Users/rotuna/Documents/cpython/Libs").relative_to(Path("./Libs"))
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/rotuna/Documents/cpython/Lib/pathlib.py", line 907, in 
relative_to
raise ValueError("{!r} is not a subpath of{!r}. NOTE: If this is not true, 
use absolute paths"
ValueError: '/Users/rotuna/Documents/cpython/Libs' does not start with 'Libs'

--
nosy: +rotuna

___
Python tracker 
<https://bugs.python.org/issue23082>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38245] Why am I getting inconsistent results in this simple List assignment?

2019-09-21 Thread Srinivasan Samuel

Srinivasan Samuel  added the comment:

Thanks Ammar for your time, service and reply. It was really helpful. I learned 
some thing more.God Bless you.Srinivasan Samuel
On Saturday, September 21, 2019, 10:50:32 PM GMT+5:30, Ammar Askar 
 wrote:  

Ammar Askar  added the comment:

Check out this part of the FAQ: 
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list

Essentially, when you did `C = 2*[[]]`, what happens is that the SAME empty 
list is placed into C[0] and C[1]. Whereas when you do `M = [[],[]]`, you're 
creating two different lists. You can confirm this using:

>>> C = 2*[[]]
>>> C[0] is C[1]
True
>>> M = [[],[]]
>>> M[0] is M[1]
False

--
nosy: +ammar2
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue38245>
___

--

___
Python tracker 
<https://bugs.python.org/issue38245>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38245] Why am I getting inconsistent results in this simple List assignment?

2019-09-21 Thread Srinivasan Samuel


New submission from Srinivasan Samuel :

Here is the my direct cut & paste from my Python 3.7.3 Shell
>>> C = 2*[[]]
>>> C
[[], []]
>>> 
>>> M = [[],[]]
>>> M
[[], []]
>>> 
>>> C == M
True
>>> 
>>> M[0].append(5)
>>> M
[[5], []]
>>> 
>>> C[0].append(5)
>>> C
[[5], [5]]
>>> 
>>> C == M
False
>>>

--
messages: 352945
nosy: pysolo
priority: normal
severity: normal
status: open
title: Why am I getting inconsistent results in this simple List assignment?
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue38245>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36113] Problem With SciPy Computation of sigma

2019-02-25 Thread N. Srinivasan


New submission from N. Srinivasan :

"""
Construct  normal probability plot

"""
import math
import scipy.stats as ss
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import prettytable
from random import seed
seed(100)

mu = 0.0
sigma = 1.0
x = np.linspace(mu - 5*sigma, mu + 5*sigma, 10)
norm_pdf_x= ss.norm.pdf(x,mu,sigma)
plt.plot(x,norm_pdf_x)
print("The Std. Dev. of normally Dist. x =", np.std(norm_pdf_x))
print()
###
Produces a wrong Result for sigma:
The Std. Dev. of normally Dist. x = 0.13142071847657633
Should be 1.0

--
components: Library (Lib)
files: test_normal.py
messages: 336604
nosy: nisthesecond
priority: normal
severity: normal
status: open
title: Problem With SciPy Computation of sigma
versions: Python 3.7
Added file: https://bugs.python.org/file48170/test_normal.py

___
Python tracker 
<https://bugs.python.org/issue36113>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: To check for empty string after a portion of the string in python 3.6

2018-12-03 Thread srinivasan
Dear Mr. Cameron

Thanks a lot for your quick responses, Could you please let me know
when the device is not enabled I get the error " I get the below error
saying "IndexError: list index out of range""

Code snippet:
cmd = "sudo hcitool scan"
res = self._helper.execute_cmd_output_string(cmd)
print("The value of res", res)
res = self._helper.execute_cmd_output_string(cmd).split("\n", 2)
print("the value", res)
print("the value", res[1])

if __name__ == "__main__":
m = Bt()
print(m.bluetooth_scan())


1. Output when device is enabled:
The value of res Scanning ...
64:A2:F9:06:63:79 OnePlus 6
the value ['Scanning ...', '\t64:A2:F9:06:63:79\tOnePlus 6']
the value 64:A2:F9:06:63:79 OnePlus 6
None

Process finished with exit code 0

2. Output when device is not enabled

When the device is not connected, I get the below error saying
"IndexError: list index out of range"
The value of res Scanning ...
Traceback (most recent call last):
the value ['Scanning ...']
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/Bt.py",
line 96, in 
print(m.bluetooth_scan())
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/Bt.py",
line 74, in bluetooth_scan
print("the value", res[1])
IndexError: list index out of range

Process finished with exit code 1

Could you please do the needful

Thanks in advance



















On Tue, Dec 4, 2018 at 3:09 AM Cameron Simpson  wrote:
>
> Note: post returned to the tutor list.
>
> Please DO NOT cross post to multiple lists (i.e. tutor and python-list,
> as you have). This makes things difficult for people who are not on both
> lists. Pick a _single_ list, and use that.
>
> On 04Dec2018 02:46, srinivasan  wrote:
> >Could you please help me, as am still learning python syntax, how can
> >I add conditional check for empty string after running "hcitool scan"
> >(ie., when there is no Bluetooth devices discovered) ie., after the
> >word  "Scanning..." , when there are no Bluetooth discover-able
> >devices and then return False in the below python code snippet?
> >
> >
> >Command:
> >~$ sudo hcitool scan
> >Scanning ...  -->
> >When there are no BT devices
> >~$ sudo hcitool scan
> >Scanning ...
> >64:A2:F9:06:63:79 OnePlus 6 ---> When there
> >are BT devices
> >~$
> >
> >Python code snippet:
> >def bluetooth_scan(self):
> >"""
> >Start bluetooth scanning process.
> >
> >:return: Return device info by mac address and name.
> >"""
> >cmd = "sudo hciconfig hci0 up"
> >self._helper.execute_cmd_return_code(cmd)
> >
> >cmd = "sudo hcitool scan"
> >res = self._helper.execute_cmd_output_string(cmd)
> >
> >return res
>
> Well you document your function as returning device info by MAC. So part
> the output if "hcitool scan" and for MAC address and name and store that
> in a dictionary (key MAC, value the name). Return the dictionary.
>
> If the dictionary is empty, there were no devices.
>
> Not that like almost all collections, empty dictionaries are "false", so
> you can go:
>
>   bluetooth_devices = scanner.bluetooth_scan()
>   if not bluetooth_devices:
> ... no devices found ...
>
> Cheers,
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


To check for empty string after a portion of the string in python 3.6

2018-12-03 Thread srinivasan
Dear Python Experts,

Could you please help me, as am still learning python syntax, how can
I add conditional check for empty string after running "hcitool scan"
(ie., when there is no Bluetooth devices discovered) ie., after the
word  "Scanning..." , when there are no Bluetooth discover-able
devices and then return False in the below python code snippet?


Command:
~$ sudo hcitool scan
Scanning ...  -->
When there are no BT devices
~$ sudo hcitool scan
Scanning ...
64:A2:F9:06:63:79 OnePlus 6 ---> When there
are BT devices
~$

Python code snippet:
def bluetooth_scan(self):
"""
Start bluetooth scanning process.

:return: Return device info by mac address and name.
"""
cmd = "sudo hciconfig hci0 up"
self._helper.execute_cmd_return_code(cmd)

cmd = "sudo hcitool scan"
res = self._helper.execute_cmd_output_string(cmd)

return res

Many Thanks in advance,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Error Python version 3.6 does not support this syntax.

2018-11-29 Thread srinivasan
Dear Mats,

Thanks a lot for your quick responses, again the below line seems to
be throwing the same error, is that should I again decode the line
where am facing the issue to str? or could you please let me if there
is any alternative solution for the same or workaround in python 3.6?

Code Snippet:

def parse_device_info(self, info_string):
"""Parse a string corresponding to a device."""
device = {}
block_list = ["[\x1b[0;", "removed"]
string_valid = not any(keyword in info_string for keyword in
block_list) ---> Again this line seems to be
the same issue

if string_valid:
try:
device_position = info_string.index("Device")
except ValueError:
pass
else:
if device_position > -1:
attribute_list = info_string[device_position:].split(" ", 2)
device = {
"mac_address": attribute_list[1],
"name": attribute_list[2]
}

return device

def get_paired_devices(self):
"""Return a list of tuples of paired devices."""
try:
out = self.get_output("paired-devices")
except BluetoothctlError as e:
print(e)
return None
else:
paired_devices = []
for line in out:
device = self.parse_device_info(line)
if device:
paired_devices.append(device)

return paired_devices

if __name__ == "__main__":

print("Init bluetooth...")
bl = Bluetoothctl()
print("Ready!")
bl.start_scan()
print("Scanning for 10 seconds...")
for i in range(0, 10):
print(i)
time.sleep(1)

bl.pair("64:A2:F9:06:63:79")
print("Pairing for 10 seconds...")
for i in range(0, 10):
print(i)
time.sleep(1)

# Seems to be an issue --
bl.get_paired_devices()
print("Getting Paired devices for 10 seconds...")
for i in range(0, 10):
    print(i)
time.sleep(1)

Error Logs:

Traceback (most recent call last):
, in parse_device_info
string_valid = not any(keyword in info_string for keyword in block_list)
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
line 52, in 
string_valid = not any(keyword in info_string for keyword in block_list)
TypeError: a bytes-like object is required, not 'str'

On Fri, Nov 30, 2018 at 1:18 AM Mats Wichmann  wrote:
>
> On 11/29/18 12:20 PM, srinivasan wrote:
> > Dear Python Experts,
> >
> > With the below code snippet, I am seeing the below error, I am using
> > python 3.6, could you please what could be the issue?
>
> > self.child = pexpect.spawn("bluetoothctl", echo = False)
> ...
> > self.child.send(command + "\n")
> > time.sleep(pause)
> > start_failed = self.child.expect(["bluetooth", pexpect.EOF])
> ...
> > return self.child.before.split("\r\n")
> > --->
> > the issue seems to be here
> > line 27, in get_output
> > return self.child.before.split("\r\n")
> > TypeError: a bytes-like object is required, not 'str'
>
> your types don't match. it's Python 3 so what you get back from talking
> to an external process is a bytes object. you're calling the split
> method on that object, but passing it a string to split on - that's what
> the error is saying.  It shouldn't be any more complicated to fix that
> than to give it a byte object:
>
> return self.child.before.split(b"\r\n")
>
> or... decode the object to a str before splitting on a string.
>
> but since you're specifically splitting on lines, you may as well use
> the splitlines method instead of the split method, since that's what it
> is designed for.
>
>
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Error Python version 3.6 does not support this syntax.

2018-11-29 Thread srinivasan
Dear Python Experts,

With the below code snippet, I am seeing the below error, I am using
python 3.6, could you please what could be the issue?

Code Snippet:
---
import time
import pexpect
import subprocess
import sys

class BluetoothctlError(Exception):
"""This exception is raised, when bluetoothctl fails to start."""
pass


class Bluetoothctl:
"""A wrapper for bluetoothctl utility."""

def __init__(self):
out = subprocess.check_output("rfkill unblock bluetooth", shell = True)
self.child = pexpect.spawn("bluetoothctl", echo = False)

def get_output(self, command, pause = 0):
"""Run a command in bluetoothctl prompt, return output as a
list of lines."""
self.child.send(command + "\n")
time.sleep(pause)
start_failed = self.child.expect(["bluetooth", pexpect.EOF])

if start_failed:
raise BluetoothctlError("Bluetoothctl failed after running
" + command)

return self.child.before.split("\r\n")
--->
the issue seems to be here

def start_scan(self):
"""Start bluetooth scanning process."""
try:
out = self.get_output("scan on")
except BluetoothctlError as e:
print(e)
return None

if __name__ == "__main__":

print("Init bluetooth...")
bl = Bluetoothctl()
print("Ready!")
    bl.start_scan()
print("Scanning for 10 seconds...")
for i in range(0, 10):
print(i)
time.sleep(1)

Error Logs:
-
/home/srinivasan/Downloads/bt_tests/qa/venv/bin/python
/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py
Init bluetooth...
Ready!
Traceback (most recent call last):
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
line 169, in 
bl.start_scan()
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
line 32, in start_scan
out = self.get_output("scan on")
  File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
line 27, in get_output
return self.child.before.split("\r\n")
TypeError: a bytes-like object is required, not 'str'

Process finished with exit code 1

On Wed, Nov 28, 2018 at 12:17 AM Mats Wichmann  wrote:
>
> On 11/27/18 5:50 AM, srinivasan wrote:
> > Dear Python Experts,
> >
> > As still I am newbie and learning python, I am trying to reuse the
> > Bluetoothctl wrapper in Python from the link (
> > https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6
> > version, In pycharm editor on the bold highlighted code snippets I see the
> > error message "Python version 3.6 does not support this syntax.",
>
> once again you've posted in a way that inserts lots of extra crud, you
> avoided that last time.
>
> The syntax change is simple (and works on most older Pythons too):
>
> except ErrorType, e:
>
> becomes
>
> except ErrorType as e:
>
>
> >
> > Could you please how help me how the below highlighted lines of code can be
> > can be ported to python3.6 version?
> >
> > *except BluetoothctlError, e:*
> >
> > *print(e)*
> > *return None*
> >
-- 
https://mail.python.org/mailman/listinfo/python-list


Error Python version 3.6 does not support this syntax.

2018-11-27 Thread srinivasan
Dear Python Experts,

As still I am newbie and learning python, I am trying to reuse the
Bluetoothctl wrapper in Python from the link (
https://gist.github.com/egorf/66d88056a9d703928f93) I am using python3.6
version, In pycharm editor on the bold highlighted code snippets I see the
error message "Python version 3.6 does not support this syntax.",

Could you please how help me how the below highlighted lines of code can be
can be ported to python3.6 version?

*except BluetoothctlError, e:*

*print(e)*
*return None*

Full Code snippet:
==

import time
import pexpect
import subprocess
import sys

class BluetoothctlError(Exception):
"""This exception is raised, when bluetoothctl fails to start."""
pass

class Bluetoothctl:
"""A wrapper for bluetoothctl utility."""

def __init__(self):
out = subprocess.check_output("rfkill unblock bluetooth", shell =
True)
self.child = pexpect.spawn("bluetoothctl", echo = False)

def get_output(self, command, pause = 0):
"""Run a command in bluetoothctl prompt, return output as a list of
lines."""
self.child.send(command + "\n")
time.sleep(pause)
start_failed = self.child.expect(["bluetooth", pexpect.EOF])

if start_failed:
raise BluetoothctlError("Bluetoothctl failed after running " +
command)

return self.child.before.split("\r\n")

def start_scan(self):
"""Start bluetooth scanning process."""
try:
out = self.get_output("scan on")


*except BluetoothctlError, e:print(e)return
None*

def make_discoverable(self):
"""Make device discoverable."""
try:
out = self.get_output("discoverable on")



*   except BluetoothctlError, e:print(e)return
None*
def parse_device_info(self, info_string):
"""Parse a string corresponding to a device."""
device = {}
block_list = ["[\x1b[0;", "removed"]
string_valid = not any(keyword in info_string for keyword in
block_list)

if string_valid:
try:
device_position = info_string.index("Device")
except ValueError:
pass
else:
if device_position > -1:
attribute_list = info_string[device_position:].split("
", 2)
device = {
"mac_address": attribute_list[1],
"name": attribute_list[2]
}

return device

def get_available_devices(self):
"""Return a list of tuples of paired and discoverable devices."""
try:
out = self.get_output("devices")


*except BluetoothctlError, e:print(e)return
None*
else:
available_devices = []
for line in out:
device = self.parse_device_info(line)
if device:
available_devices.append(device)

return available_devices

def get_paired_devices(self):
"""Return a list of tuples of paired devices."""
try:
out = self.get_output("paired-devices")


*except BluetoothctlError, e:print(e)return
None*
else:
paired_devices = []
for line in out:
device = self.parse_device_info(line)
if device:
paired_devices.append(device)

return paired_devices

def get_discoverable_devices(self):
"""Filter paired devices out of available."""
available = self.get_available_devices()
paired = self.get_paired_devices()

return [d for d in available if d not in paired]

def get_device_info(self, mac_address):
"""Get device info by mac address."""
try:
out = self.get_output("info " + mac_address)


*except BluetoothctlError, e:print(e)return
None*
else:
return out

def pair(self, mac_address):
"""Try to pair with a device by mac address."""
try:
out = self.get_output("pair " + mac_address, 4)


*except BluetoothctlError, e:print(e)return
None*
else:
res = self.child.expect(["Failed to pair", "Pairing
successful", pexpect.EOF])
success = True if res == 1 else False
return success

def remove(self, mac_address):
"""Remove paired device by mac address, return success of the
operation."""
try:
out = self.get_output("remove " + mac_address, 3)


*except BluetoothctlError, e:print(e)return
None*
else:
res = self.child.expect(["not available", "Device has been
removed", pexpect.EOF])
success = True if res == 1 else False
return 

Re: Re: Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread srinivasan
Dear Karsten,

With the help of Mrab Inputs, I tried Even with  "return
stdout.strip().decode("utf-8")", it still seems to be an issue, I am using
python 3.6, is this causing a issue?

/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
printing stdout!!
printing retcode!! 0
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 37, in 
main("Apartment 18", "40672958689850014685")
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 34, in main
return stdout.strip().decode("utf-8")
AttributeError: 'str' object has no attribute 'decode'

Process finished with exit code 1

Many Thanks in advance

On Sun, Nov 25, 2018 at 11:57 PM Karsten Hilbert 
wrote:

> > Even only with "*proc.decode("utf-8")"* in the above code still it seems
> to
> > throw the error
>
> No it does not. It throws the same TYPE of error due to the same
> SORT of mistake you made.
>
> You need to read carefully and try to think about what you read.
>
> Karsten
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread srinivasan
Dear Mrab,

Even with  "return stdout.strip().decode("utf-8")", it still seems to be an
issue, I am using python 3.6, is this causing a issue?

/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
printing stdout!!
printing retcode!! 0
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 37, in 
main("Apartment 18", "40672958689850014685")
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 34, in main
return stdout.strip().decode("utf-8")
AttributeError: 'str' object has no attribute 'decode'

Process finished with exit code 1

Many Thanks in advance


On Sun, Nov 25, 2018 at 11:49 PM MRAB  wrote:

> On 2018-11-25 17:54, srinivasan wrote:
> > Hope now I have changed on the string output as below, could you
> > please correct me if am still wrong?
> >
> > import sys
> > import subprocess
> >
> > interface = "wlan0"
> >
> >
> > def main(ssid, pw):
> >
> > try:
> > cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)
> >
> > proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE, shell=True, universal_newlines=True)
> > stdout, stderr = proc.communicate()
> > retcode = proc.returncode
> >
> > print("printing stdout!!", stdout)
> > print("printing retcode!!", retcode)
> >
> > except subprocess.CalledProcessError as e:
> > s = """While executing '{}' something went wrong.
> > Return code == '{}'
> > Return output:\n'{}'
> > """.format(cmd, e.returncode, e.output,
> > shell=True)
> > raise AssertionError(s)
> >
> > #return proc.strip().decode("utf-8")
> > *  return proc.decode("utf-8").strip()*
> >
> [snip]
>
> No. As I said in _my_ post, 'proc' is the process itself. What you want
> is the string that it output, which, in your code, is 'stdout', so:
>
>  return stdout.strip().decode("utf-8")
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread srinivasan
Thanks a lot for your quick responses Mrab and appreciate the same.

I changed the snippet as below, still it seems to be an issue,

I am using python3 version:

def main(ssid, pw):

try:
cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True, universal_newlines=True)
stdout, stderr = proc.communicate()
retcode = proc.returncode

print("printing stdout!!", stdout)
print("printing retcode!!", retcode)

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

#return proc.strip().decode("utf-8")
#return proc.decode("utf-8").strip()
#return proc.decode("utf-8")
*return stdout.strip().decode("utf-8")*


main("Apartment 18", "40672958689850014685")


/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
printing stdout!!
printing retcode!! 0
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 37, in 
main("Apartment 18", "40672958689850014685")
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 34, in main
return stdout.strip().decode("utf-8")
*AttributeError: 'str' object has no attribute 'decode'*

Process finished with exit code 1


On Sun, Nov 25, 2018 at 11:49 PM MRAB  wrote:

> On 2018-11-25 17:54, srinivasan wrote:
> > Hope now I have changed on the string output as below, could you
> > please correct me if am still wrong?
> >
> > import sys
> > import subprocess
> >
> > interface = "wlan0"
> >
> >
> > def main(ssid, pw):
> >
> > try:
> > cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)
> >
> > proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE, shell=True, universal_newlines=True)
> > stdout, stderr = proc.communicate()
> > retcode = proc.returncode
> >
> > print("printing stdout!!", stdout)
> > print("printing retcode!!", retcode)
> >
> > except subprocess.CalledProcessError as e:
> > s = """While executing '{}' something went wrong.
> > Return code == '{}'
> > Return output:\n'{}'
> > """.format(cmd, e.returncode, e.output,
> > shell=True)
> > raise AssertionError(s)
> >
> > #return proc.strip().decode("utf-8")
> > *  return proc.decode("utf-8").strip()*
> >
> [snip]
>
> No. As I said in _my_ post, 'proc' is the process itself. What you want
> is the string that it output, which, in your code, is 'stdout', so:
>
>  return stdout.strip().decode("utf-8")
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread srinivasan
Even only with "*proc.decode("utf-8")"* in the above code still it seems to
throw the error

#return proc.strip().decode("utf-8")
#return proc.decode("utf-8").strip()
*return proc.decode("utf-8")*

Error:
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
printing stdout!!
printing retcode!! 0
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 31, in 
main("Apartment 18", "40672958689850014685")
*  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 29, in main*
*return proc.decode("utf-8")*
*AttributeError: 'Popen' object has no attribute 'decode'*

Process finished with exit code 1


On Sun, Nov 25, 2018 at 11:24 PM srinivasan 
wrote:

> Hope now I have changed on the string output as below, could you please
> correct me if am still wrong?
>
> import sys
> import subprocess
>
> interface = "wlan0"
>
>
> def main(ssid, pw):
>
> try:
> cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)
>
> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> stderr=subprocess.PIPE, shell=True, universal_newlines=True)
> stdout, stderr = proc.communicate()
> retcode = proc.returncode
>
> print("printing stdout!!", stdout)
> print("printing retcode!!", retcode)
>
> except subprocess.CalledProcessError as e:
> s = """While executing '{}' something went wrong.
> Return code == '{}'
> Return output:\n'{}'
> """.format(cmd, e.returncode, e.output, shell=True)
> raise AssertionError(s)
>
> #return proc.strip().decode("utf-8")
> *return proc.decode("utf-8").strip()*
>
> main("Apartment 18", "40672958689850014685ad")
>
> Error:
>
> /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
> /home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
> Traceback (most recent call last):
>   File
> "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
> line 30, in 
> main("Apartment 18", "40672958689850014685")
> *  File
> "/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
> line 28, in main*
> *return proc.decode("utf-8").strip()*
> *AttributeError: 'Popen' object has no attribute 'decode'*
> printing stdout!!
> printing retcode!! 0
>
> Process finished with exit code 1
>
>
>
> On Sun, Nov 25, 2018 at 11:19 PM MRAB  wrote:
>
>> On 2018-11-25 17:13, srinivasan wrote:
>> > Dear Python Experts Team,
>> >
>> > As am newbie still learning the python syntax from past 2 weeks, Excuse
>> me,
>> > If this might be silly question, As I am trying to execute shell command
>> > (ie, nmcli) using "subprocess.Popen".
>> >
>> > 1. Am trying to improve the below code with "try" and "exception", could
>> > you please help me how "try" and "exception" can be used on the below
>> code
>> > snippet. I hope in my code with try and exception, seems to be a bug.
>> >
>> > 2. As I am trying to execute shell commands using "subprocess.Popen", I
>> am
>> > trying to parse the strings output by "cmd = "nmcli device wifi connect
>> > '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing
>> the
>> > below error as shown in "Output error logs:"
>> >
>> >   Could you please let me to fix the bug in the below code snippet,
>> where I
>> > need the collect the strings of the command output and later how to be
>> > parsed after execution of the command for example, I need to parse the
>> > string "Connection activation failed: " and compare it with the command
>> > output, could you please help me how this can be achieved?
>> >
>> > *Command:*
>> > :~$ nmcli device wifi connect 'Apartment 18' password
>> > '40672958689850014685abcdf'
>> > Error: Connection activation failed: (7) Secrets were required, but not
>> > provided.
>> > :~$
>> 

Re: Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread srinivasan
Hope now I have changed on the string output as below, could you please
correct me if am still wrong?

import sys
import subprocess

interface = "wlan0"


def main(ssid, pw):

try:
cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True, universal_newlines=True)
stdout, stderr = proc.communicate()
retcode = proc.returncode

print("printing stdout!!", stdout)
print("printing retcode!!", retcode)

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

#return proc.strip().decode("utf-8")
*return proc.decode("utf-8").strip()*

main("Apartment 18", "40672958689850014685ad")

Error:

/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 30, in 
main("Apartment 18", "40672958689850014685")
*  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23_homework/qa/test_library/test4.py",
line 28, in main*
*return proc.decode("utf-8").strip()*
*AttributeError: 'Popen' object has no attribute 'decode'*
printing stdout!!
printing retcode!! 0

Process finished with exit code 1



On Sun, Nov 25, 2018 at 11:19 PM MRAB  wrote:

> On 2018-11-25 17:13, srinivasan wrote:
> > Dear Python Experts Team,
> >
> > As am newbie still learning the python syntax from past 2 weeks, Excuse
> me,
> > If this might be silly question, As I am trying to execute shell command
> > (ie, nmcli) using "subprocess.Popen".
> >
> > 1. Am trying to improve the below code with "try" and "exception", could
> > you please help me how "try" and "exception" can be used on the below
> code
> > snippet. I hope in my code with try and exception, seems to be a bug.
> >
> > 2. As I am trying to execute shell commands using "subprocess.Popen", I
> am
> > trying to parse the strings output by "cmd = "nmcli device wifi connect
> > '%s' password '%s'" % (ssid, pw)" command as below, but it is throwing
> the
> > below error as shown in "Output error logs:"
> >
> >   Could you please let me to fix the bug in the below code snippet,
> where I
> > need the collect the strings of the command output and later how to be
> > parsed after execution of the command for example, I need to parse the
> > string "Connection activation failed: " and compare it with the command
> > output, could you please help me how this can be achieved?
> >
> > *Command:*
> > :~$ nmcli device wifi connect 'Apartment 18' password
> > '40672958689850014685abcdf'
> > Error: Connection activation failed: (7) Secrets were required, but not
> > provided.
> > :~$
> >
> > *Code:*
> > *import sys*
> > *import subprocess*
> >
> > *interface = "wlan0"*
> >
> >
> > *def main(ssid, pw):*
> >
> > *# cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)*
> > *#*
> > *# proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE, shell=True,  universal_newlines=True)*
> > *# stdout, stderr = proc.communicate()*
> > *# retcode = proc.returncode*
> > *#*
> > *# print("printing stdout!!", stdout)*
> > *# print("printing retcode!!", retcode)*
> >
> > *try:*
> > *cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid,
> pw)*
> >
> > *proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE, shell=True, universal_newlines=True)*
> > *stdout, stderr = proc.communicate()*
> > *    retcode = proc.returncode*
> >
> > *print("printing stdout!!", stdout)*
> > *print("printing retcode!!", retcode)*
> >
> > *except subprocess.CalledProcessError as e:*
> > *s = """While executing '{}' something went wrong.*
> > *  

Issue in using "subprocess.Popen" for parsing the command output

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

As am newbie still learning the python syntax from past 2 weeks, Excuse me,
If this might be silly question, As I am trying to execute shell command
(ie, nmcli) using "subprocess.Popen".

1. Am trying to improve the below code with "try" and "exception", could
you please help me how "try" and "exception" can be used on the below code
snippet. I hope in my code with try and exception, seems to be a bug.

2. As I am trying to execute shell commands using "subprocess.Popen", I am
trying to parse the strings output by "cmd = "nmcli device wifi connect
'%s' password '%s'" % (ssid, pw)" command as below, but it is throwing the
below error as shown in "Output error logs:"

 Could you please let me to fix the bug in the below code snippet, where I
need the collect the strings of the command output and later how to be
parsed after execution of the command for example, I need to parse the
string "Connection activation failed: " and compare it with the command
output, could you please help me how this can be achieved?

*Command:*
:~$ nmcli device wifi connect 'Apartment 18' password
'40672958689850014685abcdf'
Error: Connection activation failed: (7) Secrets were required, but not
provided.
:~$

*Code:*
*import sys*
*import subprocess*

*interface = "wlan0"*


*def main(ssid, pw):*

*# cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)*
*#*
*# proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True,  universal_newlines=True)*
*# stdout, stderr = proc.communicate()*
*# retcode = proc.returncode*
*#*
*# print("printing stdout!!", stdout)*
*# print("printing retcode!!", retcode)*

*try:*
*cmd = "nmcli device wifi connect '%s' password '%s'" % (ssid, pw)*

*proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True, universal_newlines=True)*
*stdout, stderr = proc.communicate()*
*retcode = proc.returncode*

*print("printing stdout!!", stdout)*
*print("printing retcode!!", retcode)*

*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 proc.strip().decode("utf-8")*

*main("Apartment 18", "40672958689850014685")*

*Output error logs:*

/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/venv/bin/python
/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py
Traceback (most recent call last):
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py",
line 38, in 
printing stdout!!
printing retcode!! 0
main("Apartment 18", "40672958689850014685")
  File
"/home/srinivasan/Downloads/wifidisconnectissuenov23/qa/test_library/test4.py",
line 36, in main
return proc.strip().decode("utf-8")
AttributeError: 'Popen' object has no attribute 'strip'

Process finished with exit code 1

Kindly do the needful as am stuck with this issue from 2 days

Many Thanks in advance,
-- 
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])*
> >
> &

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-99c

Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1)

2018-11-14 Thread srinivasan
Dear Python Experts,

As am newbie to python, I am planning to automate BT functionality test
using Bluez "bluetoothctl" utility  by writing python wrapper and robot
framework integrated with Jenkins

I came across the below link:
https://www.reddit.com/r/raspberry_pi/comments/4bxu2o/bluetoothctl_in_python_program/

In the above link, I saw the below code snippet
*code:*

*from sh import bluetoothctl*
*mac = "AA:BB:CC:DD:EE"*
*bluetoothctl("connect",mac)*


And firstly I wanted to verify BT functionality with my PC and the
bluetooth device (basically turned on BT option in my phone and trying to
discover my phone as a BT device) And I have installed the below packages
in my ubuntu 18.04 desktop PC
$* pip3 install sh*
Collecting sh
  Downloading
https://files.pythonhosted.org/packages/4a/22/17b22ef5b049f12080f5815c41bf94de3c229217609e469001a8f80c1b3d/sh-1.12.14-py2.py3-none-any.whl
Installing collected packages: sh
Successfully installed sh-1.12.14
*$ pip3 install bluetoothctl*
*Collecting bluetoothctl*
*  Could not find a version that satisfies the requirement bluetoothctl
(from versions: )*
*No matching distribution found for bluetoothctl*
$ *pip3 install pexpect*
Collecting pexpect
  Downloading
https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl
(57kB)
100% || 61kB 1.5MB/s
Collecting ptyprocess>=0.5 (from pexpect)
  Downloading
https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
Installing collected packages: ptyprocess, pexpect
Successfully installed pexpect-4.6.0 ptyprocess-0.6.0
$

When I try to paste the below code on pycharm and try to point on the word
"bluetoothctl" in the beginning of the line "*from sh import bluetoothctl*"

*from sh import bluetoothctl*

*mac = "your bluetooth mac"*
*bluetoothctl("connect", mac)*

In the pycharm, I see the below error message :

*Cannot find reference 'bluetoothctl' in 'sh.py' less... (Ctrl+F1) *
*Inspection info: This inspection detects names that should resolve but
don't. Due to dynamic dispatch and duck typing, this is possible in a
limited but useful number of cases. Top-level and class-level items are
supported better than instance items.*

Could you please help me to resolve the above issue, like why am I seeing
the above issue it seems to be some importing "bluetoothhctl" module issue
(sorry if my understanding is wrong)

Kindly do the needful
Many Thanks in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


All of a sudden code started throwing errors

2018-11-14 Thread srinivasan
Dear Python Experts

Could you please let me know why am I seeing the following errors as before
this it was working consistently?



root:~/qa/robot_tests# python3 -m robot --variable
SIGNAL_LEVEL_THRESHOLD:-60 wifi_testing.robot
==
Wifi Testing :: This is the Maschine Native OS Build Wi-Fi Test.

==
Initialize Wi-Fi Module   |
PASS |
--
Enable Wi-Fi Module   |
PASS |
--
Connect Wi-Fi Module to SSID  |
PASS |
--
Check for Wi-Fi Connectivity  |
PASS |
--
Log Wi-Fi Module IP   |
PASS |
--
Get Gateway IP and Check Whether Wi-Fi is Pingable|
PASS |
--
Check for Wi-Fi Signal Strength with Threshold|
FAIL |
'-68 >= -60' should be true.
--
Wifi Testing :: This is the Maschine Native OS Build Wi-Fi Test.  |
FAIL |
7 critical tests, 6 passed, 1 failed
7 tests total, 6 passed, 1 failed
==
Output:  /home/root/qa/robot_tests/output.xml
Log: /home/root/qa/robot_tests/log.html
Report:  /home/root/qa/robot_tests/report.html
root:~/qa/robot_tests# cat /proc/net/wireless
Inter-| sta-|   Quality|   Discarded packets   | Missed
| WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon
| 22
wlp1s0:    44.  -66.  -2560  0  0  0  90



Errors:
=


root:~/qa/robot_tests# python3 -m robot --variable
SIGNAL_LEVEL_THRESHOLD:-70 wifi_testing.robot
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.5/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/usr/lib/python3.5/site-packages/robot/__init__.py", line 41, in

from robot.rebot import rebot, rebot_cli
  File "/usr/lib/python3.5/site-packages/robot/rebot.py", line 40, in

from robot.conf import RebotSettings
  File "/usr/lib/python3.5/site-packages/robot/conf/__init__.py", line 27,
in 
from .settings import RobotSettings, RebotSettings
  File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 33,
in 
class _BaseSettings(object):
  File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 46,
in _BaseSettings
'OutputDir': ('outputdir', abspath('.')),
  File "/usr/lib/python3.5/site-packages/robot/utils/robotpath.py", line
84, in abspath
return normpath(_abspath(path), case_normalize)
  File "/usr/lib/python3.5/posixpath.py", line 362, in abspath
cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory
root:~/qa/robot_tests# cat /proc/net/wireless
Inter-| sta-|   Quality|   Discarded packets   | Missed
| WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon
| 22
wlp1s0:    45.  -65.  -2560  0  0  0 120
root:~/qa/robot_tests# python3 -m robot wifi_testing.robot

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.5/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/usr/lib/python3.5/site-packages/robot/__init__.py", line 41, in

from robot.rebot import rebot, rebot_cli
  File "/usr/lib/python3.5/site-packages/robot/rebot.py", line 40, in

from robot.conf import RebotSettings
  File "/usr/lib/python3.5/site-packages/robot/conf/__init__.py", line 27,
in 
from .settings import RobotSettings, RebotSettings
  File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 33,
in 
class _BaseSettings(object):
  File "/usr/lib/python3.5/site-packages/robot/conf/settings.py", line 46,
in _BaseSettings
'OutputDir': 

Re: Unable to get the gateway IP of wlan interface using python code

2018-11-13 Thread srinivasan
As am a beginner with the python Syntax, I was able to parse the gateway IP
as below, Please do let me know if anyone forsee any issues in the below?:

def get_gateway_ip(self):
"""
Get the Gateway IP address of the AP.

:return: Gateway IP.
"""

cmd = '/sbin/ifconfig wlp1s0 | grep "inet addr" | cut -d: -f2 | cut
-d" " -f1'
f = os.popen(cmd)
ip_address = f.read().strip()

list_ = ip_address.split('.')
assert len(list_) == 4
list_[3] = '1'

return '.'.join(list_)

With the above return value I was able to pass the gateway IP to my robot
framework, and process further

Many Thanks in advance,
Srini



On Tue, Nov 13, 2018 at 10:11 AM srinivasan 
wrote:

> Hi Wildman,
>
> The below snippet seems to be fine, how can I specify to get the specific
> wlan0 interface gateway IP in the below code snippet?
>
> #
> #!/usr/bin/env python
>
> import socket
> import struct
>
> def get_gateway_ip():
> try:
> with open("/proc/net/route", "r") as f:
> route = f.readlines()
> except IOError:
> return None
> for line in route:
> fields = line.strip().split()
> if fields[1] != "" or not int(fields[3], 16) & 2:
> continue
> gateway = socket.inet_ntoa(struct.pack(" break
> return gateway
>
> print get_gateway_ip()
> #
>
>
> Many Thanks in advance,
> Srini
>
>
> On Tue, Nov 13, 2018 at 5:16 AM Wildman via Python-list <
> python-list@python.org> wrote:
>
>> I tried posting this already but it didn't make it.  I am
>> trying again...
>>
>> On Tue, 13 Nov 2018 01:07:06 +0530, srinivasan wrote:
>>
>> > Dear Python Experts,
>> >
>> > *First method:*
>> >
>> > I need to get the IP address basically the gateway IP
>>
>> I am assuming your platform is Linux.  If I am incorrect then
>> ignore this post.
>>
>> The code below reads /proc/net/route to obtain the gateway and
>> then prints it.  It can be run as-is from a terminal.
>>
>> #
>> #!/usr/bin/env python
>>
>> import socket
>> import struct
>>
>> def get_gateway_ip():
>> try:
>> with open("/proc/net/route", "r") as f:
>> route = f.readlines()
>> except IOError:
>> return None
>> for line in route:
>> fields = line.strip().split()
>> if fields[1] != "" or not int(fields[3], 16) & 2:
>> continue
>> gateway = socket.inet_ntoa(struct.pack("> break
>> return gateway
>>
>> print get_gateway_ip()
>> #
>>
>> --
>>  GNU/Linux user #557453
>> The cow died so I don't need your bull!
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to get the gateway IP of wlan interface using python code

2018-11-13 Thread srinivasan
Hi Wildman,

The below snippet seems to be fine, how can I specify to get the specific
wlan0 interface gateway IP in the below code snippet?

#
#!/usr/bin/env python

import socket
import struct

def get_gateway_ip():
try:
with open("/proc/net/route", "r") as f:
route = f.readlines()
except IOError:
return None
for line in route:
fields = line.strip().split()
if fields[1] != "" or not int(fields[3], 16) & 2:
continue
gateway = socket.inet_ntoa(struct.pack(" wrote:

> I tried posting this already but it didn't make it.  I am
> trying again...
>
> On Tue, 13 Nov 2018 01:07:06 +0530, srinivasan wrote:
>
> > Dear Python Experts,
> >
> > *First method:*
> >
> > I need to get the IP address basically the gateway IP
>
> I am assuming your platform is Linux.  If I am incorrect then
> ignore this post.
>
> The code below reads /proc/net/route to obtain the gateway and
> then prints it.  It can be run as-is from a terminal.
>
> #
> #!/usr/bin/env python
>
> import socket
> import struct
>
> def get_gateway_ip():
> try:
> with open("/proc/net/route", "r") as f:
> route = f.readlines()
> except IOError:
> return None
> for line in route:
> fields = line.strip().split()
> if fields[1] != "" or not int(fields[3], 16) & 2:
> continue
> gateway = socket.inet_ntoa(struct.pack(" break
> return gateway
>
> print get_gateway_ip()
> #
>
> --
>  GNU/Linux user #557453
> The cow died so I don't need your bull!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in parsing the strings in python code

2018-11-12 Thread srinivasan
Hi Thomas,

I have Implemented as below, please let me know if you forsee any issues in
the below code snippet?as I have just started learning python from last
week


def wifi_connect_verify(self):
"""
Verify Connectivity of WIFI module to the Access.

:return: command output as True or False.
"""

*cmd = 'nmcli dev | grep "wlp1s0" | grep "connected"'*
*f = os.popen(cmd)*
*if 'connected' in f.read().strip():*
*return True*
*else:*
*return False*

Kindly do the needful
Srini

On Mon, Nov 12, 2018 at 4:02 PM Thomas Jollans  wrote:

> On 2018-11-12 10:23, srinivasan wrote:
> > Hi Thomas,
> >
> > Great to hear from you, Could you please let me know how do I get the
> UUID
> > "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID
> > "Funkloch' using "nmcli --terse" ??
>
>
> Have a look at the output. It appears to me that the fields are
> separated by colons, so you should be able to split each line on ':'.
>
> If you're stuck, let us see what you've tried!
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Unable to get the gateway IP of wlan interface using python code

2018-11-12 Thread srinivasan
Dear Python Experts,

*First method:*

I need to get the IP address basically the gateway IP in my setup I get it
as "192.168.178.1" when I run the below standalone python code.


*def get_gateway_ip(self):*
*"""*
*Get the IP address to the WIFI module from the AP*
*"""*

*cmd = 'ip route show 0.0.0.0/0  dev wlp1s0 | cut
-d\  -f3'*
*f = os.popen(cmd)*
*return str(f.read().strip())*


I am trying to log the IP in the robot framework script and ensure that my
router is able to ping but "*${SSID_GATEWAY_IP}*" doesn't seem to get
collected from the above python code and pass this value to my custom
method "*Wait Until Device Is Pingable"*

*${RET} =Wait Until Device Is Pingable ${SSID_GATEWAY_IP}*
*Should Be True${RET}*

But whenever I hardcode the "*${SSID_GATEWAY_IP}  192.168.178.1*" in the
robot framework, it seems to be working with "*Wait Until Device Is
Pingable ${SSID_GATEWAY_IP}*"

But the below robot framework script doesn't seems to work with the return
value received from the above python script, could you please do the
needful?

*Get Gateway IP of SSID*
* ${SSID_GATEWAY_IP} = Get Gateway Ip*
* Log  ${SSID_GATEWAY_IP}*
*${RET} =Wait Until Device Is Pingable ${SSID_GATEWAY_IP}*
*Should Be True${RET}*


*SECOND METHOD:*

When I use the subprocess I see the below issue:



def get_gateway_ip(self):
"""
Get the IP address to the WIFI module from the AP
"""

#cmd = 'ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\  -f3'
# f = os.popen(cmd)
# return str(f.read().strip())


p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\
-f3', stdout=subprocess.PIPE)
result = p.communicate()[0]
print(result)

#list = os.popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\
-f3').read()

# p = Popen(cmd, shell=True, stdout=PIPE)
# out, err = p.communicate()
# #return (p.returncode, out, err)
# return out
# #print('returncode: %s' % result[0])
# #print('output: %s' % result[1])
# #print('error: %s' % result[2])

#return self._helper.execute_cmd_output_string(cmd)


Error:

root:~/qa/test_library# python3 wifi.py
Enabling wifi
Verify wifi connectivity
True
Get gateway wifi ip
Traceback (most recent call last):
  File "wifi.py", line 134, in 
print(m.get_gateway_ip())
  File "wifi.py", line 76, in get_gateway_ip
p = subprocess.Popen('ip route show 0.0.0.0/0 dev wlp1s0 | cut -d\
-f3', stdout=subprocess.PIPE)
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1289, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ip route show
0.0.0.0/0 dev wlp1s0 | cut -d\\  -f3'
root:~/qa/test_library#


As I am stuck with this issue from past 2 days, wondering for any clues

Kindly do the needful as early as possible

Many Thanks in adavnce
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in parsing the strings in python code

2018-11-12 Thread srinivasan
Because the problem is every time when ever I see the output  using the
"nmcli c show", the below output is the weird output, so instead of
connecting to SSID "NIFunkloch" it randomly connects to "NIFunkloch 1552"
or sometimes to NIFunkloch 1000" or so on

root:~/qa/robot_tests# nmcli c show
NAMEUUID  TYPE  DEVICE

NIFunkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd  wifi  wlp1s0

Wired connection 1  2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0  ethernet
enp0s21f0u4
NIFunkloch  1da7d068-4548-4446-bf88-a440e49db1b1  wifi  --

NIFunkloch 10   f4d9ce13-aab0-4485-9929-6070ad52a196  wifi  --

NIFunkloch 100  8b48a220-1754-4988-84ad-d0f83a9b4ede  wifi  --

NIFunkloch 1000 4dd7ae61-8c10-4582-984a-600b4c6b008e  wifi  --

NIFunkloch 1001 2fcd1d89-1d1c-43ca-8b6a-d667fa4b0f90  wifi  --

NIFunkloch 1002 c0a31697-afa9-453b-9938-811a9315e30f  wifi  --

NIFunkloch 1003 2dc7e148-d246-492f-94f0-88314fc0cc89  wifi  --

NIFunkloch 1004 a389f24e-ef39-4886-ae13-b38932e9f00d  wifi  --

NIFunkloch 1005 c2ecc4f5-58b8-4488-9769-f7c3fc044134  wifi  --

NIFunkloch 1006 de98d76c-22bf-4e1c-89fd-577538e8a40d  wifi  --

NIFunkloch 1007 0bca5d73-03e3-4bb4-a78c-98d0adabaac9  wifi  --

NIFunkloch 1008 dc576c25-75c8-491b-847a-8a192e6c3869  wifi  --

NIFunkloch 1009 46c8fc94-62d0-48d9-9fcb-489f646a9fbd  wifi  --

NIFunkloch 101  ce8a3276-016d-4101-8002-4092af9a49f3  wifi  --

NIFunkloch 1010 814716b2-935c-40a3-89a8-4bfebd9a7f6d  wifi  --

NIFunkloch 1011 68fa4889-63a3-41f2-b6e1-1be4982e756a  wifi  --

NIFunkloch 1012 c47d66ff-ea8c-498c-9c04-012732078923  wifi  --

NIFunkloch 1013 37b51561-f3eb-4162-a87e-7c37e495c30b  wifi  --

NIFunkloch 1014 ba9b30a5-c882-4e45-8882-3fe4cfcfd191  wifi  --

NIFunkloch 1015 9327e4d5-d5e5-4f3b-a70a-0eeec1d5256f  wifi  --

NIFunkloch 1016 e24c1a9a-1f5e-4895-9656-efed574dfae2  wifi  --

NIFunkloch 1017 1cf9c60f-9efd-474c-8dbc-804d9796764b  wifi  --

NIFunkloch 1018 ec678687-f8d4-4123-bf64-f8bf67523cb6  wifi  --

NIFunkloch 1019 655579c5-74ec-4d4b-a0bc-9d31a5f40658  wifi  --

NIFunkloch 102  1de1d876-37b2-40e7-9707-ced79ab2664a  wifi  --

NIFunkloch 1020 9e90cc37-76f2-482c-8932-3173d5f15594  wifi  --

NIFunkloch 1021 1529bc15-9baa-4ee6-9603-3613be98a3c8  wifi  --

NIFunkloch 1022 25f8279d-8100-4d8b-9571-4da7d3031977  wifi  --

NIFunkloch 1023 43c73d01-7921-4887-92be-4054186c8b44  wifi  --

NIFunkloch 1024 9f433dc9-fb07-4ad0-94c4-219e3f1dd429  wifi  --

NIFunkloch 1025 d3cba1d3-3c27-4711-874a-cbfdbdc41784  wifi  --

NIFunkloch 1026 066b02d6-760f-4dd1-826a-c210b20075db  wifi  --

NIFunkloch 1027 0f13c31b-3d4b-4b25-a3a1-6b88c6a46431  wifi  --

NIFunkloch 1028 904590e5-d7e2-4cb7-8507-9838cafa411e  wifi  --

NIFunkloch 1029 89aa5931-82e6-4475-b445-03729d03ffd8  wifi  --

NIFunkloch 103  028c7347-1933-4a26-8ff5-89fd8541c038  wifi  --

NIFunkloch 1030 ba0a681b-7022-4f7b-a684-889f8560bf19  wifi  --

NIFunkloch 1031 963bf13c-16e5-4b24-a71e-778b0b2ea4a8  wifi  --

NIFunkloch 1032 6c32f2a6-e68b-44ee-b1b4-ef413cd6d45b  wifi  --

NIFunkloch 1033 da463db4-56d2-4746-aae6-63680620f7de  wifi  --

NIFunkloch 1034 821412fc-0c67-4fd5-b126-63434043ae48  wifi  --

NIFunkloch 1035 fc6dfddf-2a4a-4477-b0fa-cd90a50f35a4  wifi  --

NIFunkloch 1036 b922fef5-3c71-40cd-bb82-bea31ec15657  wifi  --

NIFunkloch 1037 c4a2c4cb-3f31-494c-bf39-aa43cd9e5d29  wifi  --

NIFunkloch 1038 ceaff9ba-7fb6-4eb1-943a-99c282789279  wifi  --

NIFunkloch 1039 a9e790a6-b31e-4ff1-becf-78a61000a441  wifi  --

NIFunkloch 104  5f2199ed-371a-4a27-872b-c945d51926de  wifi  --

NIFunkloch 1040 4a84f94e-46bd-47d3-b7e3-5dcf9dc5f54a  wifi  --

NIFunkloch 1041 9d93fe6e-6a74-4744-8edf-09160fb3583f  wifi  --


On Mon, Nov 12, 2018 at 10:23 AM srinivasan 
wrote:

> Hi Thomas,
>
> Great to hear from you, Could you please let me know how do I get the UUID
> "1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID
> "Funkloch' using "nmcli --terse" ??
>
> Many thanks in advance,
> Srini
>
> On Mon, Nov 12, 2018 at 9:59 AM Thomas Jollans  wrote:
>
>> On 12/11/2018 09:28, srinivasan wrote:
>> > Dear Python Experts team,
>> >
>> > This question might be very simple for you, As am newbie to python,
>> could
>> > you please how to parse the below strings
>> >
>> > [snip]
>> >
>> >
>> > root:~/qa/robot_tests# nmcli c show
>>
>> Pro tip: many *nix tools have a flag that makes them produce
>> machine-readable output. E.g.: from the n

Re: Issue in parsing the strings in python code

2018-11-12 Thread srinivasan
Hi Thomas,

Great to hear from you, Could you please let me know how do I get the UUID
"1da7d068-4548-4446-bf88-a440e49db1b1" by passing the name of the SSID
"Funkloch' using "nmcli --terse" ??

Many thanks in advance,
Srini

On Mon, Nov 12, 2018 at 9:59 AM Thomas Jollans  wrote:

> On 12/11/2018 09:28, srinivasan wrote:
> > Dear Python Experts team,
> >
> > This question might be very simple for you, As am newbie to python, could
> > you please how to parse the below strings
> >
> > [snip]
> >
> >
> > root:~/qa/robot_tests# nmcli c show
>
> Pro tip: many *nix tools have a flag that makes them produce
> machine-readable output. E.g.: from the nmcli man page:
>
> OPTIONS
>-t | --terse
>Output is terse. This mode is designed and suitable for
> computer (script) processing.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Issue in parsing the strings in python code

2018-11-12 Thread srinivasan
Dear Python Experts team,

This question might be very simple for you, As am newbie to python, could
you please how to parse the below strings

1. Could you please do the needful in guiding me, that how can I extract
the strings under the UUID column in python code in the below output (nmcli
c show), I need to extract the UUID of "Funkloch" ie.,
"1da7d068-4548-4446-bf88-a440e49db1b1" for "TYPE" wifi and device "wlp1s0"
and return this string ("1da7d068-4548-4446-bf88-a440e49db1b1") to the
robotframework?


root:~/qa/robot_tests# nmcli c show
NAMEUUID  TYPE  DEVICE

Funkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd  wifi  wlp1s0

Wired connection 1  2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0  ethernet
enp0s21f0u4
Funkloch  1da7d068-4548-4446-bf88-a440e49db1b1  wifi  --

Funkloch 10   f4d9ce13-aab0-4485-9929-6070ad52a196  wifi  --

Funkloch 100  8b48a220-1754-4988-84ad-d0f83a9b4ede  wifi  --



2. Similarly, As I need to verify whether the DEVICE "wlp1s0" is connected
to "Funkloch" or not? could you please help me, how can I extract the
"connected" status under "STATE column for DEVICE "wlp1s0" and CONNECTION
"Funkloch 1552"

root:~/qa/robot_tests# nmcli dev
DEVICE   TYPE  STATECONNECTION
enp0s21f0u4  ethernet  connectedWired connection 1
wlp1s0   wifi  connectedFunkloch 1552
enp2s0   ethernet  unavailable  --
sit0 iptunnel  unmanaged--
lo   loopback  unmanaged--

Kindly do the needful as am trying this from past two 2 days, still no clues

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


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
Many Thanks a lot , I can use for reliably "lsblk %s -n -o FSTYPE"  in the
reused code of mine as below

cmd = "lsblk %s -n -o FSTYPE" % partition_path
return self._helper.execute_cmd_output_string(cmd)

I really appreciate for all your support w.r.t this..

I feel I have kick started my learning in python :)

Have a great day ahead!


On Wed, Nov 7, 2018 at 3:11 PM Ben Bacarisse  wrote:

> srinivasan  writes:
>
> > Even after changing as per the below
> > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> > or:
> > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> > or:
> > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"
> >
> > Still my output is:
> > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"*
> >
> > My expected output should be only:
> > *vfat*
> >
> > Could you guys please do the needful?
>
> Why not
>
>   blkid %s -o value --match-tag TYPE
>
> ?  Or, better still,
>
>   lsblk %s -n -o FSTYPE
>
> It's not easy to answer your question about fixing the line you have,
> because the output you are getting it not consistent with what you are
> showing.  (And I can't find the original post that presumably has Python
> code I could run myself.)
>
> The format I get with -o export is:
>
> DEVNAME=/dev/sda1
> UUID=2726bf5f-2655-4986-815d-e4532374f218
> TYPE=ext3
> PARTUUID=000453d3-01
>
> for which
>
>   "blkid %s -o export | grep TYPE | cut -c6-"
>
> would work.  Alternatively I get the result you want from
>
>   "blkid %s -o export | grep TYPE | cut -d= -f2"
>
> Note that "TYPE" and "=" don't really need to be quoted at all.
>
> Someone suggested sed, and that too can be used like this:
>
>   blkid %s -o export | sed -ne '/TYPE=/s///p'
>
> --
> Ben.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
Some I managed to fix temporarily as below, might be useful for others.
Also please correct me if anything wrong or for any improvements in the
below

cmd = "blkid -o export %s" % partition_path
out = self._helper.execute_cmd_output_string(cmd)
var = out.split("TYPE=", 1)[1]
quoted = re.compile('(?<=^\")[^"]*')
for string in quoted.findall(var):
return string

On Wed, Nov 7, 2018 at 1:39 PM Chris Angelico  wrote:

> On Wed, Nov 7, 2018 at 11:36 PM Qian Cai  wrote:
> >
> > srinivasan  wrote:
> > > Even after changing as per the below
> > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> > > or:
> > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> > > or:
> > > "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"
> > >
> > > Still my output is:
> > > */dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"*
> > >
> > > My expected output should be only:
> > > *vfat*
> > >
> > > Could you guys please do the needful?
> > >
> > >
> > Perfect place to use sed instead of grep/cut.
>
> ... or to use subprocess.check_output() to run just the blkid command,
> and then do the parsing in Python.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
Even after changing as per the below
"blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
or:
'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
or:
"blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"

Still my output is:
*/dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"*

My expected output should be only:
*vfat*

Could you guys please do the needful?


On Wed, Nov 7, 2018 at 11:10 AM Brian J. Oney 
wrote:

> On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote:
> > blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3
>
> You don't need to escape the single quotes.
> Try either:
>
> "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> or:
> 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> or:
> "blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"
>
> HTH
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread srinivasan
After changing the line to *"cmd = "blkid -o export %s | grep \'TYPE\' |
cut -d\"=\" -f3" % fs"*, Now I dont see the error "SyntaxError: can't
assign to literal"
This is not returning exactly "*vfat*" instead of this, it is returning as "*
/dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* "

Could you please help me  as it seems to be like grep and cut commands are
not working in the above line ie., on *cmd = "blkid -o export %s | grep
\'TYPE\' | cut -d\"=\" -f3" % fs*?

On Wed, Nov 7, 2018 at 9:41 AM Avi Gross  wrote:

> I may be missing something but it looks like the embedded double quotes
> may be a problem in this:
>
> cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % ...
>
> if you use single quotes as in:
>
> cut -d"="
>
> becomes
>
> cut -d'='
>
> or escape the double quotes with \" and so on ...
>
> The above seems to be seen as:
>
> cmd=ALPHA=BETA % ...
>
> where ALPHA="blkid -o export %s | grep 'TYPE' | cut -d"
> and BETA=" -f3"
>
> Other issues may also be there.
> -Original Message-
> From: Tutor  On Behalf Of
> Alan Gauld via Tutor
> Sent: Tuesday, November 6, 2018 7:37 PM
> To: tu...@python.org
> Cc: python-...@python.org
> Subject: Re: [Tutor] SyntaxError: can't assign to literal while using
> ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using
> subprocess module in Python
>
> On 06/11/2018 18:07, srinivasan wrote:
>
> > bash command in python using subprocess module, I ma seeing the below
> > *cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" %
> > (fs)*
>
> In general you should try to do as little as possible using bash and
> subprocess. Especially try to avoid long pipelines since you are starting a
> new OS process for every element in the pipeline. That means, in your case,
> you are running 4 processes to get your result - Python, blkid, grep and cut
>
> Python is designed to do much of what the shell command can do almost as
> easily and much more efficiently (no new processes being started).
>
> In this case just execute the blkid bit in bash because its too difficult
> to replicate simply in Python. Then use Python to search for the TYPE lines
> and slice them to size.
>
> That will, in turn, simplify your command string and remove the issue of
> multiple quotes.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
> ___
> 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


SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

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

As am newbie to python development, I am trying to use the below function
to get verify the filesystem type of the SD card parition using bash
command in python using subprocess module, I ma seeing the below Error
"SyntaxError: can't assign to literal"

*CODE:*
**

import helper
from os import path
import subprocess
import os
import otg_ni


class emmc(object):
"""
emmc getters and setters
info:
https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
"""

def __init__(self):
self._helper = helper.helper()
self._otg_ni = otg_ni.otg_ni()


*def get_fstype_of_mounted_partition(self, fs):*
"""
Get the filesystem type of the mounted partition.

:partition_name : Partition path as string (e.g. /dev/mmcblk0p1)
:return: filesystem type as string or None if not found
"""

*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
*return self._helper.execute_cmd_output_string(cmd)*



*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 = emmc()
*m.get_fstype_of_mounted_partition("/dev/mmcblk0p1")*
*Error:*
*==*

root:~/qa/test_library# python3 sd.py
  File "sd.py", line 99
*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
* ^*
*SyntaxError: can't assign to literal*
root:~/qa/test_library#

Kindly do the needful as early as possible, as am stuck with this issue
from past 2 days no clues yet, please redirect me to the correct forum if
this is not the right place for pasting python related queries

Many Thanks in advance,
Srini
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Data exchange between python script and bash script

2017-04-19 Thread Venkatachalam Srinivasan
On Thursday, April 6, 2017 at 12:55:41 AM UTC+2, Gregory Ewing wrote:
> Anssi Saari wrote:
> > Bash manual explicitly states command substition (the $(...) structure)
> > replaces the command with the standard *output* of the command.
> 
> Another problem is your use of '&' here:
> 
> sensor_data=$(python execute_sensor_process.py) &
> 
> The '&' causes the whole command, including the variable
> assignment, to be executed in a subshell. So the variable
> is only bound in the subshell process and won't be seen
> from the main shell process.
> 
> Running the command in the background here is pointless,
> since if the shell script needs the variable value for
> subsequent processing it will have to wait for the
> command to finish. So just get rid of the '&'.
> 
> -- 
> Greg

Hi, 

I understand your point. But the issue is, I need both the program to be 
executed continuously. That is one module to control the robot and another 
module to locate the robot. The location data from one module is required by 
the other module for the entire execution. And for now, I have solved it by 
writing the data to a database and read it whenever required.

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


Re: Data exchange between python script and bash script

2017-04-19 Thread Venkatachalam Srinivasan
On Tuesday, April 4, 2017 at 7:58:56 PM UTC+2, justin walters wrote:
> On Tue, Apr 4, 2017 at 10:39 AM, Venkatachalam Srinivasan <
> venkatachalam...@gmail.com> wrote:
> 
> > Hi,
> >
> > Thanks for the answer. I need bash for connecting data exchange between
> > two python scripts. To be more specific, data from one script has to be
> > passed to the another script. You are right, I don't need the data in the
> > bash other than to pass the obtained data to the another script which uses
> > the data for further analysis.
> >
> > Regarding using the json file, I am new to this. A naive question is that
> > if the data is too large then is json file is easy to handle? Is json file
> > for large data is not computationally expensive? I am not using textfile
> > for the same reason of being computationally expensive.
> >
> > Thanks,
> > Venkatachalam Srinivasan
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> It could be expensive to create a dictionary from the json file depending
> on the amount of data.
> 
> Alternatively, you could use a Unix socket to transmit the data between
> processes
> if you're on a linux or OSx machine. This is probably the best option as
> you can send the dictionary
> object itself. This would eliminate the need for the bash script entirely.
> The first script builds the
> dictionary object and sends it to the socket. The second script is
> listening on the socket and receives
> the dictionary object. Python's standard library has built in support for
> unix sockets. This means you
> can actually run two parallel Python instances and communicate between
> them. Assuming that
> the first script can build the dictionaries before the second script is
> done processing them, you will
> probably need some kind of task queue. Celery: http://www.celeryproject.org/
> tends to be a good solution
> for this problem. In fact, Celery is probably the simplest option now that
> I think about it.
> 
> Another alternative is using a SQLite database which Python has built in
> support for. Should be
> a bit faster and less memory-intensive.

Hi,

Thank you for a clearer explanation. I tried with sqlite and now it seems to 
work fine. Yet, we have to check with the real time system which may pose some 
problems to the amount of data (I guess). So, until now everything is fine on 
this. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Data exchange between python script and bash script

2017-04-19 Thread Venkatachalam Srinivasan
On Wednesday, April 5, 2017 at 2:38:00 PM UTC+2, Anssi Saari wrote:
> venkatachalam...@gmail.com writes:
> 
> > For example, the data is printed in
> > execute_sensor_process.py as follows:
> >
> > print >>sys.stderr,sens_data
> >
> > By printing the data onto sys.stderr and assigning a return variable in the 
> > bash, I am expecting the data to be assigned.
> >
> > But this is not happening.
> 
> This part I can answer alhtough I'm not sure it helps with your actual
> problems. 
> 
> Bash manual explicitly states command substition (the $(...) structure)
> replaces the command with the standard *output* of the command. So since
> your Python program writes to standard error, you get nothing.

Hi,

I understand your point. I tried by printing the standard output, but the 
result was the same. The output of one module is not captured in the bash 
script using the $(...) operation. So, I have switched to other possibilities 
of storing the data and accessing it from other program.

Thanks for your suggestion.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Data exchange between python script and bash script

2017-04-04 Thread Venkatachalam Srinivasan
On Tuesday, April 4, 2017 at 5:42:23 PM UTC+2, justin walters wrote:
> On Tue, Apr 4, 2017 at 8:01 AM, <venkatachalam...@gmail.com> wrote:
> 
> > Hello All,
> >
> > I am writing a python code for processing a data obtained from a sensor.
> > The data from sensor is obtained by executing a python script. The data
> > obtained should be further given to another python module where the
> > received data is used for adjusting the location of an object.
> >
> > For achieving this, there is a central bash script, which runs both the
> > python modules parallel. Something like:
> >
> > python a.py &
> > python b.py &
> >
> > I am trying to return the sensor data to the bash .sh file, therefore it
> > can be provided to the other script. This, based on the online tutorials
> > looks like:
> >
> > sensor_data=$(python execute_sensor_process.py) &
> >
> > and the sensor_data is assigned by printing the required data in the
> > corresponding python script. For example, the data is printed in
> > execute_sensor_process.py as follows:
> >
> > print >>sys.stderr,sens_data
> >
> > By printing the data onto sys.stderr and assigning a return variable in
> > the bash, I am expecting the data to be assigned.
> >
> > But this is not happening. The sensor data is a dictionary and I like to
> > have this data for further analysis. I am not getting the data returned
> > from the python script on to the bash variable.
> >
> > Can someone help me to understand why the code is not working? I tried
> > other approaches of function call such as
> >
> >
> > sensor_data=$`python execute_sensor_process.py` &
> >
> >
> > python execute_sensor_process.py tempfile.txt &
> > kinexon_data=`cat tempfile.txt` &
> >
> > But none of the approaches are working.
> >
> > Thank you,
> > Venkatachalam Srinivasan
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> I'm not sure why you need the data in a bash script. What can you do with a
> bash script that you
> can't do with Python?
> 
> That said, it seems to me that you need a data persistence layer, i.e. a
> way to store the dictionary
> after it is created. My best advice would be to use the json module to
> write out to json files. I
> believe this is the best approach because json has a near 1-to-1 mapping
> with Python
> dictionaries.
> 
> Json is also a good choice because almost every language has a json parser
> as part of it's standard
> library, making you data extremely portable.

Hi,

Thanks for the answer. I need bash for connecting data exchange between two 
python scripts. To be more specific, data from one script has to be passed to 
the another script. You are right, I don't need the data in the bash other than 
to pass the obtained data to the another script which uses the data for further 
analysis.

Regarding using the json file, I am new to this. A naive question is that if 
the data is too large then is json file is easy to handle? Is json file for 
large data is not computationally expensive? I am not using textfile for the 
same reason of being computationally expensive.

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


Re: Data exchange between python script and bash script

2017-04-04 Thread Venkatachalam Srinivasan
On Tuesday, April 4, 2017 at 5:27:42 PM UTC+2, cassiope wrote:
> On Tue, 04 Apr 2017 08:01:42 -0700, venkatachalam.19 wrote:
> 
> > Hello All,
> > 
> > I am writing a python code for processing a data obtained from a sensor. 
> > The data from sensor is obtained by executing a python script. The data 
> > obtained should be further given to another python module where the 
> > received data is used for adjusting the location of an object.
> > 
> > For achieving this, there is a central bash script, which runs both the 
> > python modules parallel. Something like:
> > 
> > python a.py &
> > python b.py &
> 
> What is going on that two python scripts are needed?  Which one generates the 
> data needed by the bash script?

One python script communicates with an external sensor and receives data.
Another script controls a robot. That is based on ROS modules.
>From the given code, a.py will be the script generating the data. Both the 
>modules are independent of each other and so I have written both of them in 
>different python scripts.

> 
> > I am trying to return the sensor data to the bash .sh file, therefore it 
> > can be provided to the other script. This, based on the online tutorials 
> > looks like:
> > 
> > sensor_data=$(python execute_sensor_process.py) &
> 
> Presumably  is simply getting the exit status code from the 
> python interpreter, not the data, right?
> What are you seeing?
>  I am not getting the exit status (I am not setting or printing return status 
> in the python script). I need both the scripts running in parallel. Meaning 
> the sensor will be continuously monitoring the location of the robot and this 
> data will be used in another python script which controls the robot motion.

For now, I am printing the output in the script and as far I understood, this 
can be assigned to a variable in the bash file from where this file is 
executed. 

I am not getting any output in the assigned variable in bash.

> > and the sensor_data is assigned by printing the required data in the 
> > corresponding python script. For example, the data is printed in 
> > execute_sensor_process.py as follows:
> > 
> > print >>sys.stderr,sens_data
> > 
> > By printing the data onto sys.stderr and assigning a return variable in the 
> > bash, I am expecting the data to be assigned.
> 
> Assigned to what?  Some return variable in bash?  What??
> Why not use stdout?  Either pipe the data from python directly into a 
> (possibly modified) bash script,
> or into a file which gets read by the bash script.
>  

Yes. As shown in "sensor_data=$(python execute_sensor_process.py) &", the 
variable sensor_data is assigned to hold the return value from the python 
script.
I was using the stdout. But in some forums for similar problems, it is 
suggested to print the data to stderr (I really dont know what is the 
significance). 
I am unaware of piping the data from python. I will look into this.

 
> > But this is not happening. The sensor data is a dictionary and I like to 
> > have this data for further analysis. I am not getting the data returned 
> > from the python script on to the bash variable.
> 
> Bash doesn't have dictionaries like python.  Why is bash needed?
>  

Bash is needed to run the different scripts. I tried using multiprocess and 
thread from python, but really they are not performing parallel processing, 
when there are completely two different process. I understood it by executing 
the multiprocess/thread. Sequential operation was happening, which lead to the 
situation that only one python process is always executed.

> > Can someone help me to understand why the code is not working? I tried 
> > other approaches of function call such as
> 
> You haven't given us enough of the code to really answer. 
> 
> > sensor_data=$`python execute_sensor_process.py` &
> > 
> > python execute_sensor_process.py tempfile.txt &
> > kinexon_data=`cat tempfile.txt` &
> > 
> > But none of the approaches are working.
> > 
> > Thank you,
> > Venkatachalam Srinivasan
> 
> I wonder if you could completely eliminate the bash script - do it all in 
> python.
> I've written quite a few bash scripts, but not so many since I started using
> python.  Only exception is for low level functions on systems without a 
> functioning
> python.

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


Looking for OpenStack Developer

2015-08-05 Thread Pranesh Srinivasan
Hi,
Hope you are doing well !!!
My name is Siva and I'm a recruiter at TheAppliedthought , a global staffing 
and IT consulting company.
Please find the below job description which may suits any of your consultants 
who are available in market or who are looking for change, please send me 
latest updated resume along with contact details and expected hourly rate to my 
email id s...@theappliedthought.com or you can reach me on 407-574-7610.
Position: Python + Angular JS + Knowledge in Open Stack + Linux
Location: Houston, TX
Duration: Long Term
Job Description
Skills Required
*   Python
*   Angular JS
*   Open Stack
*   Linux
Thanks  Regards
Siva
Executive-Talent  Acquisition  Bench Sales
Email: s...@theappliedthought.com
IM: malladi sivaramakrishna88
Phone: 407-574-7610
Fax: 407-641-8184
-- 
https://mail.python.org/mailman/listinfo/python-list


This code not working, need suggetions

2012-04-23 Thread Anirudh Srinivasan
My code lists the files and directory under a folder and if we want to read
the file it uses the function  cat.

But the function cat(get_file) is not working , any suggetions?

Here is my code:


#!/usr/bin/python

import os
import sys
import commands
#import cat

def listdir(s):
   try:
 file  = os.listdir(s)
for files in file:
path = os.path.join(s, files)
 print path
#cmd = 'ls -l '+ path
#g= commands.getstatusoutput(cmd)
 #print g[1]
   except OSError:
print No such file or directory


def main():
listdir(sys.argv[1])


if __name__ == __main__:
 main()

def cat(get_file):
f = open(get_file, rU)
 text = f.read()
print text,
get_file = raw_input(Which file would you like to browse ?)

-- 
Anirudh Srinivasan | MTS QA | Nutanix.Inc | 408-569-0323
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: This code not working, need suggetions

2012-04-23 Thread Anirudh Srinivasan
Thanks Min and Chris for your ideas and suggestion, i understood my
mistake. This code is working fine now.

On Mon, Apr 23, 2012 at 2:51 AM, Min Yu yumin...@gmail.com wrote:

 try this code out. The lsdir function and cat function are both used in
 main().

 The bash commands are as following:

 yumin@yumin-think:~/src/test/python/community$ python list.py `pwd`
 /home/yumin/src/test/python/community
 list.py
 file1
 file2
 Which file would you like to browse ?file1
 This is file1
 Which file would you like to browse ?file2
 This is file2

 Which file would you like to browse ?
 yumin@yumin-think:~/src/test/python/community$

 --

 #!/usr/bin/python


 import os
 import sys
 import commands
 #import cat

 def listdir(s):
 try:
 print s
 files  = os.listdir(s)
 for f in files:
 #path = os.path.join(s, f)
 #print path
 print f

 except OSError:
 print No such file or directory

 def cat(get_file):
 f = open(get_file, rU)
 text = f.read()
 print text,

 def main():
 working_dir = sys.argv[1]
 listdir(working_dir)
 On = True
 while On:
 get_file = raw_input(Which file would you like to browse ?)
 if get_file == '':
 On = False
 #break
 else:
 cat(os.path.join(working_dir,get_file))


 if __name__ == __main__:
 main()



 2012/4/23 Chris Rebert c...@rebertia.com

 On Sun, Apr 22, 2012 at 11:16 PM, Anirudh Srinivasan anir...@nutanix.com
 
 wrote:
 
  My code lists the files and directory under a folder and if we want to
  read the file it uses the function  cat.
 
  But the function cat(get_file) is not working , any suggetions?

 Please specifically state exactly how it's deviating from the desired
 behavior (including the full text of any error messages and/or
 exception tracebacks, though I don't think those will apply here).
 I note that you don't actually call cat() anywhere in your program.

  Here is my code:
 
 
  #!/usr/bin/python
 
  import os
  import sys
  import commands
  #import cat

 Such an import (if uncommented) would require you had a *module* named
 `cat`.

  def listdir(s):

 I would suggest renaming this function to avoid confusion with
 os.listdir().

 try:
file  = os.listdir(s)

 Don't use `file` as a variable name. It shadows the name of the
 built-in `file` type.
 Also, `file` isn't a sensible variable name in this context; it's a
 list (as opposed to a single item) and may also contain directory
 names. And it contains strings rather than file objects.

for files in file:
path = os.path.join(s, files)
print path
#cmd = 'ls -l '+ path
#g= commands.getstatusoutput(cmd)

 The `commands` module has been deprecated. Its successor is `subprocess`:
 http://docs.python.org/library/subprocess.html

#print g[1]
 except OSError:
print No such file or directory
 
 
  def main():
listdir(sys.argv[1])
 
 
  if __name__ == __main__:
main()

 `if __name__ == __main__:` should normally come at the end of the
 script, after all `def`s.

 
  def cat(get_file):
f = open(get_file, rU)
text = f.read()
print text,

 You should `.close()` the file once you're done with it. Or use the
 `with` statement (http://www.python.org/dev/peps/pep-0343/ ).

  get_file = raw_input(Which file would you like to browse ?)

 Presumably this line should be under your `if __name__ ==
 __main__:`? And you're not actually doing anything with `get_file`
 after you obtain it from the user...

 Regards,
 Chris
 --
 http://mail.python.org/mailman/listinfo/python-list





-- 
Anirudh Srinivasan | MTS QA | Nutanix.Inc | 408-569-0323
-- 
http://mail.python.org/mailman/listinfo/python-list


[pyodbc] Setting values to SQL_* constants while creating a connection

2011-05-25 Thread srinivasan munisamy
Hi,
I would like to know how to set values to values to SQL_*  constants while
creating a db connection through pyodbc module.
For example, i am getting a connection object like below:

In [27]: dbh1 = pyodbc.connect(DSN=dsn;UID=
uid;PWD=pwd;DATABASE=database;APP=app_name)

In [28]: dbh1.getinfo(pyodbc.SQL_DESCRIBE_PARAMETER)

Out[28]: True

I want to set this SQL_DESCRIBE_PARAMETER to false for this connection
object. How could i do that?
Please help me in figuring it out.

Thanks,
Srini
-- 
http://mail.python.org/mailman/listinfo/python-list


Get perl method documentation in python wrapper

2010-07-31 Thread srinivasan munisamy
Hi,

I would like to get the documentation of a perl method inside python
wrapper.

To say it with example, there is a perl module ‘X.pm’. It has a method
‘print_hello()’.
x.py is a wrapper module over X.pm. when I say x.print_hello.__doc__ then I
need to get the documentation of X::print_hello. The main reason why i want
to do that i do not want to re-write the whole documentation again in
python.
Is there a way to do that?



Thanks,

Srini
-- 
http://mail.python.org/mailman/listinfo/python-list


Pdf download using mechanize

2010-07-06 Thread srinivasan srinivas
HI,
I am using mechanize module for web scraping projects. One of y tasks is to 
download pdf file from a page and store it.
Is there a way to download pdf file using mechanize how we do it in Perl's 
WWW::Mechanize?

Thanks,
Srini


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


standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
I guess why every programming language has some kind of a 'standard
library' built in within it.
In my view it must not be called as a 'library' at all. what it does
is like a 'bunch of built-in programs ready-made to do stuff'.

Lets see what a 'library' does:

1. offers books for customers
 1.1 lets user select a book by genre, etc
 1.2 lets user to use different books of same genre, etc
 1.3 lets user to use books by same author, etc for different genre

2. keeps track of all the books + their genre
 2.1 first knows what all books it has at present
 2.2 when new book comes it is added to the particular shelf sorted by
genre,author,edition, etc.
 2.3 when books become old they are kept separately for future
reference
 2.4 very old books can be sent to a museum/discarded

I guess no standard library does the minimum of this but wants to be
called a library.

As a python user I always wanted the standard library to have such
features so the user/developer decides to use what set of libraries he
want.

consider the libraries for 2.5 ,2.6, 3K are all available to the user,
the user selects what he wants with something like.

use library 2.5 or use library 2.6 etc.

The 2 main things that the library management interface has to do is
intra library management and inter library management.

intra library mgmt- consider books to be different libraries
(standard, commercial, private, hobby, etc)
inter library mgmt- consider books to be modules inside a library
( standard, commercial, private, hobby, etc)

if somehow we could accomplish this kind of mother of a all plugin/ad-
hoc system that is a real breakthrough.

Advantages:

1. new modules can be added to the stream quickly
2. let the user select what he want to do
3. modules (that interdepend on each other) can be packed into small
distribution and added to the stream quickly without waiting for new
releases
4. solution to problems like py 2.x and 3.x
5. users can be up to date
6. documentation becomes easy + elaborate to users
7. bug managing is easy too
8. more feed back
9. testing also becomes easy
10. many more , i don't know.. you have to find.

Python already has some thing like that __future__ stuff. but my
question is how many people know that? and how many use that? most of
them wait until old crust gets totally removed. that is bad for user
and python. that is why problems like py2.x py3.x originate. If there
is a newer book collection it must always be available at the library.
i must not go to another library to get that book.

These are just my views on the state of the standard libraries and to
make them state-of-the-art..! ;)





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


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
On Nov 12, 3:56 pm, Diez B. Roggisch de...@nospam.web.de wrote:
 Sriram Srinivasan schrieb:



  I guess why every programming language has some kind of a 'standard
  library' built in within it.
  In my view it must not be called as a 'library' at all. what it does
  is like a 'bunch of built-in programs ready-made to do stuff'.

  Lets see what a 'library' does:

  1. offers books for customers
   1.1 lets user select a book by genre, etc
   1.2 lets user to use different books of same genre, etc
   1.3 lets user to use books by same author, etc for different genre

  2. keeps track of all the books + their genre
   2.1 first knows what all books it has at present
   2.2 when new book comes it is added to the particular shelf sorted by
  genre,author,edition, etc.
   2.3 when books become old they are kept separately for future
  reference
   2.4 very old books can be sent to a museum/discarded

  I guess no standard library does the minimum of this but wants to be
  called a library.

  As a python user I always wanted the standard library to have such
  features so the user/developer decides to use what set of libraries he
  want.

  consider the libraries for 2.5 ,2.6, 3K are all available to the user,
  the user selects what he wants with something like.

  use library 2.5 or use library 2.6 etc.

  The 2 main things that the library management interface has to do is
  intra library management and inter library management.

  intra library mgmt- consider books to be different libraries
  (standard, commercial, private, hobby, etc)
  inter library mgmt- consider books to be modules inside a library
  ( standard, commercial, private, hobby, etc)

  if somehow we could accomplish this kind of mother of a all plugin/ad-
  hoc system that is a real breakthrough.

  Advantages:

  1. new modules can be added to the stream quickly
  2. let the user select what he want to do
  3. modules (that interdepend on each other) can be packed into small
  distribution and added to the stream quickly without waiting for new
  releases
  4. solution to problems like py 2.x and 3.x
  5. users can be up to date
  6. documentation becomes easy + elaborate to users
  7. bug managing is easy too
  8. more feed back
  9. testing also becomes easy
  10. many more , i don't know.. you have to find.

  Python already has some thing like that __future__ stuff. but my
  question is how many people know that? and how many use that? most of
  them wait until old crust gets totally removed. that is bad for user
  and python. that is why problems like py2.x py3.x originate. If there
  is a newer book collection it must always be available at the library.
  i must not go to another library to get that book.

 You are greatly oversimplifying things, and ignoring a *lot* of issues
 here. The reason for __future__ is that it can *break* things if new
 features were just introduced. Take the with-statement, reachable in
 python2.5 throug

    from __future__ import with_statement

 It introduces a new keyword, which until then could be happily used as
 variable name.

 So you can't arbirtarily mix code that is written with one or the other
 feature missing.

 Then there is the issue of evolving C-APIs (or ABI), wich makes modules
 incompatible between interpreters.

 And frankly, for most of your list I don't see how you think your
 approach reaches the stated advantages. Why is documentation becoming
 easier? Why bug managing? Why testing?

 I'm sorry, but this isn't thought out in any way, it's just wishful
 thinking IMHO.

 Diez

I don't know if you have used Dev-C++.http://www.bloodshed.net/dev/
packages/index.html It has a 'package management' mechanism for the
standard libraries.
please see the http://devpaks.org/ webpage where all the packaged
libraries are stored.

In python we have the PyPI which is equivalent to the http://devpacks.org
but in PyPI the packages are mostly user made applications.
What I want is similar to PyPI but for the python standard libraries,
so that they (libraries) are as add-on as possible.
check this out too.. http://molhanec.net/devcpphelp/packages.php


I guess you understand what I am thinking... and do pardon my english
too..

--

Regards,
Sriram.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
On Nov 12, 3:56 pm, Diez B. Roggisch de...@nospam.web.de wrote:
 Sriram Srinivasan schrieb:



  I guess why every programming language has some kind of a 'standard
  library' built in within it.
  In my view it must not be called as a 'library' at all. what it does
  is like a 'bunch of built-in programs ready-made to do stuff'.

  Lets see what a 'library' does:

  1. offers books for customers
   1.1 lets user select a book by genre, etc
   1.2 lets user to use different books of same genre, etc
   1.3 lets user to use books by same author, etc for different genre

  2. keeps track of all the books + their genre
   2.1 first knows what all books it has at present
   2.2 when new book comes it is added to the particular shelf sorted by
  genre,author,edition, etc.
   2.3 when books become old they are kept separately for future
  reference
   2.4 very old books can be sent to a museum/discarded

  I guess no standard library does the minimum of this but wants to be
  called a library.

  As a python user I always wanted the standard library to have such
  features so the user/developer decides to use what set of libraries he
  want.

  consider the libraries for 2.5 ,2.6, 3K are all available to the user,
  the user selects what he wants with something like.

  use library 2.5 or use library 2.6 etc.

  The 2 main things that the library management interface has to do is
  intra library management and inter library management.

  intra library mgmt- consider books to be different libraries
  (standard, commercial, private, hobby, etc)
  inter library mgmt- consider books to be modules inside a library
  ( standard, commercial, private, hobby, etc)

  if somehow we could accomplish this kind of mother of a all plugin/ad-
  hoc system that is a real breakthrough.

  Advantages:

  1. new modules can be added to the stream quickly
  2. let the user select what he want to do
  3. modules (that interdepend on each other) can be packed into small
  distribution and added to the stream quickly without waiting for new
  releases
  4. solution to problems like py 2.x and 3.x
  5. users can be up to date
  6. documentation becomes easy + elaborate to users
  7. bug managing is easy too
  8. more feed back
  9. testing also becomes easy
  10. many more , i don't know.. you have to find.

  Python already has some thing like that __future__ stuff. but my
  question is how many people know that? and how many use that? most of
  them wait until old crust gets totally removed. that is bad for user
  and python. that is why problems like py2.x py3.x originate. If there
  is a newer book collection it must always be available at the library.
  i must not go to another library to get that book.

 You are greatly oversimplifying things, and ignoring a *lot* of issues
 here. The reason for __future__ is that it can *break* things if new
 features were just introduced. Take the with-statement, reachable in
 python2.5 throug

    from __future__ import with_statement

 It introduces a new keyword, which until then could be happily used as
 variable name.

 So you can't arbirtarily mix code that is written with one or the other
 feature missing.

 Then there is the issue of evolving C-APIs (or ABI), wich makes modules
 incompatible between interpreters.

 And frankly, for most of your list I don't see how you think your
 approach reaches the stated advantages. Why is documentation becoming
 easier? Why bug managing? Why testing?

 I'm sorry, but this isn't thought out in any way, it's just wishful
 thinking IMHO.

 Diez

__future__ as you said helps in stop breaking things. what i suggest
that if both the libraries (in yr case-with is defined in one and
other with is not defined is a simple one) like py2.x and py3.x exists
and i want to use 3.x features in the morning then in the evening i
want to use 2.x or something like that just add on the library and i
get the require functionality
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
On Nov 12, 4:35 pm, Diez B. Roggisch de...@nospam.web.de wrote:
 Sriram Srinivasan schrieb:



  On Nov 12, 3:56 pm, Diez B. Roggisch de...@nospam.web.de wrote:
  Sriram Srinivasan schrieb:

  I guess why every programming language has some kind of a 'standard
  library' built in within it.
  In my view it must not be called as a 'library' at all. what it does
  is like a 'bunch of built-in programs ready-made to do stuff'.
  Lets see what a 'library' does:
  1. offers books for customers
   1.1 lets user select a book by genre, etc
   1.2 lets user to use different books of same genre, etc
   1.3 lets user to use books by same author, etc for different genre
  2. keeps track of all the books + their genre
   2.1 first knows what all books it has at present
   2.2 when new book comes it is added to the particular shelf sorted by
  genre,author,edition, etc.
   2.3 when books become old they are kept separately for future
  reference
   2.4 very old books can be sent to a museum/discarded
  I guess no standard library does the minimum of this but wants to be
  called a library.
  As a python user I always wanted the standard library to have such
  features so the user/developer decides to use what set of libraries he
  want.
  consider the libraries for 2.5 ,2.6, 3K are all available to the user,
  the user selects what he wants with something like.
  use library 2.5 or use library 2.6 etc.
  The 2 main things that the library management interface has to do is
  intra library management and inter library management.
  intra library mgmt- consider books to be different libraries
  (standard, commercial, private, hobby, etc)
  inter library mgmt- consider books to be modules inside a library
  ( standard, commercial, private, hobby, etc)
  if somehow we could accomplish this kind of mother of a all plugin/ad-
  hoc system that is a real breakthrough.
  Advantages:
  1. new modules can be added to the stream quickly
  2. let the user select what he want to do
  3. modules (that interdepend on each other) can be packed into small
  distribution and added to the stream quickly without waiting for new
  releases
  4. solution to problems like py 2.x and 3.x
  5. users can be up to date
  6. documentation becomes easy + elaborate to users
  7. bug managing is easy too
  8. more feed back
  9. testing also becomes easy
  10. many more , i don't know.. you have to find.
  Python already has some thing like that __future__ stuff. but my
  question is how many people know that? and how many use that? most of
  them wait until old crust gets totally removed. that is bad for user
  and python. that is why problems like py2.x py3.x originate. If there
  is a newer book collection it must always be available at the library.
  i must not go to another library to get that book.
  You are greatly oversimplifying things, and ignoring a *lot* of issues
  here. The reason for __future__ is that it can *break* things if new
  features were just introduced. Take the with-statement, reachable in
  python2.5 throug

     from __future__ import with_statement

  It introduces a new keyword, which until then could be happily used as
  variable name.

  So you can't arbirtarily mix code that is written with one or the other
  feature missing.

  Then there is the issue of evolving C-APIs (or ABI), wich makes modules
  incompatible between interpreters.

  And frankly, for most of your list I don't see how you think your
  approach reaches the stated advantages. Why is documentation becoming
  easier? Why bug managing? Why testing?

  I'm sorry, but this isn't thought out in any way, it's just wishful
  thinking IMHO.

  Diez

  __future__ as you said helps in stop breaking things. what i suggest
  that if both the libraries (in yr case-with is defined in one and
  other with is not defined is a simple one) like py2.x and py3.x exists
  and i want to use 3.x features in the morning then in the evening i
  want to use 2.x or something like that just add on the library and i
  get the require functionality

 This doesn't make sense to me. What are you doing in the morning, and
 what in the evening, and to what extend is the code the same or are you
 talking about different pieces of code?

 Diez


ok let me make it more clear..
forget how you use python now.. i am talking about __futuristic__
python programming.

there is no more python2.x or python3.x or python y.x releases. there
is only updates of python and standard library say 1.1.5 and 1.1.6.
let the difference be an old xml library updated with a new regex
support.

i am coding my program now.
i want my application to be compatible with 1.1.5 library

use library 1.1.5
import blah form blahblah
...
...

i cannot use regex feature of xml in this application
i then update my library in the evening
now both the libraries are present in my system.
now i try using the new feature

use library 1.1.6 #thats all now i get all features
import blah from blahblah
...
...

-- 
http

Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
On Nov 12, 6:07 pm, Diez B. Roggisch de...@nospam.web.de wrote:
  ok let me make it more clear..
  forget how you use python now.. i am talking about __futuristic__
  python programming.

  there is no more python2.x or python3.x or python y.x releases. there
  is only updates of python and standard library say 1.1.5 and 1.1.6.
  let the difference be an old xml library updated with a new regex
  support.

  i am coding my program now.
  i want my application to be compatible with 1.1.5 library

  use library 1.1.5
  import blah form blahblah
  ...
  ...

  i cannot use regex feature of xml in this application
  i then update my library in the evening
  now both the libraries are present in my system.
  now i try using the new feature

  use library 1.1.6 #thats all now i get all features
  import blah from blahblah

 This is not futuristic, this is state of the art with PyPI  setuptools.

 You still haven't addressed all the issues that arise though, regarding
 different python interpreter versions having different syntax and ABI.

 Diez

haha... it would be awesome if they implement it in the 'future' .. i
posted the same to python-...@python.org, it seems the distutil is
getting a big overhaul. (i hope they make a new uninstall option for
setuptools n easy_install) they say there are many ways to do that
using pkg tools... but python wants one and only one way- the python
way.
regarding issues:

1.security is always a issue
2. regarding problems like with statement you mentioned earlier.. i
think there will be a basic feature set that is common for all
versions of add-on libraries.
3.when you want the new feature you have to update your python
interpreter

use interpreter 1.5.2

may trigger the proper interpreter plugin(responsible for additional
feature) to load and add functionality.. its simple to say but it is
hard to make the compiler pluggable, may be they figure out.

use library x.y.z

while issuing this command the default interpreter has to
automatically resolve dependencies of the core c/cpp static libraries
and other shared libraries. so that must not be an issue. if they have
implemented this much, dep solving is nothing.

futuristic python may also contain an option for compiling a module
into a static library. so we can code python libraries in python
(mostly) itself. think of pypy. it is already state of the art.


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


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan

 You are describing a lending library, which is not the only sort of
 library. My personal library doesn't do any of those things. It is just a
 room with shelves filled with books.

how i see is all libraries are libraries, for a personal library you
are the only customer and you are the management too.!

 Words in English can have more than one meaning. Horses run,
 refrigerators run, and even though they don't have either legs or motors,
 programs run too. The argument that code libraries don't behave like
 lending libraries won't get you anywhere.

first this is not an argument at all...i clearly stated these were my
imaginations cum ideas.

 Since library features are tied closely to the features available in the
 Python interpreter, the way to use library 2.5 is to use Python 2.5. You
 *might* be able to use library 2.5 with Python 2.6 or 2.4; you absolutely
 won't be able to use it with Python 1.5 or 3.1.

i am not talking about the past..past were experiences! that the
developers had and what is happening today *might be* another
experience for the future.

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


Re: standard libraries don't behave like standard 'libraries'

2009-11-12 Thread Sriram Srinivasan
 So all libraries written have to use the common subset, which - unless
 things are *removed*, which with python3 actually happened - is always
 the oldest interpreter. And if a feature goes away, they have to be
 rewritten with the then common subset.

you see that's the problem with py3. instead of slowly removing the
features one by one till the end they made a jump. the problem is not
with the jump but with other libraries/packages that depend on py2.
what i felt was if the new version was available as soon as it is into
the stream, developers/users try to use them and get accustomed. now
they follow this. they have frozen py3 for may be 2-3 years so ppl
would move slowly to py2.6 ,2.7, 2.8... most. also the corporate
companies are the most influential.

also a point to note: if new updates keep on coming (for eg. daily
antivirus update) developers tend to accept and move on *easily*.

i am not an expert in programming/interpreter design/library writing/
packaging. i just wanted the standard library *too* to be pluggable,
not just the applications based on it.
i am not even experienced in python to make bold accusations so all i
can say is 'how it would be if?' and i always stick to one thing 'why
not?'.

 In other words: as a library writer, I can't use shiny, new  better
 features, I'm stuck with the old stuff, and whenever the interpreter
 evolves I have to rewrite even the old ones. Not appealing. Why develop
 the interpreter at all then?

if you are app developer you needn't rewrite anything. that is the
main point here! just specifying the interpreter and library version
is enough every thing has to work like magic. as the previous
libraryinterpreter wont be removed (unless and until it is your will)
u can use them. thats how everybody would like it to be.

as for a library writer is concerned: as you say it depends on certain
things like other libraries,interpreter,etc. but i would like to say
that change is inevitable. if some core developer has to change
something he might change. and if you have to update your library you
have to. this applies to the interpreter too. what python now does is
make every update work with the minimal set (giving minimal backward
compatibility) plus the new features too. which is exactly the right
thing. what i wanted is the users have to be aware now and then when
of the modification, deletion, addition stuff not in every release as
in py3k. then the whole backward incompatibility issue would be
*dissolved* or what i mean is *diffused* and ppl dont even know that
they have switched over to a very new thing.



 In other words: the problem is solved by somehow solving the problem -
 but not by a concrete solution you propose?

as i told before i neither know the problem nor the solution. i just
wrote my ideas/imagination down

 PyPy is cool, but by far not advanced enough to replace external,
 C-based libraries such as NUMPY and PyQt and whatnot.

 I don't say that the current situation is by any means ideal. There is a
 lot to be said about package creation, distribution, installation,
 removal, dependency handling, and even system-packaging-integration if
 one likes.

 You IMHO just add another layer of complexity on top of it, without
 proposing solutions to any of the layers in between, nor your new one -
 namely, the interpreter version agnosticism.

yes you are right. python has a lot of bindings to a lot of stuff. but
it is the strength and weakness. not exactly pythons weakness but with
the thing on the other side. yes it may be looking complex because
most of the 'standard library' system was not designed to be adhoc/add-
on/pluggable from the start.
-- 
http://mail.python.org/mailman/listinfo/python-list


conversion of Python object to perl object

2009-08-18 Thread srinivasan srinivas
Hi,
I have to call a perl method which takes a hash as its argument from a python 
module. Is there a way to convert python dictionary to perl hash ( not hash 
ref)?

Thanks,
Srini


  See the Web#39;s breaking stories, chosen by people like you. Check out 
Yahoo! Buzz. http://in.buzz.yahoo.com/

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


calling obect method

2009-07-30 Thread srinivasan srinivas
Hi,
I would like to know if i have an object and one of its methods as a string. 
How to call the method using this string?
For ex
If object is x and string y has one of its method names. 
x.value(y)() ---. Is there a way to do this?

Thanks,
Srini


  See the Web#39;s breaking stories, chosen by people like you. Check out 
Yahoo! Buzz. http://in.buzz.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python debugger

2009-07-03 Thread srinivasan srinivas

Hi,
Could you suggest some python debuggers?

Thanks,
Srini


  Love Cricket? Check out live scores, photos, video highlights and more. 
Click here http://cricket.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Which one is best Python or Java for developing GUI applications?

2009-05-05 Thread srinivasan srinivas

Could you tell me does Python have any advantages over Java for the development 
of GUI applications?

Thanks,
Srini


  Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! 
Edition http://downloads.yahoo.com/in/firefox/?fr=om_email_firefox
--
http://mail.python.org/mailman/listinfo/python-list


Re: Which one is best Python or Java for developing GUI applications?

2009-05-05 Thread srinivasan srinivas

Could you list down those advantages??



- Original Message 
From: Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid
To: python-list@python.org
Sent: Tuesday, 5 May, 2009 1:07:41 PM
Subject: Re: Which one is best Python or Java for developing GUI applications?

Paul Rubin a écrit :
 srinivasan srinivas sri_anna...@yahoo.co.in writes:
 Could you tell me does Python have any advantages over Java for the 
 development of GUI applications?
 
 Yes.

Indeed.
--
http://mail.python.org/mailman/listinfo/python-list



  Cricket on your mind? Visit the ultimate cricket website. Enter 
http://beta.cricket.yahoo.com
--
http://mail.python.org/mailman/listinfo/python-list


Query related to matplotlib

2009-04-28 Thread srinivasan srinivas

I would like to draw a chart which takes 'dates' in x axes and some values in y 
axes.  
I would like to draw a simple chart using matplotlib. Can someone tell me which 
submodule i could use for this purpose? The module has to support in the way 
that i can draw more than one set can be passed to Y axes. So it will generate 
more than one line.

Thanks,
Srini



  Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! 
Edition http://downloads.yahoo.com/in/firefox/
--
http://mail.python.org/mailman/listinfo/python-list


What is the best framework or module in Python for a small GUI based application development?

2009-04-22 Thread srinivasan srinivas

Hi,
Could you suggest me some modules in Python which can be used to develop GUI 
based applications? and tell me which could be the best(in terms of 
efficiency) one for a small GUI based application development?

Thanks,
Srini


  Bollywood news, movie reviews, film trailers and more! Go to 
http://in.movies.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the best framework or module in Python for a small GUI based application development?

2009-04-22 Thread srinivasan srinivas

Thanks for the info.
My requirement is to write an application which is GUI based has to run on 
browsers. Could you tell me which one would be suitable for this?



- Original Message 
From: Mike Driscoll kyoso...@gmail.com
To: python-list@python.org
Sent: Wednesday, 22 April, 2009 7:51:33 PM
Subject: Re: What is the best framework or module in Python for a small GUI 
based application development?

On Apr 22, 8:11 am, srinivasan srinivas sri_anna...@yahoo.co.in
wrote:
 Hi,
 Could you suggest me some modules in Python which can be used to develop GUI 
 based applications? and tell me which could be the best(in terms of 
 efficiency) one for a small GUI based application development?

 Thanks,
 Srini


See the Python Wiki: http://wiki.python.org/moin/GuiProgramming

Python comes with Tkinter, which is good for simple programs and some
of the people on this list use it for very complicated programs. I
like wxPython. There are many others as well. It really depends on
what you want to do and whether or not you need special widgets.

- Mike
--
http://mail.python.org/mailman/listinfo/python-list



  Now surf faster and smarter ! Check out the new Firefox 3 - Yahoo! 
Edition http://downloads.yahoo.com/in/firefox/
--
http://mail.python.org/mailman/listinfo/python-list


Can someone explain about the usage of unittest.TestSuite?

2009-04-09 Thread srinivasan srinivas

Hi,
I would like to know about the unittest.TestSuite clearly like at what 
situations i can use this TestSuite? I am not getting the clear difference 
between this and unittest.TestCase.

Thanks,
Srini


  Cricket on your mind? Visit the ultimate cricket website. Enter 
http://beta.cricket.yahoo.com
--
http://mail.python.org/mailman/listinfo/python-list


Fw: Query regarding Python sybase module

2009-03-25 Thread srinivasan srinivas





- Forwarded Message 
From: srinivasan srinivas sri_anna...@yahoo.co.in
To: s...@pobox.com
Sent: Tuesday, 24 March, 2009 7:42:35 PM
Subject: Re: Query regarding Python sybase module

NO. I tried with what u have mentioned in the previous update.
But it gave only one result set.

Thanks,
Srini



- Original Message 
From: s...@pobox.com s...@pobox.com
To: srinivasan srinivas sri_anna...@yahoo.co.in
Cc: python-list@python.org
Sent: Tuesday, 24 March, 2009 6:40:37 PM
Subject: Re: Query regarding Python sybase module

    Srini Does Sybase Python driver module implement multiple result sets
    Srini from a single command?

I've used it to get multiple result sets from stored procedures, so I guess
the answer would be yes.  Something like this:

     params = curs.callproc('stored_procedure', params)
     while True:
    ...  rows = curs.fetchall()
    ...  print rows
    ...  if not curs.nextset():
    ...    break

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/



      Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/



  Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list


What way is the best to check an empty list?

2009-03-25 Thread srinivasan srinivas

For ex: to check list 'A' is empty or not..
if A == []:
if A.count == 0:
if len(A) == 0:
if not A:

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


What way is the best to check an empty list?

2009-03-25 Thread srinivasan srinivas

For ex: to check list 'A' is empty or not..
if A == []:
if A.count == 0:
if len(A) == 0:
if not A:


  Connect with friends all over the world. Get Yahoo! India Messenger at 
http://in.messenger.yahoo.com/?wm=n/
--
http://mail.python.org/mailman/listinfo/python-list


Query regarding Python sybase module

2009-03-23 Thread srinivasan srinivas

Hi,
Does Sybase Python driver module implement multiple result sets from a single 
command?
Could anyone guide e in finding answer for this?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Is there any way for a program to choose between 32 bit or 64-bit python dynamically?

2009-03-20 Thread srinivasan srinivas

Hi,
Is thera any way for a program to choose between 32-bit or 64-bit dynamically?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


what does 64-bit python mean?

2009-03-19 Thread srinivasan srinivas

Hi,
Could someone help me in understanding what 64-bit python means?

tahnks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Difference between 32 bit and 64 bit Python

2009-03-04 Thread srinivasan srinivas

Hi,
I would like to know more about the advantages of 64-bit python.
What appliactions can use 64-bit python and all?
Can someone help me out in this?

Thanks,
Srini


  Bring your gang together. Do your thing. Find your favourite Yahoo! group 
at http://in.promos.yahoo.com/groups/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Module for console text formatting?

2009-02-18 Thread srinivasan srinivas
Hi,
Is it possible to apply more than one formatting to a string? 
For ex: the string 'test' has to be underlined and it should be bold. How to do 
that?

Thanks,
Srini



From: geremy condra c...@openmigration.net
To: python-list@python.org
Sent: Wednesday, 18 February, 2009 10:04:34 AM
Subject: Re: Python Module for console text formatting?

You can insert those codes just like you would any other character. If there's 
enough interest I can whip up a wrapper library for you.

http://www.linux.gr/cgi-bin/man2html?console_codes+4


On Tue, Feb 17, 2009 at 11:19 PM, srinivasan srinivas sri_anna...@yahoo.co.in 
wrote:


Hi,
Does anyone know any python module other than 'ConsoleFormat0.1.1' used to 
format text on console?
For example, printing bold characters on console.

Thanks,
Srini


     Did you know? You can CHAT without downloading messenger. Go to 
http://in.webmessenger.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list



-- 
OpenMigration LLC- Open Source solutions for your business. Visit us at 
http://OpenMigration.net.



  Share files, take polls, and make new friends - all under one roof. Go to 
http://in.promos.yahoo.com/groups/--
http://mail.python.org/mailman/listinfo/python-list


Python Module for console text formatting?

2009-02-17 Thread srinivasan srinivas

Hi,
Does anyone know any python module other than 'ConsoleFormat0.1.1' used to 
format text on console?
For example, printing bold characters on console.

Thanks,
Srini


  Did you know? You can CHAT without downloading messenger. Go to 
http://in.webmessenger.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list


How do i add body to email.mime.multipart.MIMEMultipart instance?

2009-02-04 Thread srinivasan srinivas
Hi,
Could someone tell me the way to add body to the instance 
email.mime.multipart.MIMEMultipart instance which has attachments?

Thanks,
Srini


  Bollywood news, movie reviews, film trailers and more! Go to 
http://in.movies.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list


How do i add body to 'email.mime.multipart.MIMEMultipart' instance?

2009-02-03 Thread srinivasan srinivas
Hi,
Could someone tell me the way to add body content to 
'email.mime.multipart.MIMEMultipart' instance?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Doubts related to subprocess.Popen()

2009-01-20 Thread srinivasan srinivas
Hi,
Does subprocess.Popen() count a new open file for each suprocess? I mean does 
it occupy an entry in file descriptor table of parent process?
If so, wat is each file descriptor connected to?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Doubts related to subprocess.Popen()

2009-01-20 Thread srinivasan srinivas
Do parent process will have different file descriptor in it for each 
subprocesses or paprent uses a single file descriptor for all?
I really want to know creation of each subprocess will occupy an entry in 
parents'file descriptor table. B'cos if i create more than 200 subprocesses, i 
am getting 'Too many open files' error.

Thanks,
Srini
- Original Message 
From: Mark Wooding m...@distorted.org.uk
To: python-list@python.org
Sent: Tuesday, 20 January, 2009 6:16:17 PM
Subject: Re: Doubts related to subprocess.Popen()

srinivasan srinivas sri_anna...@yahoo.co.in writes:

 Does subprocess.Popen() count a new open file for each suprocess? I
 mean does it occupy an entry in file descriptor table of parent
 process?  If so, wat is each file descriptor connected to?

On Unix, subprocess.Popen will use up a file descriptor in the parent
for each use of subprocess.PIPE.  The descriptor in question is one end
of a pipe; the child process holds the other end.

I guess the situation is similar on Windows, but I don't know for sure.

-- [mdw]
--
http://mail.python.org/mailman/listinfo/python-list



  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Getting OSError, Could someone suggest?

2009-01-19 Thread srinivasan srinivas
Hi,
 I have written a script which will spawn more than 200 no of subprocesses. I 
have used subprocess.Popen to do that.

 OSError: [Error 24] Too many open files.

Could someone help me in fixing this error?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


How to deepcopy a list of user defined lists?

2009-01-08 Thread srinivasan srinivas
Hi,
I have a class which is a subclass of builtin-type list.

#--
class clist(list):
    def __new__(cls, values, ctor):
    val = []
    for item in values:
    item = ctor(item)
    val.append(item)
    
    self = list.__new__(cls, val)
    self.__values = val
    self.__ctor = ctor
    return self
#---

I have a list of clists, say c1 = [clist1, clist2, clist3]
How do i deepcopy this list? I tried using copy.deepcopy() method. But i 
got some errors. Please suggest me.

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to deepcopy a list of user defined lists?

2009-01-08 Thread srinivasan srinivas
-- 964 self.__tmp_data = copy.deepcopy(self.__data)
    965
/usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil)
    160 copier = _deepcopy_dispatch.get(cls)
    161 if copier:
-- 162 y = copier(x, memo)
    163 else:
    164 try:
/usr/local/python-2.5.1/lib/python2.5/copy.py in _deepcopy_list(x, memo)
    225 memo[id(x)] = y
    226 for a in x:
-- 227 y.append(deepcopy(a, memo))
    228 return y
    229 d[list] = _deepcopy_list
/usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil)
    187 raise Error(
    188 un(deep)copyable object of type %s % 
cls)
-- 189 y = _reconstruct(x, rv, 1, memo)
    190
    191 memo[d] = y
/usr/local/python-2.5.1/lib/python2.5/copy.py in _reconstruct(x, info, deep, 
memo)
    320 if deep:
    321 args = deepcopy(args, memo)
-- 322 y = callable(*args)
    323 memo[id(x)] = y
    324 if listiter is not None:
/usr/local/python-2.5.1/lib/python2.5/copy_reg.py in __newobj__(cls, *args)
 90
 91 def __newobj__(cls, *args):
--- 92 return cls.__new__(cls, *args)
 93
 94 def _slotnames(cls):
type 'exceptions.TypeError': __new__() takes exactly 3 arguments (1 given)

- Original Message 
From: Chris Rebert c...@rebertia.com
To: srinivasan srinivas sri_anna...@yahoo.co.in
Cc: python-list@python.org
Sent: Thursday, 8 January, 2009 1:56:27 PM
Subject: Re: How to deepcopy a list of user defined lists?

On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas
sri_anna...@yahoo.co.in wrote:
 Hi,
 I have a class which is a subclass of builtin-type list.

 #--
 class clist(list):
    def __new__(cls, values, ctor):
        val = []
        for item in values:
            item = ctor(item)
            val.append(item)

        self = list.__new__(cls, val)
        self.__values = val
        self.__ctor = ctor
        return self
 #---

 I have a list of clists, say c1 = [clist1, clist2, clist3]
 How do i deepcopy this list? I tried using copy.deepcopy() method. But i got 
 some errors. Please suggest me.

And those errors are? Please include a full Traceback.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



  Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/
--
http://mail.python.org/mailman/listinfo/python-list


How to send body and attachements in an email message?

2008-12-03 Thread srinivasan srinivas
HI,
I would like to send an email message with body-content 'test' and an 
attachment.
The snippet i used is:
outer = email.mime.multipart.MIMEMultipart()
msg1 = email.mime.text.MIMEText(filename1, _subtype = 'text')
msg1.add_header('Content-Disposition', 'attachment')
outer.attach(msg1)

body = email.mime.text.MIMEText(filename1, _subtype = 'text')
outer.attach(body)

smtp_client = smtplib.SMTP()
smtp_client.connect()
smtp_client.sendmail(sender, recipient, outer.as_string())
smtp_client.close()

If i do like above, i am receiving the body also as an attachment. How to set 
body to Multipart email message?

Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Inheriting frozenset gives bug if i overwrite __repr__ method

2008-11-19 Thread srinivasan srinivas
Hi,
I am getting an error while executing the following snippet. If i comment out 
method __repr__ , it works fine.

class fs(frozenset):
    def __new__(cls, *data):
    data = sorted(data)
    self = frozenset.__new__(cls, data)
    self.__data = data
    return self

    def __repr__(self):
    return %s(%r) % (self.__class__.__name__, self.__data)

a1 = fs(1,2,3)
a2 = fs(3,4,5)
print a1.difference(a2)

Error:
    return %s(%r) % (self.__class__.__name__, self.__data)
AttributeError: 'fs' object has no attribute '_fs__data'

Please help me in fixing this.

Thanks,
Srini



  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
Yes. But it didn't give only the expected decimals.
For ex:
 a = 1.23
 abs(int(a) -a)
0.22998

I would like to get the result '0.23' only.

Thanks,
Srini





From: Jeremiah Dodds [EMAIL PROTECTED]
To: python-list@python.org
Sent: Wednesday, 19 November, 2008 7:14:17 PM
Subject: Re: Getting fractional part from a float without using string 
operations




On Wed, Nov 19, 2008 at 8:35 AM, srinivasan srinivas [EMAIL PROTECTED] wrote:

Thanks,
Srini


     Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list

x = 2.99340584
y = abs(int(x) - x)
y
0.99340584

Is that what you wanted?



  Get perfect Email ID for your Resume. Grab now 
http://in.promos.yahoo.com/address--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting fractional part from a float without using string operations

2008-11-19 Thread srinivasan srinivas
Yes it works for most of the cases.  But it doesn't for the following case:

 str(abs(int(1234567.89)-1234567.89))
'0.88999898'

Thanks,
Srini


- Original Message 
From: Tino Wildenhain [EMAIL PROTECTED]
To: srinivasan srinivas [EMAIL PROTECTED]
Cc: Jeremiah Dodds [EMAIL PROTECTED]; python-list@python.org
Sent: Wednesday, 19 November, 2008 7:33:46 PM
Subject: Re: Getting fractional part from a float without using string 
operations

srinivasan srinivas wrote:
 Yes. But it didn't give only the expected decimals.
 For ex:
   a = 1.23
   abs(int(a) -a)
 0.22998
  I would like to get the result '0.23' only.

well, thats what get stored internally - there
is no way around it if you are using floating
point numbers:

 0.23
0.23001

but str() handles the rounding correctly:

 print 0.23
0.23

 print abs(int(a) -a)
0.23

See also http://en.wikipedia.org/wiki/Floating_point
for the problems with FP figures.

Regards
Tino



  Get perfect Email ID for your Resume. Grab now 
http://in.promos.yahoo.com/address
--
http://mail.python.org/mailman/listinfo/python-list


Python certification

2008-10-17 Thread srinivasan srinivas
Hi,
I m planning to do certification in Python??
Is therr any good certification available in Python like Sun certification for 
java??

Thanks,
Sirni

Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download 
Now! http://messenger.yahoo.com/download.php
--
http://mail.python.org/mailman/listinfo/python-list


Is there any nice way to unpack a list of unknown size??

2008-09-14 Thread srinivasan srinivas
I want to do something like below:

1. first, second, third, *rest = foo

 2. for (a,b,c,*rest) in list_of_lists:

Please suggest.

Thanks,
Srini


  Bring your gang together. Do your thing. Find your favourite Yahoo! group 
at http://in.promos.yahoo.com/groups/
--
http://mail.python.org/mailman/listinfo/python-list


Extracing data from webpage

2008-09-11 Thread srinivasan srinivas
Hi,
I am trying to download data from a webpage. I use mechanize python module. 
Could someone tell me how to set/pass an agent like Mozilla or IE that we do in 
perl's WWW::Mechanize??

Thanks,
Srini


  Be the first one to try the new Messenger 9 Beta! Go to 
http://in.messenger.yahoo.com/win/
--
http://mail.python.org/mailman/listinfo/python-list


Directory creation

2008-09-06 Thread srinivasan srinivas
Can someone tell me is there any module available to create directories??

I tried os, tempfile.
I was facing some issues with os.mkdir(). The mode setting was not proper with 
this method.

I created the directory 'stdin' with '0700' mode using os.mkdir() method.

$ ls -alR stdin/
stdin/:
total 12
drwx--S---   2 munisams munisams 4096 Sep  3 02:00 .

What is that 'S' in the group permission field??

Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Creating directories

2008-09-04 Thread srinivasan srinivas
Can someone tell me is there any module available to create directories??

I tried os, tempfile.
I was facing some issues with os.mkdir(). The mode setting was not proper with 
this method.

I created the directory 'stdin' with '0700' mode using os.mkdir() method.
$ ls -alR stdin/
stdin/:
total 12
drwx--S---   2 munisams munisams 4096 Sep  3 02:00 .
What is that 'S' in the group permission field??

Thanks,
Srini



  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Do we have python equivalent of 'perl -e'??

2008-08-22 Thread srinivasan srinivas
HI,
Like we run perl small code snippet using perl -e, do we have anything like 
that in python??
Thanks,
Srini



  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Python one-liner??

2008-08-22 Thread srinivasan srinivas
Hi,
Do we have python one-liner like perl one-liner 'perl -e'??
Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting pid of a remote process

2008-08-19 Thread srinivasan srinivas
This is wat i am doing :

args = [ SSH, hostname,  script_name]
I am giving this to subprocess.Popen()
Thanks,
Srini


- Original Message 
From: Diez B. Roggisch [EMAIL PROTECTED]
To: python-list@python.org
Sent: Tuesday, 19 August, 2008 12:26:20 PM
Subject: Re: Getting pid of a remote process

srinivasan srinivas schrieb:
 HI,
 I am using Solaris and subprocess.Popen to spawn a process on a remote 
 machine.

No, you are *not* doing that. You are maybe using subproces to run SSH 
to spawn a remote process. Why don't you *show* us how you actually do that?

DIEZ
--
http://mail.python.org/mailman/listinfo/python-list



  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting pid of a remote process

2008-08-19 Thread srinivasan srinivas
Thanks a lot.
But i am wondeing will it return correct pid if more than one instance of 
scriptname run on the remote machine??
Thanks,
Srini



- Original Message 
From: Diez B. Roggisch [EMAIL PROTECTED]
To: python-list@python.org
Sent: Tuesday, 19 August, 2008 2:54:52 PM
Subject: Re: Getting pid of a remote process

srinivasan srinivas wrote:

 This is wat i am doing :
 
 args = [ SSH, hostname,  script_name]
 I am giving this to subprocess.Popen()
 Thanks,
 Srini

Then the answer is simple: how would you figure out the remote process pid
using ssh? Once you found that out, pass that to Popen. Make sure you
capture stdout of the Popen-class to get the answer.

Something like

ps aux | grep script_name | grep -v grep | awk '{print $2}'

should be the command.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


  Cricket on your mind? Visit the ultimate cricket website. Enter 
http://in.sports.yahoo.com/cricket/
--
http://mail.python.org/mailman/listinfo/python-list


Getting pid of a remote process

2008-08-18 Thread srinivasan srinivas
Hi,
Could you please suggest me a way to find pid of a process started on a remote 
machine by the current process?? I should get pid in the current process 
environment. The approach should be somewhat generic. It shouldn't expect the 
remote process to print its pid.
Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Getting pid of a remote process

2008-08-18 Thread srinivasan srinivas
HI,
I am using Solaris and subprocess.Popen to spawn a process on a remote machine.
Thanks,
Srini



- Original Message 
From: Diez B. Roggisch [EMAIL PROTECTED]
To: python-list@python.org
Sent: Monday, 18 August, 2008 9:23:20 PM
Subject: Re: Getting pid of a remote process

srinivasan srinivas schrieb:
 Hi,
 Could you please suggest me a way to find pid of a process started on a 
 remote machine by the current process?? I should get pid in the current 
 process environment. The approach should be somewhat generic. It shouldn't 
 expect the remote process to print its pid.

Without information about

  - the OS you use

  - the technique you use for spawning processes remote

there is no answer to this.

Diez
--
http://mail.python.org/mailman/listinfo/python-list



  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Suggestion for converting PDF files to HTML/txt files

2008-08-11 Thread srinivasan srinivas
Could someone suggest me ways to convert PDF files to HTML files??
Does Python have any modules to do that job??

Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


Python Modules To convert PDF files to HTML files

2008-07-30 Thread srinivasan srinivas
Hi,
could someone tel me any python modules which can be used to convert PDF files 
to HTML files??
Thanks,
Srini


  Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >