Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
def shut_down(s):
s = s.Lower()
if s == 'yes' :
return "Shutting down..."
elif s == 'no':
return "Shutdown aborted!"
else :
return "Sorry, I didn't understand you."
the computer tell me that Your shut_down function threw the following error: 'str' object has no attribute 'Lower'
Your .Lower() is not available in python because it's case sensitive language use .lower()
def shut_down(s):
s = s.lower()
if s == 'yes' :
return "Shutting down..."
elif s == 'no':
return "Shutdown aborted!"
else :
return "Sorry, I didn't understand you."
Related
This post was returned to Unix & Linux Stack Exchange. It is not currently accepting new answers or interactions. Learn more
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
#!/usr/bin/env python3
# tarchiver.py
# Purpose: Creates a tar archive of a directory
#
# USAGE: ./tarchiver.py
#
# Author:
# Date January 15th 2023
import os
correct_answer = 'yes'
correct_answer2 = 'no'
compression1 = 'gzip'
compression2 = 'bzip2'
compression3 = 'xzip'
print("Please enter the directory you would like to archive")
directory = input()
print("Please enter the name of the archive")
name = input()
print("Would you like your archive to be compressed?")
answer = input()
while correct_answer != answer or correct_answer2 != answer:
answer = input()
print('Please enter either yes or no')
if answer == correct_answer or answer == correct_answer2:
break
if answer == 'yes':
print("What kind of compression do you want?")
print("gzip, bzip2, or xzip?")
answer2 = input()
while compression1 != answer2 or compression2 != answer2 or compression3 != answer2:
print('Please enter a valid answer')
answer2 = input()
if answer2 == compression1 or answer == compression2 or answer == compression3:
break
if answer2 == "gzip":
os.system(f"tar -cvPzf {name} {directory}")
if answer2 == "bzip2":
os.system(f"tar -cvPjf {name} {directory}")
if answer2 == "xzip":
os.system(f"tar -cvPJf {name} {directory}")
I'm having trouble with the logic in the code. When it asks whether or not I would like compression and I type 'yes', I have to type it twice in order for the code to proceed to the next section. Also, when it asks for type and I input 'gzip', it tells me at first that it's an invalid input and that I need to correct my answer, but I just enter the same thing and then it proceeds to execute the rest of the code. This is for a school project and I'm new to python so excuse me if there is an obvious solution to this problem.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Well, I just noticed that variables in if name == 'main': are shared to the classes in the same file - why is this? I don't recall having this issue in python2...
class A:
def __init__(self, b):
self.b = b
def func_a(self):
return d
if __name__ == '__main__':
classA = A(1)
d = 2
print(classA.func_a())
prints out 2.
What's the reasoning?
this definitely also happens in python2
and is very simple: declaring variables outside of functions/classes makes them global and when python searches for variables with the name d it doesn't find it in the local scope but it does find the global variable
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
cur.execute(command, tuple(values))
if (fetch := cur.fatchone()) is not None:
return fetch[0]
#bot_has_permissions(manage_roles=True)
#has_permissions(manage_roles=True, manage_guild=True)
async def unmute_members(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "لا يكثر هرجك"):
if not len(members):
await ctx.send("!unmute #member [reason]")
else:
await self.unmute(ctx, members, reason=reason)
AttributeError: 'sqlite3.Cursor' object has no attribute 'fatchone'
Typo.
if (fetch := cur.fatchone()) is not None:
should be
if (fetch := cur.fetchone()) is not None:
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I created a simple program to python that check if this X is expired.
import datetime
expired_on = datetime.datetime.now() + datetime.timedelta(0, 20) # add 20 seconds for expiration time
while True:
X = datetime.datetime.now()
if expired_on == X:
print(f"this {X} is expired.")
break
but it didn't break after 20 seconds.
This will be much cleaner.
import datetime
expired_on = datetime.datetime.now() + datetime.timedelta(seconds=20) # Add 20 seconds for expiration time
while True:
now = datetime.datetime.now()
if expired_on <= now:
print('Expired.')
break
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Having used pandas for a long time, this is the first time I got an error as shown in the title of this question and I'm stuck because I don't see any reason why the DataFrame would not have the groupby function "available." Already reinstalled pandas, even looked in the code that is being used (groupby is defined in the core modules).
This is what I'm doing, the error is shown below:
def _bin_by_answer(row):
collocated_answer = row['colname']
if collocated_answer <= -1:
return -1
elif collocated_answer >= 1:
return 1
else:
return 0
df = pd.read_pickle(somepath)
df['binned'] = df.apply(func=lambda row: _bin_by_answer(row), axis=1)
df_sampled = df.groupyby(by='binned', group_keys=False).apply(lambda grp: grp.sample(n=50))
Here is the error:
Traceback (most recent call last):
File "/Users/felix/IdeaProjects/cope/ann4class/exportfromaestoretomturk.py", line 858, in <module>
process_and_export_ps2_inductive()
File "/Users/felix/IdeaProjects/cope/ann4class/exportfromaestoretomturk.py", line 786, in process_and_export_ps2_inductive
df_sampled = df_results.groupyby(by=COL_ANSWER1_COLLOCATED_MAJORITY, group_keys=False).apply(
File "/Users/felix/anaconda3/envs/cope/lib/python3.7/site-packages/pandas/core/generic.py", line 5179, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'groupyby'
As suggested by ddoGas, the cause of this error was a typo. So, I guess the general answer would be: In case you're reading this question because you're running into a similar problem, double check that you wrote the function name correctly.