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
So, here I am, playing around with the ipfsapi in python and yesterday, to start somewhere, I ran some code from the following blogpost that connects to the local node: https://medium.com/python-pandemonium/getting-started-with-python-and-ipfs-94d14fdffd10
Last night it worked perfectly, but today when I began a new project where I would actually use this method and rewrote the code, I got an invalid syntax error in the except statement. Right now the code looks like this
if __name__ == '__main__':
try:
api = ipfshttpclient.connect('127.0.0.1', 5001)
print(api)
except: ipfshttpclient.exceptions.ConnectionError as ce: #the invalid syntax error is marked at as
print(str(ce))
Traceback:
File "/home/", line 17
except: ipfshttpclient.exceptions.ConnectionError as ce:
^
SyntaxError: invalid syntax
The odd thing is that I'm getting an invalid syntax error on the as. I've changed ipfsapi due to deprecation warning to ipfshttpclient, but it doesn't work with either now, same erreor. How is that even possible? Am I just not seeing something I should? Is my brain smoothing out? Sorry if it's a dumb issue and thanks in advance!
Python 3.7.4 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Linux 5.5.10-arch1-1
You should remove the colon : after the except.
Related
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 10 months ago.
Improve this question
I am working on a course via Pluralsight called Building your first Python Analytics Solution. The current module is teaching about the IDE - IDLE. The demo I am following uses a prebuilt python file called price.py that is supposed to output a list of items along with the total price. Within the example the instructor is solving for a zero entry using except and continue, as show within the picture, which works when the instructor runs it. Course Example
But when I try to mirror the code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
price_data = pd.read_csv('~/Desktop/price.csv')
print(price_data.head())
price_data = price_data.fillna(0)
print(price_data.head())
def get_price_info():
for index, row in price_data.iterrows():
total_price = row['Total_Price']
quantity = row['Quantity']
try:
price_of_a_unit = (total_price/quantity)
print(price_of_a_unit)
except ZeroDivisionError :
continue
get_price_info()
plt.bar(price_data.Things, height=price_data.Total_Price)
plt.title('Barplot of Things vs Total_Price')
plt.show()
I get the error 'continue' not properly in the loop.
The course is using Python IDLE 3.8.
The current version that I am running is IDLE 3.10.4.
I have repeatedly gone over the code in the screenshot and it seems to me that the code is exactly the same. I have also researched the error and still could not come up with a solution that will allow me to run the script. I am really new at this and would love to understand where the issue is.
Based on a point, that the code did not match the screen shot. I reloaded the original price.py file and mage the edits needed to make it match. If I am still missing something I would be grateful to know where the mistake is.
After doing some research on try catch blocks I was able to edit the code
try:
price_of_a_unit = (total_price/quantity)
print(price_of_a_unit)
except ZeroDivisionError:
print("Make sure no divisions by 0 are made.")
except NameError:
print("Make sure both numbers are defined.")
and get the code to run. Thank you
Your try-except block is indented incorrectly: it runs after your for loop completes and therefore the continue statement is outside of the loop (invalid).
# loop begins
for index, row in price_data.iterrows():
total_price = row['Total_Price']
quantity = row['Quantity']
# loop ends
# try/catch begins
try:
price_of_a_unit = (total_price/quantity)
print(price_of_a_unit)
except ZeroDivisionError:
continue # outside of a loop - invalid
# try/catch ends
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'm studying 'inheritance' in Pycharm.
I just followed tutorial. And it doesn't work. What's the problem
##Chef.py##
class Chef:
def make_chicken(self):
print("The chef makes a chicken")
def make_salad(self):
print("The chef makes a salad")
def make_special_dish(self):
print("The chef makes bbq ribs")
##another.py##
from Chef import Chef
class another(Chef):
##app.py##
from another import another
a = another()
a.make_salad()
run>>>
error message :
Traceback (most recent call last):
File "C:/Users/NEWS1/PycharmProjects/exc/app.py", line 1, in <module>
from another import another
File "C:\Users\NEWS1\PycharmProjects\exc\another.py", line 9
^
SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
What is the problem....
The issue is in your 'another' class, there's nothing following the colon. You can either add methods to the class or just a 'pass' like so
##another.py##
from Chef import Chef
class another(Chef):
# other content
pass
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
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.
Improve this question
I'm new in python and I'm trying to add an attribute to a maya light shape. The script should works like that: for each light.shape I've selected add a 'mtoa_constant_lightGroup' attribute:
import maya.cmds as pm
lightSelect= pm.ls (sl=True, dag=True, leaf=True)
for elem in lightSelect:
pm.addAttr (elem, ln='mtoa_constant_lightGroup', at=long, dv=0)
pm.setAttr (e=True, keyable=True, elem +'.mtoa_constant_lightGroup')
But when I run the script I've got this error:
Error: line 1: non-keyword arg after keyword arg
Any suggestions please.
In the following line from your code you have a positional argument after a keyword argument, which does not make sense.
pm.setAttr (e=True, keyable=True, elem +'.mtoa_constant_lightGroup')
# ---- here ----------------------^
fix it!
so as Martin said I had to move the keyword arguments to the end
then for the error " # Error: line 1: RuntimeError: file line 6: Type specified for new attribute is unknown." I needed to set at=long as a string, e.g.
`pm.addAttr (elem, ln='mtoa_constant_lightGroup', at="long", dv=0)`
The final scripts is this:
import maya.cmds as pm
lightSelect= pm.ls (sl=True, dag=True, leaf=True)
for elem in lightSelect:
pm.addAttr (elem, ln='mtoa_constant_lightGroup', at="long", dv=0)
pm.setAttr(elem +'.mtoa_constant_lightGroup', e=True, keyable=True)
thanks for all your helps
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 6 years ago.
Improve this question
So I created this function:
def bs_obj(url, lan="html.parser"):
try:
html = urlopen(url)
bsObj = BeautifulSoup(html, lan)
print(lan)
return bsObj
except HTTPError as e:
print(e)
Now, if I call the function with the next code: object = bs_obj(html, "lxml"), the console prints html.parser. Same goes if the code is object = bs_obj(html, lan="lxml"). What's going on?
EDIT: (SOLVED) I'm ashamed. I was calling bs_obj(html) some lines before the codeline I used as example.
I believe you are running the wrong file. For reference.
def bs_obj(lan="html.parser"):
print(lan)
if __name__ == "__main__":
bs_obj()
bs_obj("lxml")
bs_obj(lan='html5.parser')
Correctly outputs
html.parser
lxml
html5.parser
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 4 years ago.
Improve this question
I am trying to make a mac address spoofer in python for my mac as i find other software to be unnecessary advance/hard to understand. First i want a choicebox asking what device you want to spoof but i can not get the if else statement to work. The point if if coice is the first then input this value elif the choice is the second one input that value. If none of the above, you did somthing wrong. and i am running python 2.7
TlDr; If Else Statement do not work as i want (python 2.7).
Here is the code:
#_._# Mac Changer #_._#
import easygui
msg = "What Device do you want to spoof you're mac addresse?"
title = "SpoofMyMac"
choices = ["en0 (Ethernet)", "en1 (WiFi)"]
choice = easygui.choicebox(msg, title, choices)
#####################################
if choice == choice[0]: #
easygui.msgbox("Ethernet") #
elif choice == choice[1]: # This is where the problem seems to be.
easygui.msgbox("Wifi") #
else: #
easygui.msgbox("chus somthin!") #
#####################################
Now this is just the begining of the code, anyone care to help me out with this if else statement?
In advance Thank you! :)
From what I can see, you just have a typo. You want to index choices, not choice:
if choice == choices[0]:
#index choices ^
easygui.msgbox("Ethernet")
elif choice == choices[1]:
#index choices ^
easygui.msgbox("Wifi")
else:
easygui.msgbox("chus somthin!")