Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 22nd, 2012, 10:44 AM
amb1s1 amb1s1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 25 amb1s1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 28 sec
Reputation Power: 0
Make a list into one big string

Hi, I'm encountering a problem where I capture an output from a device, but it seems as every word is an item on a list.
This is my capture out put.
Code:
print results

!
interface GigabitEthernet0/1
 description Reserved for Infrastructure
 switchport access vlan 101
 switchport mode access
 spanning-tree portfast
end
print results[0]
s
print results[1]
h


As you can see it look like that each word is item on a list, but if I type print results[0], I would expect ! to print not the s. I'm a little confude about that. But my end result is that the output is just one string. Thanks

Reply With Quote
  #2  
Old August 22nd, 2012, 10:56 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
I cannot tell much from your post. Do this:

print(type(results))



When you discover that results is not type(str()) investigate the type that it is.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old August 22nd, 2012, 11:00 AM
amb1s1 amb1s1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 25 amb1s1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 28 sec
Reputation Power: 0
This is what I get:

print (type(results))
TypeError: 'str' object is not callable

Reply With Quote
  #4  
Old August 22nd, 2012, 11:18 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
Great. I don't write code that overwrites my system's available names. You seem to have a code that violates my rules.

Try

print(__builtins__.type(results))

Reply With Quote
  #5  
Old August 22nd, 2012, 02:37 PM
amb1s1 amb1s1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 25 amb1s1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Great. I don't write code that overwrites my system's available names. You seem to have a code that violates my rules.

Try

print(__builtins__.type(results))

The result was one big string already. Thanks

Reply With Quote
  #6  
Old August 22nd, 2012, 02:53 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
Look,
Code:
>>> def f(o):print __builtins__.type(o)
... 
>>> f(3)
<type 'int'>
>>> f('string')
<type 'str'>
>>> f(object)
<type 'type'>
>>> f(object())
<type 'object'>
>>> 

It's not "one big string".

Furthermore, the substring "sh" given by your results[0]+results[1] does not appear in your first post.

Something screwy's happening and we're both clueless. Were we given complete information we might untangle things.

Reply With Quote
  #7  
Old September 3rd, 2012, 05:43 PM
Max00355 Max00355 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 Max00355 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 49 sec
Reputation Power: 0
The only way I can think to do this would be something like this.

Code:

list = [1,2,3]
string = ""
for x in list:
  string += x
print string

Reply With Quote
  #8  
Old September 4th, 2012, 03:57 AM
SuperOscar SuperOscar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Joensuu, Finland
Posts: 404 SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 5 h 17 m 59 sec
Reputation Power: 65
Quote:
Originally Posted by amb1s1
As you can see it look like that each word is item on a list,


It most definitely does NOT look like that. It looks like a string with line terminators in it, as for example in:

Code:
>>> results = '''
!
interface GigabitEthernet0/1
 description Reserved for Infrastructure
 switchport access vlan 101
 switchport mode access
 spanning-tree portfast
end'''
>>> print(results)

!
interface GigabitEthernet0/1
 description Reserved for Infrastructure
 switchport access vlan 101
 switchport mode access
 spanning-tree portfast
end
>>> print(results[0])


>>> print(results[1])
!


But as b49P23TIvg already pointed out, it’s hard to see why results[0] could be “s” and results[1] “h”.
__________________
My armada: openSUSE 12.3 (home desktop, laptop, work desktop), Ubuntu 12.04 LTS (mini laptop), Debian GNU/Linux 7.0 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), FreeBSD 9.1 (test server)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Make a list into one big string

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap