PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.

  • Thread starter subhabrata.iisc
  • Start date
S

subhabrata.iisc

I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.
I am encountering the following problems:
(i) a1=1
a2=2
a3=a1+a2
print a3
# The result is coming sometimes as 3 sometimes as vague numbers.

(ii) x1="Bangalore is called the Silicon Valley of India"
x2="NewYork"
x3=x1.find(x2)
print x3
# The result of x3 is coming as -1 as well as +ve numbers.

(iii) I have been designing one crawler using "urllib". For crawling
one web page it is perfect. But when I am giving around 100 URLs by
and their links and sublinks the IDLE is not responding. Presently I
have been running with 10 URLs but can't it be ported?

(iv) I have designed a program with more than 500 if elif else but
sometimes it is running fine sometimes it is giving hugely erroneous
results, one view of the code:
elif a4==3:
print "YOU HAVE NOW ENTERED THREE WORDS"
if a3[0] not in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] not
in a6"
elif a3[2] in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] in
a6"
else:
print "NONE3.1"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] not in a6,a3[1] in a6, a3[2] in a6"
else:
print "NONE3.2"
else:
print "NONE3.3"
elif a3[0] in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] in a6"
else:
print "NONE3.4"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] not in a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] in a6"
else:
print "NONE3.5"
else:
print "NONE3.6"
else:
print "NONE3.7"
Why it is behaving like that?
If someone can help me.
Best Regards,
Subhabrata Banerjee,
Indian Institute of Science,
Bangalore,
India.
 
V

Vladimir Kropylev

yes, ths is known problem. I can just recomend you to use Linux or
FreeBSD, though cygwin maybe also possible
 
C

cokofreedom

'I have designed a program with more than 500 if elif else'

This was your first mistake...

(ii) x3=x1.find(x2)

returns an integer corresponding to the start position in x1 where it
found x2, otherwise it will return -1.

(i) ...

what kind of vague numbers? It should just give you an integer
response...
 
S

Steve Holden

I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.
I am encountering the following problems:
(i) a1=1
a2=2
a3=a1+a2
print a3
# The result is coming sometimes as 3 sometimes as vague numbers.
Sorry, this just isn't true. There is no known implementation for which
1+2 does not equal 3.
(ii) x1="Bangalore is called the Silicon Valley of India"
x2="NewYork"
x3=x1.find(x2)
print x3
# The result of x3 is coming as -1 as well as +ve numbers.
Presumably you get -1 when the substring isn't found. Look at the
documentation of str.find() to discover *why* this happens.
(iii) I have been designing one crawler using "urllib". For crawling
one web page it is perfect. But when I am giving around 100 URLs by
and their links and sublinks the IDLE is not responding. Presently I
have been running with 10 URLs but can't it be ported?
Not enough information. "I have a program, please tell me waht is wrong
with it" overtaxes even this group's psychic abilities.
(iv) I have designed a program with more than 500 if elif else but
sometimes it is running fine sometimes it is giving hugely erroneous
results, one view of the code:

I am afraid that for code like this "designed" is far too kind a term. I
would have suggested "thrown together".

On what analysis of your problem was this solution based?
elif a4==3:
print "YOU HAVE NOW ENTERED THREE WORDS"
if a3[0] not in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] not
in a6"
elif a3[2] in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] in
a6"
else:
print "NONE3.1"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] not in a6,a3[1] in a6, a3[2] in a6"
else:
print "NONE3.2"
else:
print "NONE3.3"
elif a3[0] in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] in a6"
else:
print "NONE3.4"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] not in a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] in a6"
else:
print "NONE3.5"
else:
print "NONE3.6"
else:
print "NONE3.7"
Why it is behaving like that?

Like what? You don't even say what results you expect, and only describe
the results you *do* obtain as "hugely erroneous".

I have a car. I have turned the ignition key but it fails to start.
Please tell me what is wrong with it.

regards
Steve
 
R

Robert Bossy

Hi,

First thing, I appreciate (and I'm positive we all do) if you DID'N YELL
AT ME.

I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.
I am encountering the following problems:
(i) a1=1
a2=2
a3=a1+a2
print a3
# The result is coming sometimes as 3 sometimes as vague numbers.
On all computers I work with (two at work and one at home), it always
gives me 3.
(ii) x1="Bangalore is called the Silicon Valley of India"
x2="NewYork"
x3=x1.find(x2)
print x3
# The result of x3 is coming as -1 as well as +ve numbers.
On my computer, this always gives me -1 which is what I expected since
x2 not in x1.
Are you sure you posted what you wanted to show us?
(iii) I have been designing one crawler using "urllib". For crawling
one web page it is perfect. But when I am giving around 100 URLs by
and their links and sublinks the IDLE is not responding. Presently I
have been running with 10 URLs but can't it be ported?
Maybe you've implemented quadratic algorithms, or even exponential.
Sorry, I cannot see without more specifics...
(iv) I have designed a program with more than 500 if elif else but
sometimes it is running fine sometimes it is giving hugely erroneous
results, one view of the code:
elif a4==3:
print "YOU HAVE NOW ENTERED THREE WORDS"
if a3[0] not in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] not
in a6"
elif a3[2] in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] in
a6"
else:
print "NONE3.1"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] not in a6,a3[1] in a6, a3[2] in a6"
else:
print "NONE3.2"
else:
print "NONE3.3"
elif a3[0] in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] in a6"
else:
print "NONE3.4"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] not in a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] in a6"
else:
print "NONE3.5"
else:
print "NONE3.6"
else:
print "NONE3.7"
I guess you're looking for one or several of three strings inside a
longer string. The algorithm is quadratic, no wonder your software
doesn't respond for larger datasets. Someone spoke about Aho-Corasick
recently on this list, you should defenitely consider it.

Moreover, the least we could say is that it doesn't loks pythonic, do
you think the following does the same thing as your snip?

L = []
for i, x in enumerate(a3):
if x in a6:
L.append('a3[%d] in a6' % i)
else:
L.append('a3[%d] not in a6' % i)
print ', '.join(L)


RB
 
G

Gabriel Genellina

2008/4/8 said:
I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.

En Tue, 08 Apr 2008 06:02:00 -0300, Vladimir Kropylev
yes, ths is known problem. I can just recomend you to use Linux or
FreeBSD, though cygwin maybe also possible

Disregard that comment.
 
S

subhabrata.iisc

Dear Sir,
Thank you for taking time out to answer.
For (i) It is happening. On trial it ran so well that when on
demonstration I got questions from tester, I felt amazed.
For (ii) For answer no.2 I'll check str.find.
For (iii) Well I said you most of crawler's algorithm. It works like a
MS IE synchronizer, if not better. The URLs are taken in a file the
file is read the URL's taken and put into
urllib.urlopen("http://.....") as it crawls the result is stored in a
text file, from the text file the garbage is cleaned, the sublinks are
extracted, the result files are again cleaned and sublinks extracted
we carry on this till we reach an optimum. For n-gram calculaion of
sublinks I am using numpy and decimal and pattern search in a unique
combination, it has no prob but this IDLE is getting no response if I
port more than 10 sites. I am willing to put 100 to 1000 URLs at one
go. If you know anyone in Bangalore, India expert in python kindly
send him across I can show him the problem in my machine and Indian
Institute of Science(IISc-locally known as TATA INSTITUTE) is a
distinguished place.Any one should know it.
I am in no mood of doing a joke.
Best Regards,
Subhabrata Banerjee.

Steve said:
I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.
I am encountering the following problems:
(i) a1=1
a2=2
a3=a1+a2
print a3
# The result is coming sometimes as 3 sometimes as vague numbers.
Sorry, this just isn't true. There is no known implementation for which
1+2 does not equal 3.
(ii) x1="Bangalore is called the Silicon Valley of India"
x2="NewYork"
x3=x1.find(x2)
print x3
# The result of x3 is coming as -1 as well as +ve numbers.
Presumably you get -1 when the substring isn't found. Look at the
documentation of str.find() to discover *why* this happens.
(iii) I have been designing one crawler using "urllib". For crawling
one web page it is perfect. But when I am giving around 100 URLs by
and their links and sublinks the IDLE is not responding. Presently I
have been running with 10 URLs but can't it be ported?
Not enough information. "I have a program, please tell me waht is wrong
with it" overtaxes even this group's psychic abilities.
(iv) I have designed a program with more than 500 if elif else but
sometimes it is running fine sometimes it is giving hugely erroneous
results, one view of the code:

I am afraid that for code like this "designed" is far too kind a term. I
would have suggested "thrown together".

On what analysis of your problem was this solution based?
elif a4==3:
print "YOU HAVE NOW ENTERED THREE WORDS"
if a3[0] not in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] not
in a6"
elif a3[2] in a6:
print "a3[0] not in a6, a3[1] not in a6, a3[2] in
a6"
else:
print "NONE3.1"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] not in a6, a3[1] in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] not in a6,a3[1] in a6, a3[2] in a6"
else:
print "NONE3.2"
else:
print "NONE3.3"
elif a3[0] in a6:
if a3[1] not in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] not in
a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] not in a6, a3[2] in a6"
else:
print "NONE3.4"
elif a3[1] in a6:
if a3[2] not in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] not in a6"
elif a3[2] in a6:
print "a3[0] in a6, a3[1] in a6, a3[2] in a6"
else:
print "NONE3.5"
else:
print "NONE3.6"
else:
print "NONE3.7"
Why it is behaving like that?

Like what? You don't even say what results you expect, and only describe
the results you *do* obtain as "hugely erroneous".

I have a car. I have turned the ignition key but it fails to start.
Please tell me what is wrong with it.

regards
Steve
 
S

Steve Holden

If you know anyone in Bangalore, India expert in python kindly
send him across I can show him the problem in my machine and Indian
Institute of Science(IISc-locally known as TATA INSTITUTE) is a
distinguished place.Any one should know it.
I am in no mood of doing a joke.
[...]
I have a car. I have turned the ignition key but it fails to start.
Please tell me what is wrong with it.
Please understand: this is the Internet. The chances that a random
responder will know anyone in Bangalore are vanishingly small.

I wasn't joking: I was simply (perhaps sarcastically) pointing out that
you do not provide enough information for anyone to help with your
problem, since you don't explain what the problem is.

Fortunately nobody is under any obligation to help here, it's simply
done out of kindness.

regards
Steve
 
S

subhabrata.iisc

Hi Steve,
comp.lang.python is supposed to be a serious group not anyone knowing
nothing and giving comment. Well, original code snippet I don't know
why an expert person like you fails to understand, I told it almost
can't you guess the next portion? Tough indeed, then. I've to take
permission from my organization if we can bring out this code in
public domain as we are working out an MT system that performs better
than Systran. And if it is a public domain I donot have security for
my code. Any one can copy.
But well if this group people are helping out of kindness, then I have
to think.
I thought if you know then only you can help. I am waiting for a
knowledgeable answer from a knowledgeable person. I think I can show a
person right direction only if I know it, that is not kindness but
power of my knowledge.
Let me solve it myself only, I will let you know how I solved them and
with many are quite innovative.
Like you can use index or re.search or in/not in instead of find....
Sad to have a response from a person like you I had just great hope,
and when python can be coded so fast.
Best Regards,
Subhabrata.


Steve said:
If you know anyone in Bangalore, India expert in python kindly
send him across I can show him the problem in my machine and Indian
Institute of Science(IISc-locally known as TATA INSTITUTE) is a
distinguished place.Any one should know it.
I am in no mood of doing a joke.
[...]
I have a car. I have turned the ignition key but it fails to start.
Please tell me what is wrong with it.
Please understand: this is the Internet. The chances that a random
responder will know anyone in Bangalore are vanishingly small.

I wasn't joking: I was simply (perhaps sarcastically) pointing out that
you do not provide enough information for anyone to help with your
problem, since you don't explain what the problem is.

Fortunately nobody is under any obligation to help here, it's simply
done out of kindness.

regards
Steve
 
G

Gabriel Genellina

comp.lang.python is supposed to be a serious group not anyone knowing
nothing and giving comment.

Anyone is welcome to post in this group - from beginners to gurus, and
that's a very good thing. All people here is usually very kind and
helpful, and that's not very common on Usenet.
Well, original code snippet I don't know
why an expert person like you fails to understand, I told it almost
can't you guess the next portion? Tough indeed, then. I've to take
permission from my organization if we can bring out this code in
public domain as we are working out an MT system that performs better
than Systran. And if it is a public domain I donot have security for
my code. Any one can copy.

How could anyone give some advise on what's wrong with your code, if
you don't show it? All you said is that you used urllib2 - there are
millions of ways to use the library, good and bad.
But well if this group people are helping out of kindness, then I have
to think.

Nobody here is being paid for helping others, they're all volunteers.
But even if there were some paid consultants, nobody has a crystall
ball, nobody can *guess* what's wrong with your code if you don't post
it.

About your crazy 500 if/elif: if all of them are like your posted
fragment, this needs a huge refactoring. After three repeats of the
same structure any sane programmer would say "hey, let's rearrange
this!". Someone posted an alternative, after guessing a bit what you
actually want to do.
Note that "a in b" and "a not in b" cover ALL possibilities ("tertium
non datur") so your 3-way ifs are wrong. If you want to determine
which strings from a set -if any- are contained in another string, use
some variant of the Aho-Corasick algorithm.
 
D

Diez B. Roggisch

I thought if you know then only you can help. I am waiting for a
knowledgeable answer from a knowledgeable person. I think I can show a

ALL the answers you got here so far indicate that you did NOT give enough
details to actually answer the question. Moreover, you claim to observe
phenomena that simply are ridiculously and obviously wrong -

a1=1
a2=2
a3=a1+a2

will yield 3 under ALL circumstances.

Instead, you posted random snippets of non-working code that show the worst
in coding style claiming they don't work, without telling us WHAT is not
working.

And then you reply telling us about the greatness of Bangalore and your
product to come. Which is somewhat amusing that people who claim to produce
the greatest software being incapable of debugging it deems me as odd - to
say the least. Because they should be more experienced.

I suggest you read this:

http://catb.org/~esr/faqs/smart-questions.html

At least two times.

And then come back and post self-contained examples of whatever behavior you
observe, and this community will be as helpful as it is. But we can't read
sense in anything you posted so far, despite the best efforts. So unless
that changes, you won't be helped here.

Diez
 
S

Steve Holden

Diez B. Roggisch wrote:
[...]
And then come back and post self-contained examples of whatever behavior you
observe, and this community will be as helpful as it is. But we can't read
sense in anything you posted so far, despite the best efforts. So unless
that changes, you won't be helped here.
Thank heavens you and Gabriel chimed in: I was beginning to think it was
just me!

regards
Steve
 
D

Diez B. Roggisch

Hi Steve,
comp.lang.python is supposed to be a serious group not anyone knowing
nothing and giving comment. Well, original code snippet I don't know
why an expert person like you fails to understand, I told it almost
can't you guess the next portion?

And this is outright outrageous. You are actually *aware* that people
must guess what you mean and expect them to do so, sparing yourself the
work of providing better information - willfully? This is as close to
impertinence as it can get.

Diez
 
M

Marc 'BlackJack' Rintsch

And then you reply telling us about the greatness of Bangalore and your
product to come. Which is somewhat amusing that people who claim to produce
the greatest software being incapable of debugging it deems me as odd - to
say the least.

That's not odd, that's perfectly normal for really clever code:

Debugging is twice as hard as writing the code in the first
place.Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it. -- Brian W. Kernighan

;-)

Ciao,
Marc 'BlackJack' Rintsch
 
S

subhabrata.iisc

I am getting the comments. So any one can post any comment like
Steve knows nothing of Python.
California has still lot to catch up to be at par with Mesopatamia.
comp.lang.python seems a group of fools.
Anyhow, all I learnt take whichever suits and ignore rest many people
have lot of time to carry out lot of nonsense.
Well I should have looked for a paid help and my stand about not
giving out my code in open forum stands as prolific. Better not lose
time unnecessarily going back to work and debugging the problems is
much sensical work that I can do instead of listening to jokes in the
morning!!!!
 
C

cokofreedom

Umm, Mesopotamia is an area geographically located between the Tigris
and Euphrates rivers, Bangalore isn't anywhere near that. And most of
that is presently under American control.

If you don't want to give out your code then try explaining it better.
What is the input, what is the output, how are you currently
processing. Describe these and people might be willing to aid more. Or
complain more about how unhelpful people are. Suits us.
 
G

Gabriel Genellina

I am getting the comments. So any one can post any comment like
Steve knows nothing of Python.
California has still lot to catch up to be at par with Mesopatamia.
comp.lang.python seems a group of fools.
Anyhow, all I learnt take whichever suits and ignore rest many people
have lot of time to carry out lot of nonsense.
Well I should have looked for a paid help and my stand about not
giving out my code in open forum stands as prolific. Better not lose
time unnecessarily going back to work and debugging the problems is
much sensical work that I can do instead of listening to jokes in the
morning!!!!

I hope this whole thread is just a big misunderstanding, maybe a
linguistic problem.
Nobody wants to steal your work, but if you say "my code is slow, what's
wrong with it?", nobody can give any useful answer if you don't post the
code. That's what everyone is saying, it's just common sense, in
California, Mesopotamia or Buenos Aires.

Have a great life,
 
J

John Nagle

I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
1310 32 bit (Intel)] on win32 with IDLE 1.2.1
My O/S is Windows XP SP2 I use 512 MB RAM.
I am encountering the following problems:
(i) a1=1
a2=2
a3=a1+a2
print a3
# The result is coming sometimes as 3 sometimes as vague numbers.

Are you pasting that code into IDLE with cut and paste?
IDLE doesn't process multiple-line paste operations properly,
and usually ignores all lines after the first. When it does
this, it does not produce an error message. That may be
your first problem.

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top