how to use replace ?

l1=l2.replace(’ ', ’ ’ )

I want to remove the character = ’

like ‘123’ and get only 123

how can this be done in python using the replace command ?

thanks
happy bl

import bpy

data_block =  " '126','3', '0.2616086194324392' "

data_block = data_block.replace('\'', '') # remove all single quotes
print(data_block)

ws = data_block.split(',') 
for w in ws:
    fn = float(w)
    print(fn)

https://docs.python.org/2.0/ref/strings.html

nice link with all the Escape Sequence !

what do u use for a space?
is it an empty space or nothing?

seems that this replace does not work inside a list ?
anyway to get it to work ?

I think there is another method using some S(I ) = ,
don’t even know the exact name for this !

but did not see much example for that in python pages !

thanks

Can you give a sample of list?

printed it before the replace

l2 = [‘126,3,3,0,0,0,0,0.2616086194324392,0.2616086194324392,0.2616086194324392,
0.2616086194324392,0.4910397950841697,0.4910397950841697,0.4910397950841697,0.49
10397950841697,1.0,1.0,1.0,1.0,-33.924464276447154,0.0,0.012439746295797206,-33.
7989555001879,-167.86485625699467,0.19737330997559258,-10.937760369203255,-335.0
0240616187074,1.1031748789797822,33.496529298011815,-496.2873437565651,2.3225086
70290246,0.2616086194324392,0.4910397950841697,0.0,0.0,1.0’]

l1=l2.replace(’’’, ‘’)

IGES-test1.py", line 241, in split_into_individual_paths
AttributeError: ‘list’ object has no attribute ‘replace’

what does the ‘’ represent
is it empty or space ?

it is a list with a big string inside

thanks

i’m reading 1 line of numbers from a file
so this seems to be as a string with numbers

but then I need to convert each number as a float

there must be away to do that somehow without doing a loop!

thanks

someone give me one way to do it using a for loop

a1=[‘126.00,3,3,0,0.00,0.00,0.00,0.26,0.26’]
print (‘a1 =’, a1 )
print ()

mylist = a1[0].split(",")
print (‘mylist =’, mylist )
print ()
mylist = [float(i) for i in mylist]
print (‘mylist =’, mylist )
print ()

so I guess not possible without using a for loop!

thanks

RickyBlender, thanks for data sample. Following code tries to remove special characters before split

import bpy

l2 = ['126,3,3,0,0,0,0,0.2616086194324392,0.261608619432 4392,0.2616086194324392,\
0.2616086194324392,0.4910397950841697,0.4910397950 841697,0.4910397950841697,0.49\
10397950841697,1.0,1.0,1.0,1.0,-33.924464276447154,0.0,0.012439746295797206,-33.\
7989555001879,-167.86485625699467,0.19737330997559258,-10.937760369203255,-335.0\
0240616187074,1.1031748789797822,33.49652929801181 5,-496.2873437565651,2.3225086\
70290246,0.2616086194324392,0.4910397950841697,0.0 ,0.0,1.0']

#l1=l2.replace('\'', '')

# assign a list item to a string
l1=l2[0]
print (l1)

# remove extra characters
l1=l1.replace('\'', '') # remove single quote
l1=l1.replace(' ', '') # remove spaces

l1=l1.replace('\r', '') # remove (0x0d) carriage returns
l1=l1.replace('
', '') # remove (0x0a) newlines
l1=l1.replace('	', '') # remove tabs
print (l1)

# split into words using ',' as separator
ws = l1.split(',')
print (ws)

# convert each word to float
fs = []
for w in ws:
    fs.append(float(w))

print(fs)