[Tutor] Variable Question

Bryon Adams bryonadams at openmailbox.org
Fri Nov 18 16:00:31 EST 2016


Hello,
   Variable throwing me off in a script I'm running on Python3.5, on 
Fedora 24. I take four strings and create a list of them. In my below 
code, if I print out prefix and as_path, both give me the same (I 
included the output below). What causes this behavior? Is this just how 
Python is handling the variables in memory and I'm actually working on 
'entries' each time? I fixed it already by changing how I assign prefix 
and as_path.


# Given 'show ip bgp'
entry1 = "*  1.0.192.0/18   157.130.10.233     0 701 38040 9737 i"
entry2 = "*  1.1.1.0/24     157.130.10.233     0 701 1299 15169 i"
entry3 = "*  1.1.42.0/24    157.130.10.233     0 701 9505 17408 2.1465 i"
entry4 = "*  1.0.192.0/19   157.130.10.233     0 701 6762 6762 6762 6762 
38040 9737 i"

entries = [entry1.split(), entry2.split(), entry3.split(), entry4.split()]
prefix  = entries
as_path = entries

n = 0
for i in prefix:
   prefix[n] = prefix[n][1]
   n += 1

print(prefix)
print(as_path)

[bryon at fedberry ~/pynet]$ python3 week3-2.py
['1.0.192.0/18', '1.1.1.0/24', '1.1.42.0/24', '1.0.192.0/19']
['1.0.192.0/18', '1.1.1.0/24', '1.1.42.0/24', '1.0.192.0/19']
192.0/1
1.0/2
42.0/2
192.0/1

Thanks,
   Bryon


More information about the Tutor mailing list