[{"data":1,"prerenderedAt":1736},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fattributeerror-str-object-has-no-attribute-fix":3},{"id":4,"title":5,"body":6,"description":1729,"extension":1730,"meta":1731,"navigation":82,"path":1732,"seo":1733,"stem":1734,"__hash__":1735},"content\u002Ferrors\u002Fattributeerror-str-object-has-no-attribute-fix.md","AttributeError: 'str' object has no attribute (Fix)",{"type":7,"value":8,"toc":1697},"minimark",[9,19,23,26,36,39,44,210,213,292,299,303,306,309,337,340,354,357,374,378,381,402,405,446,453,477,484,488,496,533,539,542,586,592,628,633,636,644,686,691,694,768,770,779,790,797,834,846,850,885,894,897,924,928,931,983,986,1086,1088,1165,1172,1176,1179,1203,1206,1281,1284,1316,1322,1325,1328,1345,1348,1382,1385,1412,1415,1468,1470,1479,1483,1486,1526,1529,1555,1559,1563,1569,1573,1578,1609,1620,1627,1633,1640,1647,1653,1660,1664,1693],[10,11,13,14,18],"h1",{"id":12},"attributeerror-str-object-has-no-attribute-fix","AttributeError: ",[15,16,17],"code",{},"'str' object has no attribute"," (Fix)",[20,21,22],"p",{},"This error happens when your variable is a string, but your code uses a method or attribute that does not belong to Python strings.",[20,24,25],{},"In simple terms, Python is telling you:",[27,28,29,33],"ul",{},[30,31,32],"li",{},"“This value is text”",[30,34,35],{},"“The thing after the dot does not exist on text”",[20,37,38],{},"This often happens when you expected a list, dictionary, or custom object, but the variable is actually a string.",[40,41,43],"h2",{"id":42},"quick-fix","Quick fix",[45,46,51],"pre",{"className":47,"code":48,"language":49,"meta":50,"style":50},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","value = \"hello\"\n\n# Wrong: strings do not have append()\n# value.append(\"!\")\n\n# Fix 1: use string concatenation\nvalue = value + \"!\"\nprint(value)\n\n# Fix 2: convert to the right type before using list methods\nchars = list(value)\nchars.append(\"?\")\nprint(chars)\n","python","",[15,52,53,77,84,91,97,102,108,128,146,151,157,175,199],{"__ignoreMap":50},[54,55,58,62,66,70,74],"span",{"class":56,"line":57},"line",1,[54,59,61],{"class":60},"su5hD","value ",[54,63,65],{"class":64},"smGrS","=",[54,67,69],{"class":68},"sjJ54"," \"",[54,71,73],{"class":72},"s_sjI","hello",[54,75,76],{"class":68},"\"\n",[54,78,80],{"class":56,"line":79},2,[54,81,83],{"emptyLinePlaceholder":82},true,"\n",[54,85,87],{"class":56,"line":86},3,[54,88,90],{"class":89},"sutJx","# Wrong: strings do not have append()\n",[54,92,94],{"class":56,"line":93},4,[54,95,96],{"class":89},"# value.append(\"!\")\n",[54,98,100],{"class":56,"line":99},5,[54,101,83],{"emptyLinePlaceholder":82},[54,103,105],{"class":56,"line":104},6,[54,106,107],{"class":89},"# Fix 1: use string concatenation\n",[54,109,111,113,115,118,121,123,126],{"class":56,"line":110},7,[54,112,61],{"class":60},[54,114,65],{"class":64},[54,116,117],{"class":60}," value ",[54,119,120],{"class":64},"+",[54,122,69],{"class":68},[54,124,125],{"class":72},"!",[54,127,76],{"class":68},[54,129,131,135,139,143],{"class":56,"line":130},8,[54,132,134],{"class":133},"sptTA","print",[54,136,138],{"class":137},"sP7_E","(",[54,140,142],{"class":141},"slqww","value",[54,144,145],{"class":137},")\n",[54,147,149],{"class":56,"line":148},9,[54,150,83],{"emptyLinePlaceholder":82},[54,152,154],{"class":56,"line":153},10,[54,155,156],{"class":89},"# Fix 2: convert to the right type before using list methods\n",[54,158,160,163,165,169,171,173],{"class":56,"line":159},11,[54,161,162],{"class":60},"chars ",[54,164,65],{"class":64},[54,166,168],{"class":167},"sZMiF"," list",[54,170,138],{"class":137},[54,172,142],{"class":141},[54,174,145],{"class":137},[54,176,178,181,184,187,189,192,195,197],{"class":56,"line":177},12,[54,179,180],{"class":60},"chars",[54,182,183],{"class":137},".",[54,185,186],{"class":141},"append",[54,188,138],{"class":137},[54,190,191],{"class":68},"\"",[54,193,194],{"class":72},"?",[54,196,191],{"class":68},[54,198,145],{"class":137},[54,200,202,204,206,208],{"class":56,"line":201},13,[54,203,134],{"class":133},[54,205,138],{"class":137},[54,207,180],{"class":141},[54,209,145],{"class":137},[20,211,212],{},"Expected output:",[45,214,216],{"className":47,"code":215,"language":49,"meta":50,"style":50},"hello!\n['h', 'e', 'l', 'l', 'o', '!', '?']\n",[15,217,218,223],{"__ignoreMap":50},[54,219,220],{"class":56,"line":57},[54,221,222],{"class":60},"hello!\n",[54,224,225,228,231,234,236,239,242,245,247,249,251,254,256,258,260,262,264,266,268,271,273,275,277,279,281,283,285,287,289],{"class":56,"line":79},[54,226,227],{"class":137},"[",[54,229,230],{"class":68},"'",[54,232,233],{"class":72},"h",[54,235,230],{"class":68},[54,237,238],{"class":137},",",[54,240,241],{"class":68}," '",[54,243,244],{"class":72},"e",[54,246,230],{"class":68},[54,248,238],{"class":137},[54,250,241],{"class":68},[54,252,253],{"class":72},"l",[54,255,230],{"class":68},[54,257,238],{"class":137},[54,259,241],{"class":68},[54,261,253],{"class":72},[54,263,230],{"class":68},[54,265,238],{"class":137},[54,267,241],{"class":68},[54,269,270],{"class":72},"o",[54,272,230],{"class":68},[54,274,238],{"class":137},[54,276,241],{"class":68},[54,278,125],{"class":72},[54,280,230],{"class":68},[54,282,238],{"class":137},[54,284,241],{"class":68},[54,286,194],{"class":72},[54,288,230],{"class":68},[54,290,291],{"class":137},"]\n",[20,293,294,295,298],{},"First check the type of the variable with ",[15,296,297],{},"type(value)",". This error usually means you expected a list, dictionary, or custom object, but the variable is actually a string.",[40,300,302],{"id":301},"what-this-error-means","What this error means",[20,304,305],{},"Python raises this error when you try to use an attribute or method that a string does not have.",[20,307,308],{},"An attribute is the part after the dot:",[45,310,312],{"className":47,"code":311,"language":49,"meta":50,"style":50},"name.lower()\nname.append()\n",[15,313,314,327],{"__ignoreMap":50},[54,315,316,319,321,324],{"class":56,"line":57},[54,317,318],{"class":60},"name",[54,320,183],{"class":137},[54,322,323],{"class":141},"lower",[54,325,326],{"class":137},"()\n",[54,328,329,331,333,335],{"class":56,"line":79},[54,330,318],{"class":60},[54,332,183],{"class":137},[54,334,186],{"class":141},[54,336,326],{"class":137},[20,338,339],{},"Here:",[27,341,342,348],{},[30,343,344,347],{},[15,345,346],{},"lower()"," is a valid string method",[30,349,350,353],{},[15,351,352],{},"append()"," is not a string method",[20,355,356],{},"Some methods belong to strings, but many belong to other types like lists or dictionaries.",[20,358,359,360,365,366,183],{},"The main fix is to confirm the variable type and use a method that matches that type. If you need a refresher, see ",[361,362,364],"a",{"href":363},"\u002Flearn\u002Fpython-strings-explained-basics-and-examples\u002F","Python strings explained"," and ",[361,367,369,370,373],{"href":368},"\u002Freference\u002Fpython-type-function-explained\u002F","the Python ",[15,371,372],{},"type()"," function",[40,375,377],{"id":376},"why-this-happens","Why this happens",[20,379,380],{},"Common reasons include:",[27,382,383,386,389,392,399],{},[30,384,385],{},"You thought the variable was a list, but it is actually a string.",[30,387,388],{},"You tried to call a dictionary method on text data.",[30,390,391],{},"You reassigned a variable and changed its type earlier in the code.",[30,393,394,395,398],{},"User input from ",[15,396,397],{},"input()"," is always a string unless you convert it.",[30,400,401],{},"Data read from a file or API may be text, not a Python object yet.",[20,403,404],{},"For example, this is a very common mistake:",[45,406,408],{"className":47,"code":407,"language":49,"meta":50,"style":50},"value = input(\"Enter numbers: \")\nprint(type(value))\n",[15,409,410,430],{"__ignoreMap":50},[54,411,412,414,416,419,421,423,426,428],{"class":56,"line":57},[54,413,61],{"class":60},[54,415,65],{"class":64},[54,417,418],{"class":133}," input",[54,420,138],{"class":137},[54,422,191],{"class":68},[54,424,425],{"class":72},"Enter numbers: ",[54,427,191],{"class":68},[54,429,145],{"class":137},[54,431,432,434,436,439,441,443],{"class":56,"line":79},[54,433,134],{"class":133},[54,435,138],{"class":137},[54,437,438],{"class":167},"type",[54,440,138],{"class":137},[54,442,142],{"class":141},[54,444,445],{"class":137},"))\n",[20,447,448,449,452],{},"If the user types ",[15,450,451],{},"123",", the result is still a string:",[45,454,456],{"className":47,"code":455,"language":49,"meta":50,"style":50},"\u003Cclass 'str'>\n",[15,457,458],{"__ignoreMap":50},[54,459,460,463,467,469,472,474],{"class":56,"line":57},[54,461,462],{"class":64},"\u003C",[54,464,466],{"class":465},"sbsja","class",[54,468,241],{"class":68},[54,470,471],{"class":72},"str",[54,473,230],{"class":68},[54,475,476],{"class":64},">\n",[20,478,479,480,183],{},"If you need a number, convert it first. See ",[361,481,483],{"href":482},"\u002Fhow-to\u002Fhow-to-convert-string-to-int-in-python\u002F","how to convert a string to int in Python",[40,485,487],{"id":486},"common-examples-that-cause-the-error","Common examples that cause the error",[489,490,492,493,495],"h3",{"id":491},"calling-append-on-a-string","Calling ",[15,494,352],{}," on a string",[45,497,499],{"className":47,"code":498,"language":49,"meta":50,"style":50},"text = \"hello\"\ntext.append(\"!\")\n",[15,500,501,514],{"__ignoreMap":50},[54,502,503,506,508,510,512],{"class":56,"line":57},[54,504,505],{"class":60},"text ",[54,507,65],{"class":64},[54,509,69],{"class":68},[54,511,73],{"class":72},[54,513,76],{"class":68},[54,515,516,519,521,523,525,527,529,531],{"class":56,"line":79},[54,517,518],{"class":60},"text",[54,520,183],{"class":137},[54,522,186],{"class":141},[54,524,138],{"class":137},[54,526,191],{"class":68},[54,528,125],{"class":72},[54,530,191],{"class":68},[54,532,145],{"class":137},[20,534,535,536,538],{},"This fails because ",[15,537,352],{}," is a list method, not a string method.",[20,540,541],{},"Fix:",[45,543,545],{"className":47,"code":544,"language":49,"meta":50,"style":50},"text = \"hello\"\ntext = text + \"!\"\nprint(text)\n",[15,546,547,559,576],{"__ignoreMap":50},[54,548,549,551,553,555,557],{"class":56,"line":57},[54,550,505],{"class":60},[54,552,65],{"class":64},[54,554,69],{"class":68},[54,556,73],{"class":72},[54,558,76],{"class":68},[54,560,561,563,565,568,570,572,574],{"class":56,"line":79},[54,562,505],{"class":60},[54,564,65],{"class":64},[54,566,567],{"class":60}," text ",[54,569,120],{"class":64},[54,571,69],{"class":68},[54,573,125],{"class":72},[54,575,76],{"class":68},[54,577,578,580,582,584],{"class":56,"line":86},[54,579,134],{"class":133},[54,581,138],{"class":137},[54,583,518],{"class":141},[54,585,145],{"class":137},[489,587,492,589,495],{"id":588},"calling-keys-on-a-string",[15,590,591],{},"keys()",[45,593,595],{"className":47,"code":594,"language":49,"meta":50,"style":50},"data = \"name,age\"\nprint(data.keys())\n",[15,596,597,611],{"__ignoreMap":50},[54,598,599,602,604,606,609],{"class":56,"line":57},[54,600,601],{"class":60},"data ",[54,603,65],{"class":64},[54,605,69],{"class":68},[54,607,608],{"class":72},"name,age",[54,610,76],{"class":68},[54,612,613,615,617,620,622,625],{"class":56,"line":79},[54,614,134],{"class":133},[54,616,138],{"class":137},[54,618,619],{"class":141},"data",[54,621,183],{"class":137},[54,623,624],{"class":141},"keys",[54,626,627],{"class":137},"())\n",[20,629,535,630,632],{},[15,631,591],{}," belongs to dictionaries.",[20,634,635],{},"If your data is plain text, use string methods instead. If it should be structured data, convert or parse it first.",[489,637,639,640,643],{"id":638},"using-get-on-a-string-instead-of-a-dictionary","Using ",[15,641,642],{},"get()"," on a string instead of a dictionary",[45,645,647],{"className":47,"code":646,"language":49,"meta":50,"style":50},"data = '{\"name\": \"Ana\"}'\nprint(data.get(\"name\"))\n",[15,648,649,663],{"__ignoreMap":50},[54,650,651,653,655,657,660],{"class":56,"line":57},[54,652,601],{"class":60},[54,654,65],{"class":64},[54,656,241],{"class":68},[54,658,659],{"class":72},"{\"name\": \"Ana\"}",[54,661,662],{"class":68},"'\n",[54,664,665,667,669,671,673,676,678,680,682,684],{"class":56,"line":79},[54,666,134],{"class":133},[54,668,138],{"class":137},[54,670,619],{"class":141},[54,672,183],{"class":137},[54,674,675],{"class":141},"get",[54,677,138],{"class":137},[54,679,191],{"class":68},[54,681,318],{"class":72},[54,683,191],{"class":68},[54,685,445],{"class":137},[20,687,535,688,690],{},[15,689,619],{}," is still a string, not a dictionary.",[20,692,693],{},"Fix it by parsing the JSON text:",[45,695,697],{"className":47,"code":696,"language":49,"meta":50,"style":50},"import json\n\ndata = '{\"name\": \"Ana\"}'\nparsed = json.loads(data)\nprint(parsed.get(\"name\"))\n",[15,698,699,708,712,724,745],{"__ignoreMap":50},[54,700,701,705],{"class":56,"line":57},[54,702,704],{"class":703},"sVHd0","import",[54,706,707],{"class":60}," json\n",[54,709,710],{"class":56,"line":79},[54,711,83],{"emptyLinePlaceholder":82},[54,713,714,716,718,720,722],{"class":56,"line":86},[54,715,601],{"class":60},[54,717,65],{"class":64},[54,719,241],{"class":68},[54,721,659],{"class":72},[54,723,662],{"class":68},[54,725,726,729,731,734,736,739,741,743],{"class":56,"line":93},[54,727,728],{"class":60},"parsed ",[54,730,65],{"class":64},[54,732,733],{"class":60}," json",[54,735,183],{"class":137},[54,737,738],{"class":141},"loads",[54,740,138],{"class":137},[54,742,619],{"class":141},[54,744,145],{"class":137},[54,746,747,749,751,754,756,758,760,762,764,766],{"class":56,"line":99},[54,748,134],{"class":133},[54,750,138],{"class":137},[54,752,753],{"class":141},"parsed",[54,755,183],{"class":137},[54,757,675],{"class":141},[54,759,138],{"class":137},[54,761,191],{"class":68},[54,763,318],{"class":72},[54,765,191],{"class":68},[54,767,445],{"class":137},[20,769,212],{},[45,771,773],{"className":47,"code":772,"language":49,"meta":50,"style":50},"Ana\n",[15,774,775],{"__ignoreMap":50},[54,776,777],{"class":56,"line":57},[54,778,772],{"class":60},[20,780,781,782,183],{},"If you are working with JSON text, see ",[361,783,785,786,789],{"href":784},"\u002Fstandard-library\u002Fjson.loads-function-explained","the ",[15,787,788],{},"json.loads()"," function explained",[489,791,492,793,796],{"id":792},"calling-decode-on-a-string-in-python-3",[15,794,795],{},"decode()"," on a string in Python 3",[45,798,800],{"className":47,"code":799,"language":49,"meta":50,"style":50},"text = \"hello\"\ntext.decode(\"utf-8\")\n",[15,801,802,814],{"__ignoreMap":50},[54,803,804,806,808,810,812],{"class":56,"line":57},[54,805,505],{"class":60},[54,807,65],{"class":64},[54,809,69],{"class":68},[54,811,73],{"class":72},[54,813,76],{"class":68},[54,815,816,818,820,823,825,827,830,832],{"class":56,"line":79},[54,817,518],{"class":60},[54,819,183],{"class":137},[54,821,822],{"class":141},"decode",[54,824,138],{"class":137},[54,826,191],{"class":68},[54,828,829],{"class":72},"utf-8",[54,831,191],{"class":68},[54,833,145],{"class":137},[20,835,535,836,838,839,842,843,845],{},[15,837,795],{}," is for ",[15,840,841],{},"bytes",", not ",[15,844,471],{}," in Python 3.",[489,847,849],{"id":848},"trying-to-access-a-custom-object-attribute-on-plain-text","Trying to access a custom object attribute on plain text",[45,851,853],{"className":47,"code":852,"language":49,"meta":50,"style":50},"user = \"Alice\"\nprint(user.name)\n",[15,854,855,869],{"__ignoreMap":50},[54,856,857,860,862,864,867],{"class":56,"line":57},[54,858,859],{"class":60},"user ",[54,861,65],{"class":64},[54,863,69],{"class":68},[54,865,866],{"class":72},"Alice",[54,868,76],{"class":68},[54,870,871,873,875,878,880,883],{"class":56,"line":79},[54,872,134],{"class":133},[54,874,138],{"class":137},[54,876,877],{"class":141},"user",[54,879,183],{"class":137},[54,881,318],{"class":882},"skxfh",[54,884,145],{"class":137},[20,886,535,887,889,890,893],{},[15,888,877],{}," is a string, not an object with a ",[15,891,892],{},".name"," attribute.",[20,895,896],{},"If you want the string itself, use it directly:",[45,898,900],{"className":47,"code":899,"language":49,"meta":50,"style":50},"user = \"Alice\"\nprint(user)\n",[15,901,902,914],{"__ignoreMap":50},[54,903,904,906,908,910,912],{"class":56,"line":57},[54,905,859],{"class":60},[54,907,65],{"class":64},[54,909,69],{"class":68},[54,911,866],{"class":72},[54,913,76],{"class":68},[54,915,916,918,920,922],{"class":56,"line":79},[54,917,134],{"class":133},[54,919,138],{"class":137},[54,921,877],{"class":141},[54,923,145],{"class":137},[40,925,927],{"id":926},"how-to-fix-it","How to fix it",[20,929,930],{},"Use these steps to solve the error:",[27,932,933,936,943,954,960,978],{},[30,934,935],{},"Print the variable and its type before the failing line.",[30,937,938,939,942],{},"Use ",[15,940,941],{},"type(variable)"," to confirm what the object really is.",[30,944,945,946,949,950,953],{},"If you need a list, convert with ",[15,947,948],{},"list(text)"," or ",[15,951,952],{},"split()"," depending on your goal.",[30,955,956,957,959],{},"If you need a dictionary, parse the string first, for example with ",[15,958,788],{}," when the text contains JSON.",[30,961,962,963,965,966,965,969,965,971,974,975,183],{},"If you only need string operations, use valid string methods like ",[15,964,346],{},", ",[15,967,968],{},"upper()",[15,970,952],{},[15,972,973],{},"replace()",", or ",[15,976,977],{},"strip()",[30,979,980,981,183],{},"Check earlier lines to see where the variable changed from another type to ",[15,982,471],{},[20,984,985],{},"Example:",[45,987,989],{"className":47,"code":988,"language":49,"meta":50,"style":50},"value = \"a,b,c\"\n\nprint(value)\nprint(type(value))\n\nitems = value.split(\",\")\nprint(items)\nprint(type(items))\n",[15,990,991,1004,1008,1018,1032,1036,1061,1072],{"__ignoreMap":50},[54,992,993,995,997,999,1002],{"class":56,"line":57},[54,994,61],{"class":60},[54,996,65],{"class":64},[54,998,69],{"class":68},[54,1000,1001],{"class":72},"a,b,c",[54,1003,76],{"class":68},[54,1005,1006],{"class":56,"line":79},[54,1007,83],{"emptyLinePlaceholder":82},[54,1009,1010,1012,1014,1016],{"class":56,"line":86},[54,1011,134],{"class":133},[54,1013,138],{"class":137},[54,1015,142],{"class":141},[54,1017,145],{"class":137},[54,1019,1020,1022,1024,1026,1028,1030],{"class":56,"line":93},[54,1021,134],{"class":133},[54,1023,138],{"class":137},[54,1025,438],{"class":167},[54,1027,138],{"class":137},[54,1029,142],{"class":141},[54,1031,445],{"class":137},[54,1033,1034],{"class":56,"line":99},[54,1035,83],{"emptyLinePlaceholder":82},[54,1037,1038,1041,1043,1046,1048,1051,1053,1055,1057,1059],{"class":56,"line":104},[54,1039,1040],{"class":60},"items ",[54,1042,65],{"class":64},[54,1044,1045],{"class":60}," value",[54,1047,183],{"class":137},[54,1049,1050],{"class":141},"split",[54,1052,138],{"class":137},[54,1054,191],{"class":68},[54,1056,238],{"class":72},[54,1058,191],{"class":68},[54,1060,145],{"class":137},[54,1062,1063,1065,1067,1070],{"class":56,"line":110},[54,1064,134],{"class":133},[54,1066,138],{"class":137},[54,1068,1069],{"class":141},"items",[54,1071,145],{"class":137},[54,1073,1074,1076,1078,1080,1082,1084],{"class":56,"line":130},[54,1075,134],{"class":133},[54,1077,138],{"class":137},[54,1079,438],{"class":167},[54,1081,138],{"class":137},[54,1083,1069],{"class":141},[54,1085,445],{"class":137},[20,1087,212],{},[45,1089,1091],{"className":47,"code":1090,"language":49,"meta":50,"style":50},"a,b,c\n\u003Cclass 'str'>\n['a', 'b', 'c']\n\u003Cclass 'list'>\n",[15,1092,1093,1107,1121,1150],{"__ignoreMap":50},[54,1094,1095,1097,1099,1102,1104],{"class":56,"line":57},[54,1096,361],{"class":60},[54,1098,238],{"class":137},[54,1100,1101],{"class":60},"b",[54,1103,238],{"class":137},[54,1105,1106],{"class":60},"c\n",[54,1108,1109,1111,1113,1115,1117,1119],{"class":56,"line":79},[54,1110,462],{"class":64},[54,1112,466],{"class":465},[54,1114,241],{"class":68},[54,1116,471],{"class":72},[54,1118,230],{"class":68},[54,1120,476],{"class":64},[54,1122,1123,1125,1127,1129,1131,1133,1135,1137,1139,1141,1143,1146,1148],{"class":56,"line":86},[54,1124,227],{"class":137},[54,1126,230],{"class":68},[54,1128,361],{"class":72},[54,1130,230],{"class":68},[54,1132,238],{"class":137},[54,1134,241],{"class":68},[54,1136,1101],{"class":72},[54,1138,230],{"class":68},[54,1140,238],{"class":137},[54,1142,241],{"class":68},[54,1144,1145],{"class":72},"c",[54,1147,230],{"class":68},[54,1149,291],{"class":137},[54,1151,1152,1154,1156,1158,1161,1163],{"class":56,"line":93},[54,1153,462],{"class":64},[54,1155,466],{"class":465},[54,1157,241],{"class":68},[54,1159,1160],{"class":72},"list",[54,1162,230],{"class":68},[54,1164,476],{"class":64},[20,1166,1167,1168,183],{},"If your goal is to break text into parts, see ",[361,1169,1171],{"href":1170},"\u002Fhow-to\u002Fhow-to-split-a-string-in-python\u002F","how to split a string in Python",[40,1173,1175],{"id":1174},"step-by-step-debugging-checklist","Step-by-step debugging checklist",[20,1177,1178],{},"When you see this error, do this in order:",[1180,1181,1182,1185,1191,1197,1200],"ol",{},[30,1183,1184],{},"Look at the exact name after the dot in the error message.",[30,1186,1187,1188,183],{},"Check the variable value with ",[15,1189,1190],{},"print(variable)",[30,1192,1193,1194,183],{},"Check the type with ",[15,1195,1196],{},"print(type(variable))",[30,1198,1199],{},"Find where the variable was created or reassigned.",[30,1201,1202],{},"Replace the method with the correct one for strings, or convert the data to the correct type.",[20,1204,1205],{},"Useful debugging commands:",[45,1207,1209],{"className":47,"code":1208,"language":49,"meta":50,"style":50},"print(value)\nprint(type(value))\nprint(isinstance(value, str))\nprint(dir(value))\nhelp(str)\n",[15,1210,1211,1221,1235,1255,1270],{"__ignoreMap":50},[54,1212,1213,1215,1217,1219],{"class":56,"line":57},[54,1214,134],{"class":133},[54,1216,138],{"class":137},[54,1218,142],{"class":141},[54,1220,145],{"class":137},[54,1222,1223,1225,1227,1229,1231,1233],{"class":56,"line":79},[54,1224,134],{"class":133},[54,1226,138],{"class":137},[54,1228,438],{"class":167},[54,1230,138],{"class":137},[54,1232,142],{"class":141},[54,1234,445],{"class":137},[54,1236,1237,1239,1241,1244,1246,1248,1250,1253],{"class":56,"line":86},[54,1238,134],{"class":133},[54,1240,138],{"class":137},[54,1242,1243],{"class":133},"isinstance",[54,1245,138],{"class":137},[54,1247,142],{"class":141},[54,1249,238],{"class":137},[54,1251,1252],{"class":167}," str",[54,1254,445],{"class":137},[54,1256,1257,1259,1261,1264,1266,1268],{"class":56,"line":93},[54,1258,134],{"class":133},[54,1260,138],{"class":137},[54,1262,1263],{"class":133},"dir",[54,1265,138],{"class":137},[54,1267,142],{"class":141},[54,1269,445],{"class":137},[54,1271,1272,1275,1277,1279],{"class":56,"line":99},[54,1273,1274],{"class":133},"help",[54,1276,138],{"class":137},[54,1278,471],{"class":167},[54,1280,145],{"class":137},[20,1282,1283],{},"What these do:",[27,1285,1286,1292,1298,1304,1310],{},[30,1287,1288,1291],{},[15,1289,1290],{},"print(value)"," shows the current value",[30,1293,1294,1297],{},[15,1295,1296],{},"print(type(value))"," shows the real type",[30,1299,1300,1303],{},[15,1301,1302],{},"isinstance(value, str)"," checks if it is a string",[30,1305,1306,1309],{},[15,1307,1308],{},"dir(value)"," shows available attributes and methods",[30,1311,1312,1315],{},[15,1313,1314],{},"help(str)"," shows documentation for strings",[40,1317,1319,1320,495],{"id":1318},"special-case-decode-on-a-string","Special case: ",[15,1321,795],{},[20,1323,1324],{},"This specific version is very common in Python 3.",[20,1326,1327],{},"Key point:",[27,1329,1330,1335],{},[30,1331,1332,1334],{},[15,1333,471],{}," is already decoded text",[30,1336,1337,1339,1340,1342,1343],{},[15,1338,795],{}," is used on ",[15,1341,841],{},", not on ",[15,1344,471],{},[20,1346,1347],{},"Wrong:",[45,1349,1350],{"className":47,"code":799,"language":49,"meta":50,"style":50},[15,1351,1352,1364],{"__ignoreMap":50},[54,1353,1354,1356,1358,1360,1362],{"class":56,"line":57},[54,1355,505],{"class":60},[54,1357,65],{"class":64},[54,1359,69],{"class":68},[54,1361,73],{"class":72},[54,1363,76],{"class":68},[54,1365,1366,1368,1370,1372,1374,1376,1378,1380],{"class":56,"line":79},[54,1367,518],{"class":60},[54,1369,183],{"class":137},[54,1371,822],{"class":141},[54,1373,138],{"class":137},[54,1375,191],{"class":68},[54,1377,829],{"class":72},[54,1379,191],{"class":68},[54,1381,145],{"class":137},[20,1383,1384],{},"Right:",[45,1386,1388],{"className":47,"code":1387,"language":49,"meta":50,"style":50},"text = \"hello\"\nprint(text)\n",[15,1389,1390,1402],{"__ignoreMap":50},[54,1391,1392,1394,1396,1398,1400],{"class":56,"line":57},[54,1393,505],{"class":60},[54,1395,65],{"class":64},[54,1397,69],{"class":68},[54,1399,73],{"class":72},[54,1401,76],{"class":68},[54,1403,1404,1406,1408,1410],{"class":56,"line":79},[54,1405,134],{"class":133},[54,1407,138],{"class":137},[54,1409,518],{"class":141},[54,1411,145],{"class":137},[20,1413,1414],{},"If you actually have bytes, decode them first:",[45,1416,1418],{"className":47,"code":1417,"language":49,"meta":50,"style":50},"data = b\"hello\"\ntext = data.decode(\"utf-8\")\nprint(text)\n",[15,1419,1420,1435,1458],{"__ignoreMap":50},[54,1421,1422,1424,1426,1429,1431,1433],{"class":56,"line":57},[54,1423,601],{"class":60},[54,1425,65],{"class":64},[54,1427,1428],{"class":465}," b",[54,1430,191],{"class":68},[54,1432,73],{"class":72},[54,1434,76],{"class":68},[54,1436,1437,1439,1441,1444,1446,1448,1450,1452,1454,1456],{"class":56,"line":79},[54,1438,505],{"class":60},[54,1440,65],{"class":64},[54,1442,1443],{"class":60}," data",[54,1445,183],{"class":137},[54,1447,822],{"class":141},[54,1449,138],{"class":137},[54,1451,191],{"class":68},[54,1453,829],{"class":72},[54,1455,191],{"class":68},[54,1457,145],{"class":137},[54,1459,1460,1462,1464,1466],{"class":56,"line":86},[54,1461,134],{"class":133},[54,1463,138],{"class":137},[54,1465,518],{"class":141},[54,1467,145],{"class":137},[20,1469,212],{},[45,1471,1473],{"className":47,"code":1472,"language":49,"meta":50,"style":50},"hello\n",[15,1474,1475],{"__ignoreMap":50},[54,1476,1477],{"class":56,"line":57},[54,1478,1472],{"class":60},[40,1480,1482],{"id":1481},"common-mistakes","Common mistakes",[20,1484,1485],{},"These are some of the most common causes of this error:",[27,1487,1488,1496,1503,1509,1512,1515],{},[30,1489,1490,1491,949,1493,495],{},"Using list methods like ",[15,1492,352],{},[15,1494,1495],{},"extend()",[30,1497,1498,1499,949,1501,495],{},"Using dictionary methods like ",[15,1500,591],{},[15,1502,642],{},[30,1504,1505,1506,1508],{},"Assuming ",[15,1507,397],{}," returns numbers or lists instead of text",[30,1510,1511],{},"Reading JSON or CSV as plain text and not parsing it",[30,1513,1514],{},"Reusing the same variable name for different types",[30,1516,639,1517,1519,1520,1522,1523,1525],{},[15,1518,795],{}," on ",[15,1521,471],{}," instead of ",[15,1524,841],{}," in Python 3",[20,1527,1528],{},"If the same problem happens with another type, you may also want to read:",[27,1530,1531,1539,1547],{},[30,1532,1533],{},[361,1534,13,1536,18],{"href":1535},"\u002Ferrors\u002Fattributeerror-list-object-has-no-attribute-fix\u002F",[15,1537,1538],{},"'list' object has no attribute",[30,1540,1541],{},[361,1542,13,1544,18],{"href":1543},"\u002Ferrors\u002Fattributeerror-nonetype-object-has-no-attribute-fix\u002F",[15,1545,1546],{},"'NoneType' object has no attribute",[30,1548,1549],{},[361,1550,13,1552,18],{"href":1551},"\u002Ferrors\u002Fattributeerror-object-has-no-attribute-fix\u002F",[15,1553,1554],{},"'object' has no attribute",[40,1556,1558],{"id":1557},"faq","FAQ",[489,1560,1562],{"id":1561},"why-does-python-say-a-string-has-no-attribute","Why does Python say a string has no attribute?",[20,1564,1565,1566,1568],{},"Because the method or attribute you used does not belong to the ",[15,1567,471],{}," type. The variable is text, but your code treats it like another type.",[489,1570,1572],{"id":1571},"how-do-i-know-what-type-my-variable-is","How do I know what type my variable is?",[20,1574,938,1575,1577],{},[15,1576,941],{},". For example:",[45,1579,1581],{"className":47,"code":1580,"language":49,"meta":50,"style":50},"value = \"hello\"\nprint(type(value))\n",[15,1582,1583,1595],{"__ignoreMap":50},[54,1584,1585,1587,1589,1591,1593],{"class":56,"line":57},[54,1586,61],{"class":60},[54,1588,65],{"class":64},[54,1590,69],{"class":68},[54,1592,73],{"class":72},[54,1594,76],{"class":68},[54,1596,1597,1599,1601,1603,1605,1607],{"class":56,"line":79},[54,1598,134],{"class":133},[54,1600,138],{"class":137},[54,1602,438],{"class":167},[54,1604,138],{"class":137},[54,1606,142],{"class":141},[54,1608,445],{"class":137},[20,1610,1611,1612,965,1614,965,1616,1619],{},"This shows whether it is ",[15,1613,471],{},[15,1615,1160],{},[15,1617,1618],{},"dict",", or something else.",[489,1621,1623,1624,1626],{"id":1622},"why-does-input-often-lead-to-this-error","Why does ",[15,1625,397],{}," often lead to this error?",[20,1628,1629,1630,1632],{},"Because ",[15,1631,397],{}," always returns a string. If you expect a number or another type, you must convert it first.",[489,1634,1636,1637,1639],{"id":1635},"can-i-use-append-on-a-string","Can I use ",[15,1638,352],{}," on a string?",[20,1641,1642,1643,1646],{},"No. Strings are immutable. Use concatenation, ",[15,1644,1645],{},"join()",", or convert the string to a list if you need list behavior.",[489,1648,1623,1650,1652],{"id":1649},"why-does-decode-fail-on-a-string-in-python-3",[15,1651,795],{}," fail on a string in Python 3?",[20,1654,1629,1655,838,1657,1659],{},[15,1656,795],{},[15,1658,841],{},". A Python 3 string is already text, so it does not need decoding.",[40,1661,1663],{"id":1662},"see-also","See also",[27,1665,1666,1670,1677,1682,1687],{},[30,1667,1668],{},[361,1669,364],{"href":363},[30,1671,1672],{},[361,1673,1674,1675,789],{"href":368},"Python ",[15,1676,372],{},[30,1678,1679],{},[361,1680,1681],{"href":1170},"How to split a string in Python",[30,1683,1684],{},[361,1685,1686],{"href":482},"How to convert string to int in Python",[30,1688,1689],{},[361,1690,1691,789],{"href":784},[15,1692,788],{},[1694,1695,1696],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}",{"title":50,"searchDepth":79,"depth":79,"links":1698},[1699,1700,1701,1702,1713,1714,1715,1717,1718,1728],{"id":42,"depth":79,"text":43},{"id":301,"depth":79,"text":302},{"id":376,"depth":79,"text":377},{"id":486,"depth":79,"text":487,"children":1703},[1704,1706,1708,1710,1712],{"id":491,"depth":86,"text":1705},"Calling append() on a string",{"id":588,"depth":86,"text":1707},"Calling keys() on a string",{"id":638,"depth":86,"text":1709},"Using get() on a string instead of a dictionary",{"id":792,"depth":86,"text":1711},"Calling decode() on a string in Python 3",{"id":848,"depth":86,"text":849},{"id":926,"depth":79,"text":927},{"id":1174,"depth":79,"text":1175},{"id":1318,"depth":79,"text":1716},"Special case: decode() on a string",{"id":1481,"depth":79,"text":1482},{"id":1557,"depth":79,"text":1558,"children":1719},[1720,1721,1722,1724,1726],{"id":1561,"depth":86,"text":1562},{"id":1571,"depth":86,"text":1572},{"id":1622,"depth":86,"text":1723},"Why does input() often lead to this error?",{"id":1635,"depth":86,"text":1725},"Can I use append() on a string?",{"id":1649,"depth":86,"text":1727},"Why does decode() fail on a string in Python 3?",{"id":1662,"depth":79,"text":1663},"Master attributeerror str object has no attribute fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fattributeerror-str-object-has-no-attribute-fix",{"title":5,"description":1729},"errors\u002Fattributeerror-str-object-has-no-attribute-fix","Vwszesyo5GNlWQlaNjXkRjN_yUwO5rkglt5JHCq4iys",1777585510441]