for line3 in myips matching too longer matches.

2019-06-26 Thread Chris Roberts

###
CODE:
   elif line1.rstrip(‘\n’) in line2.strip(‘\n’):
   for line3 in myips:
   print “###”
   print “line1 is %s” % line1.rstrip(‘\n’)
   print “line2 is %s” % line2.strip(‘\n’)
###
OUTPUT:
line1 is 10.10.168.2
line2 is  - address: 10.10.168.27  # myhost
###

I think the problem is here: 
line1.rstrip(‘\n’) in line2.strip(‘\n’):  

I want it to
match only 10.10.168.2 AND 10.10.168.2:
NOT match 10.10.168.2[0-9]

If someone out there knows a simple solution. I would love to see it.
Thanks in advance. 
crzzy1

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


Python, convert an integer into an index?

2015-09-22 Thread Chris Roberts

(How do I make it into an index? )
Preferably something fairly easy to understand as I am new at this.

results = 134523  #(Integer) 

Desired: 
results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)

Somehow I see ways to convert index to list to int, but not back again.

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


Re: Python, convert an integer into an index?

2015-09-23 Thread Chris Roberts
Fantastic!
I started a course, but I have been having issues with
string/index/list/integer conversions and manipulations.
This variation wasn't in any of my texts or class exercises either.
Your way was both simple enough to understand and very informative!
Thanks.


On Tue, Sep 22, 2015 at 6:21 PM, Laura Creighton  wrote:

> In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes:
> >
> >
> >(How do I make it into an index? )
> >Preferably something fairly easy to understand as I am new at this.
> >
> >results = 134523  #(Integer)
> >
> >Desired:
> >results = [1, 2, 3, 4, 5, 2, 3]   #(INDEX)
> >
> >Somehow I see ways to convert index to list to int, but not back again.
> >
> >Thanks,
> >crzzy1
>
> You need to convert your results into a string first.
>
> result_int=1234523
> result_list=[]
>
> for digit in str(result_int):
> result_list.append(int(digit))
>
> digit will be assigned to successive 1 character long strings.  Since
> you wanted a list of integers, you have to convert it back.
>
> If you are learning python you may be interested in the tutor mailing
> list. https://mail.python.org/mailman/listinfo/tutor
>
> Laura
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python... feeding an instance as an argument into a new instance.

2017-09-02 Thread Chris Roberts
Perhaps someone here could help me to get this into perspective. 
Somehow when we start to feed an instance as the argument in a new instance. my 
head explodes..
in this case...
a = Foo()
b = Bar(a)
So... 
 a is a 'Foo instance' with properties and methods. 
b is a 'Bar instance'
Since b is using the "a" instance as an argument?? 
b=Bar(a)  has what?? 

Is there an easier way to put into perspective how an instance of one class is 
used as the argument into the instance of another class? 

Code below: 

class Foo(object):
bar = "Bar"  # Class attribute.

def __init__(self):
##^ The first variable is the class instance in methods.
##  This is called "self" by convention, but could be any name 
you want.
# ^ double underscore (dunder) methods are usually special.  This one
#  gets called immediately after a new instance is created.

self.variable = "Foo"  # instance attribute.
print self.variable, self.bar  # <---self.bar references class attribute
self.bar = " Bar is now Baz"  # <---self.bar is now an instance 
attribute
print self.variable, self.bar #variable will be a property of "a" and 
self is the bound variable of a.

def method(self, arg1, arg2):
# This method has arguments.  You would call it like this:  
instance.method(1, 2)
print "in method (args):", arg1, arg2
print "in method (attributes):", self.variable, self.bar


a = Foo()  # this calls __init__ (indirectly), output:
#a is Foo, a has a method called method, and properties such as "variable and 
bar".
# Foo bar
# Foo  Bar is now Baz
print a.variable  # Foo
a.variable = "bar"
a.method(1, 2)  # output:
# in method (args): 1 2
# in method (attributes): bar  Bar is now Baz
Foo.method(a, 1,
   2)  # <--- Same as a.method(1, 2).  This makes it a little more 
explicit what the argument "self" actually is.
print "##Above is all the a Foo object, and below is the b Bar object"

class Bar(object):
def __init__(self, arg):
self.arg = arg
self.Foo = Foo() #this calls and runs the Foo class again.


b = Bar(a)  #b is a Bar object, a is a Foo object with properties and methods. 
then Bar() calls the Foo class again.
b.arg.variable = "something"
print a.variable  # something !(I don't know why "a" prints "something" here.)
print b.Foo.variable  # Foo


OUTPUT: 
Foo Bar
Foo  Bar is now Baz
Foo
in method (args): 1 2
in method (attributes): bar  Bar is now Baz
in method (args): 1 2
in method (attributes): bar  Bar is now Baz
##Above is all the a Foo object, and below is the b Bar object
Foo Bar
Foo  Bar is now Baz
something
Foo

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


Re: Python... feeding an instance as an argument into a new instance.

2017-09-03 Thread Chris Roberts
On Saturday, September 2, 2017 at 6:34:59 PM UTC-4, Chris Roberts wrote:
> Perhaps someone here could help me to get this into perspective. 
> Somehow when we start to feed an instance as the argument in a new instance. 
> my head explodes..
> in this case...
> a = Foo()
> b = Bar(a)
> So... 
>  a is a 'Foo instance' with properties and methods. 
> b is a 'Bar instance'
> Since b is using the "a" instance as an argument?? 
> b=Bar(a)  has what?? 
> 
> Is there an easier way to put into perspective how an instance of one class 
> is used as the argument into the instance of another class? 
> 
> Code below: 
> 
> class Foo(object):
> bar = "Bar"  # Class attribute.
> 
> def __init__(self):
> ##^ The first variable is the class instance in methods.
> ##  This is called "self" by convention, but could be any 
> name you want.
> # ^ double underscore (dunder) methods are usually special.  This one
> #  gets called immediately after a new instance is created.
> 
> self.variable = "Foo"  # instance attribute.
> print self.variable, self.bar  # <---self.bar references class 
> attribute
> self.bar = " Bar is now Baz"  # <---self.bar is now an instance 
> attribute
> print self.variable, self.bar #variable will be a property of "a" and 
> self is the bound variable of a.
> 
> def method(self, arg1, arg2):
> # This method has arguments.  You would call it like this:  
> instance.method(1, 2)
> print "in method (args):", arg1, arg2
> print "in method (attributes):", self.variable, self.bar
> 
> 
> a = Foo()  # this calls __init__ (indirectly), output:
> #a is Foo, a has a method called method, and properties such as "variable and 
> bar".
> # Foo bar
> # Foo  Bar is now Baz
> print a.variable  # Foo
> a.variable = "bar"
> a.method(1, 2)  # output:
> # in method (args): 1 2
> # in method (attributes): bar  Bar is now Baz
> Foo.method(a, 1,
>2)  # <--- Same as a.method(1, 2).  This makes it a little more 
> explicit what the argument "self" actually is.
> print "##Above is all the a Foo object, and below is the b Bar object"
> 
> class Bar(object):
> def __init__(self, arg):
> self.arg = arg
> self.Foo = Foo() #this calls and runs the Foo class again.
> 
> 
> b = Bar(a)  #b is a Bar object, a is a Foo object with properties and 
> methods. then Bar() calls the Foo class again.
> b.arg.variable = "something"
> print a.variable  # something !(I don't know why "a" prints "something" here.)
> print b.Foo.variable  # Foo
> 
> 
> OUTPUT: 
> Foo Bar
> Foo  Bar is now Baz
> Foo
> in method (args): 1 2
> in method (attributes): bar  Bar is now Baz
> in method (args): 1 2
> in method (attributes): bar  Bar is now Baz
> ##Above is all the a Foo object, and below is the b Bar object
> Foo Bar
> Foo  Bar is now Baz
> something
> Foo
> 
>  Thanks in advance... crzzy1 ...

Steve and Irv, 
I see what you mean... I picked up on this example online and then tried to 
work it out on my own, but after seeing your replies, and looking further into 
cars examples I found how much more intuitive that makes it...
Anyways, now I know where to better redirect my studies and energies.
My work is sending me to a semi advanced (Core Python) class, and I am not 
ready, so trying to work on all my weak spots.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list