Really? I just checked, in my terminal: hasattr("abc", "__iter__") and it came up with False. I'm on Python 2.7, could that be the difference? — Luke Taylor52 secs ago
is there better way to solve this task : User enters natural number 6<N<100 and program needs to find how many x+y+z = N ( x,y,z are natural too), and the following must be considered x<y<z.The program should output the number of possible combinations.
import time
try:
konacno = 0
broj = int(raw_input("Enter number >> "))
start = time.clock()
x1=0
y1=0
z1=0
if broj<6 or broj > 99:
raise ValueError
for x in range(1,broj+1-y1-z1):
x1=x
for y in range(1,broj+1-x1-z1):
My brain doesn't work after a large lunch - you've got a maximum possible of 830,584 in the total search space, you then remove the number where x < y < z can't be met...
This comes from a discussion yesterday with Antti about that error and how there was no good canon dupe for it. So, I'm planning on making an SO Q & A for it once the fine details are sorted out in the wiki first.
How can a standard-library module (say math) be accessed when a file prog.py is placed in the same directory as a local module with the same name (math.py)?
I'm asking this question because I would like to create a package uncertainties that one can use as
import uncertainties
from uncertaintie...
@idjaw I can find a bunch of questions about the problem, but they're not well written or thoroughly answered for the most part. I say go ahead and post.
The reason why this is happening is because your module that you named requests.py is now shadowing the intended requests module you are trying to use.
To avoid this, you should rename your module to something else to avoid these situations. Furthermore, chances are you will have generated a re...
and added to the wiki.
do I up-vote and accept my answer? This is so exciting
@AnttiHaapala ^^ because we were talking about it yesterday, thought you'd be interested to know AttributeError question is up.
@Ffisegydd I am sorry, The link I paste was for finding prime number. If you look at line 7. I set range(i, num) this gives me wrong output, however when I change that to range(2, num) I get the result I want
@cricket_007 Precisely. THe problem comes up quite a bit where OP will have a script name matching the standard module they are trying to import and they get that exception. So when it comes up, we want to dupe it to just help categorize the topics better.
@davidism thanks for the edit. I have to help my wife with something, feel free to do whatever edits you feel necessary. I'll jump back in when I'm back
@idjaw I'm just thinking if anyone were to search for their error, and they weren't using requests, they wouldn't find (or bother looking at) that post
Your mistake is using the same variable name for two different things.
durum=True
num=1
start=2
while num < 100:
num = num + 1
for i in range(start, num):
if num % i == 0:
durum = False
if durum == True:
print(num)
durum = True
Well, the error is AttributeError, so thats an important keyword. So is the phrase "module has no attribute" since that describes the problem... As far as filling in the blanks, just something generic
Now we need to monitor that question to reopen it if someone decides to close it. Or put some warning like
Please note that this is intended as a canonical answer to a common question ... please don't close as duplicate unless you're sure the other question has a better, more complete answer. — Zero PiraeusSep 4 '14 at 22:29
There's other ways that error can happen, and sometimes it will show up apparently in other code, because a different local name is shadowing. Need to figure out how to work that into the answer.
Huh, that's interesting. If you make a file called sys.py or os.py, the right one still gets imported correctly. Probably something the interpreter imports before the path is modified.
There's a ridiculous amount of things you can customize for the import process, and I've never seen a good example of needing most of that.
The only examples I've seen are more clever "never actually do this" things. Importing JSON files to get parsed structures, pip installing packages if they don't exist.
@poke not at all. I was in my living room. The kids were napping and we promised my parents we would visit once they woke up. My wife had them at the door quickly. I just didn't realize she ninja-prepared them without me knowing