Python - How do you print a list item / entry's text instead of its value? [duplicate]
up vote
0
down vote
favorite
This question already has an answer here:
How do I create a variable number of variables?
15 answers
e.g.
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = [r2,r3]
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
Output of this is....
192.168.122.72
['192.168.122.72', '192.168.122.73']
192.168.122.72
192.168.122.73
['192.168.122.72', '192.168.122.73']
192.168.122.73
I actually want to see an output that will say the items literal text, not its value, so i actually want to see this.......
r2
r3
Ultimately, want to create a file that is the name of the router, not its IP.
Thank you in advance!
python list printing
                    marked as duplicate by timgeb
    StackExchange.ready(function() {
        if (StackExchange.options.isMobile) return;
        $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
            var $hover = $(this).addClass('hover-bound'),
                $msg = $hover.siblings('.dupe-hammer-message');
            
            $hover.hover(
                function() {
                    $hover.showInfoMessage('', {
                        messageElement: $msg.clone().show(),
                        transient: false,
                        position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
                        dismissable: false,
                        relativeToBody: true
                    });
                },
                function() {
                    StackExchange.helpers.removeMessages();
                }
            );
        });
    });
 Nov 22 at 16:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
0
down vote
favorite
This question already has an answer here:
How do I create a variable number of variables?
15 answers
e.g.
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = [r2,r3]
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
Output of this is....
192.168.122.72
['192.168.122.72', '192.168.122.73']
192.168.122.72
192.168.122.73
['192.168.122.72', '192.168.122.73']
192.168.122.73
I actually want to see an output that will say the items literal text, not its value, so i actually want to see this.......
r2
r3
Ultimately, want to create a file that is the name of the router, not its IP.
Thank you in advance!
python list printing
                    marked as duplicate by timgeb
    StackExchange.ready(function() {
        if (StackExchange.options.isMobile) return;
        $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
            var $hover = $(this).addClass('hover-bound'),
                $msg = $hover.siblings('.dupe-hammer-message');
            
            $hover.hover(
                function() {
                    $hover.showInfoMessage('', {
                        messageElement: $msg.clone().show(),
                        transient: false,
                        position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
                        dismissable: false,
                        relativeToBody: true
                    });
                },
                function() {
                    StackExchange.helpers.removeMessages();
                }
            );
        });
    });
 Nov 22 at 16:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dictsitemsattribute.
– timgeb
Nov 22 at 16:59
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use adict.
– juanpa.arrivillaga
Nov 22 at 17:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
How do I create a variable number of variables?
15 answers
e.g.
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = [r2,r3]
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
Output of this is....
192.168.122.72
['192.168.122.72', '192.168.122.73']
192.168.122.72
192.168.122.73
['192.168.122.72', '192.168.122.73']
192.168.122.73
I actually want to see an output that will say the items literal text, not its value, so i actually want to see this.......
r2
r3
Ultimately, want to create a file that is the name of the router, not its IP.
Thank you in advance!
python list printing
This question already has an answer here:
How do I create a variable number of variables?
15 answers
e.g.
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = [r2,r3]
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
Output of this is....
192.168.122.72
['192.168.122.72', '192.168.122.73']
192.168.122.72
192.168.122.73
['192.168.122.72', '192.168.122.73']
192.168.122.73
I actually want to see an output that will say the items literal text, not its value, so i actually want to see this.......
r2
r3
Ultimately, want to create a file that is the name of the router, not its IP.
Thank you in advance!
This question already has an answer here:
How do I create a variable number of variables?
15 answers
python list printing
python list printing
asked Nov 22 at 16:56
kaj0103
11
11
                    marked as duplicate by timgeb
    StackExchange.ready(function() {
        if (StackExchange.options.isMobile) return;
        $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
            var $hover = $(this).addClass('hover-bound'),
                $msg = $hover.siblings('.dupe-hammer-message');
            
            $hover.hover(
                function() {
                    $hover.showInfoMessage('', {
                        messageElement: $msg.clone().show(),
                        transient: false,
                        position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
                        dismissable: false,
                        relativeToBody: true
                    });
                },
                function() {
                    StackExchange.helpers.removeMessages();
                }
            );
        });
    });
 Nov 22 at 16:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
                    marked as duplicate by timgeb
    StackExchange.ready(function() {
        if (StackExchange.options.isMobile) return;
        $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
            var $hover = $(this).addClass('hover-bound'),
                $msg = $hover.siblings('.dupe-hammer-message');
            
            $hover.hover(
                function() {
                    $hover.showInfoMessage('', {
                        messageElement: $msg.clone().show(),
                        transient: false,
                        position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
                        dismissable: false,
                        relativeToBody: true
                    });
                },
                function() {
                    StackExchange.helpers.removeMessages();
                }
            );
        });
    });
 Nov 22 at 16:58
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dictsitemsattribute.
– timgeb
Nov 22 at 16:59
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use adict.
– juanpa.arrivillaga
Nov 22 at 17:09
add a comment |
1
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dictsitemsattribute.
– timgeb
Nov 22 at 16:59
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use adict.
– juanpa.arrivillaga
Nov 22 at 17:09
1
1
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dicts
items attribute.– timgeb
Nov 22 at 16:59
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dicts
items attribute.– timgeb
Nov 22 at 16:59
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use a
dict.– juanpa.arrivillaga
Nov 22 at 17:09
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use a
dict.– juanpa.arrivillaga
Nov 22 at 17:09
add a comment |
                                1 Answer
                                1
                        
active
oldest
votes
up vote
2
down vote
This is not possible. You have to use a dictionary for that.
Example:
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = {'r2':r2,'r3':r3}
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
add a comment |
                                1 Answer
                                1
                        
active
oldest
votes
                                1 Answer
                                1
                        
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
This is not possible. You have to use a dictionary for that.
Example:
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = {'r2':r2,'r3':r3}
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
add a comment |
up vote
2
down vote
This is not possible. You have to use a dictionary for that.
Example:
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = {'r2':r2,'r3':r3}
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
add a comment |
up vote
2
down vote
up vote
2
down vote
This is not possible. You have to use a dictionary for that.
Example:
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = {'r2':r2,'r3':r3}
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
This is not possible. You have to use a dictionary for that.
Example:
r2 = '192.168.122.72'
r3 = '192.168.122.73'
hostnames = {'r2':r2,'r3':r3}
#commands = ['term len 0','show run']
for r in hostnames:
    print (r)
    print (hostnames)
    print str(r)
answered Nov 22 at 16:58
FMarazzi
318213
318213
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
add a comment |
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
This is great, thank you. I have been able to call either the IP address or the hostname now.
– kaj0103
Nov 22 at 21:53
add a comment |
1
You can't. Variable names refer to values unidirectionally. Use a dictionary mapping IPs to names (or vice versa) and then iterate over the dicts
itemsattribute.– timgeb
Nov 22 at 16:59
It is the programmers job to properly organize your code if you want to associate a string to some other value. Variables are not strings, they are source code. You should use a
dict.– juanpa.arrivillaga
Nov 22 at 17:09