473,832 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List conversion

Hello, I have a piece of code:

command = raw_input("comm and> ")
words = string.split(co mmand, ' ')
temparg = words
if len(words)<= 3:
temparg = words[4:]
else:
temparg = words[5:]
funcarg = string.upper(te mparg)
str(funcarg)
continue

There's a little snippet of code from my script, it all looks fine,
well, then I have a function that looks something like:

def nick(funcarg):
sock.send(funca rg\r\n)
Well, that's okay, but i get this error when I try to run that command
at the commmand prompt like enviroment I wrote:

TypeError: send() argument 1 must be string or read-only buffer, not list

Well, that is why I put in the str(funcarg) line, hoping that it would
convert it to a string, instead of being a list, does anyone have any
suggestions, thanks, bye.
--
gurusnetwork.or g ( Note, it's not dead..under heavy contruction).
Gurus'Network - Are you a guru?
/me goes off and codes.
Mar 30 '06 #1
1 1525
yawgmoth7 wrote:
Hello, I have a piece of code:

command = raw_input("comm and> ")
words = string.split(co mmand, ' ')
temparg = words
if len(words)<= 3:
temparg = words[4:]
else:
temparg = words[5:]
funcarg = string.upper(te mparg)
str(funcarg)
continue

There's a little snippet of code from my script, it all looks fine,
Well, I'm sorry to have to say this, but it doesn't look fine at all:
words = "one two three".split()
words ['one', 'two', 'three'] len(words) 3 words[4:] [] import string
string.upper(wo rds[4:]) Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib64/python2.4/string.py", line 235, in upper
return s.upper()
AttributeError: 'list' object has no attribute 'upper' str(words[4:]) '[]' words[4:] []
Python comes with an interactive interpreter that makes testing and
exploring a breeze. Why not using it to see how things works and avoid
obvious errors ?-)
well, then I have a function that looks something like:

def nick(funcarg):
sock.send(funca rg\r\n)
Either it's not your real code or you should have another error:
def send(aString): .... print "sending %s" % aString
.... send(words[4:]\r\n) File "<stdin>", line 1
send(words[4:]\r\n)
^
SyntaxError: invalid token
Well, that's okay, but i get this error when I try to run that command
at the commmand prompt like enviroment I wrote:

TypeError: send() argument 1 must be string or read-only buffer, not list

Well, that is why I put in the str(funcarg) line, hoping that it would
convert it to a string,
This is called "programmin g by accident", and it's the worst thing to
do. Don't "hope", try and make sure:
str(words) "['one', 'two', 'three']" words ['one', 'two', 'three']
As you can see, str() :
- returns a *representation * of it's arg as a string - but this
representation may not be what your looking for
- does *not* modify it's argument.

What you want here is to join the parts of the list:
" ".join(word s)

'one two three'

instead of being a list, does anyone have any
suggestions,
Yes :
1/ there are at least two good tutorials, the one in the official
documentation and Dive Into Python (diveintopython .org IIRC).

2/ don't guess, don't hope, *test* (hint : use the interactive interpreter).

3/ (optional) don't hold it against me if all this sounds a bit harsh.

thanks, bye. --


<OT>
needs a whitespace after the two dashes. It's '-- ', not '--'.
</OT>

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Mar 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2311
by: Michele Simionato | last post by:
Let me show first how does it work for tuples: >>> class MyTuple(tuple): .... def __new__(cls,strng): # implicit conversion string of ints => tuple .... return super(MyTuple,cls).__new__(cls,map(int,strng.split())) >>> MyTuple('1 2') (1, 2) No wonder here, everything is fine. However, if I do the same for lists I get the following:
2
2394
by: Alexander Malkis | last post by:
//Consider: class A { /*...*/ }; template<class T> class list {/*... */ }; void f(const list<const A*> lst) { /*...doesn't change the arg...*/ } void g(list<A*> lst) { f(lst); //Intuitively ok, but compiler rejects. }
65
4256
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the difference is between these and: (3) mylist =
4
2283
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option value="2">2</option>
2
3246
by: k1ckthem1dget | last post by:
I need to display the unsorted list of names and display the sorted list of names. My program is getting a bunch of errors though, and i dont know why. I am getting the following errors. 28: error: cannot convert `char (*)' to `int*' for argument `1' to `void showArray(int*, int)' 33: error: expected unqualified-id before "for" 33: error: expected constructor, destructor, or type conversion before '<' token 33: error: expected...
8
8470
by: Neil Webster | last post by:
Hi, I was wondering whether anybody could help me out. I have a program, for part of it I am trying to pass a variable to a glob function, this returns an empty list. The strange thing is when I hard code in the variable the glob section works. Does anybody have any ideas as why it is not working?
10
2747
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
40
2739
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
4
1315
by: thomas.pohl | last post by:
Hi, let's assume you want to nicely print the content of a list except for one (or some) individual item. You could do it like this: t = print("text: %s\nvalues: %i %i %i" % (t, t, t, t)) If there was a conversion type which simply ignores the corresponding list item
5
2908
by: shapper | last post by:
Hello, I have a Linq query which returns items of List<TagTags = new List<Tag(from t in database.Tags where t.Category = MyCategory).ToList(); Each tag has three properties: ID, Name and Category
0
9795
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10498
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10540
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5623
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3077
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.