python &#39

python &#39

Skip to content

Sign in
Sign up


  • Watch

    8


  • Star

    99


  • Fork

    89


/ Bokeh-Python-Visualization

Join GitHub today

GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.

Sign up

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account


AttributeError: ‘str’ object has no attribute ‘append’ using Python 3.5.3 and bokeh 0.12.16

#3


Closed

dazzag24 opened this Issue
May 24, 2018
· 2 comments

Comments

Labels
None yet

2 participants

@dazzag24

@WillKoehrsen

@dazzag24




Copy link

dazzag24

commented

May 24, 2018





I had to comment out these 2 lines in scripts/draw_map.py

hover_line.renderers.append(lines_glyph)
hover_circle.renderers.append(circles_glyph)

otherwise I would receive the following error and a blank page in the browser.

2018-05-24 16:59:06,237 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-05-24 16:59:06,243 Bokeh app running at: http://localhost:5006/bokeh_app
2018-05-24 16:59:06,243 Starting Bokeh server with process id: 18459
[18471:18493:0524/165906.877041:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process.
Created new window in existing browser session.
/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/pandas/core/frame.py:6201: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass ‘sort=True’.

To retain the current behavior and silence the warning, pass sort=False

sort=sort)
2018-05-24 16:59:10,798 Error running application handler <bokeh.application.handlers.directory.DirectoryHandler object at 0x7fe98e428fd0>: ‘str’ object has no attribute ‘append’
File “draw_map.py”, line 142, in make_plot:
hover_circle.renderers.append(circles_glyph) Traceback (most recent call last):
File “/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/bokeh/application/handlers/code_runner.py”, line 163, in run
exec(self._code, module.dict)
File “/home/foo/code/BokehDashbord/bokeh_app/main.py”, line 34, in
tab4 = map_tab(map_data, states)
File “/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py”, line 208, in map_tab
p = make_plot(src, xs, ys)
File “/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py”, line 142, in make_plot
hover_circle.renderers.append(circles_glyph)
AttributeError: ‘str’ object has no attribute ‘append’

@WillKoehrsen

This comment has been minimized.

Sign in to view




Copy link


Owner

WillKoehrsen

commented

May 24, 2018



edited




Thanks for pointing this out. I have made the fix in draw_map.py in the make_plot function:

  1. Remove the lines
    hover_circle.renderers.append(circles_glyph)
    and hover_line.renderers.append(line_glyph)

  2. Replace by adding the renderer argument to the HoverTool creation code:

# Hover tooltip for flight lines, assign only the line rendererhover_line = HoverTool(tooltips=[('Airline', '@carrier'),	('Number of Flights', '@count'),	('Average Delay', '@mean_delay0.0'),	('Max Delay', '@max_delay0.0'),	('Min Delay', '@min_delay0.0')], line_policy = 'next', renderers = [lines_glyph])
# Hover tooltip for origin and destination, assign only the circle rendererhover_circle = HoverTool(tooltips=[('Origin', '@origin'), ('Dest', '@dest'), ('Distance (miles)', '@distance')], renderers = [circles_glyph])
  1. Move the HoverTool creation code to affect the definition for circles_glyph and lines_glyph.

The most recent commit implements this change and the application is once again running.




@WillKoehrsen
WillKoehrsen

closed this

May 24, 2018



WillKoehrsen

added a commit
that referenced
this issue

May 24, 2018

@WillKoehrsen


Resolved issue #3


24103c2

@dazzag24

This comment has been minimized.

Sign in to view




Copy link

dazzag24

commented

May 25, 2018





Thanks. That works now.


Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

  • © 2018 GitHub, Inc.
  • Terms
  • Privacy
  • Security
  • Status
  • Help

  • Contact GitHub
  • Pricing
  • API
  • Training
  • Blog
  • About


You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.

Press h to open a hovercard with more details.
Skip to content

Sign in
Sign up


  • Watch

    8


  • Star

    99


  • Fork

    89


/ Bokeh-Python-Visualization

Join GitHub today

GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.

Sign up

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account


AttributeError: ‘str’ object has no attribute ‘append’ using Python 3.5.3 and bokeh 0.12.16

#3


Closed

dazzag24 opened this Issue
May 24, 2018
· 2 comments

Comments

Labels
None yet

2 participants

@dazzag24

@WillKoehrsen

@dazzag24




Copy link

dazzag24

commented

May 24, 2018





I had to comment out these 2 lines in scripts/draw_map.py

hover_line.renderers.append(lines_glyph)
hover_circle.renderers.append(circles_glyph)

otherwise I would receive the following error and a blank page in the browser.

2018-05-24 16:59:06,237 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-05-24 16:59:06,243 Bokeh app running at: http://localhost:5006/bokeh_app
2018-05-24 16:59:06,243 Starting Bokeh server with process id: 18459
[18471:18493:0524/165906.877041:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process.
Created new window in existing browser session.
/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/pandas/core/frame.py:6201: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass ‘sort=True’.

To retain the current behavior and silence the warning, pass sort=False

sort=sort)
2018-05-24 16:59:10,798 Error running application handler <bokeh.application.handlers.directory.DirectoryHandler object at 0x7fe98e428fd0>: ‘str’ object has no attribute ‘append’
File “draw_map.py”, line 142, in make_plot:
hover_circle.renderers.append(circles_glyph) Traceback (most recent call last):
File “/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/bokeh/application/handlers/code_runner.py”, line 163, in run
exec(self._code, module.dict)
File “/home/foo/code/BokehDashbord/bokeh_app/main.py”, line 34, in
tab4 = map_tab(map_data, states)
File “/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py”, line 208, in map_tab
p = make_plot(src, xs, ys)
File “/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py”, line 142, in make_plot
hover_circle.renderers.append(circles_glyph)
AttributeError: ‘str’ object has no attribute ‘append’

@WillKoehrsen

This comment has been minimized.

Sign in to view




Copy link


Owner

WillKoehrsen

commented

May 24, 2018



edited




Thanks for pointing this out. I have made the fix in draw_map.py in the make_plot function:

  1. Remove the lines
    hover_circle.renderers.append(circles_glyph)
    and hover_line.renderers.append(line_glyph)

  2. Replace by adding the renderer argument to the HoverTool creation code:

# Hover tooltip for flight lines, assign only the line rendererhover_line = HoverTool(tooltips=[('Airline', '@carrier'),	('Number of Flights', '@count'),	('Average Delay', '@mean_delay0.0'),	('Max Delay', '@max_delay0.0'),	('Min Delay', '@min_delay0.0')], line_policy = 'next', renderers = [lines_glyph])
# Hover tooltip for origin and destination, assign only the circle rendererhover_circle = HoverTool(tooltips=[('Origin', '@origin'), ('Dest', '@dest'), ('Distance (miles)', '@distance')], renderers = [circles_glyph])
  1. Move the HoverTool creation code to affect the definition for circles_glyph and lines_glyph.

The most recent commit implements this change and the application is once again running.




@WillKoehrsen
WillKoehrsen

closed this

May 24, 2018



WillKoehrsen

added a commit
that referenced
this issue

May 24, 2018

@WillKoehrsen


Resolved issue #3


24103c2

@dazzag24

This comment has been minimized.

Sign in to view




Copy link

dazzag24

commented

May 25, 2018





Thanks. That works now.


Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

  • © 2018 GitHub, Inc.
  • Terms
  • Privacy
  • Security
  • Status
  • Help

  • Contact GitHub
  • Pricing
  • API
  • Training
  • Blog
  • About


You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.

Press h to open a hovercard with more details.

Stack Overflow



  1. Log In
    Sign Up

  2. current community


    • Stack Overflow

      help
      chat

    • Meta Stack Overflow

    your communities

    Sign up or log in to customize your list.

    more stack exchange communities

    company blog

    • Tour

      Start here for a quick overview of the site

    • Help Center

      Detailed answers to any questions you might have

    • Meta

      Discuss the workings and policies of this site

    • About Us

      Learn more about Stack Overflow the company

    • Business

      Learn more about hiring developers or posting ads with us

By using our site, you acknowledge that you have read and understand our Cookie Policy , Privacy Policy , and our Terms of Service .

AttributeError: ‘str’ object has no attribute ‘append’

Ask Question


up vote
15
down vote

favorite

5
>>> myList[1]
'from form'
>>> myList[1].append(s)
Traceback (most recent call last): File "<pyshell#144>", line 1, in <module> myList[1].append(s)
AttributeError: 'str' object has no attribute 'append'
>>>

Why myList[1] is considered a 'str' object? mList[1] returns the first item in the list 'from form' but I cannot append to item 1 in the list myList. Thank you.

Edit01:

@pyfunc: Thank you for the explanation; now I understand.

I need to have a list of lists; so ‘from form’ should be a list. I did this (please correct if this not the right way):

>>> myList
[1, 'from form', [1, 2, 't']]
>>> s = myList[1]
>>> s
'from form'
>>> s = [myList[1]]
>>> s
['from form']
>>> myList[1] = s
>>> myList
[1, ['from form'], [1, 2, 't']]
>>> 

python

share | improve this question

edited Oct 23 ’10 at 20:16

asked Oct 23 ’10 at 19:59

Zeynel

4,5292076127

  • 1

    mList[1] returns second item of the mList
    –  SilentGhost
    Oct 23 ’10 at 20:06

add a comment  | 

4 Answers
4

active

oldest

votes


up vote
18
down vote

accepted

myList[1] is an element of myList and it’s type is string.

myList[1] is str, you can not append to it.
myList is a list, you should have been appending to it.

>>> myList = [1, 'from form', [1,2]]
>>> myList[1]
'from form'
>>> myList[2]
[1, 2]
>>> myList[2].append('t')
>>> myList
[1, 'from form', [1, 2, 't']]
>>> myList[1].append('t')
Traceback (most recent call last): File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'append'
>>> 

share | improve this answer

answered Oct 23 ’10 at 20:00

pyfunc

51.7k12124125

add a comment  | 


up vote
5
down vote

If you want to append a value to myList, use myList.append(s).

Strings are immutable — you can’t append to them.

share | improve this answer

answered Oct 23 ’10 at 20:00

bstpierre

19.9k145495

add a comment  | 


up vote
1
down vote

Why myList[1] is considered a ‘str’ object?

Because it is a string. What else is 'from form', if not a string? (Actually, strings are sequences too, i.e. they can be indexed, sliced, iterated, etc. as well – but that’s part of the str class and doesn’t make it a list or something).

mList[1] returns the first item in the list 'from form'

If you mean that myList is 'from form', no it’s not!!! The second (indexing starts at 0) element is 'from form'. That’s a BIG difference. It’s the difference between a house and a person.

Also, myList doesn’t have to be a list from your short code sample – it could be anything that accepts 1 as index – a dict with 1 as index, a list, a tuple, most other sequences, etc. But that’s irrelevant.

but I cannot append to item 1 in the list myList

Of course not, because it’s a string and you can’t append to string. String are immutable. You can concatenate (as in, “there’s a new object that consists of these two”) strings. But you cannot append (as in, “this specific object now has this at the end”) to them.

share | improve this answer

answered Oct 23 ’10 at 20:09
user395760

  • Thanks for the explanation; now I understand that myList[1] is the string "from form".
    –  Zeynel
    Oct 23 ’10 at 20:22

add a comment  | 


up vote
1
down vote

What you are trying to do is add additional information to each item in the list that you already created so

 alist[ 'from form', 'stuff 2', 'stuff 3'] for j in range( 0,len[alist]): temp= [] temp.append(alist[j]) # alist[0] is 'from form' temp.append('t') # slot for first piece of data 't' temp.append('-') # slot for second piece of data blist.append(temp) # will be alist with 2 additional fields for extra stuff assocated with each item in alist 

share | improve this answer

answered Mar 14 ’15 at 15:53

Dr. Bob

111

add a comment  | 

Not the answer you’re looking for? Browse other questions tagged python or ask your own question .

asked

8 years, 1 month ago

viewed

143,078 times

active

3 years, 8 months ago

Linked

0

AttributeError: str has no attribute append ( web scrapping , links )

0

Python AttributeError: ‘str’ object has no attribute ‘append’

0

AttributeError: ‘str’ object has no attribute ‘sign’

Related

2848

Difference between append vs. extend list methods in Python

1212

How to know if an object has an attribute in Python

1482

Determine the type of an object?

100

AttributeError: ‘module’ object has no attribute ‘urlopen’

1249

How do you append to a file?

2

Python – AttributeError: ‘str’ object has no attribute ‘append’

0

Python list append to list “AttributeError: ‘tuple’ object has no attribute ‘append’”

0

Object has no attribute error

-1

AttributeError: ‘str’ object has no attribute ‘append’ python

-1

Python AttributeError: ‘str’ object has no attribute ‘pop’ Learnpythonthehardway

Hot Network Questions

  • Dealing with a team member who ignores company structure

  • Could "live" video be transmitted from Mars?

  • What is a common name and response for when someone gives little information for the sole purpose of getting people to ask what happened?

  • I’m chopped. Yet, I’m joined

  • Taking an Emotional Support Animal on an overnight trip to Hawaii

  • Double checkmark symbol

  • How can I be more frugal with salt when cooking (dried) pasta?

  • How do PCIe to SATA expansion cards work, and does my PC support them?

  • Why is PCA sensitive to outliers?

  • Is there any way to fake/conceal your identity when casting Sending?

  • Software that shows space travel accurately in 3d from a physics point of view

  • How to convey to foreign recruiters that the education I received from a catholic university was in no way religious?

  • Should software refer to itself in the first-person, especially in error messages?

  • Why is May in charge of Brexit negotiations? What happened to the prominent Brexiteers?

  • What logical fallacy is "If you don’t like it, move!"?

  • submission review is taking too long

  • Pronunciation of PhD

  • Does the EU require preferential trade within itself?

  • What will become of the two cubesats deployed as part of the Insight mission?

  • Is there a term for "the user can’t use anything wrong" design?

  • Where can I find the primary source for Herodotus’ Histories?

  • What’s the Difference?

  • Does my racial feature count as a spell or cantrip?

  • Can an HTTPS server accidentally leak its private key?

more hot questions


question feed

lang-py

Stack Overflow works best with JavaScript enabled

This forum is now read-only.
Please use our new forums at discuss.codecademy.com .

724 points
0ca3ceda1c3406f6e94c3d5480696215?s=140&d=retro
Submitted by
JackVo
over 3 years ago

16/18 : AttributeError: 'str' object has no attribute 'append'

I have my code below :

n = ["Michael", "Lieberman"]
def join_strings(words):
result = ""
for i in range(len(words)): result.append(words[i])
return result
print join_strings(n)

The error message is :

Traceback (most recent call last):
File "python", line 8 , in
File "python", line 6 , in join_strings
AttributeError: ‘str’ object has no
attribute ‘append’

Please help to solve this issue ?


1 vote

permalink

n = ["Michael", "Lieberman"] # Add your function here def join_strings(words): result = "" for w in words: result = result + w return result print join_strings(n)

200 points
B997e9b726d35233b07df3525de4532e?s=140&d=retro
Submitted by
Kenny John
over 3 years ago


-1 votes

permalink

Ok I found that reason.
In Instructions tab, you knew that on step 3 :

Iterate through the words list and append each word to result.

Please notice that "append" not mean use append function in this case.
So after for loop, you should use the operator below :

result += words[i]

And it’s successful.

724 points
0ca3ceda1c3406f6e94c3d5480696215?s=140&d=retro
Submitted by
JackVo
over 3 years ago

This forum is now read-only.
Please use our new forums at discuss.codecademy.com .

724 points
0ca3ceda1c3406f6e94c3d5480696215?s=140&d=retro
Submitted by
JackVo
over 3 years ago

16/18 : AttributeError: 'str' object has no attribute 'append'

I have my code below :

n = ["Michael", "Lieberman"]
def join_strings(words):
result = ""
for i in range(len(words)): result.append(words[i])
return result
print join_strings(n)

The error message is :

Traceback (most recent call last):
File "python", line 8 , in
File "python", line 6 , in join_strings
AttributeError: ‘str’ object has no
attribute ‘append’

Please help to solve this issue ?


1 vote

permalink

n = ["Michael", "Lieberman"] # Add your function here def join_strings(words): result = "" for w in words: result = result + w return result print join_strings(n)

200 points
B997e9b726d35233b07df3525de4532e?s=140&d=retro
Submitted by
Kenny John
over 3 years ago


-1 votes

permalink

Ok I found that reason.
In Instructions tab, you knew that on step 3 :

Iterate through the words list and append each word to result.

Please notice that "append" not mean use append function in this case.
So after for loop, you should use the operator below :

result += words[i]

And it’s successful.

724 points
0ca3ceda1c3406f6e94c3d5480696215?s=140&d=retro
Submitted by
JackVo
over 3 years ago