[Tutor] I think I've broken my Python

2018-11-12 Thread Matthew Ngaha
I haven't coded in about 3 years and I used to use Python3.4 on
openSUSE13.1. I had a virtual environment with this Python for a
development Django website. Before I stopped coding, I upgraded to
Python3.5, but everything still worked if I remember correctly. But
now I'm back to coding I tried to load up my Django website but I get
the error:
Traceback (most recent call last):
  File "manage.py", line 8, in 
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

What happens is Django's manage.py can't be found so the line:
"from django.core.management import execute_from_command_line"
throws the error. In the virtual environment when I type python in the
command line, it opens Python2.7 and when I type Python3, it opens
Python3.5. So it seems my Python3.4 is lost. I thought the virtual
environment only loaded up the Python version it was installed for, in
my case Python3.4 when I type python or python3 in the command line,
had I known this wasn't the case I would have never upgraded Python.
Is there anything I can do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Mats Wichmann
On 11/12/18 4:45 AM, Matthew Ngaha wrote:
> I haven't coded in about 3 years and I used to use Python3.4 on
> openSUSE13.1. I had a virtual environment with this Python for a
> development Django website. Before I stopped coding, I upgraded to
> Python3.5, but everything still worked if I remember correctly. But
> now I'm back to coding I tried to load up my Django website but I get
> the error:
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ImportError: No module named django.core.management
> 
> What happens is Django's manage.py can't be found so the line:
> "from django.core.management import execute_from_command_line"
> throws the error. In the virtual environment when I type python in the
> command line, it opens Python2.7 and when I type Python3, it opens
> Python3.5. So it seems my Python3.4 is lost. I thought the virtual
> environment only loaded up the Python version it was installed for, in
> my case Python3.4 when I type python or python3 in the command line,
> had I known this wasn't the case I would have never upgraded Python.
> Is there anything I can do?

Reconstruct the virtualenv you want maybe? Their whole concept is that
they're cheap and easy and can just be thrown away.  Of course, you then
have to remember what you did to create it in order to make a new one...

Virtualenv *can* make a full copy of the Python environment you are
building it from, but does not by default - it uses links to save space
if the platform is okay with that.  That does mean that if the original
goes away due to version upgrade, you're likely to be left with an
unusable virtualenv (see the --always-copy argument to virtualenv).

Since you're on a Linux platform, use "which" to see how the names you
are typing are resolving

which python
which python3

Usually if the virtualenv has been broken by external factors, it won't
even activate. Are you sure you remembered to try to activate it?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Matthew Ngaha
On Mon, Nov 12, 2018 at 3:31 PM Mats Wichmann  wrote:
>
> Reconstruct the virtualenv you want maybe? Their whole concept is that
> they're cheap and easy and can just be thrown away.  Of course, you then
> have to remember what you did to create it in order to make a new one...

It's been 3 years, I'm clueless as to how I created it. Also I'm a
noob when it comes to Linux which makes this even more confusing for
me. The 3 years I've been absent from Programming I went back to
Windows.

> Since you're on a Linux platform, use "which" to see how the names you
> are typing are resolving
>
> which python
> which python3

The "command" gives this output:

(website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
which python
/usr/bin/python
(website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
which python3
/usr/bin/python3

> Usually if the virtualenv has been broken by external factors, it won't
> even activate. Are you sure you remembered to try to activate it?
>
Yep, I double checked to make sure I remembered to try to activate it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Mats Wichmann
On 11/12/18 10:07 AM, Matthew Ngaha wrote:
> On Mon, Nov 12, 2018 at 3:31 PM Mats Wichmann  wrote:
>>
>> Reconstruct the virtualenv you want maybe? Their whole concept is that
>> they're cheap and easy and can just be thrown away.  Of course, you then
>> have to remember what you did to create it in order to make a new one...
> 
> It's been 3 years, I'm clueless as to how I created it. Also I'm a
> noob when it comes to Linux which makes this even more confusing for
> me. The 3 years I've been absent from Programming I went back to
> Windows.
> 
>> Since you're on a Linux platform, use "which" to see how the names you
>> are typing are resolving
>>
>> which python
>> which python3
> 
> The "command" gives this output:
> 
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python
> /usr/bin/python
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python3
> /usr/bin/python3
> 
>> Usually if the virtualenv has been broken by external factors, it won't
>> even activate. Are you sure you remembered to try to activate it?
>>
> Yep, I double checked to make sure I remembered to try to activate it.
> 

it's possible there was never a virtualenv involved... on a Linux system
you'd normally install the distribution package for django, instead of
installing bits in a virtualenv. The distro package contains a template
manage.py. Which, on a current Fedora, contains wording suggesting maybe
a virtualenv wasn't started - but the real message is that it couldn't
find necessary Django pieces in the python environment (this is
consistent with your original message, suggesting it found and is
running manage, but other things are missing).

Here's the interesting part of the content of that template for those
who might have more ideas:


if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name
}}.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Matthew Ngaha
On Mon, Nov 12, 2018 at 5:35 PM Roger B. Atkins  wrote:
>
> What about installing or reinstalling Django using the python version
> that produced the error message?

Yeah if all else fails I'll try this. Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Matthew Ngaha
On Mon, Nov 12, 2018 at 5:52 PM Mats Wichmann  wrote:
> but the real message is that it couldn't
> find necessary Django pieces in the python environment (this is
> consistent with your original message, suggesting it found and is
> running manage, but other things are missing).
>
You're right, I was wrong when I said "manage.py can't be found." It's
the import statement from manage.py that causes the problem.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Example for read and readlines() (Asad)

2018-11-12 Thread Asad
Hi All ,

   Thanks for the reply . I am building a framework for the two error
conditions, therefore I need to read and readlines because in one only
regex is required and in other regex+ n-1 line is required to process :

#Here we are opening the file and substituting space " " for each \n
encountered
f3 = open  (r"D:\QI\log.log", 'r')
string = f3.read()
string1 = f3.readlines()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )

if re.search('ERR1',st):
y=re.findall("[A-Z][a-z][a-z] [ 123][0-9]
[012][0-9]:[0-5][0-9]:[0-5][0-9] [0-9][0-9][0-9][0-9]",st)
print y

patchnumber = re.compile(r'(\d+)\/(\d+)')==> doesnot
work it only works if I use  #string = f3.read()
for j in range(len(string1)):
if re.search ( r'ERR2', string1[j] ):
print "Error line \n", string1[j - 1]
mo = patchnumber.search (string1[j-1])
a = mo.group()
print a
print os.getcwd()
break

Please advice how to proceed.

Thanks,


On Sun, Nov 11, 2018 at 10:30 PM  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> Today's Topics:
>
>1. Re: Require Python assistance (Alan Gauld)
>2. Re: Example for read and readlines() (Alan Gauld)
>3. Re: Example for read and readlines() (Alan Gauld)
>4. Re: Example for read and readlines() (Asad)
>5. Re: Example for read and readlines() (Alan Gauld)
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 09:53:23 +
> Subject: Re: [Tutor] Require Python assistance
> On 10/11/2018 18:10, Avi Gross wrote:
> > WARNING to any that care:
> >
> > As the following letter  is a repeat request without any hint they read
> the earlier comments here, I did a little searching and see very much the
> same request on another forum asking how to do this in MATLAB:
>
> The OP has also repeated posted the same message to this list
> (which I rejected as moderator).
>
>
> --
> 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
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 10:00:33 +
> Subject: Re: [Tutor] Example for read and readlines()
> On 11/11/2018 06:49, Asad wrote:
> > Hi All ,
> >
> >  If I am loading a logfile what should I use from the option
> 1,2,3
> >
> > f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r' )
> >
> > 1) should only iterate over f3
>
> This is best for processing line by line which is the most
> common way to handle files. It saves memory and allows you
> to exit early, without reading the entire file if you are
> only looking for say a single entry.
>
> for line in file:
>if terminal_Condition: break
># process line here
>
> > 2) st = f3.read()
>
> The best solution if you want to process individual characters
> or small character groups. Also best if you want to process
> the entire file at once, for example using a regular expression
> which might span lines.
>
> > 3) st1 = f3.readlines()
>
> Mainly historical and superseded by iterating over the file.
> But sometimes useful if you need to do multiple passes over
> the lines since it only reads the file once. Very heavy
> memory footprint for big files.
>
>
> --
> 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
>
>
>
>
>
>
> -- Forwarded message --
> From: Alan Gauld 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 10:02:40 +
> Subject: Re: [Tutor] Example for read and readlines()
> On 11/11/2018 09:40, Steven D'Aprano wrote:
>
> >> f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log",
> 'r' )
> >
> > Don't use raw strings r"..." for pathnames.
>
> Umm, Why not?
>
> --
> 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
>
>
>
>
>
>
> -- Forwarded message --
> From: Asad 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Sun, 11 Nov 2018 15:34:35 +0530
> Subject: Re: [Tutor] Example for read and readlines()
> Hi All,
>
>   thanks for the reply so to put into context say I have a file
> l

[Tutor] 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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to create a html hyperlink for a document

2018-11-12 Thread Asad
Hi All ,

I am creating a python script to analyze the log and provide a
solution , in the solution part I want to include a document and create a
hyperlink to the document so that its clickable .
I have python 2.6.6 cannot use :hyperlink module because this is production
server and the module cannot be installed on it . Need some trick to create
it .

Please advice ,

Thanks,
-- 
Asad Hasan
+91 9582111698
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Roger B. Atkins
What about installing or reinstalling Django using the python version
that produced the error message?
On Mon, Nov 12, 2018 at 10:10 AM Matthew Ngaha  wrote:
>
> On Mon, Nov 12, 2018 at 3:31 PM Mats Wichmann  wrote:
> >
> > Reconstruct the virtualenv you want maybe? Their whole concept is that
> > they're cheap and easy and can just be thrown away.  Of course, you then
> > have to remember what you did to create it in order to make a new one...
>
> It's been 3 years, I'm clueless as to how I created it. Also I'm a
> noob when it comes to Linux which makes this even more confusing for
> me. The 3 years I've been absent from Programming I went back to
> Windows.
>
> > Since you're on a Linux platform, use "which" to see how the names you
> > are typing are resolving
> >
> > which python
> > which python3
>
> The "command" gives this output:
>
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python
> /usr/bin/python
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python3
> /usr/bin/python3
>
> > Usually if the virtualenv has been broken by external factors, it won't
> > even activate. Are you sure you remembered to try to activate it?
> >
> Yep, I double checked to make sure I remembered to try to activate it.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2018-11-12 Thread Avi Gross
In replying to what "Stealth Fleet" asked, I have too many comments,
starting with a suggestion to put a SUBECT on the Subject: line.

Your first error was not converting the text input to an integer or floating
point number.

tokenAmount = input( "How many tokens would you like to buy or cash
in?:  ")

Fix that and then see if other things fail.

BTW, you created functions which take no arguments and use a global variable
but then create local variables that would not persist in a real
application. If your assignment was just to print what would have been
calculated, that may suffice but that may be another area you think more
about.


-Original Message-
From: Tutor  On Behalf Of
Stealth Fleet
Sent: Sunday, November 11, 2018 6:00 PM
To: tutor@python.org
Subject: [Tutor] (no subject)

tokenAmount = input( "How many tokens would you like to buy or cash in?:  ")

print (tokenAmount)



def buy ():

if tokenAmount <= 400:

buy = tokenAmount * .2099

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount > "400" <= "549":

buy = tokenAmount * .3999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "550" <= "749":

buy = tokenAmount * .4999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

elif tokenAmount >= "750" <= "999":

buy = tokenAmount * .6299

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")

else:

buy = tokenAmount * .7999

print( " You would like to spend $"+(buy) + "on" + (tokenAmount) +
"tokens.")



def cashIn ():

cashIn = tokenAmount * .05

print( "The amount of money you will receive is $"+ (cashIn))



tokenAmount works but the buy and cashIn are not being ran why? When I put
"print(buy, cashIn)" it gives me a long message that ends in an error any
and all help is greatly appreciated. Sent from Mail
 for Windows 10
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue in parsing the strings in python code

2018-11-12 Thread Shakti Kumar
On Mon, 12 Nov 2018 at 14:02, 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
>
> 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
>

You can look into textfsm parser for the same, it was released specifically
for this purpose of parsing CLI outputs.
It should be the ideal solution for your scenario since I see some rows in
your cli output which have spaces in the same column, so a hardcoded index
after splitting each line on spaces will not work out.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] 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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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

2018-11-12 Thread Bill Campbell
On Tue, Nov 13, 2018, srinivasan wrote:
>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())*

This command should get the gateway IP.

Linux: cmd = "ip route list | awk '/^default/{print $3}'"

or perhaps

Linux: cmd = "netstat -rn | awk '/^0.0.0.0/{print $2}'"

OSX: cmd = "netstat -rn | awk '/^default/{print $2}'"

I don't have a freebsd system available to test this, but I think
this pattern should work:

re.compile(r'^(default|0\.0\.0\.0)\s+(\S+)')

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ PO Box 820; 6641 E. Mercer Way
Mobile: (206) 947-5591  Mercer Island, WA 98040-0820
Fax:(206) 232-9186  Skype: jwccsllc

On the free market, everyone earns according to his productive
value in satisfying consumer desires. Under statist distribution,
everyone earns in proportion to the amount he can plunder from
the producers. -- Murray N. Rothbard
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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

2018-11-12 Thread David Rock

> On Nov 12, 2018, at 13:37, srinivasan  wrote:
> 
> 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.

Is there a requirement to use only what comes in the standard libraries, or can 
you use things from pypi?
Getting interface details is exactly why netifaces was created

https://pypi.org/project/netifaces/

damocles:src drock$ python3
Python 3.7.0 (default, Oct 28 2018, 22:17:08) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import netifaces
>>> gws = netifaces.gateways()
>>> gws
{'default': {2: ('192.168.69.1', 'en0')}, 2: [('192.168.69.1', 'en0', True)]}
>>> gws['default']
{2: ('192.168.69.1', 'en0’)}

— 
David Rock
da...@graniteweb.com




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor