G'day,
I'm currently blundering through a script that will let me configure and
then connect to PPTP VPNs from a Linux box. Just a text-based front-end
to pptp-client, really.
Adding in new VPN configurations was simple. Connecting is a little
harder. From the command-line I would normally
The Python Cookbook (1st ed) suggests this, in recipe 10.4 (Finding Your
Own Name and Address):
import socket
myname = socket.getfqdn(socket.gethostname())
myaddr = socket.gethostbyname(myname)
myaddr
'192.168.1.120'
___
Tutor maillist -
Lee Cullens wrote:
Well, I've tried both and can't produce what I was doing with the for
construct.
With a listpl = ['a', 'b', 'c', 'd'] of the path components I'm
trying to add justified non repeated path elements, say pl[2] and pl [3]
to csvline so that csvline would end up ','*x
At present, the only thing I can think of is to redirect the
output of 'ifconfig' into a temporary file, then read it back in and use
Python and regular expressions to try and extract the IP info from that.
That is basically how I do it. See here:
There is no need for the if(dlst); if the list is empty the iteration will do nothing. You can write this as
for dlf in os.listdir(pname): Though it is quite distant, there is an else statement which makesthe if construct a requierement.Javier
You could just do -
if not len(dlst):
#Your
Such would serve to pull the test and the reason for it together -
more obvious.
Which is a good point in writing code that others may read.
Thanks Liam
On Jun 5, 2005, at 9:29 AM, Liam Clarke wrote:
There is no need for the if(dlst); if the list is empty the
iteration will do
OK Kent - got it:My little formating function could be written as (tested) def cellpos(pname, alvl, blvl, clvl): # breakout path components into list pl = pname.split('/') # insert empty cells for repeated names and # add new path components (cells) to csvline
On Sun, Jun 05, 2005, Lee Harr wrote:
At present, the only thing I can think of is to redirect the
output of 'ifconfig' into a temporary file, then read it back in and use
Python and regular expressions to try and extract the IP info from that.
Why go to a temporary file when you can open a pipe?
David Pratt wrote:
Hi Kent. Thank you for your reply. I gave this a go but get the
following traceback:
...
result = validator(name, value)
TypeError: 'str' object is not callable
Have put validators in list and iterate over it as in following:
validator_list =
Sorry, forwarded to the wrong list.
Kent
Original Message
Subject: Re: [Tutor] Iterate through a list calling functions
Date: Sun, 05 Jun 2005 21:53:16 -0400
From: Kent Johnson [EMAIL PROTECTED]
To: Python Tutor tutor@python.org
References: [EMAIL PROTECTED]
David Pratt wrote:
Thank you for your suggestions everyone.
I do wish to parse ifconfig, as I'm specifically after the address of
ppp0. At this stage, I'm only writing the script for my own machine,
so the downside to parsing ifconfig does not yet apply. I'm a little
curious, however. When you say 'varies depending
On Mon, Jun 06, 2005, Simon Gerber wrote:
Thank you for your suggestions everyone.
I do wish to parse ifconfig, as I'm specifically after the address of
ppp0. At this stage, I'm only writing the script for my own machine,
so the downside to parsing ifconfig does not yet apply. I'm a little
12 matches
Mail list logo