Hi,

I am new to Python programming...

I have a .txt file....... It looks like..

0,Salary,14000
0,Bonus,5000
0,gift,6000

I want to to replace the first '0' value to '1' in each line. How can I do this? Any one can help me.... With sample code..

Thanks in advance.
Nimmyliji

Recommended Answers

All 2 Replies

After you read Gribouillis' suggestion and also read some more of the Python tutorial on string operations, you could explore the hint below.

Hint, you could go through your data string line by line this way ...

data_str = """\
0,Salary,14000
0,Bonus,5000
0,gift,6000
"""

for line in data_str.split('\n'):
    print(line)

... then process each line and rebuild the string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.