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'm trying to import pyplot from matplotlib but I get this error:
~/PycharmProject/untitled # jims-mbp (jim)
| => python math.py
Traceback (most recent call last):
File "math.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/Users/jim/PycharmProject/untitled/matplotlib.py", line 1, in
<module>
from matplotlib import pyplot
ImportError: cannot import name 'pyplot'
___________________ | ~/PycharmProject/untitled # jims-mbp (jim)
| =>
I've seen other posts related to this issue but no answers that solve my problem.
this is what I'm running:
import matplotlib.pyplot as plt
plt.plot(range(10))
I guess you run into problems, as your file is called "/Users/jim/PycharmProject/untitled/matplotlib.py" and you have a naming conflict there.
Try to rename it to sth else and rerun.
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 yesterday.
Improve this question
def get_hidden_card(credit_number, star_count=4):
short_credit_number = str(credit_number[12:16])
return str('*' * star_count + short_credit_number)
print(get_hidden_card(2034399002125581))
As i understand python don't wanna work because he think that str(credit_number[12:16]) is int type, how can i fix it?
The error is:
Traceback (most recent call last):
File "C:\Users\Ivan\PycharmProjects\pythonProject\main.py", line 10, in <module>
print(get_hidden_card(2034399002125581))
File "C:\Users\Ivan\PycharmProjects\pythonProject\main.py", line 4, in get_hidden_card
short_credit_number = str(credit_number[12:16])
TypeError: 'int' object is not subscriptable
Process finished with exit code 1
This is must solve your issue
def get_hidden_card(credit_number, star_count=4):
short_credit_number = str(credit_number)[12:16]
return str('*' * star_count + short_credit_number)
print(get_hidden_card(2034399002125581))
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 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 have this code that I typed into Python and I'm getting "Syntax error: invalid syntax" for b=Od/T. Does it have to do with how it's defined? How can I fix it
import scipy.integrate as sci
import scipy.constant as scc
import math
import numpy as np
import matplotlib.pyplot as plt
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
def f(T):
n=6.022*(10**28)
Od=429
V=10**(-3)
ft=lambda x: ((x**4)*math.exp(x)/(((math.exp(x))-1**2))
b = Od/T
a=0
C=9*V*n((T/Od)**3)*scc.k*(sci.quad(ft,a, b.any(),limit=10))[0]
return C
T1=np.arange(5,500,1)
plt.plot(T1,f(T1),'r-')
You're missing a closing parentheses on the previous line:
ft=lambda x: ((x**4)*math.exp(x)/(((math.exp(x))-1**2))
# ^ This parenthesis is never closed.
Error in the line before that. You can try this.
fr=lambda x: (x**4)*math.exp(x)/((math.exp(x))-1**2)
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 1 year ago.
Improve this question
Here is my code:
r = random.randint(1,10)
But for some reason it's giving me the error
NameError: name 'random' is not defined
Other info: Mac, Python, 3.4.0 pylauncher
You have to import the module random:
import random
r = random.randint(1,10)
# ...
>>> import random
>>> r = random.randint(1,10)
>>> r
10
you need to import the random library with the import keyword
import random
random.randint(1,10) #no. between 0 and 10
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
I am writing a Python script that will print out a random value from a list I have written,
from random import randint
class_list=[0,1,2,3,4,5,5,6,7,8,9,10,11,12]
people_called=[]
randomized_number = random.randint(0,12)
print "debug number" + str(randomized_number)
print "The student is" + str(class_list[randomized_number])
class_list[randomized_number].append(people_called)
However when I run this file I get I get
Traceback (most recent call last):
File "./Code/class list.py", line 4, in <module>
number = random.randint(0,12)
NameError: name 'random' is not defined
from random import randint imports randint from random module. That is, you can just use it as randint. If you would import it as import random, you'd have to use random.randint instead.
When importing using just import random, you must call the function with random.randint().
When using from random import randint, Python lets you call the function with just randint()