• Register
1 vote
57 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,240 points

Related questions

0 votes
1 answer 10 views
10 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 6.1k points
0 votes
1 answer 134 views
134 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
0 votes
1 answer 512 views
512 views
Problem: I am working on the sort function but while doing a small problem I am getting a error can you please what I am doing wrong,Program that takes a list of student name and sorts them to create a class roll number. The list of names will be given on line separated by ... item.sort(lambda x, y: cmp(x.lower(),y.lower())) print(item) AttributeError: 'str' object has no attribute 'sort'" Error"
asked Jun 9, 2020 Gavin 15.3k points
1 vote
1 answer 488 views
488 views
Problem: I am newbee in python program and I wrote this code: def DeletChar(e, b) : counts = e.count(b) while counts : e.remove(b) counts -= 1 print(e) if __name__ == '__main__' : e = "LOVENOTLOLOVE" DeletChar(e,'L') But this code gives me the following ... main.py", line 9, in DeletChar e.remove(b) AttributeError: 'str' object has no attribute 'remove' Can anyone help me out to fix this problem?
asked Apr 8, 2020 LizzyM 6.1k points
0 votes
1 answer 7 views
7 views
Problem: At the bottom of the code you have to add these lines: simFlips(100,100) show() Here is the error that I get when I run it on ubuntu: Traceback (most recent call last): File "coin.py", line 36, in <module> simFlips(100,100) File "coin.py", ... (heads - tails)) AttributeError: 'numpy.ndarray' object has no attribute 'append' Please tell me what I'm doing wrong that gives me the last error
asked Jan 11 Mashhoodch 6.1k points
0 votes
1 answer 3 views
3 views
Problem: I use Regex to retrieve certain content from a search box on a webpage with selenium.webDriver. searchbox = driver.find_element_by_class_name("searchbox") searchbox_result = re.match(r"^.*(?=(\())", searchbox).group() The code works as long as the search ... get error: AttributeError: 'NoneType' object has no attribute 'group' How can I make the script handle the "No results" situation?
asked Jan 9 Mashhoodch 6.1k points
0 votes
1 answer 6 views
6 views
Problem: The CSV file contains 37 attributes + the label (last column). it doesn't contain header or index. Exp of the 1st row: 63651000000.0,63651000000.0,153.1,0,0,0,0,0,0,5,1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 ... "csv2libsvm.py", line 47, in <module> headers = reader.next() AttributeError: '_csv.reader' object has no attribute 'next' Do you have any idea about the problem ?
asked Jan 9 Mashhoodch 6.1k points
0 votes
1 answer 44 views
44 views
Problem: Hi there! I am new to the world of Python, and I am just trying new things in programming. I learned somewhere about the split() method and tried the following program: number = 43.42 another = number.split() print(another) When I executed this program ... numbers before and after the decimal point. I have no idea what caused this error. Can anyone here help me solve the problem, please?
asked Jan 4 Code Learner 5.5k points
0 votes
1 answer 213 views
213 views
When trying to find the index of v but it gave me: 'numpy.ndarray' object has no attribute 'index' none of them have answered my question v = np.random.randn(10) print(v) maximum = np.max(v) minimum = np.min(v) print(maximum, minimum) v.index(maximum, minimum)
asked Oct 30, 2020 psandprop 2.4k points