473,387 Members | 1,812 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,387 software developers and data experts.

attribute error

HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

but i always thought that something like this will be standard stuff.
Any ideas?

thanks
moe smadi
Sep 26 '05 #1
9 5543
On Mon, 26 Sep 2005 18:28:56 -0400, M.N.A.Smadi wrote:
HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'


Since you haven't told us what you have passed as argv, I will look into
my crystal ball and use my psychic powers...

Things are unclear... no, wait, I see a glimmer of light... are you using
a single string, something like "this is a list of arguments"? The
function is expecting a list of strings ["this", "is", "a", "list", "of",
"arguments"].

You may find the split() method useful for breaking up a single string
into a list of strings.
--
Steven.

Sep 26 '05 #2
"M.N.A.Smadi" <sm*****@grads.ece.mcmaster.ca> writes:
HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

but i always thought that something like this will be standard stuff.
Any ideas?


Yes - show us the rest of the code. execute_action is never called in
the snippets you posted, and it's pretty clear that it's being invoked
with the wrong thing as an argument. Can you provide a minimal working
(well, executable) code sample that generates the error message you
are getting?

Oh yeah - post the full traceback as well.

<mike

--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Sep 26 '05 #3
HI;

I am having the following error:

AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

The code being executed is:
if command not in commands:
raise ArgumentsError('invalid arguments.')

if command == 'usage':
return usage(argv[0], sys.stdout)

manager = Manager.Manager(*Config.Config().get_connection())

if command == 'actions':
show_actions()

if command == 'help':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

show_actions(argv[2])

elif command == 'action':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

try:
execute_action(manager, argv[2:])
except TypeError, e:
print "Bad arguments specified. Help for %s:" % (argv[2],)
show_actions(argv[2])

elif command == 'command':
execute_action('command', argv[2])

def execute_action(manager, argv):
method_name = argv.pop(0).lower()

but i always thought that something like this will be standard stuff.
Any ideas?
Mike Meyer wrote:
"M.N.A.Smadi" <sm*****@grads.ece.mcmaster.ca> writes:
HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

but i always thought that something like this will be standard stuff.
Any ideas?


Yes - show us the rest of the code. execute_action is never called in
the snippets you posted, and it's pretty clear that it's being invoked
with the wrong thing as an argument. Can you provide a minimal working
(well, executable) code sample that generates the error message you
are getting?

Oh yeah - post the full traceback as well.

<mike


Sep 29 '05 #4
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:
HI;

I am having the following error:

AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

The code being executed is:
if command not in commands:
raise ArgumentsError('invalid arguments.')

if command == 'usage':
return usage(argv[0], sys.stdout)

manager = Manager.Manager(*Config.Config().get_connection())

if command == 'actions':
show_actions()

if command == 'help':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

show_actions(argv[2])

elif command == 'action':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

try:
execute_action(manager, argv[2:])
except TypeError, e:
print "Bad arguments specified. Help for %s:" % (argv[2],)
show_actions(argv[2])

elif command == 'command':
execute_action('command', argv[2])
This should be execute_action('command', argv[2:]), with the ':' added.

<mike
def execute_action(manager, argv):
method_name = argv.pop(0).lower()

but i always thought that something like this will be standard stuff.
Any ideas?
Mike Meyer wrote:
"M.N.A.Smadi" <sm*****@grads.ece.mcmaster.ca> writes:
HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

but i always thought that something like this will be standard stuff.
Any ideas?


Yes - show us the rest of the code. execute_action is never called in
the snippets you posted, and it's pretty clear that it's being invoked
with the wrong thing as an argument. Can you provide a minimal working
(well, executable) code sample that generates the error message you
are getting?

Oh yeah - post the full traceback as well.

<mike



--
Mike Meyer <mw*@mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
Sep 29 '05 #5
This has nothing to do with how the argument is passed. It is prob
something wrong with str.pop in my python because when i run python and type
import os
import string
x = '1 2 3'
x.pop()

i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop'
Mike Meyer wrote:
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:

HI;

I am having the following error:

AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

The code being executed is:
if command not in commands:
raise ArgumentsError('invalid arguments.')

if command == 'usage':
return usage(argv[0], sys.stdout)

manager = Manager.Manager(*Config.Config().get_connection())

if command == 'actions':
show_actions()

if command == 'help':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

show_actions(argv[2])

elif command == 'action':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

try:
execute_action(manager, argv[2:])
except TypeError, e:
print "Bad arguments specified. Help for %s:" % (argv[2],)
show_actions(argv[2])

elif command == 'command':
execute_action('command', argv[2])


This should be execute_action('command', argv[2:]), with the ':' added.

<mike
def execute_action(manager, argv):
method_name = argv.pop(0).lower()

but i always thought that something like this will be standard stuff.
Any ideas?
Mike Meyer wrote:
"M.N.A.Smadi" <sm*****@grads.ece.mcmaster.ca> writes:

HI;

I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then

def execute_action(manager, argv):
method_name = argv.pop(0).lower()
and am getting this strange error.
AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

but i always thought that something like this will be standard stuff.
Any ideas?


Yes - show us the rest of the code. execute_action is never called in
the snippets you posted, and it's pretty clear that it's being invoked
with the wrong thing as an argument. Can you provide a minimal working
(well, executable) code sample that generates the error message you
are getting?

Oh yeah - post the full traceback as well.

<mike





Sep 29 '05 #6
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:
This has nothing to do with how the argument is passed. It is prob
something wrong with str.pop in my python because when i run python and type
import os
import string
x = '1 2 3'
x.pop()

i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop'
The only thing wrong with str.pop is that you're trying to invoke
it. The interpreter is telling you that string doesn't *have* a pop
method. The interpreter is right. Strings are immutable, so "pop"
doesn't make any sense for them.

<mike

Mike Meyer wrote:
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:

HI;

I am having the following error:

AttributeError: 'str' object has no attribute 'pop'

am using Python 2.3.4 and am importing the following libraries:

import sys, os, inspect
from Asterisk import Manager, BaseException, Config
import Asterisk.Util

The code being executed is:
if command not in commands:
raise ArgumentsError('invalid arguments.')

if command == 'usage':
return usage(argv[0], sys.stdout)

manager = Manager.Manager(*Config.Config().get_connection())

if command == 'actions':
show_actions()

if command == 'help':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

show_actions(argv[2])

elif command == 'action':
if len(argv) < 3:
raise ArgumentsError('please specify an action.')

try:
execute_action(manager, argv[2:])
except TypeError, e:
print "Bad arguments specified. Help for %s:" % (argv[2],)
show_actions(argv[2])

elif command == 'command':
execute_action('command', argv[2])


This should be execute_action('command', argv[2:]), with the ':' added.

<mike
def execute_action(manager, argv):
method_name = argv.pop(0).lower()

but i always thought that something like this will be standard stuff.
Any ideas?
Mike Meyer wrote:

"M.N.A.Smadi" <sm*****@grads.ece.mcmaster.ca> writes:

>HI;
>
>I am having the following error. I am using someone else's code and
>all they are doing is pass an argv to a function then
>
>def execute_action(manager, argv):
> method_name = argv.pop(0).lower()
>
>
>and am getting this strange error.
>AttributeError: 'str' object has no attribute 'pop'
>
>am using Python 2.3.4 and am importing the following libraries:
>
>import sys, os, inspect
>
>
>from Asterisk import Manager, BaseException, Config
>import Asterisk.Util
>
>but i always thought that something like this will be standard stuff.
>Any ideas?
>
>
>
>
Yes - show us the rest of the code. execute_action is never called in
the snippets you posted, and it's pretty clear that it's being invoked
with the wrong thing as an argument. Can you provide a minimal working
(well, executable) code sample that generates the error message you
are getting?

Oh yeah - post the full traceback as well.

<mike





--
Mike Meyer <mw*@mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
Sep 29 '05 #7
Mike Meyer wrote:
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:
This has nothing to do with how the argument is passed. It is prob
something wrong with str.pop in my python because when i run python and type
import os
import string
x = '1 2 3'
x.pop()

i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop'

The only thing wrong with str.pop is that you're trying to invoke
it. The interpreter is telling you that string doesn't *have* a pop
method. The interpreter is right. Strings are immutable, so "pop"
doesn't make any sense for them.

<mike
[...]


Just to hammer the point home:

Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
x = '1 2 3'
x.pop() Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop' x = [1, 2, 3]
x.pop() 3 x.pop() 2 x [1]


So if you genuinely have a string containing the values, split it onto a
list first using something like

x = x.split()

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org
Sep 29 '05 #8
Mike Meyer wrote:
In <43**************@grads.ece.mcmaster.ca>, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> typed:
This has nothing to do with how the argument is passed. It is prob
something wrong with str.pop in my python because when i run python and type
import os
import string
x = '1 2 3'
x.pop()

i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop'

The only thing wrong with str.pop is that you're trying to invoke
it. The interpreter is telling you that string doesn't *have* a pop
method. The interpreter is right. Strings are immutable, so "pop"
doesn't make any sense for them.

<mike
[...]


Just to hammer the point home:

Python 2.4.1 (#1, May 27 2005, 18:02:40)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
x = '1 2 3'
x.pop() Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop' x = [1, 2, 3]
x.pop() 3 x.pop() 2 x [1]


So if you genuinely have a string containing the values, split it onto a
list first using something like

x = x.split()

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.pycon.org

Sep 29 '05 #9
On Thu, 29 Sep 2005 15:57:47 -0400, M.N.A.Smadi wrote:
This has nothing to do with how the argument is passed. It is prob
something wrong with str.pop in my python because when i run python and type
import os
import string
x = '1 2 3'
x.pop()

i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'str' object has no attribute 'pop'

That's because strings don't have a pop method, just like the error says.
Did you read the error? Error messages frequently tell you what the error
is.

Lists have a pop method. You can't pop from a string. If you try
to pop from a string, you will get an error. You tried to pop from a
string, and it gave an error. The error told you what you did wrong:
you tried to pop from a string. Why are you surprised?

Go back to your code. Look at the variable that you are trying to pop
from, and notice that it is a string, just like the error message says.
Now search back through your code until you find the place where you
assign a string to that variable. Don't assign a string to it.

Problem fixed.

Like I said the first time I answered your question, I think your problem
is that you are passing in a single argument string like:

"this is a list of commands"

instead of a real list like:

["this", "is", "a", "list", "of", "commands"]

As I also said the first time I answered this, you may find the split()
string method useful for creating that list. (Hint: if x is a string, you
call x.split() and get back a list.)

For future reference: any time you think you have found a bug in Python,
the chances are about 999,999 in a million that you've found a bug in your
code.
--
Steven.

Sep 29 '05 #10

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

Similar topics

2
by: bjam | last post by:
Hi, I am hoping someone can answer the following question it seems when I put in an & in the query string to be translated as the link in the XML to HTML I get an error, just using the ? mark is...
4
by: Manuel Faux | last post by:
Hello! I used the "File Upload - Validator" and the result is like the following: Line 13, column 204: there is no attribute "border" ....irefox!" title="Get Firefox!" border="0" /></a></p>...
2
by: Keith Chadwick | last post by:
Is there a way to append to an attribute in XSLT. For example: <input name="emailaddress" style="width:200px"> <xsl:apply-templates select="//object"/> </input> <xsl:template...
2
by: Ian Griffiths | last post by:
I have been given a schema, instances of which I'm required to be able to consume and generate. I'd like to be able to manipulate these instances as DataSets internally in my application. The...
0
by: Doug Bailey | last post by:
I am trying to create a coclass attribute for an outproc COM server (i.e. an EXE). The project was created using the ATL Project wizard using .NET2003. The coclass is defined as follows: ...
3
by: Peter Seif | last post by:
I have a PC that has windows 2000 Server ,Microsoft .Net Framework 1.0 installed First time I tried to create a web application and debug it i had the error "unable to debub ..." so i changed the...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
3
by: Andy | last post by:
Hello Guys: What am I doing wrong with this code? I can't seem to get it to simply add an attribute to my node. The node already exists. I am simply opening the XMLDocument and creating one...
0
by: Aray | last post by:
Let us see the test file following: -------file nowork.xsd begin----------- <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
by: BiraRai | last post by:
def getAttributeForProperty(self,rollnumber,attribute): # attribute have the value _ward ''' If year is null then use current year. Returns the value of the attribute for the given roll number...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.