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()
Related
When i run this below script, i am getting this error and not able to identify what is it?
can someone help here?
Seeing error in line 14 as below
SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?
test = db.profiles_data.count_documents({"createdOn": {"$lt": {"ISODate"("2020-12-01T12:00:00.000+0000")}}, "createdOn": {"$gte": {"ISODate"("2020-11-30T11:00:00.000+0000")}}})
TypeError: 'str' object is not callable
Code:
import pymongo
import json
from collections import namedtuple
import pandas as pd
import numpy as np
def getLogCount():
uri = "mongodb connection string comes here"
client = pymongo.MongoClient(uri)
db = client.get_database('profile')
test = db.profiles_data.count_documents({"createdOn": {"$lt": {"ISODate"("2020-12-01T12:00:00.000+0000")}}, "createdOn": {"$gte": {"ISODate"("2020-11-30T11:00:00.000+0000")}}})
print("Test Count : %d" %test)
LogCount = getLogCount()
"ISODate"("2020-12-01T12:00:00.000+0000")
should probably be
"ISODate": "2020-12-01T12:00:00.000+0000"
or possibly
"ISODate(2020-12-01T12:00:00.000+0000)"
(both places where ISODate appears)
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
I've got an issue where when i try to print 'filename' i get this error
line 101, in purchase_code_fn
print("QR Code Created: %s") %(filename)
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
Below is the offending function.
def purchase_code_fn():
count=+1
name = raw_input("Name: ")
email_prompt = raw_input("Please enter your email address: ")
userid = uuid.uuid4()
filename = (str(email_prompt)+str(count))
print("QR Code Created: %s") %(filename)
qr_code_fn(email_prompt, userid)
A pointer in the right direction would be fantastic.
Cheers!
I think you're trying to run Python 2 code with Python 3. In Python 3, print is a function, but a statement in Python 2.
The print function had already been executed and the formatting did not come a priori as you intended or would have in Python 2. So you are trying to format the None returned by print, which is clearly not going to work.
You should remove the closing parenthesis trailing the string:
print("QR Code Created: %s" % filename)
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.
I try to create simple sublime 3 plugin:
import sublime, sublime_plugin, os.path
class RelativeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, sublime.getClipboard())
It must insert current file path to beginning of current file.
I found method sublime.getClipboard() here.
But it fails:
File "/Users/maks/Library/Application Support/Sublime Text 3/Packages/relative/relative.py", line 7, in run
self.view.insert(edit, 0, sublime.getClipboard())
AttributeError: 'module' object has no attribute 'getClipboard'
Dont know why, but method name is actually get_clipboard
sublime.get_clipboard()
Allthough in documentation it is getClipboard