I am trying to translate from one language to another using python on power bi but my code seems to bring out error [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
My code seems to bring up an Attribution error when I run it- AttributeError: 'list' object has no attribute 'strip'
This is the detail of my code
# 'dataset' holds the input data for this script
from textblob import TextBlob
from textblob.exceptions import NotTranslated
def translate_comment(x):
try:
# Try to translate the string version of the comment
return TextBlob(str(x)).translate(to='en')
except NotTranslated:
# If the output is the same as the input just return the TextBlob version of the input
return TextBlob(str(x))
dataset['new_translation'] = dataset['review_comment_title'].apply(translate_comment)

Related

whats wrong in this code i want to send 100 messages in viber using python code [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
This is my code. I want to send 100 messages in Viber using Python code, and it gives this error:
text_message: TextMessage = TextMessage(text=message, to=recipient)
TypeError: TextMessage.init() got an unexpected keyword argument 'to'
i changed 'to' 'to receiver', it still doesn't work
''''''
import time
from **********
from *************************
from *******************************
viber = Api(BotConfiguration(
name='MyBot',
avatar='http://viber.com/avatar.jpg',
auth_token='*******************************'
))
message = "Hello"
recipient = "1234567890"
for i in range(100):
text_message = TextMessage(text=message, to=recipient)
viber.send_messages(text_message)
time.sleep(60)
TextMessage only takes one argument: text.
The keywordargument to belongs to the send_messages method.
example:
text_message = TextMessage(text=message)
viber.send_messages(text_message, to=recipient)

Key Error even though key IS in dictionary? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Dictionary:
section of dictionary
My Code:
code
Error says:
3
So how come the date key works fine but for freq it fails?
ps. my first time posting, so am very sorry for the sloppy structure of the post
This can only happen when one of your day is missing the freq parameter.
Try catching the day in which the error is happening. Then manually check that particular entry.
date_list = []
frequency_list = []
try:
for i in obj:
date = obj[i]["date"]
frequency = obj[i]["freq"]
date_list.append(date)
frequency_list.append(frequency)
except:
print(i)

list index out of range when upgrating python/django [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
fa = Fa.objects.filter(fa_name = tag)[0]
It was working in python 2.7 and django 1.8 but now that I migrated to django 2.2 and python 3.6 its not working
If you want to get the first if no data then None you should use first method:
fa = Fa.objects.filter(fa_name = tag).first()
It will return you None if you have no data and if you do have then it will return the first element
If you want to avoid any None values then you should check before executing it:
if Fa.objects.filter(fa_name = tag).count() > 0:
fa = fa = Fa.objects.filter(fa_name = tag)[0]

how to fix error 'int' object has no attribute 'text' when trying to make a word cloud image [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
How can I fix this error, I'm trying to combine text and create a word cloud image.
from os import path
from PIL import Image
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
text = []
cb = cbData #text dataset
tc = 0
for t in cb.text:
text.append(t)
tc += 1
all_text = " ".join(t for t in text)
print("Total words in all posts: ", len(all_text))
this is the error:
----> 3 for t in cb.text:
AttributeError: 'int' object has no attribute 'text'
The error is simply telling you that you are trying to use an attribute or method that doesn't exist. I suggest listing the attributes/methods that do exist and figuring out what to do from there. This can be done as such:
# code that generates variable "cb" (not supplied in post)
print(dir(cb))
Now, look at the output and see what method/attribute you should be trying to access. Perhaps it is something as simple as it being .Text or .text()
Note: the list generated will not tell you if it should be .text or .text() (the difference being the parenthesis) so if one doesn't work just use the other!

Python generator expression Twitter [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am kinda new to working with json and python and I am stuck on the parsing the data in js to generate an expression. I would really appreciate anyone suggestions on the best path to take.
Here is the Data I am working with
{"statuses":[{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Dec 06 15:06:44 +0000 2013","id":408975801577926656,"id_str":"408975801577926656","text":"RT #jk636575: #GhanaNudes contact me if you want to swing\njk636575#gmail.com","user":{"id":974873810,"id_str":"974873810","name":"Gh Nudes","screen_name":"GhanaNudes","location"
Here is my code:
def main():
ts = TwitterSearch()
response, data = ts.search('#gmail.com', result_type='recent')
js = json.loads(data)
messages = ([data_items] for msg in js)
I need to parse the content in js and turn it into a generator expression so that I only write: Created_at , text , user:{is
Based on the Twitter search API docs,
messages = ([msg['created_at'], msg['txt'], msg['user']['id']] for msg in js['statuses'])
Note that I have updated my answer to the original question to include this.
Edit: It might be a bit safer to replace in js['statuses'] with in js.get('statuses', []).

Categories