• Register
1 vote
208 views

Problem:

Hello all,

I’ve started learning python very recently. On the other day, I found a method called decode() 

I wrote a simple code using this method but unfortunately, it’s not working. What is the way to use the method decode()? 

Find my sample code attached below:

for lines in open('file','r'):
    decodedLine = lines.decode('dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=')
    line = decodedLine.split('\t')

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution:

Let me show you the basic usages of decode() and encode().

Str = "Hello World!";
Str = Str.encode('base64','strict');

print "Encoded String: " + Str
print "Decoded String: " + Str.decode('base64','strict')

I wrote a program that encodes our program and decodes it later on. And my program is producing the output:

Encoded String: SGVsbG8gV29ybGQh

Decoded String: Hello World!

 

For more information, please check this documentation

13 9 6
94,260 points

Related questions

0 votes
1 answer 24 views
24 views
Problem: In Java, a string is an object that represents a sequence of characters or char values. There are two ways to create a String object: By string literal : Java String literal is created by using double quotes. For Example: String s=“Welcome”; By new keyword : Java String is created by using a keyword “new”. How ro fix error of attribute decode in java?
asked Dec 2, 2020 Mashhoodch 13k points
0 votes
1 answer 4 views
4 views
Problem: I am in trouble while solving it .. please help me .. Charmap' codec can't encode character
asked Apr 27 Ifra 37.2k points
0 votes
1 answer 2 views
2 views
Problem: Does anyone grasp the problem? >Attributeerror: 'dataframe' object has no attribute 'str'
asked 1 day ago Chi Omega 13.6k points
1 vote
1 answer 15 views
15 views
Problem: I’m using following code regarding how to use date in a specific format and getting an error. My code: from datetime import datetime, date def main (): cr_date = '2013-10-31 18:23:29.000227' crrdate = cr_date.strftime(cr_date,"%m/%d/%Y") if __name__ == '__main__': main() My error: AttributeError: 'str' object has no attribute 'strftime'
asked 6 days ago Raj Tyagi 15.6k points
0 votes
1 answer 11 views
11 views
Problem: Hello! I am a beginner. I came accross a code in which a string was being written in a variable using the write function so, I decided to try that myself too. In an attempt to try doing the same I wrote the following program: Information = " " strng ... "main.py", line 4, in <module> Information = Information.write(strng) AttributeError: 'str' object has no attribute 'write' Please help!
asked Apr 19 Code Learner 9.9k points
0 votes
1 answer 7 views
7 views
Problem: who know this problem please help? str' object has no attribute 'str'
asked Apr 10 Rohit kr 17.5k points
0 votes
1 answer 6 views
6 views
Problem: i don&rsquo;t understand this problem? please help me. attributeerror: 'str' object has no attribute 'keys'
asked Apr 8 Rohit kr 17.5k points
0 votes
1 answer 43 views
43 views
Problem: Having an error I'm not quite sure how to solve, have a nested dictionary where the last item does not contain the asked get and gives an error, Not sure how to fix it. Error: Str' object has no attribute 'get'
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 9 views
9 views
Problem: In Python I'm getting an error: Str' object has no attribute 'read' What does this error mean and what did I do to cause it?
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 819 views
819 views
Python 3.3.2 import json & urllib.request Json [{"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}, {"link":"","orderid":"100000222"}] print(response.info()) Date: Sun, 20 Oct 2013 07:06:51 GMT Server: Apache X-Powered-By: PHP/5.4.12 Content ... line 271, in load return loads(fp.read(), AttributeError: 'str' object has no attribute 'read' >>> . Any idea how i can fix this issue?
asked Oct 25, 2020 psandprop 2.4k points