- list[1].extend(data_ncdc[il][3])
it gives me an error that 'str' object has no attribute 'extend'. but I also tried - list[1].extend(float(data_ncdc[il][3]))
Anybody? THANKS
6 4859 bvdet 2,851
Expert Mod 2GB
You should not use "list" as an identifier. The assignment masks the built-in Python function "list()".
You are receiving the error because "list[1]" is a str object, which has no append() method. Use print statements in your code prior to the error to see what the object is.
Yes, I did print all of these.....
However, in my program I have: - if coord_ind == None:
-
ncdc_station.append(data_ncdc[il][3])
-
else:
-
ncdc_station[coord_ind[0]].extend(data_ncdc[il][3])
In this program append works just fine but then I go to extend it does not. I thought that if extend does not work, append will not either?
Could you please help me to correct this problem. THANKS
bvdet 2,851
Expert Mod 2GB
Please use code tags when posting code. append() and extend() are list methods and will fail on str objects. It's hard for me to know what is going on with your data. - >>> a = [1,2,3]
-
>>> a.extend('a')
-
>>> a
-
[1, 2, 3, 'a']
-
>>> a.extend([1,2,3])
-
>>> a
-
[1, 2, 3, 'a', 1, 2, 3]
-
>>> 's'.extend([3,4,5])
-
Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
AttributeError: 'str' object has no attribute 'extend'
-
>>> 's'.append(1)
-
Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
AttributeError: 'str' object has no attribute 'append'
-
>>>
well, I have array a=['0','1','2','3']. I need now to do the following val1='9', then set
a=['0',['1','9'],'2','3']. Is there a way to do it? Thanks.
-
In [5]: a=['0','1','2','3']
-
-
In [6]: type(a[1])
-
Out[6]: <type 'str'>
-
-
In [7]: a[1]=list(a[1])
-
-
In [8]: a
-
Out[8]: ['0', ['1'], '2', '3']
-
-
In [9]: a[1].append('9')
-
-
In [10]: a
-
Out[10]: ['0', ['1', '9'], '2', '3']
-
You just need to be clear about what type a variable is. Appending to a string is not valid.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Simom Thorpe |
last post by:
Hi,
I'm trying to insert a line into a MS access DB using ASP on IIS 5.
This is the line:
con.execute "INSERT INTO newProds(title,desc,catcode) VALUES
('Champagne Muff Scarf','','AC304B')"...
|
by: Neal |
last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog
entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A
quite good article.
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for...
|
by: WindAndWaves |
last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one
of those NEVER USE.
I can understand that it may lead to confusing code, but I often use it like
this:
is this...
|
by: noridotjabi |
last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get
files to work. I don't know what the problem is. Is there something
wrong with this: (file related)
#include <stdio.h>...
|
by: Phil |
last post by:
Problem code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace Streams {
class Program {
|
by: Rod |
last post by:
I've been struggling with this thing for 2 days, and after searching the
'net for help, I cannot find what is wrong.
We're using Crystal Reports XI Release 2, with Visual Studio .NET 2003 in...
|
by: Enkidu |
last post by:
Beginner question, sorry!
I am using indexers to access an array of StringBuilders in an instance
of a class:
Getting:
value = board1;
Setting:
board1 = value1 ;
|
by: Kid Programmer |
last post by:
Hello guys. I have a question. What's wrong with my compiler. In a simple number averaging program in a GUI window have way into the project I compile the program and I get the following errors:
...
|
by: hirsh.dan |
last post by:
i have a functions that writes information to a file.
inside that function i have a line in which i call another function.
if this line is executed, nothing is written to the file, but if i
remark...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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...
|
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,...
| |