Man M
Man M

Reputation: 19

How to remove ' ' quotation marks and square brackets [] from strings when adding to file

I have the following lists:

list = []
a = 'a'
b = 'b'
c = 2
d = 3
list.append(a)
list.append(b)
list.append(c)
list.append(d)

And I'm adding list to a new txt file, which I want to show like that:

a,b,2,3

However, instead I'm getting:

['a','b',2,3]

How do I remove the [] and ''s?

Upvotes: 0

Views: 282

Answers (2)

Scott Cannon
Scott Cannon

Reputation: 47

Here is something to try instead

sub output()
Dim a as string, b as string
Dim c as integer, d as integer
a = "a"
b = "b"
c = 2
d = 3
list = a & "," & b & "," & c & "," & d
end sub

this should concatenate the string data to be the value of each variable with commas between. I think the output you are getting is the reference, not the string value. so you just make the location you want the data to show up = to list.

Upvotes: 0

LogiStack
LogiStack

Reputation: 1006

Join the list with ',' separator. And then write to file.

res = ",".join(str(x) for x in list)

Upvotes: 1

Related Questions