I'm new to python. I'm trying to unzip a file in my current script directory but I can't get this work...
zip = zipfile.ZipFile(os.getcwd() + '/Sample_APE_File.zip')
zip.extractall(os.getcwd())
Error: AttributeError: 'str' object has no attribute 'getcwd'
You assigned a string value to os, it is no longer bound to the module:
os = 'some string'
Rename that to something else.
Related
I have an object self.config which has some variables, I would like to first check if a variable ('db_password') exist in self.config and if it exists then modify the variable value something like self.config.db_password = 'modified values' . following is the python code
if hasattr(self.config, enc_variable):
setattr(self.config, enc_variable, f.decrypt(self.config.enc_variable.encode('ascii')).decode('ascii'))
AttributeError: 'Config' object has no attribute 'enc_variable'
This part is buggy:
self.config.enc_variable
It should be
getattr(self.config, enc_variable)
Or
self.config.db_password
I have module with name Ioanv1:
...
person1={"temp_lags": [-21.96,-21.82,-21.89,-21.99]}
...
def ....
Now I want to replace person1 with new data in another script:
import json
import Ioanv1
person1={"temp_lags": [-21,-21,-21,-21]}
jsonToPython = Ioanv1(person1)
print(jsonToPython)
I get TypeError: 'module' object is not callable
Could you please help me.
Error message is simple and clear.
Ioanv1 is module
You are using Ioanv1(person1) which you can not.
You probably want something like: Ioanv1.person1
from sys import argv
from os.path import exists
print "Look what I can do"
script,This_file,That_file,=argv
print "I'm gonna paste this into that"
Whatever=open(That_file)
Whatevers = That_file.read()
"So That_file is %d bytes long"%len(Whatever)
"Do the input and output files exist?"% exists(This_file,That_file)
Huh=open(That_file)
Huh.write(Whatever)
AttributeError: 'str' object has no attribute 'read'
it's:
Whatever=open(That_file)
Whatevers = Whatever.read()
import requests
import json
s = requests.Session()
s.params["key"] = "MY_KEY"
s.params["cx"] = "MY_CX"
s.params["num"] = 1
result = s.get('https://www.googleapis.com/customsearch/v1', params={"q": "Search query"})
Everything is working fine and I do get a result back but it's JSON. What I want is one thing. Since my result only gives 1 search result, I want the link of that search result. From I've understood that link value is under the keys "item" and then "link". I've tried lots of things but I keep getting either one of these errors below.
TypeError: 'Response' object is not subscriptable
NameError: name 'json' is not defined
AttributeError: 'Response' object has no attribute 'read'
TypeError: the JSON object must be str, not 'Response'
What am i doing wrong and what's the solution?
I receive an error
File.open(classname+'.txt','a')
AttributeError: '_io.TextIOWrapper' object has no attribute 'open'
while trying to open a file. I need to open the file and write to the file with the scores.
Here is the code
if Exists==False:
File.open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
else:
File=open(classname+'.txt','w')
linecount=len(filelines)
for i in range(0,linecount):
File.write(filelines[i])
it should be
File=open(classname+'.txt','a')
File.write(name+','+surname+','+str(1)+','+str(score)+'/n')
File.close()
The problem is that at the beginning you declare
File=open(classname+'.txt','r+')
and then you ask again to open File
File.open(classname+'.txt','a')
but File is already open(classname+'.txt','r+'). Just skip File.open(classname+'.txt','a') and it should work fine.