473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

List conversion

Hello, I have a piece of code:

command = raw_input("command> ")
words = string.split(command, ' ')
temparg = words
if len(words)<= 3:
temparg = words[4:]
else:
temparg = words[5:]
funcarg = string.upper(temparg)
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(funcarg\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.org ( Note, it's not dead..under heavy contruction).
Gurus'Network - Are you a guru?
/me goes off and codes.
Mar 30 '06 #1
1 1506
yawgmoth7 wrote:
Hello, I have a piece of code:

command = raw_input("command> ")
words = string.split(command, ' ')
temparg = words
if len(words)<= 3:
temparg = words[4:]
else:
temparg = words[5:]
funcarg = string.upper(temparg)
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(words[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(funcarg\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 "programming 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(words)

'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
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...
2
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);...
65
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...
4
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...
2
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:...
8
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...
10
by: Angel Tsankov | last post by:
Hello! Is the following code illformed or does it yield undefined behaviour: class a {}; class b {
40
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...
4
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)) ...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.