Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-31 Thread Steven D'Aprano
On Thu, 31 Oct 2013 21:41:32 -0700, rurpy wrote:

> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>> On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:
>>> On 10/30/2013 04:22 AM, Steven D'Aprano wrote:
 Skybuck's experience at programming *is relevant* to the question of
 whether or not he understands what he is talking about.
>>> No.  You claimed his proposition "made no sense" based on your
>>> analysis of it.
>> 
>> I said absolutely nothing of the sort. You're making that quote up --
>> not just misinterpreting what I said, or taking my words in the worst
>> possible way, but completely inventing things I never said.
> 
> Yes, on rereading you are correct, you did not say his proposition made
> no sense, you disagreed with him that "putting this exit condition on
> the top makes no sense" and claimed he had no business making such a
> statement

I said nothing of the sort.

Good lord Rurpy, I've already called you out once for misrepresenting 
what I've said, and here you are doing it again. You didn't have the good 
graces to even say sorry, instead trying to weasel out of an apology with 
a feeble "acknowledge[ment] that I overstated your position", and here 
you are again digging yourself deeper into the hole. That's three posts 
in a row -- your original post where you characterised me as making an 
"attack" on Skybuck, the second post where you escalated by attributing 
words I never wrote to me, and now this one where yet again you continue 
to misrepresent my post despite being called out on it.


[...]
> I am saying that your claim
> that he has no programming experience is not supported by what he wrote

I did not claim Skybuck had "no business" (your words) making such a 
statement about loop conditions. Far from it, I treated his opinion as a 
serious one worthy of discussion, discussing situations that both support 
and contradict his idea.

I *asked him* if he had programming experience, with an explicit 
question, and even began the question with the sort of social lubricant 
that acknowledges that the question is a touchy one ("please excuse my 
question"). I suggested that *it seems* that he doesn't have such 
experience. The normal, good-faith implication of this is that I am 
stating an opinion of how it seems to me, not an absolute fact. The whole 
exercise was to engage Skybuck in conversation, give him a chance to 
demonstrate (or at least assert) that I was mistaken about his lack of 
experience, and defend or amend his claim that putting the loop condition 
at the beginning of the loop makes no sense.

Unless you are prepared to discuss this in good faith, instead of 
continuing to misrepresent what I say, I am done discussing this with you.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-31 Thread rurpy
On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
> On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:
>> On 10/30/2013 04:22 AM, Steven D'Aprano wrote:
>>> Skybuck's experience at programming *is relevant* to the question of
>>> whether or not he understands what he is talking about.
>> No.  You claimed his proposition "made no sense" based on your analysis
>> of it.  
> 
> I said absolutely nothing of the sort. You're making that quote up -- not 
> just misinterpreting what I said, or taking my words in the worst 
> possible way, but completely inventing things I never said.

Yes, on rereading you are correct, you did not say his 
proposition made no sense, you disagreed with him that 
"putting this exit condition on the top makes no sense"
and claimed he had no business making such a statement
since he had no programming experience.
I misattributed the "no sense" quote.  Please note that 
that is not the same as "making something up".

> Not only did 
> I never say that Skybuck's proposition "made no sense", but I gave an 
> example of a language with a loop that does exactly what he wants, and 
> explicitly described as making sense:
> 
> "There is one sort of loop where it makes sense to have the loop condition
> at the end. Python doesn't have such a loop, but Pascal does: the repeat
> until loop."

As I said above, I read your response as disagreeing with 
Skybuck's idea: that the loop test should *always* go at 
the bottom.

That you agree with *sometimes* putting the test at the 
bottom does not contradict that you disagreed with his 
general proposition.

> I don't know whether to be more offended for myself, that you would 
> invent such a bare-faced falsehood about what I said, or for anyone else 
> reading this thread, that you should assume they would fail to notice 
> that not only did I not say what you quote me as saying, but that it is 
> the *opposite* of what I actually said.

No, it was *not* the opposite.  It was an overstatement 
of your position: "I think the proposition is nutty" versus
"I disagree with the proposition".  Presumably if you think
a proposition is nutty or non-nonsensical you also disagree 
with it and the former is a stronger version of the latter.

> I don't know whether you are deliberately lying, or whether you're just 
> such a careless reader that you have attributed words actually written by 
> Skybuck to me, but either way I expect an apology from you for putting 
> false words into my mouth.

An apology is due when someone does some damage to things 
or people (including reputation or feelings) that should 
have been avoided.

My overstating your disagreement with Skybuck was inadvertent, 
does not change the points I was making (it does not matter 
whether you thought he was wrong or nutty) and did no 
significant damage to you or your reputation.  

You damage your own reputation far more by your use of 
erroneous protestations, hyperpole and faux indignation [*1]
to distract from the actual issue, your implications that I 
may be lying, deliberately misrepresenting and inventing 
bare-faced falsehoods, and your propensity to attack others 
based on unsubstantiated speculation which was the origin 
of this discussion.

So I acknowledge I overstated your position, but sorry, 
no apology beyond that.

Now hopefully having addressed the indignation bit we can
get back to the actual points under discussion?

> As for the rest of your argument, I am not of the opinion that he is an 
> inexperienced programmer because his proposal is "nutty" (YOUR word, not 
> mine) since I don't think his proposal is completely nutty. There are use-
> cases for putting the loop condition at the end. I think he is an 
> inexperienced programmer because of the lack of any sign in his emails 
> that he has any meaningful experience in programming.

Replacing "his proposal is nutty" with "his proposal is wrong",
what "signs" did you expect to be present beyond the fact he 
advocated looping in a way you don't agree with?  A CV?  
As I pointed out (again missing from your quotes) he *did*
claim programing experience in his original post.

I also note your change from your original "no programming 
experience" to "no meaningful programming experience".

> As for your defence[1] of the ad hominem "Clearly Julie is mistaken, 
> she's just a girl, what would she know about programming?", [...]

That part was poorly written and was not intended to be a 
defense of the Julie ad hominen.  My intent was to acknowledge 
that it was an ad hominem, show a reason why it was an ad 
hominem and show that that same reason also applied to your 
ad hominem attack against Skybuck.  Unfortunately in a late-
night last-minute edit I screwed it up pretty badly.  I 
started off,

>>  Secondly, the example ad hominem argument you gave, "Clearly 
>>  Julie is mistaken, she's just a girl, what would she know about
>>  programming?" depends on the non-validity of the logical
>>  implication.
 
When what I meant w

Re: Python wart

2013-10-31 Thread Michael Torrie
On 10/31/2013 08:56 PM, Mark Lawrence wrote:
> On 01/11/2013 02:41, Michael Torrie wrote:
>> On 10/31/2013 07:45 PM, Mark Lawrence wrote:
>>> Quite often I type this
>>>
>>> print('Total of accounts %.2f', total)
>>>
>>> when I meant to type this
>>>
>>> print('Total of accounts %.2f' % total)
>>>
>>> Do I have to raise a PEP to get this stupid language changed so that it
>>> dynamically recognises what I want it to do and acts accordingly?
>>>
>>> Yours most frustratedly.
>>
>> This is one reason I've started using the new string formatting method
>> in all my new code.
>>
> 
> I'll admit to being a lazy, bone idle git and not wanting to change my 
> code as a former C programmer, but that strikes me as a cunning plan, 
> thanks.  Now where's my Windows desktop shortcut to the Python compiled 
> help file? :)

I only know enough to do the basic stuff that works for me 3/4 of the
time.

"{} {} {}".format(one, two, three)

Anything more than that I have to look up! Sometimes the ability to use
keywords and dictionaries in variable placement is kind of nice.



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Testing python command line apps -- Running from within the projects w/o installing

2013-10-31 Thread Göktuğ Kayaalp
On Fri, Nov 01, 2013 at 10:42:23AM +1100, Ben Finney wrote:
> Göktuğ Kayaalp  writes:
>
> > I'm using python to write command line apps from time to time. I
> > wonder *what is the conventional way to test-run these apps from
> > within the project itself, while developing, without installing*.
>
> [So] the advice for testing the program's main module specialises to: Keep
> the body of “if __name__ == '__main__':” to an absolute minimum. Put all
> of the set-up and process-end functionality into discrete functions with
> discrete purposes, clear return values, and explicit parameters.

This is usually the way I write my modules, and I do test my command
line interfaces in a manner similar to your example.  But what I was
asking is how to actually run these programs within a command shell
session and test them in a more *tangible* fashion:

(app) ~/app% ls
scripts/ app/ tests/ setup.py LICENSE README
(app) ~/app% cat scripts/app
#!/usr/bin/env python
from app import main; import sys
if __name__ == '__main__': exit(main.main(sys.argv[1:]))
(app) ~/app% scripts/app -CMdargs -- testdata.txt
Traceback (most recent call last):
  File "app", line 1, in 
from app import main; import sys
ImportError: no module named 'app'

I write a secondary script, 'app_tester', which is similar to 'app', but
before running app.main.main, it inserts ~/app to the front of sys.path.
What I want to find out is how to achieve this w/o having a secondary
script that manipulates the path.

> This is adapted from an article by Guido van Rossum
> http://www.artima.com/weblogs/viewpost.jsp?thread=4829>.

I'll definitely give this a read.

> [...]

cheers,
göktuğ


signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread rusi
On Friday, November 1, 2013 4:29:35 AM UTC+5:30, Denis McMahon wrote:

> My mistake, that was what Albert said, you were simply standing up for 
> him.

> Please s/you/he/ in the lines of my previous post quoted above, and 
> accept my apologies for my mistake.

Heh! Chill!  Yeah there is some hamming distance between the strings
"Albert van der Horst" and "Rusi Mody".  But you were objecting not to the 
state-er but to the statement...


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread rusi
On Friday, November 1, 2013 8:55:03 AM UTC+5:30, Mark Lawrence wrote:
> On 01/11/2013 02:27, William Ray Wing wrote:
> > supper computers

> Somebody must have tough teeth, though thinking about it I recall people 
> eating bicycles :)


You just have to be sufficiently non-vegetarian
http://en.wikipedia.org/wiki/DNA_computing

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: personal library

2013-10-31 Thread rusi
On Wednesday, October 30, 2013 10:18:20 AM UTC+5:30, Chris Angelico wrote:
> On Wed, Oct 30, 2013 at 3:33 PM, Ben Finney  wrote:
> > Chris Angelico  writes:
> >> *Definitely* use source control.
> > +1, but prefer to call it a “version control system” which is (a) more
> > easily searched on the internet, and (b) somewhat more accurate.

> Right. I've picked up some bad habits, and I think Dave may also
> have... but yes, "distributed version control system" is what I'm
> talking about here.

There is this article by Joel Spolsky
http://www.joelonsoftware.com/items/2010/03/17.html
-- putatively around mercurial but really about modern distributed
version control systems (DVCS). He says:

-
With distributed version control, the distributed part is actually not
the most interesting part.

The interesting part is that these systems think in terms of changes,
not in terms of versions.


So from that POV both 'source code' and 'version control' are
misnomers. So -- as usually happens in our field -- the acronym DVCS
becomes the closest non-misnomer to a really new concept
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Mark Lawrence

On 01/11/2013 02:27, William Ray Wing wrote:


supper computers



Somebody must have tough teeth, though thinking about it I recall people 
eating bicycles :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread William Ray Wing
On Oct 31, 2013, at 1:17 PM, Neil Cerutti  wrote:

> On 2013-10-31, rusi  wrote:
>> On Thursday, October 31, 2013 8:50:27 PM UTC+5:30, Neil Cerutti wrote:
>>> wrote:
 This suggests that Pascal went against established practice.
 This is false. FORTRAN used = and that was a mistake caused by
 the language being hacked together haphazardly.
>>> Respectfully, the designers of FORTRAN deserve more respect than
>>> that characterization accords.
>> 
>> ???
>> 
>> If I say: "My uncle -- a pilot -- knows more about flying
>> planes than the Wright brothers" am I disrespecting the Wright
>> brothers??
> 
> No, of course not.
> 
>> The state of art shifts with time. Fortran was more pioneering
>> than most languages that followed -- does not mean it got
>> everything right.
> 
> They obviously couldn't have gotten everything right; they had to
> work largely in a vaccuum. but in no sense were they haphazardly
> throwing syntax together. They designed it as well as anyone at
> the time knew how. It's stood the test of time, too. There's
> probably a lot more FORTRAN in use and maintained today than
> Wright Brothers airplane parts. ;)
> 

Actually, FORTRAN is probably responsible for more CPU cycles being executed 
even today than most other languages.  If you think about the fact that most 
large scientific simulation codes (weather forecasting, combustion modeling, 
finite-element modeling and so on), are still FORTRAN based, and that those are 
the codes that occupy multi-hundred-thousand-core petaflop class supper 
computers for weeks on end, you have to respect its longevity.

-Bill



>> From Backus Turing award speech:
>> 
>> Although I refer to conventional languages as "von Neumann
>> languages" to take note of their origin and style, I do not, of
>> course, blame the great mathematician for their complexity. In
>> fact, some might say that I bear some responsibility for that
>> problem.
>> 
>> http://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf
> 
> Thanks for that reference.
> 
> -- 
> Neil Cerutti
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python wart

2013-10-31 Thread Mark Lawrence

On 01/11/2013 02:41, Michael Torrie wrote:

On 10/31/2013 07:45 PM, Mark Lawrence wrote:

Quite often I type this

print('Total of accounts %.2f', total)

when I meant to type this

print('Total of accounts %.2f' % total)

Do I have to raise a PEP to get this stupid language changed so that it
dynamically recognises what I want it to do and acts accordingly?

Yours most frustratedly.


This is one reason I've started using the new string formatting method
in all my new code.



I'll admit to being a lazy, bone idle git and not wanting to change my 
code as a former C programmer, but that strikes me as a cunning plan, 
thanks.  Now where's my Windows desktop shortcut to the Python compiled 
help file? :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


looking for a pattern to change function behaviour by context

2013-10-31 Thread Zhang Weiwu


Problem:

library method request() requests data from external server. Sometimes, if a 
request is failed, it should be ignored, like price inquiry - if we don't 
get the price, then no decision could be made based on the price, then we 
simply do nothing about it; Sometimes, if a request is failed, it should 
retry, and if retry failed, it should throw an exception, like the case with 
placing order.


The problem is how to write the retry/exception code once only, not 
everywhere when needed.


Solution:

1. Inheritance. Add a new parameter 'critical' to the inherited method:

class New(requests.Session): # inherit a library class
def request(self, *args, critical = False, *kwargs):
if not critical:
return super().request(*args, *kwargs)
else:
result = super().request(*args, *kwargs)
if result.status_code != 200: # unsuccessful
result = super().request(*args, *kwargs)
if result.status_code != 200: # unsuccessful
raise SpecificException()
return result

class BusinessLogic:

def place_order(self, *args):
...
server.request(method, URL, critical = True)

Disadvantage: sometimes request is not called directly. The business logic 
class may call other wrappers of request() (e.g. post() and get()), thus we 
need repeat the above code to all the wrappers.


2. Use method 1, and also use decorator to add 'critical' paramter to all 
wrappers of request()


class New(requests.Session): # inherit a library class
def AddCriticalParamter(func):
 # add an optional parameter 'critical', which, if set,
 # cause to retry and exception to func

@New.AddCriticalParameter
def get(self, *args, critical = False, *kwargs):
return super().request(*args, *kwargs)

@New.AddCriticalParameter
def post(self, *args, critical = False, *kwargs):
return super().request(*args, *kwargs)

class BusinessLogic:

def place_order(self, *args):
...
server.get(method, URL, critical = True)

3. Use a wrapper class in business logic

class New(requests.Session): # inherit a library class
def Critical(func):
 # change behavior, add retry and exception to func

class BusinessLogic: 
def place_order(self, *args):
...
critical(server.get)(method, URL)


4. Any other method?

Question is: 1) am I thinking along the right line? and 2) what method will 
you use/recommend?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python wart

2013-10-31 Thread Michael Torrie
On 10/31/2013 07:45 PM, Mark Lawrence wrote:
> Quite often I type this
> 
> print('Total of accounts %.2f', total)
> 
> when I meant to type this
> 
> print('Total of accounts %.2f' % total)
> 
> Do I have to raise a PEP to get this stupid language changed so that it 
> dynamically recognises what I want it to do and acts accordingly?
> 
> Yours most frustratedly.

This is one reason I've started using the new string formatting method
in all my new code.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python wart

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 12:45 PM, Mark Lawrence  wrote:
> Quite often I type this
>
> print('Total of accounts %.2f', total)
>
> when I meant to type this
>
> print('Total of accounts %.2f' % total)
>
> Do I have to raise a PEP to get this stupid language changed so that it
> dynamically recognises what I want it to do and acts accordingly?

I feel your frustration there, especially since the usage you're
attempting parallels C's printf function. But the parsing would be
ambiguous - is it that any percent sign changes the meaning of print's
arguments? Or is this some kind of DWIM system, where the meaning
depends on whether the arguments "would work" if you used a percent
sign?

What you _could_ do, though, is decide that you will never EVER use
print with multiple arguments. Then just do this:

orig_print = print
def print(fmt, *args, **kwargs):
orig_print(fmt%args, **kwargs)

Now your print function takes printf-style arguments. Note that this
WILL error out if you have percent signs and no arguments; you may
want to use "if args" to guard against that, or else just accept that
it'll break if you do stuff that would be broken with printf.

(You may want to play with functools.wraps for the benefit of
docstrings and stuff... or maybe you don't care.)

One of the advantages of print being a function is that you can
actually do this :) With print as a statement, that option isn't
there.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python wart

2013-10-31 Thread MRAB

On 01/11/2013 01:45, Mark Lawrence wrote:

Quite often I type this

print('Total of accounts %.2f', total)

when I meant to type this

print('Total of accounts %.2f' % total)

Do I have to raise a PEP to get this stupid language changed so that it
dynamically recognises what I want it to do and acts accordingly?

Yours most frustratedly.


Could something like pylint recognise a format string literal as the
first argument of 'print' and warn if it's followed by a comma?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Mark Lawrence

On 30/10/2013 21:43, Albert van der Horst wrote:


FORTRAN used = and that was a mistake caused by the
language being hacked together haphazardly.

Groetjes Albert



Yes, just imagine the massive amount of research that they had to go on, 
given that Alan Turing had written *THE* paper some 20 years earlier and 
it was 10 years since Tommy Flowers delivered Colussus.  Mind you, maybe 
there's just a tiny little bit of hindsight behind your remark :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Python wart

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 12:53 PM, Chris Angelico  wrote:
> orig_print = print
> def print(fmt, *args, **kwargs):
> orig_print(fmt%args, **kwargs)

PS. To be courteous to subsequent developers, you might want to
instead leave print as it is, and create your own printf:

def printf(fmt, *args, **kwargs):
print(fmt%args, **kwargs)

Take your pick, whichever way works for you.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Python wart

2013-10-31 Thread Mark Lawrence

Quite often I type this

print('Total of accounts %.2f', total)

when I meant to type this

print('Total of accounts %.2f' % total)

Do I have to raise a PEP to get this stupid language changed so that it 
dynamically recognises what I want it to do and acts accordingly?


Yours most frustratedly.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: getpeername() on stdin?

2013-10-31 Thread Nobody
On Thu, 31 Oct 2013 12:16:23 -0400, Roy Smith wrote:

> I want to do getpeername() on stdin.  I know I can do this by wrapping a
> socket object around stdin, with
> 
> s = socket.fromfd(sys.stdin.fileno(), family, type)
> 
> but that requires that I know what the family and type are.   What I want
> to do is discover the family and type by looking at what getpeername()
> and/or getsockname() return.  Can this be done with the standard library?

I think that you'd need to use ctypes to access the underlying
getpeername() function from libc.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread alex23

On 31/10/2013 2:14 AM, jonas.thornv...@gmail.com wrote:

Well i ain't going to change


Thanks for your honesty. As I use an actual standards-compliant 
newsreader, I can now safely killfile you and never have to notice your 
laziness again.


--
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread alex23

On 30/10/2013 8:19 PM, jonas.thornv...@gmail.com wrote:

It is quite simple i could program it in a day...


There is certainly nothing stopping you from doing so. Once finished, I 
recommend placing it on PyPI; if it reaches a critical mass of downloads 
that support your thesis that "it will save millions of hours of bug 
searching all over world in a month", then the Python devs would 
consider adding it to the library or default interpreter.


Until then, you're projecting your personal preference onto everyone.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Testing python command line apps -- Running from within the projects w/o installing

2013-10-31 Thread Tim Chase
On 2013-10-31 22:12, Göktuğ Kayaalp wrote:
> My usual practise is to have two entry points to the program as
> executable scripts. 

When I create stand-alone command-line scripts that take arguments,
usually they're akin to version-control tools, so I have the form

  scriptname.py [--global-opts]  [--command-opts] [args]

so I just make one of my s allow for "test".  That way, I
can execute my tests as easily as my program.  If I've added config
parsing and script behavior depends on them, I might even create a
test harness that does something like

  #!/bin/sh
  for f in one.ini two.ini three.ini
  do
scriptname.py --config="$f" test
  done

That way, if some of my tests take a long time to run, I can even
make sub-commands to test a subset of the functionality to speed it
up:

  scriptname.py test web-ui
  scriptname.py test database
  ...

-tkc



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-31 Thread Bernhard Schornak

Skybuck Flying wrote:


>> Because it's logical.
>
> "
> What is logical?
> "
>
> To put the exit condition at the bottom is logical.


As "logical" as to put it anywhere else inside the loop body. As long as we 
write code
on machine language level, we are asked to choose the most efficient 
instruction chain
we can find. The decision where to place which instructions is up to the 
programmers -
not to a counter-productive "Universal Law".


> The exit condition glues the loop to the code that will be executed next 
which is also at the bottom.
>
> Example:
>
> Loop
>
> NextCode


Yes. As you should know, jump targets should be aligned to 32 byte boundaries 
to avoid
prefetch stalls. Hence, it is absolutely illogical to let a loop run into a set 
of NOP
instructions at the bottom of the loop's body. Therefore, we had to end each 
loop with
a jump to the next label to avoid the execution of a couple of extra NOP 
instructions.
This is as illogical as the attempt to declare some artificial restrictions as 
the new
Non-Plus-Ultra of programming.


> Placing the exit ondition near next code makes more sense at least in 
situation where I was
> programming.
>
> I will give you an example:
>
>
>
> LoopBegin( Step = 10 )
>
> if ButtonExists then
> begin
> ClickButton()
> end;
>
> LoopEnd( ButtonClicked )
>
> Execute next code...
>
> This loop waits for the button to appear, once it's found it is clicked and 
then the loop exits to
> continue the next code.
>
> Putting this exit condition on the top makes no sense.


Ever thought about how a compiler might translate this construct? Here are 2 
partially
optimised results:

ButtonExists  = bit 0 in RCX
ButtonClicked = bit 1 in RCX

  ...
  movl  $0x0A, %ebp
  testl $0x01, %ecx# does button exist?
  je1f
  jmp   0f

  .p2align 5,,31
0:decl  %ebp
  je1f
  call  _ClickButton
  jmp   0b

  .p2align 5,,31
 1:orl  $0x02, %ecx# button was clicked ten times...
  ...


Alternative:

  ...
  movl  $0x0A, %ebp
  testl $0x01, %ecx# does button exist?
  je1f
  jmp   0f

  .p2align 5,,31
0:call  _ClickButton
  decl  %ebp
  jne   0b
  jmp   1f

  .p2align 5,,31
 1:orl  $0x02, %ecx# button was clicked ten times...
  ...


The code with the conditional branch at top is faster than the alternative code,
because putting calls at places used as branch target, even if properly aligned,
is punished with some penalty cycles. As the loop ends at the bottom, we have to
insert a second jump to bypass the second set of NOPs.

Placing an exit condition at the top possibly looks odd for HLL programmers, but
it's faster in many cases. Placing all exit conditions at the bottom of the loop
body can never be faster, but often will be the slower solution.

You should translate your HLL constructs into simple machine language before you
start to declare "Universal Laws" which are none.

I am still wondering why you post to alt.lang.asm if you do not accept that your
proposals are analysed and their flaws are revealed. ;)


BTW: If this button ever existed, it'll exist throughout the runtime of the loop
without disappearing.  Hence, it is not necessary to query its existence in each
iteration, because it costs a lot of precious time. The best solution is the one
above - check if the button exists, then start the loop.


Greetings from Augsburg

Bernhard Schornak

--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-31 Thread Bernhard Schornak

wolfgang kern wrote:


> Bernhard Schornak replied to a "Flying-Bucket-post":
>
> Methink we all know about the often not-so-logical ideas from
> Buck, they merely come from an abstracted view and are far away
> from todays hardware given opportunities.
>
> OTOH, I sometimes got to think about his weird ideas, but mainly
> figured that his demands are already covered by hardware but may
> not have entered his Delphi/Python-HLL-world yet.
> Most of the asked features may be found implemented in the C/C+-
> area even just as intrisincs since a while anyway now.


Oops. I am a free human, so I am a natural enemy of declarations of
quite pointless "Universal Laws" - in simple words: Plights are the
opposite of rights.


> wolfgang
> (for those who dont know:
>   I'm a purist machine code programmer since more than 35 years)


Bis zum selba z'sammg'schtrickt'n ZX80 (1980) ko I grod no midhoid'n...


Pfüat'Di

Bernhard

--
https://mail.python.org/mailman/listinfo/python-list


Re: Testing python command line apps -- Running from within the projects w/o installing

2013-10-31 Thread Ben Finney
Göktuğ Kayaalp  writes:

> I'm using python to write command line apps from time to time. I
> wonder *what is the conventional way to test-run these apps from
> within the project itself, while developing, without installing*.

As with making any application testable: Make small functions that do
one thing well, with narrow, clearly-defined interfaces.

With testing the module which will be run as the program, though, there
are special considerations; in particular, command-line parsing and
system exit.

So the advice for testing the program's main module specialises to: Keep
the body of “if __name__ == '__main__':” to an absolute minimum. Put all
of the set-up and process-end functionality into discrete functions with
discrete purposes, clear return values, and explicit parameters.

That, for me, usually looks like this (or something with fewer moving
parts if the application doesn't need them)::

import argparse

class FrobApplication:
""" An application to frobnicate spiggleworts. """

def __init__(self):
""" Set up a new instance of FrobApplication. """
self.argument_parser = self.make_argument_parser()

def make_argument_parser(self):
""" Make an argument parser for this application. """
parser = argparse.ArgumentParser(
description="Frobnicate one or more spiggleworts.")
parser.add_argument(…)
…
self.argument_parser = parser

def parse_args(self, argv):
""" Parse command-line arguments to this application.

:param argv: The full sequence of command-line arguments.
:return: None.

"""
self.program_name = argv[0]
args = self.argument_parser.parse_args(argv[1:])
self.foo_flag = …

def run(self):
""" Run the application. """
self.argument_parser.parse_args(
…


def main(argv=None):
""" Mainline code for this module.

:param argv: The full sequence of command-line arguments. If
``None``, the Python runtime ``sys.argv`` is used.
:return: The exit code for the process.

"""
if argv is None:
from sys import argv as sys_argv
argv = sys_argv

exit_code = 0
try:
frob_app = FrobApplication()
frob_app.parse_args(argv)
frob_app.main()
except SystemExit, exc:
exit_code = exc.code

return exit_code

if __name__ == '__main__':
exit_code = __main__(sys.argv)
sys.exit(exit_code)

This is adapted from an article by Guido van Rossum
http://www.artima.com/weblogs/viewpost.jsp?thread=4829>.

The purpose of the distinct module-level ‘main’ is to turn into a normal
function interface what Python usually handles in less-easily-tested
ways: You want to normally use ‘sys.argv’, which ‘argparse’ will do by
default; but you want the same code to also accept your own value for
testing. You normally want to raise ‘SystemExit’ from any appropriate
point in your application and have that exit the program with the exit
code; but when testing, you just want a return value.

This allows you to test each of the parts with a narrow interface: you
can call ‘main’ feeding it your constructed command line, and getting a
return value instead of a System Exit exception. You can test the
application as a class: just the application initialisation, just the
command-line parsing, just the main run routine. And so on.

Yes, it's a whole lot of scaffolding; and no, I don't always use it all.
But making testable code entails dividing your code into small, easily
isolated, easily testable units. Sometimes that means you need to set up
a bunch of divisions where normally Python takes care of it all — such
as in the handling of command-line arguments or the exit of the process.

-- 
 \  “That's all very good in practice, but how does it work in |
  `\ *theory*?” —anonymous |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Backward"-Iterator - Beginners question

2013-10-31 Thread Dan Stromberg
On Thu, Oct 31, 2013 at 2:29 PM, Ulrich Goebel  wrote:

> Hallo,
>
> I'm locking for an "iterator" type with not only the .next() method, but
> with a .previous(), .first() and .last() method, so that I can through it
> from the beginning or from the end, and in both directions, even
> alternately (for example two steps forward, one backward, two steps
> forward).
>

I'm thinking maybe you want a list.

EG:
   list_ = list(my_iterator())
   i = 0
   print list_[i]
   i += 1
   print list_[i]
   print list_[i-1]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Try-except for flow control in reading Sqlite

2013-10-31 Thread Victor Hooi
Hi,

You're right, if the databse doesn't exist, the sqlite3 library will simply 
create it.

Hmm, in that case, what is the Pythonic way to handle this then?

If the database is new, then it won't have the table I need, and it will return 
something like:

sqlite3.OperationalError: no such table: my_table

I suppose I can try the query, and catch OperationalError, and if so, create 
the new schema then?

However, that seems a bit ugly, as I'm guessing OperationalError could be 
caused by a number of other reasons?

Should I perhaps be using some kind of version table as Burak Aslan suggested?

Cheers,
victor 

On Tuesday, 29 October 2013 10:43:19 UTC+11, Dennis Lee Bieber  wrote:
> On Sun, 27 Oct 2013 20:43:07 -0700 (PDT), Victor Hooi
> 
>  declaimed the following:
> 
> 
> 
> >Hi,
> 
> >
> 
> >I'd like to double-check something regarding using try-except for 
> >controlling flow.
> 
> >
> 
> >I have a script that needs to lookup things in a SQLite database.
> 
> >
> 
> >If the SQLite database file doesn't exist, I'd like to create an empty 
> >database, and then setup the schema.
> 
> >
> 
> >Is it acceptable to use try-except in order to achieve this? E.g.:
> 
> >
> 
> >try:
> 
> ># Try to open up the SQLite file, and lookup the required entries
> 
> >except OSError:
> 
> ># Open an empty SQLite file, and create the schema
> 
> >
> 
> >
> 
>   In my experience, SQLite will /create/ an empty database file if the
> 
> specified name does not exit. So just executing the connect() call is all
> 
> that is needed. After all, checking for data IN the database will either
> 
> return something or fail at that point in which case you can now populate
> 
> the schema.
> 
> 
> 
> -=-=-=-=-=-
> 
> >>> import sqlite3 as db
> 
> >>> con = db.connect("anUnknown.db")
> 
> >>> cur = con.cursor()
> 
> >>> rst = cur.execute("pragma table_info('aTable')")
> 
> >>> rst
> 
> 
> 
> >>> for ln in rst:
> 
> ...   print ln
> 
> ...   
> 
> >>> for ln in cur:
> 
> ...   print ln
> 
> ...   
> 
> >>> rst = cur.execute("create table aTable ( junk varchar )")
> 
> >>> con.commit()
> 
> >>> rst = cur.execute("pragma table_info('aTable')")
> 
> >>> for ln in rst:
> 
> ...   print ln
> 
> ... 
> 
> (0, u'junk', u'varchar', 0, None, 0)
> 
> >>> 
> 
> 
> 
> 
> 
>   No try/except needed -- just an a conditional testing the length of the
> 
> result returned by the pragma instruction on the table you expect to find
> 
> in the database.
> 
> -- 
> 
>   Wulfraed Dennis Lee Bieber AF6VN
> 
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Denis McMahon
On Thu, 31 Oct 2013 10:56:12 -0700, rusi wrote:

> On Thursday, October 31, 2013 11:20:52 PM UTC+5:30, Denis McMahon wrote:
>> On Thu, 31 Oct 2013 09:05:04 -0700, rusi wrote:

>> > If I say: "My uncle knows more about flying planes than the Wright
>> > brothers" am I disrespecting the Wright brothers??

>> No, but that's not what you said.

>> What you said was that "the [FORTRAN] language [was] hacked together
>> haphazardly."

> I did?!

My mistake, that was what Albert said, you were simply standing up for 
him.

Please s/you/he/ in the lines of my previous post quoted above, and 
accept my apologies for my mistake.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Backward"-Iterator - Beginners question

2013-10-31 Thread Terry Reedy

On 10/31/2013 5:29 PM, Ulrich Goebel wrote:


I'm locking for an "iterator" type with not only the .next() method, but
with a .previous(), .first() and .last() method, so that I can through
it from the beginning or from the end, and in both directions, even
alternately (for example two steps forward, one backward, two steps
forward).


You are free to write such a class, if it is appropriate for your actual 
use case.


If you have a concrete sequence object seq with random access, there is 
no reason to do so. First and last are seq[0] and seq[-1]. Given 
'cursor' i, prev and next are 'i-=1;seq[i]' and 'i+=1;seq[i]'.


There *are* virtual sequences where first and last are known or 
relatively easy to compute and for which prev and next are much easier 
to compute than a random nth item. Note that if you start with first and 
mostly move forward, prev might best be implemented using a list of 
items already seen. The list and the prev function might be limited to 
the last N items seen. It you give up the last function, the underlying 
sequence does not even have to have a definite end.


A somewhat realistic (useful) example might be the following. You have a 
very long sequence of bytes that represent utf-8 encoded characters. You 
want to view the sequence as a sequence of sentences. The sequence is 
too long to simply create a list of (decoded) sentences in memory.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: "Backward"-Iterator - Beginners question

2013-10-31 Thread Bernd Nawothnig
On 2013-10-31, Ulrich Goebel wrote:
> I'm locking for an "iterator" type with not only the .next() method, but 
> with a .previous(), .first() and .last() method, so that I can through 
> it from the beginning or from the end, and in both directions, even 
> alternately (for example two steps forward, one backward, two steps 
> forward).

Simply write a class with these methods. Where is the problem?




Bernd

-- 
no time toulouse
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k

Στις 31/10/2013 9:22 μμ, ο/η ru...@yahoo.com έγραψε:


You set the value of 'downloads' to a list:

downloads = []
if data:
for torrent in data:
downloads.append( torrent )

and when you use 'downloads', use have:

   INSERT INTO visitors (..., downloads) VALUES (..., %s), (..., downloads)

If the 'downloads' column in table 'visitors' is a
normal scalar value (text string or such) then perhaps
you can't insert a value that is a list into it?  And
that may be causing your problem?

If that is in fact the problem (I am only guessing), you
could convert 'downloads' to a single string for insertion
into your database with something like,

   downloads = ', '.join( downloads )


create table visitors
(
  counterID integer(5) not null,
  host varchar(50) not null,
  refs varchar(25) not null,
  city varchar(20) not null,
  userOS varchar(10) not null,
  browser varchar(10) not null,
  hits integer(5) not null default 1,
  visits datetime not null,
  downloads set('Καμία Ακόμη'),
  foreign key (counterID) references counters(ID),
  unique index (visits)
 )ENGINE = MYISAM;

Decided to declare downlods as  SET column type.
and maintain this:

downloads = []
if data:
for torrent in data:
downloads.append( torrent )


but error still is:

[Thu Oct 31 22:24:41 2013] [error] [client 46.198.103.93] 
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

--
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k

Στις 31/10/2013 9:22 μμ, ο/η ru...@yahoo.com έγραψε:


You set the value of 'downloads' to a list:

downloads = []
if data:
for torrent in data:
downloads.append( torrent )

and when you use 'downloads', use have:

   INSERT INTO visitors (..., downloads) VALUES (..., %s), (..., downloads)

If the 'downloads' column in table 'visitors' is a
normal scalar value (text string or such) then perhaps
you can't insert a value that is a list into it?  And
that may be causing your problem?

If that is in fact the problem (I am only guessing), you
could convert 'downloads' to a single string for insertion
into your database with something like,

   downloads = ', '.join( downloads )


Hello rurpy! I haven't forget ypu still have to answer you i  the other 
thread for the big explanation you provided, i just didnt had the time yet!


Yes indeed by MySQL's time definition 'downloads' columns is set as:
'varchar(50) not null'

So we have 2 options as you said:

1. Alter the type of 'downloads' colums to soemthign that can hold a list

2. Alter the code to make list beceome an alltogether joined string.

# find out if visitor had downloaded torrents in the past
cur.execute('''SELECT torrent FROM files WHERE host = %s''', 
host )
data = cur.fetchall()

downloads = []
if data:
for torrent in data:
downloads = ', '.join( downloads )
else:
downloads = None

# add this visitor entry into database (host && downloads are 
unique)
		cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
%s)''', (cID, refs, host, city, useros, browser, visits, downloads) )



I can be seen here:   http://superhost.gr/?show=log&page=index.html


But this unfortunate;y do not produce proper results
--
https://mail.python.org/mailman/listinfo/python-list


Re: personal library

2013-10-31 Thread patrick vrijlandt
Chris Angelico  wrote:
> On Thu, Oct 31, 2013 at 7:19 AM, Tim Delaney
> But yeah. Either git or hg will serve you well, and Bazaar (bzr) also
> has its advocates. Getting to know all three (or at least git/hg) to
> at least some extent will serve you well - at least be comfortable
> enough with the basics to clone someone else's project, pull changes
> from upstream, and see where it's at.
> 
> ChrisA

Thank you all. I will download and start learning!

-- 
patrick
-- 
https://mail.python.org/mailman/listinfo/python-list


"Backward"-Iterator - Beginners question

2013-10-31 Thread Ulrich Goebel

Hallo,

I'm locking for an "iterator" type with not only the .next() method, but 
with a .previous(), .first() and .last() method, so that I can through 
it from the beginning or from the end, and in both directions, even 
alternately (for example two steps forward, one backward, two steps 
forward).


Any help will be wellcome!

Ulrich


--
Ulrich Goebel
Paracelsusstr. 120, 53177 Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 4:56 AM, rusi  wrote:
> On Thursday, October 31, 2013 11:20:52 PM UTC+5:30, Denis McMahon wrote:
>> On Thu, 31 Oct 2013 09:05:04 -0700, rusi wrote:
>> > If I say: "My uncle knows more about flying planes than
>> > the Wright brothers" am I disrespecting the Wright brothers??
>
>> No, but that's not what you said.
>
>> What you said was that "the [FORTRAN] language [was] hacked together
>> haphazardly."
>
>
> I did?!

No, it wasn't you said it (it was Albert, I think). But that _is_ the
line that was said, it's just not yours.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Testing python command line apps -- Running from within the projects w/o installing

2013-10-31 Thread Göktuğ Kayaalp
Hi all,

I'm using python to write command line apps from time to time. I wonder
*what is the conventional way to test-run these apps from within the
project itself, while developing, without installing*.

My usual practise is to have two entry points to the program as
executable scripts.  I usually put executables into a directory called
`scripts/'.  The source code of the program is organized into a package,
and the package has an entry point which is a function that is passed
the command line arguments (sys.argv[1:]).  One of the scripts -- the
one that will be installed -- assumes that the package is installed.  It
imports the entry function of the package and calls it:

#!/usr/bin/env python3.3
from package.module import main
import sys

if __name__ == '__main__':
exit(main(sys.argv[1:]))

The other script is for running the version of the package that is
currently being developed in the project directory.  In that script,
I manipulate sys.path to have the project root at the very front:

#!/usr/bin/env python3.3
import sys
import os

sys.path.insert(0, os.path.join(os.path.realpath(".."), "sug/"))

from package import module

if __name__ == '__main__':
exit(module.main(sys.argv[1:]))

Even though I use virtualenvs for each project and have tests, I still
want to run and see effects of my changes immediately and do not like to
install the package every time I make a small change.

I have surveyed most popular projects on Github, only to see nothing in
common: some only have scripts like the first example, some use entry
point attributes in setup.py, some have these scripts very deep in the
package hierarchy etc.  What is the `one true way' to achieve this?
I want to emphasise that I do not want to have to install the package
in order to be able to run the executable scripts.

cheers,
göktuğ



signature.asc
Description: Digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread rurpy
On 10/31/2013 03:24 AM, Nick the Gr33k wrote:
>[...] 
> # find out if visitor has downloaded torrents in the past
>   cur.execute('''SELECT torrent FROM files WHERE host = %s''', host )
>   data = cur.fetchall()
> 
>   downloads = []
>   if data:
>   for torrent in data:
>   downloads.append( torrent )
>   else:
>   downloads.append( 'None Yet' )
> 
> # add this visitor entry into database
> cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
> useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
> %s)''', (cID, refs, host, city, useros, browser, visits, downloads) )
>[...]

and 

On 10/31/2013 03:32 AM, Nick the Gr33k wrote:
> The error seen form error log is:
> 
> [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
> [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] Traceback 
> (most recent call last):
> [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]   File 
> "/home/nikos/public_html/cgi-bin/metrites.py", line 274, in 
> [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] (cID, 
> refs, host, city, useros, browser, visits, downloads) )
> 
> [Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] 
> pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')
> 
> line 274 is:
> 
> # add this visitor entry into database
> cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
> useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
> %s)''',  (cID, refs, host, city, useros, browser, visits, downloads) )


You set the value of 'downloads' to a list:

>   downloads = []
>   if data:
>   for torrent in data:
>   downloads.append( torrent )

and when you use 'downloads', use have:

  INSERT INTO visitors (..., downloads) VALUES (..., %s), (..., downloads)

If the 'downloads' column in table 'visitors' is a 
normal scalar value (text string or such) then perhaps
you can't insert a value that is a list into it?  And
that may be causing your problem?

If that is in fact the problem (I am only guessing), you 
could convert 'downloads' to a single string for insertion
into your database with something like,

  downloads = ', '.join( downloads ) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread Roy Smith
On Oct 31, 2013, at 2:43 PM, Joel Goldstick wrote:

>> The "normal" way a redirect is done is to return a 301 (or 302) status code, 
>> and include a Location: line in the HTTP response headers.  If that was the 
>> case, you would just do a GET on the url with a library like requests and 
>> examine the status code and headers in the response object you got back.
>> 
>> This URL, however, doesn't do that.  What it does do is include:
>> 
>> http://amazon.in/gp/offer-listing/B00AF856T2/?/ref=as_li_tf_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9380349300&linkCode=as2&tag=mysm-21";>
>> 
>> in the body, which does kind of the same thing, but in a horrible way.  I 
>> suspect they do this provide a hook for the google analytics tracking code 
>> in the window.onload handler.  Unless you wanted to include a full HTML and 
>> javascript execution environment in your application, you're pretty much 
>> toast here.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
> 
> You might look at the requests module:
> http://www.python-requests.org/en/latest/api/
> 
> It has an 'allow_redirects' parameter that looks like you can set to
> get the final url.  Haven't tried it


I can't imagine this does anything other than the 30x processing described 
above (which won't work in the OP's case because that's not the mechanism used).

---
Roy Smith
r...@panix.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread Joel Goldstick
On Thu, Oct 31, 2013 at 2:33 PM, Roy Smith  wrote:
> On Thursday, October 31, 2013 2:10:35 PM UTC-4, nishant bhakta wrote:
>
>> I was only giving an example as bitly, actually i need to proceed with 
>> "http://www.mysmartprice.com/out/sendtostore.php?id=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30";
>>  this is the link that landed at "www.amazong.com" and i want write code 
>> that take this link and append something to the final landing link that is 
>> "www.amazon.com"
>
> When asking a question, it really helps to ask the question you want to ask, 
> not some other question which you think is similar :-)  Details matter.
>
> The "normal" way a redirect is done is to return a 301 (or 302) status code, 
> and include a Location: line in the HTTP response headers.  If that was the 
> case, you would just do a GET on the url with a library like requests and 
> examine the status code and headers in the response object you got back.
>
> This URL, however, doesn't do that.  What it does do is include:
>
> http://amazon.in/gp/offer-listing/B00AF856T2/?/ref=as_li_tf_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9380349300&linkCode=as2&tag=mysm-21";>
>
> in the body, which does kind of the same thing, but in a horrible way.  I 
> suspect they do this provide a hook for the google analytics tracking code in 
> the window.onload handler.  Unless you wanted to include a full HTML and 
> javascript execution environment in your application, you're pretty much 
> toast here.
> --
> https://mail.python.org/mailman/listinfo/python-list

You might look at the requests module:
http://www.python-requests.org/en/latest/api/

It has an 'allow_redirects' parameter that looks like you can set to
get the final url.  Haven't tried it

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread Roy Smith
On Thursday, October 31, 2013 2:10:35 PM UTC-4, nishant bhakta wrote:
 
> I was only giving an example as bitly, actually i need to proceed with 
> "http://www.mysmartprice.com/out/sendtostore.php?id=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30";
>  this is the link that landed at "www.amazong.com" and i want write code that 
> take this link and append something to the final landing link that is 
> "www.amazon.com"

When asking a question, it really helps to ask the question you want to ask, 
not some other question which you think is similar :-)  Details matter.

The "normal" way a redirect is done is to return a 301 (or 302) status code, 
and include a Location: line in the HTTP response headers.  If that was the 
case, you would just do a GET on the url with a library like requests and 
examine the status code and headers in the response object you got back.

This URL, however, doesn't do that.  What it does do is include:

http://amazon.in/gp/offer-listing/B00AF856T2/?/ref=as_li_tf_tl?ie=UTF8&camp=3626&creative=24790&creativeASIN=9380349300&linkCode=as2&tag=mysm-21";>

in the body, which does kind of the same thing, but in a horrible way.  I 
suspect they do this provide a hook for the google analytics tracking code in 
the window.onload handler.  Unless you wanted to include a full HTML and 
javascript execution environment in your application, you're pretty much toast 
here.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread nishant bhakta
> There is a python module for interacting with it:
> 
> https://github.com/bitly/bitly-api-python
> 
> 
> 
> Bye, Andreas

I was only giving an example as bitly, actually i need to proceed with 
"http://www.mysmartprice.com/out/sendtostore.php?id=107120529&top_category=electronics&store=amazon&mspid=51889&category=computer&rk=30";
 this is the link that landed at "www.amazong.com" and i want write code that 
take this link and append something to the final landing link that is 
"www.amazon.com"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Christian Gollwitzer

Am 31.10.13 17:49, schrieb Nick the Gr33k:

Στις 31/10/2013 1:19 μμ, ο/η Nick the Gr33k έγραψε:

someone please that is aware of what's wrong?


Your attitude.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread rusi
On Thursday, October 31, 2013 11:20:52 PM UTC+5:30, Denis McMahon wrote:
> On Thu, 31 Oct 2013 09:05:04 -0700, rusi wrote:
> > If I say: "My uncle knows more about flying planes than
> > the Wright brothers" am I disrespecting the Wright brothers??

> No, but that's not what you said.

> What you said was that "the [FORTRAN] language [was] hacked together 
> haphazardly."


I did?!


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get final URL after redirection

2013-10-31 Thread Andreas Perstinger
nishant bhakta  wrote:

>I have a link that will redirect to any-other link and i have to work
>with that final link. For example if i have a link "www.bit.ly/2V6CFi"
>that will redirect to "www.google.com". Here i want that i take
>"www.bit.ly/2V6CFi" and find the final redirect link and append
>"#q=python" to that link and produce an output that is
>"www.google.com/#q=python".

For bitly links you need to use their API:
http://dev.bitly.com/links.html#v3_expand

There is a python module for interacting with it:
https://github.com/bitly/bitly-api-python

Bye, Andreas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Denis McMahon
On Thu, 31 Oct 2013 09:05:04 -0700, rusi wrote:

> On Thursday, October 31, 2013 8:50:27 PM UTC+5:30, Neil Cerutti wrote:
>> wrote:

>> > This suggests that Pascal went against established practice. This is
>> > false. FORTRAN used = and that was a mistake caused by the language
>> > being hacked together haphazardly.

>> Respectfully, the designers of FORTRAN deserve more respect than that
>> characterization accords.

> If I say: "My uncle knows more about flying planes than
> the Wright brothers" am I disrespecting the Wright brothers??

No, but that's not what you said.

What you said was that "the [FORTRAN] language [was] hacked together 
haphazardly."

That's like me saying that when your uncle flies, he just pulls and 
pushes levers and knobs randomly hoping he doesn't crash - and that would 
be disrespecting your uncle.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to extract page-URL using BeautifulSoup

2013-10-31 Thread MRAB

On 31/10/2013 15:59, bhaktanish...@gmail.com wrote:

I want to extract the page-url. for example:
if i have this code

import urllib2
from bs4 import BeautifulSoup
link = "http://www.google.com";
page = urllib2.urlopen(link).read()
soup = BeautifulSoup(page)

then i can extract title of page by:

title = soup.title

but i want to know that how to extract page-URL from "soup" that will be 
"http://www.google.com";


Have a look at what you're passing to BeautifulSoup (save it to a file
and look at it in an editor). It's HTML. Does it contain anything that
says where it came from? No. So BeautifulSoup can't know either.

All BeautifulSoup does is parse the HTML that it's given.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Neil Cerutti
On 2013-10-31, rusi  wrote:
> On Thursday, October 31, 2013 8:50:27 PM UTC+5:30, Neil Cerutti wrote:
>> wrote:
>> > This suggests that Pascal went against established practice.
>> > This is false. FORTRAN used = and that was a mistake caused by
>> > the language being hacked together haphazardly.
>> Respectfully, the designers of FORTRAN deserve more respect than
>> that characterization accords.
>
> ???
>
> If I say: "My uncle -- a pilot -- knows more about flying
> planes than the Wright brothers" am I disrespecting the Wright
> brothers??

No, of course not.

> The state of art shifts with time. Fortran was more pioneering
> than most languages that followed -- does not mean it got
> everything right.

They obviously couldn't have gotten everything right; they had to
work largely in a vaccuum. but in no sense were they haphazardly
throwing syntax together. They designed it as well as anyone at
the time knew how. It's stood the test of time, too. There's
probably a lot more FORTRAN in use and maintained today than
Wright Brothers airplane parts. ;)

> From Backus Turing award speech:
>
> Although I refer to conventional languages as "von Neumann
> languages" to take note of their origin and style, I do not, of
> course, blame the great mathematician for their complexity. In
> fact, some might say that I bear some responsibility for that
> problem.
>
> http://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf

Thanks for that reference.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k

Στις 31/10/2013 1:19 μμ, ο/η Nick the Gr33k έγραψε:

Στις 31/10/2013 11:32 πμ, ο/η Nick the Gr33k έγραψε:

The error seen form error log is:

[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] Traceback
(most recent call last):
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]   File
"/home/nikos/public_html/cgi-bin/metrites.py", line 274, in 
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] (cID,
refs, host, city, useros, browser, visits, downloads) )

[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

line 274 is:

# add this visitor entry into database
cur.execute('''INSERT INTO visitors (counterID, refs, host, city,
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s,
%s)''',  (cID, refs, host, city, useros, browser, visits, downloads) )



This error happened at the moment when i decided to insert the
'downloads' column into the 'visitors' database




someone please that is aware of what's wrong?
--
https://mail.python.org/mailman/listinfo/python-list


How to get final URL after redirection

2013-10-31 Thread nishant bhakta
I have a link that will redirect to any-other link and i have to work with that 
final link.
For example if i have a link "www.bit.ly/2V6CFi" that will redirect to 
"www.google.com".
Here i want that i take "www.bit.ly/2V6CFi" and find the final redirect link 
and append "#q=python" to that link and produce an output that is 
"www.google.com/#q=python".
-- 
https://mail.python.org/mailman/listinfo/python-list


getpeername() on stdin?

2013-10-31 Thread Roy Smith
I want to do getpeername() on stdin.  I know I can do this by wrapping a socket 
object around stdin, with

s = socket.fromfd(sys.stdin.fileno(), family, type)

but that requires that I know what the family and type are.   What I want to do 
is discover the family and type by looking at what getpeername() and/or 
getsockname() return.  Can this be done with the standard library?

---
Roy Smith
r...@panix.com



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Skip Montanaro
> 1.  How fast can Python do math calculations compared with other languages
> such as Fortran and fast versions of Basic.  I would have to believe that it
> is much faster than Perl for doing math calculations.

As others have indicated, a lot depends on the form of your
calculations. There is a cost to crossing the Python/C boundary, and
you may or may not care about the other stuff Python can do
on-the-fly, like promote ints to Python longs, check for zero
division, etc. If you have floating point code that is array-like,
then organizing it to use numpy can be a big win, as you will cross
that expensive boundary much less often per underlying operation. (I'm
thinking here of more complex operations like trigonometric functions,
not simple adds and subtracts, which are handled by the Python virtual
machine.)

I will relate one anecdote from my job here which highlights the cost
of the boundary. I work at a trading firm. I work solely within a
Python world, but my stuff is built on top of a lot of C++ code
developed by others at the firm. Several years ago, it was decided
that we needed a price library because some exchanges (the London
Stock Exchange, for example) sets the minimum price change based on
the current trading price range. Consider a stock like AAPL, which
closed yesterday at 489.56. It trades in pennies on NASDAQ, no matter
its price. If it was on the LSE, it might trade in half pennies if it
was trading in a $100 range, or in dimes if it was trading near $1000
range. (I'm making this stuff up, just to give you an idea what I'm
referring to.)

So, a price library was written in C++. You could ask for the next
higher or lower valid price. It was all very peppy, because of course,
it relied heavily on C++ inline functions for all these simple
operations. It was wrapped with Boost::Python and tossed over the
fence for us Python peons to use. Guess what? It was unbearably slow,
because not only did we were crossing the Python/C boundary to do
little more (most of the time) than a single add or subtract.

The solution was to write a pure Python version of the parts that mattered most.

Moral of the story: consider how your code is structured and whether
it makes sense to reorganize it when implementing in Python.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread rusi
On Thursday, October 31, 2013 8:50:27 PM UTC+5:30, Neil Cerutti wrote:
> wrote:
> > This suggests that Pascal went against established practice.
> > This is false. FORTRAN used = and that was a mistake caused by
> > the language being hacked together haphazardly.
> Respectfully, the designers of FORTRAN deserve more respect than
> that characterization accords.

???

If I say: "My uncle -- a pilot -- knows more about flying planes than
the Wright brothers" am I disrespecting the Wright brothers??

The state of art shifts with time. Fortran was more pioneering than
most languages that followed -- does not mean it got everything right.

>From Backus Turing award speech:

-
Although I refer to conventional languages as "von Neumann languages"
to take note of their origin and style, I do not, of course, blame the
great mathematician for their complexity. In fact, some might say that
I bear some responsibility for that problem.

http://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf
-- 
https://mail.python.org/mailman/listinfo/python-list


how to extract page-URL using BeautifulSoup

2013-10-31 Thread bhaktanishant
I want to extract the page-url. for example:
if i have this code

import urllib2
from bs4 import BeautifulSoup
link = "http://www.google.com";
page = urllib2.urlopen(link).read()
soup = BeautifulSoup(page)

then i can extract title of page by:

title = soup.title

but i want to know that how to extract page-URL from "soup" that will be 
"http://www.google.com";
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Skip Montanaro
On Thu, Oct 31, 2013 at 10:20 AM, Neil Cerutti  wrote:
> On 2013-10-30, Albert van der Horst 
> wrote:
>> This suggests that Pascal went against established practice.
>> This is false. FORTRAN used = and that was a mistake caused by
>> the language being hacked together haphazardly.
>
> Respectfully, the designers of FORTRAN deserve more respect than
> that characterization accords.

Especially considering the environment in which they worked. The core
foundations of FORTRAN predate most language design research by a
decade or more.

From: http://math.scu.edu/~dsmolars/ma169/notesfortran.html#history

FORTRAN "0" report - 1954
FORTRAN I compiler - 1957
FORTRAN II - 1958
---> added subroutine definition and invocation
FORTRAN IV - developed 1960-62, definitive report in 1966
---> added logical IF, type declaration

In contrast, Algol wasn't first formalized until 1958. From:
http://en.wikipedia.org/wiki/ALGOL#History

ALGOL was developed jointly by a committee of European and American
computer scientists in a meeting in 1958 at ETH Zurich (cf. ALGOL 58).

Lisp also got its start in 1958
(http://en.wikipedia.org/wiki/Lisp_%28programming_language%29#History)

In contrast, Python wasn't started until the late 1980s (1989, I
believe). While it owes a fair debt to ABC, that language wasn't
developed at CWI until the early 1980s.

I'd like to see the reference for "hacked together haphazardly" in
reference to FORTRAN's origins.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread rusi
On Thursday, October 31, 2013 4:08:48 PM UTC+5:30, E.D.G. wrote:
> Posted by E.D.G. October 31, 2013

> Hi Chris,

>Thanks for the responses. Several of my questions were answered.

>The calculation speed question just involves relatively
> simple math such as multiplications and divisions and trig
> calculations such as sin and tan etc. Presently I am using Perl to
> do those types of calculations. And I am starting to run into
> problems with how long it takes Perl to do thousands and even
> millions of calculations like that even though they are relatively
> simple.

If raw machine performance is your main concern, python will likely
not will prizes*

Not sure what will… you may look at Julia: http://julialang.org/

Some extracts from there:

Julia is a dynamic language in the tradition of Lisp, Perl, Python and
Ruby. It aims to advance expressiveness and convenience for scientific
and technical computing beyond that of environments like Matlab and
NumPy, while simultaneously closing the performance gap with compiled
languages like C, C++, Fortran and Java.

Most high-performance dynamic language implementations have taken an
existing interpreted language and worked to accelerate its
execution. In creating Julia, we have reconsidered the basic language
design, taking into account the capabilities of modern JIT compilers
and the specific needs of technical computing. Our design includes:

- Multiple dispatch as the core language paradigm.  
- Exposing a sophisticated type system including parametric dependent types.
- Dynamic type inference to generate fast code from programs with no
declarations.
- Aggressive specialization of generated code for types encountered at run-time.

Julia feels light and natural for data exploration and algorithm
prototyping, but has performance that lets you deploy your prototypes.



* Considering my recent posts "treat python as a given", Im not being 
consistent. Must be getting senile :D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread rusi
On Thursday, October 31, 2013 7:31:14 PM UTC+5:30, Mark Lawrence wrote:
> On 31/10/2013 11:40, rusi wrote:
> > Please treat python as a given -- like the sun, moon and taxes."

> You missed the most obvious one, trolls :)

:D

Only that's not an element but a set -- trolls, nuts, dicks, philosophers -- 
and other yet-to-be-classified denizens of internetia
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Error Testing

2013-10-31 Thread Neil Cerutti
On 2013-10-30, Albert van der Horst 
wrote:
> This suggests that Pascal went against established practice.
> This is false. FORTRAN used = and that was a mistake caused by
> the language being hacked together haphazardly.

Respectfully, the designers of FORTRAN deserve more respect than
that characterization accords.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Robert Kern

On 2013-10-31 14:49, Chris Angelico wrote:

On Fri, Nov 1, 2013 at 1:41 AM, Robert Kern  wrote:

On 2013-10-31 14:05, Chris Angelico wrote:


On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
 wrote:


"E.D.G."  writes:


The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such
as sin and tan etc.



These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).



Well, they may not be simple to do, but chances are you can push the
work down to the CPU/FPU on most modern hardware - that is, if you're
working with IEEE floating point, which I'm pretty sure CPython always
does; not sure about other Pythons. No need to actually calculate trig
functions unless you need arbitrary precision (and even then, I'd bet
the GMP libraries have that all sewn up for you). So the language
doesn't make a lot of difference.



Sure it does. Python boxes floats into a PyObject structure. Both Python and
C will ultimately implement the arithmetic of "a + b" with an FADD
instruction, but Python will do a bunch of pointer dereferencing, hash
lookups, and function calls before it gets down to that. All of that
overhead typically outweighs the floating point computations down at the
bottom, even for the more expensive trig functions.


Of course that's true, but that difference is just as much whether
you're working with addition or trig functions. That overhead is the
same. So if, as I said in the other post, you're doing some heavy
crypto work or something, then yes, all that boxing and unboxing is
expensive.


Yes, Alain was wrong to suggest that these are not "simple calculations" and 
thus will benefit from a lower-level language. In fact, the relationship is 
reversed. These are *such* simple operations that they do benefit from the 
immediate surrounding code being done in C. The amount of time spent on overhead 
doesn't change based on the operation itself but the immediate surrounding code, 
the inner loops. That's where the language (implementation) matters.


> Most programs aren't doing that, so the advantage is far
> less (by proportion).

But we're not talking about most programs. We are talking about the OP's 
programs, which apparently *do* involve lots of iterated floating point 
calculations.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list


Re: tuple __repr__ non-ascii characters

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 1:59 AM, Yaşar Arabacı  wrote:
> Is there a better way to handle this problem?

There is, but I don't know how easy it'll be. In Python 3, the repr of
a tuple will show Unicode strings as Unicode. :)

For what you're showing there, I'm not actually quite sure what's
going on. Is the string a Unicode string, or a byte string? If it's a
byte string (which I suspect, since it's coming up as \xfe and the
character you're showing us isn't U+00FE), then you have to worry
about encodings. If you're using it to store non-ASCII data, you
probably want to be using a Unicode string:

a = u"yaşar"

The best solution is definitely to move to Python 3, though - if you
can. Do you have much code to migrate, or are you starting fresh? Are
there any libraries/modules that you need that don't support Py3?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


tuple __repr__ non-ascii characters

2013-10-31 Thread Yaşar Arabacı
Hi,

while this:

a = "yaşar"
print a

prints "yaşar"

this:

a = ("yaşar",)
print a

prints ('ya\xfear',)

At first I tried decoding repr(a) with different encodings, but later
I realised there is actually 4 charaters \, x, f and e in return value
of repr.

Therefore, I wrote this:

def byte_replacement(bstring):
return chr(int(bstring[2:],16))

def prettyprint(obj):
text = repr(obj)
while True:
try:
start = text.index("\\x")
text = text[:start] +
byte_replacement(text[start:start+4]) + text[start+4:]
except ValueError:
break
print text

Is there a better way to handle this problem?

-- 
http://ysar.net/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
Mark Lawrence  writes:

> On 31/10/2013 13:17, Alain Ketterlin wrote:
>> "E.D.G."  writes:
>>
>>>The calculation speed question just involves relatively simple
>>> math such as multiplications and divisions and trig calculations such
>>> as sin and tan etc.
>>
>> These are not "simple" computations.
>>
>> Any compiled language (Fortran, C, C++, typically) will probably go much
>> faster than any interpreted/bytecode-based language (like python or
>> perl, anything that does not use a jit).
>>
>
> From http://docs.python.org/3/library/math.html "CPython
> implementation detail: The math module consists mostly of thin
> wrappers around the platform C math library functions."

Of course, at the end, you need to do the computation.

I was not clear enough. I meant: the time taken by the bytecode
interpreter is probably larger than the time taken to compute the
result (and not only for +).

> There's only one way I know of to find if it's actually fast enough
> and that's test it.

Whether they are "fast enough" or not is another question and depends on
the application. It seems that the OP feels they are not fast enough (in
perl, but I see no reason why it would be better in python).

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 1:41 AM, Robert Kern  wrote:
> On 2013-10-31 14:05, Chris Angelico wrote:
>>
>> On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
>>  wrote:
>>>
>>> "E.D.G."  writes:
>>>
The calculation speed question just involves relatively simple
 math such as multiplications and divisions and trig calculations such
 as sin and tan etc.
>>>
>>>
>>> These are not "simple" computations.
>>>
>>> Any compiled language (Fortran, C, C++, typically) will probably go much
>>> faster than any interpreted/bytecode-based language (like python or
>>> perl, anything that does not use a jit).
>>
>>
>> Well, they may not be simple to do, but chances are you can push the
>> work down to the CPU/FPU on most modern hardware - that is, if you're
>> working with IEEE floating point, which I'm pretty sure CPython always
>> does; not sure about other Pythons. No need to actually calculate trig
>> functions unless you need arbitrary precision (and even then, I'd bet
>> the GMP libraries have that all sewn up for you). So the language
>> doesn't make a lot of difference.
>
>
> Sure it does. Python boxes floats into a PyObject structure. Both Python and
> C will ultimately implement the arithmetic of "a + b" with an FADD
> instruction, but Python will do a bunch of pointer dereferencing, hash
> lookups, and function calls before it gets down to that. All of that
> overhead typically outweighs the floating point computations down at the
> bottom, even for the more expensive trig functions.

Of course that's true, but that difference is just as much whether
you're working with addition or trig functions. That overhead is the
same. So if, as I said in the other post, you're doing some heavy
crypto work or something, then yes, all that boxing and unboxing is
expensive. Most programs aren't doing that, so the advantage is far
less (by proportion).

Plus, high level languages like Python make it a *LOT* easier to work
with arbitrary-precision integers than C does. In Python, you just
work with the default integer type and it's infinite-precision. In C,
you have to switch to explicitly using GMP (or equivalent). I'd much
rather pay the overhead and have the convenience of int being able to
store any integer.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 1:18 AM, Alain Ketterlin
 wrote:
> Well, sure, yes, I agree with you and hope they are left to the FP
> engine (still, fp ops are often multi-cycle, but that's a minor point).
>
> But what I meant was: a (bytecode) interpreted program will always be
> slower than a compiled program, probably by an order of magnitude when
> doing number crunching.

Yeah, but it depends on what your number crunching actually involves.

If you're implementing crypto in Python, then yes, there's a lot of
actual Python number crunching, and it's going to be slow. But
calculating the cosine of 1.23456 is going to take very close to the
same amount of time in each - the work isn't being done in Python.

But yes, Python code does tend to be a lot slower than equivalent C.
The goal of Python is not to lick (or even challenge) C for raw speed,
but to be "fast enough", and to be easy to write and clear to read. It
does a fairly good job at that.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Robert Kern

On 2013-10-31 14:05, Chris Angelico wrote:

On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
 wrote:

"E.D.G."  writes:


   The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such
as sin and tan etc.


These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).


Well, they may not be simple to do, but chances are you can push the
work down to the CPU/FPU on most modern hardware - that is, if you're
working with IEEE floating point, which I'm pretty sure CPython always
does; not sure about other Pythons. No need to actually calculate trig
functions unless you need arbitrary precision (and even then, I'd bet
the GMP libraries have that all sewn up for you). So the language
doesn't make a lot of difference.


Sure it does. Python boxes floats into a PyObject structure. Both Python and C 
will ultimately implement the arithmetic of "a + b" with an FADD instruction, 
but Python will do a bunch of pointer dereferencing, hash lookups, and function 
calls before it gets down to that. All of that overhead typically outweighs the 
floating point computations down at the bottom, even for the more expensive trig 
functions.


This is where numpy comes in. If you can arrange your computation on arrays, 
then only the arrays need to be unboxed once, then the rest of the arithmetic 
happens in C.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
Chris Angelico  writes:

> On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
>  wrote:
>> "E.D.G."  writes:
>>
>>>   The calculation speed question just involves relatively simple
>>> math such as multiplications and divisions and trig calculations such
>>> as sin and tan etc.
>>
>> These are not "simple" computations.
>>
>> Any compiled language (Fortran, C, C++, typically) will probably go much
>> faster than any interpreted/bytecode-based language (like python or
>> perl, anything that does not use a jit).
>
> Well, they may not be simple to do, but chances are you can push the
> work down to the CPU/FPU on most modern hardware - that is, if you're
> working with IEEE floating point, which I'm pretty sure CPython always
> does; not sure about other Pythons. No need to actually calculate trig
> functions unless you need arbitrary precision (and even then, I'd bet
> the GMP libraries have that all sewn up for you). So the language
> doesn't make a lot of difference.

Well, sure, yes, I agree with you and hope they are left to the FP
engine (still, fp ops are often multi-cycle, but that's a minor point).

But what I meant was: a (bytecode) interpreted program will always be
slower than a compiled program, probably by an order of magnitude when
doing number crunching.

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Mark Lawrence

On 31/10/2013 13:17, Alain Ketterlin wrote:

"E.D.G."  writes:


   The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such
as sin and tan etc.


These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).



From http://docs.python.org/3/library/math.html "CPython implementation 
detail: The math module consists mostly of thin wrappers around the 
platform C math library functions."


There's only one way I know of to find if it's actually fast enough and 
that's test it.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Chris Angelico
On Fri, Nov 1, 2013 at 12:17 AM, Alain Ketterlin
 wrote:
> "E.D.G."  writes:
>
>>   The calculation speed question just involves relatively simple
>> math such as multiplications and divisions and trig calculations such
>> as sin and tan etc.
>
> These are not "simple" computations.
>
> Any compiled language (Fortran, C, C++, typically) will probably go much
> faster than any interpreted/bytecode-based language (like python or
> perl, anything that does not use a jit).

Well, they may not be simple to do, but chances are you can push the
work down to the CPU/FPU on most modern hardware - that is, if you're
working with IEEE floating point, which I'm pretty sure CPython always
does; not sure about other Pythons. No need to actually calculate trig
functions unless you need arbitrary precision (and even then, I'd bet
the GMP libraries have that all sewn up for you). So the language
doesn't make a lot of difference.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread Mark Lawrence

On 31/10/2013 11:40, rusi wrote:


Please treat python as a given -- like the sun, moon and taxes."



You missed the most obvious one, trolls :)

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Mark Lawrence

On 31/10/2013 10:38, E.D.G. wrote:

Posted by E.D.G. October 31, 2013

Hi Chris,

   Thanks for the responses. Several of my questions were answered.

   The calculation speed question just involves relatively simple
math such as multiplications and divisions and trig calculations such as
sin and tan etc. Presently I am using Perl to do those types of
calculations. And I am starting to run into problems with how long it
takes Perl to do thousands and even millions of calculations like that
even though they are relatively simple.

   The version of Perl that I am presently using has the usual Print
statements for printing to the Perl program window.  It sends Windows
programs or files information in the following manner:

Win32::GuiTest::SendKeys("The text within these two parentheses marks
will print as text in an active Notepad window.");

   It would be my guess that Python has some type of statement like
that.



https://pypi.python.org/pypi/pywinauto/0.3.9 or 
http://stackoverflow.com/questions/1823762/sendkeys-for-python-3-1-on-windows 
of any use?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Alain Ketterlin
"E.D.G."  writes:

>   The calculation speed question just involves relatively simple
> math such as multiplications and divisions and trig calculations such
> as sin and tan etc.

These are not "simple" computations.

Any compiled language (Fortran, C, C++, typically) will probably go much
faster than any interpreted/bytecode-based language (like python or
perl, anything that does not use a jit).

I have never seen any serious use of python for numerical computations
without use of numpy/scipy, which is basically a python wrapper around
compiled libraries. You probably should consider such a combination.

> Presently I am using Perl to do those types of calculations. And I am
> starting to run into problems with how long it takes Perl to do
> thousands and even millions of calculations like that even though they
> are relatively simple.

No surprise.

> [...] It sends Windows programs or files information in the following
> manner:
>
> Win32::GuiTest::SendKeys("...");
>

I have no idea on what this could be useful for, but it took me a few
seconds to type "python sendkeys" and get some interesting results.

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Roy Smith
In article ,
 "E.D.G."  wrote:
 
> 1.  How fast can Python do math calculations compared with other languages 
> such as Fortran and fast versions of Basic.  I would have to believe that it 
> is much faster than Perl for doing math calculations.

Getting a handle on Python's execution speed is not easy.  The problem 
is that the core library is mostly written in C, so operations that 
happen inside the core library are fast.  Operations that happen in 
user-written Python code are slow.  How fast your overall program will 
run is largely determined by how much you're executing user code and how 
much you're executing library calls.

People have done lots of comparisons of language execution speed over 
the years.  If you google for "python speed comparison", you'll find 
plenty of more detailed answers than you'll get here.

> 2.  Can Python be used to create CGI programs?  These are the ones that run 
> on Internet server computers and process data submitted through Web site 
> data entry screens etc.  I know that Perl CGI programs will do that.

Yes, they can.  However, CGI is largely an obsolete interface, partly 
because it's so inefficient.  If you're worried about execution speed, 
CGI is not what you should be looking at.

> 3.  If Python can be used for CGI programming, can it draw charts such as 
> .png files that will then display on Web pages at a Web site?

Yes.  There are a number of modules out there for doing this.  Again, 
google is your friend.  Search for "python charting module", or 
variations on that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Algorithm that makes maximum compression of completly diffused data.

2013-10-31 Thread rusi
On Thursday, October 31, 2013 3:00:24 AM UTC+5:30, Joshua Landau wrote:

> What I'm confounded about is this list's inability to recognise a
> troll when it slaps it vocally in the face.

> This isn't like Nikos. There's no "troll vs. incompetent" debate to be
> had.


Its usually called "entertainment". Something related:

http://onceuponatimeinindia.blogspot.in/2009/07/hard-drive-weight-increasing.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-31 Thread Tim Chase
On 2013-10-30 19:28, Roy Smith wrote:
> For example, it's reasonable to consider any vowel (or string of
> vowels, for that matter) to be closer to another vowel than to a
> consonant.  A great example is the word, "bureaucrat".  As far as
> I'm concerned, it's spelled {b, vowels, r, vowels, c, r, a, t}.  It
> usually takes me three or four tries to get auto-correct to even
> recognize what I'm trying to type and fix it for me.

[glad I'm not the only one who has trouble spelling "bureaucrat"]

Steven D'Aprano wisely mentioned elsewhere in the thread that "The
right solution to that is to treat it no differently from other fuzzy
searches. A good search engine should be tolerant of spelling errors
and alternative spellings for any letter, not just those with
diacritics."

Often the Levenshtein distance is used for calculating closeness, and
the off-the-shelf algorithm assigns a cost of one per difference
(addition, change, or removal).  It doesn't sound like it would be
that hard[1] to assign varying costs based on what character was
added/changed/removed.  A diacritic might have a cost of N while a
similar character (vowel->vowel or consonant->consonant, or
consonant-cluster shift) might have a cost of 2N, and a totally
arbitrary character shift might have a cost of 3N (or higher).
Unfortunately, the Levenshtein algorithm is already O(M*N) slow and
can't be reasonably precalculated without knowing both strings, so
this just ends up heaping additional lookups/comparisons atop
already-slow code.

-tkc

[1]
http://en.wikipedia.org/wiki/Levenshtein_distance#Possible_modifications








.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread rusi
On Thursday, October 31, 2013 4:42:15 PM UTC+5:30, Antoon Pardon wrote:
> Op 31-10-13 08:37, rusi schreef:

> > 2. Antoon: I was a bit surprised at your siding with the indentation 
> > business.
> > As an old-geezer programmer I can think of a number of reasons why,
> > indentation=structure is a problem. Thats a subject for another thread.

> You didn't expect me to be perfect, did you? 

:-)

> What bothered me was that some
> responses made using python like a religion. Remarks like: "Your mind was
> poisoned by other languages" or "You will grow to love some python aspect".
> People can argue the advantages of how python does it, but my buttons get
> pushed when they do it in a way that suggest you are just not a true convert
> yet.

Ok fair enough.
It just seems to me that if (ever!) something like a guideline/code
for this list is made, one thing needed is that somethings are
negotiable some not.  In particular, python programs are what we discuss, PL 
design only at the fringes.

Especially when an absolute noob starts holding forth about python without 
having a clue, I feel the most fruitful lines is to not agree or disagree but 
to say: "Python programs are what we discuss here; not python. Please treat 
python as a given -- like the sun, moon and taxes."

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Chris “Kwpolska” Warrick
On Thu, Oct 31, 2013 at 11:38 AM, E.D.G.  wrote:
> Posted by E.D.G. October 31, 2013

no need to write that.

>
> Hi Chris,
>
>   Thanks for the responses. Several of my questions were answered.
>
>   The calculation speed question just involves relatively simple math
> such as multiplications and divisions and trig calculations such as sin and
> tan etc. Presently I am using Perl to do those types of calculations. And I
> am starting to run into problems with how long it takes Perl to do thousands
> and even millions of calculations like that even though they are relatively
> simple.

I suggest that you try Python out yourself, on your data.  I can’t

>   The version of Perl that I am presently using has the usual Print
> statements for printing to the Perl program window.  It sends Windows
> programs or files information in the following manner:
>
> Win32::GuiTest::SendKeys("The text within these two parentheses marks will
> print as text in an active Notepad window.");
>
>   It would be my guess that Python has some type of statement like that.
>

Looks like you want something like [0] (requires pywin32 from [1]).

[0]: http://win32com.goermezer.de/content/view/136/254/
[1]: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k

Στις 31/10/2013 11:32 πμ, ο/η Nick the Gr33k έγραψε:

The error seen form error log is:

[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] Traceback
(most recent call last):
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]   File
"/home/nikos/public_html/cgi-bin/metrites.py", line 274, in 
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] (cID,
refs, host, city, useros, browser, visits, downloads) )

[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')

line 274 is:

# add this visitor entry into database
cur.execute('''INSERT INTO visitors (counterID, refs, host, city,
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s,
%s)''',  (cID, refs, host, city, useros, browser, visits, downloads) )



This error happened at the moment when i decided to insert the 
'downloads' column into the 'visitors' database

--
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread Antoon Pardon
Op 31-10-13 08:37, rusi schreef:
> On Thursday, October 31, 2013 2:37:31 AM UTC+5:30, Antoon Pardon wrote:
>> Op 30-10-13 21:52, Ned Batchelder schreef:
>>> On 10/30/13 3:59 PM, Antoon Pardon wrote:
 Op 30-10-13 20:13, Jonas schreef:
> No it isn't...
> The programmers of the tools on either of side will have to adapt.
> I wish it would be Google but it could be a database problem, but what do 
> i know maybe their fucking with you.
 Why should people who are using good functioning tools have to adapt to
 someone, in this case being you, who is using tools that are behaving 
 faulty and as an effect is polluting the news group with hard to read
 contributions?
>>> Can I suggest that perhaps Jonas is someone best ignored?  It's clear
>>> he is not willing to join the community, and does not value much of
>>> what we have to say.  In addition, he seems to be above providing details
>>> for claims he makes.
> 
>> Yes, you can suggest that. I might extend him the benefit of doubt for one
>> or two more exchanges, but if I don't notice any appearance of good will by
>> then I will in the future mostly ignore him.
> 
> Couple of things I wish to say:
> 1. One of the tragedies of human relations is escalation:
>  - I shout at you
>  - You hit me
>  - I shoot you
>  - You bomb me and mine (and not remotely mine) out of existence
>  - and so on
> 
> If Mark had not been rude to Jonas and explained to him at a little more
> length, maybe he would not be assholing in full-blast.
> Or maybe not… Maybe he is just trolling… Just sayin': We dont really know

Let's assume you are correct. I don't find it makes that much of a difference.
If it takes one person being rude to you, to make you go assholing in full-blast
then you are a problem. If one person being rude to you makes you blind to the
negative effects your bahaviour has on a whole group and makes you effectively
say you don't care about the annoyance you are causing then you are a biiger
problem than the person being rude.

> 
> 2. Antoon: I was a bit surprised at your siding with the indentation business.
> As an old-geezer programmer I can think of a number of reasons why,
> indentation=structure is a problem. Thats a subject for another thread.

You didn't expect me to be perfect, did you? What bothered me was that some
responses made using python like a religion. Remarks like: "Your mind was
poisoned by other languages" or "You will grow to love some python aspect".
People can argue the advantages of how python does it, but my buttons get
pushed when they do it in a way that suggest you are just not a true convert
yet.

> However for a thread whose subject-line says "First day beginner to python…"
> I am surprised that you (ie Antoon) participated.
> I say this since wrt the Nikos-issue, you seem to be the only sane guy around
> who feels the Nikos-threads are more the problem than Nikos.

Nikos has a history, Jonas didn't. So I was willing to give Jonas the benefit of
doubt, while Nikos has spend that a long time ago. As you, I considered it a 
real
possibility that Jonas had been provoked somehow, so I was willing to give him
a chance by trying to explain things to him in a not provocative way, in the 
hope
he would calm down and be willing to be more cooperative. In the end that 
doesn't
seem to have worked out well but I thought he deserved a chance.

Now I wouldn't mind if some people would still give Jonas some benefit of doubt
where mine is exhausted. People can have wider boundaries than mine. However 
with
Nikos, it seemed that some people just didn't had any boundaries and expected
Nikos to be treated as if he had no history.

-- 
Antoon Pardon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread rusi
On Thursday, October 31, 2013 3:41:41 PM UTC+5:30, Mark Lawrence wrote:
> On 31/10/2013 07:37, rusi wrote:
> > If Mark had not been rude to Jonas and explained to him at a little more 
> > length, maybe he would not be assholing in full-blast.
> What rubbish.  The OP was asked repeatedly, first by Dave Angel and then 
> by myself, not to post double spaced crap.  He simply refused to do so. 
>   I then stated that the best solution was for him to stop posting. 
> Where in this exchange was I rude?

Well I wonder whether I want to get in here… I am assuming you are
genuinely asking and I am correspondingly answering:

When you tell someone to get out -- 'to stop posting' is kind of equivalent
to that -- you dont leave much scope for dialogue :-)

I see that you asked him some 6-7 times before that. So I am not really
blaming you for what you did.  Just trying to suggest that those half-dozen
times could have been louder and more detailed before saying: Please go
away from here!

Also others (Alister?) were double-space-reply-posting as well.  When you
mean to point out a behavior without getting personal, it helps
to point out all instances of that behavior.  Otherwise it looks like you
are going for someone, when in fact you are going against something.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread E.D.G.

Posted by E.D.G. October 31, 2013

Hi Chris,

  Thanks for the responses. Several of my questions were answered.

  The calculation speed question just involves relatively simple math 
such as multiplications and divisions and trig calculations such as sin and 
tan etc. Presently I am using Perl to do those types of calculations. And I 
am starting to run into problems with how long it takes Perl to do thousands 
and even millions of calculations like that even though they are relatively 
simple.


  The version of Perl that I am presently using has the usual Print 
statements for printing to the Perl program window.  It sends Windows 
programs or files information in the following manner:


Win32::GuiTest::SendKeys("The text within these two parentheses marks will 
print as text in an active Notepad window.");


  It would be my guess that Python has some type of statement like 
that.


--
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-31 Thread wxjmfauth
Le jeudi 31 octobre 2013 08:10:18 UTC+1, Steven D'Aprano a écrit :
> On Wed, 30 Oct 2013 01:49:28 -0700, wxjmfauth wrote:
> 
> 
> 
> >> The right solution to that is to treat it no differently from other
> 
> >> fuzzy
> 
> >> searches. A good search engine should be tolerant of spelling errors
> 
> >> and
> 
> >> alternative spellings for any letter, not just those with diacritics.
> 
> >> Ideally, a good search engine would successfully match all three of
> 
> >> "naïve", "naive" and "niave", and it shouldn't rely on special handling
> 
> >> of diacritics.
> 
> > 
> 
> > This is a non sense. The purpose of a diacritical mark is to make a
> 
> > letter a different letter. If a tool is supposed to match an ô, there is
> 
> > absolutely no reason to match something else.
> 
> 
> 
> 
> 
> I'm glad that you know so much better than Google, Bing, Yahoo, and other 
> 
> search engines. When I search for "mispealled" Google gives me:
> 
> 
> 
> Showing results for misspelled
> 
> Search instead for mispealled
> 
> 
> 
> 
> 
> But I see now that this is nonsense and there is *absolutely no reason* 
> 
> to match something other than the ecaxt wrods I typed.
> 
> 
> 
> Perhaps you should submit a bug report to Google:
> 
> 
> 
> "When I mistype a word, Google correctly gives me the search results I 
> 
> wanted, instead of the wrong results I didn't want."
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven


As far as I know, I recognized my mistake. I had more
text processing systems in mind, than search engines.

I can even tell you, I am really stupid. I wrote pure
Unicode software to sort French or German strings.

Pure unicode == independent from any locale.

jmf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread Mark Lawrence

On 31/10/2013 07:37, rusi wrote:


If Mark had not been rude to Jonas and explained to him at a little more 
length, maybe he would not be assholing in full-blast.



What rubbish.  The OP was asked repeatedly, first by Dave Angel and then 
by myself, not to post double spaced crap.  He simply refused to do so. 
 I then stated that the best solution was for him to stop posting. 
Where in this exchange was I rude?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread Chris “Kwpolska” Warrick
On Thu, Oct 31, 2013 at 10:31 AM, E.D.G.  wrote:
> Posted by E.D.G. on October 31, 2013
>
>   The following are several relatively basic questions regarding
> Python's capabilities.  I am not presently using it myself.  At the moment a
> number of people including myself are comparing it with other programs such
> as XBasic for possible use.
>
> 1.  How fast can Python do math calculations compared with other languages
> such as Fortran and fast versions of Basic.  I would have to believe that it
> is much faster than Perl for doing math calculations.

Depends on what do you want to calculate.  Also, note that Python is
liked by the scientific community to use for calculations.  This might
be a hint.

> 2.  Can Python be used to create CGI programs?  These are the ones that run
> on Internet server computers and process data submitted through Web site
> data entry screens etc.  I know that Perl CGI programs will do that.

Yes.  Although most people in the Python community dislike the
old-style “CGI” and use “web apps” instead.  They are also connected
with a different philosophy, for example we do not store .py files in
/cgi-bin/, we never expose our .py files and put it somewhere else on
the system and let the web server act as a proxy to a WSGI server
(gunicorn/uwsgi).

> 3.  If Python can be used for CGI programming, can it draw charts such as
> .png files that will then display on Web pages at a Web site?

Yes, but you need to install additional libraries for that.

> 4.  How well does Python work for interactive programming.  For example, if
> a Python program is running on a PC and is drawing a chart, can that chart
> be modified by simply pressing a key while the Python program is running.  I
> have Perl and Gnuplot program combinations that can do that.  Their
> interactive speed is not that great.  But it is adequate for my own uses.

Doable, but I cannot give you any information on the speed.

> 5.  Can a running Python program send information to the Windows operating
> system as if it were typed in from the keyboard?  Perl can do that and I
> would imagine that Python probably has that same capability.

Definitely possible, but might take you a bit of work and knowledge of
Windows internals (go ask Google).

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k

The error seen form error log is:

[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] Traceback 
(most recent call last):
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93]   File 
"/home/nikos/public_html/cgi-bin/metrites.py", line 274, in 
[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] (cID, 
refs, host, city, useros, browser, visits, downloads) )


[Thu Oct 31 09:29:35 2013] [error] [client 46.198.103.93] 
pymysql.err.InternalError: (1241, 'Operand should contain 1 column(s)')


line 274 is:

# add this visitor entry into database
cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
%s)''',  (cID, refs, host, city, useros, browser, visits, downloads) )

--
https://mail.python.org/mailman/listinfo/python-list


Basic Python Questions - Oct. 31, 2013

2013-10-31 Thread E.D.G.

Posted by E.D.G. on October 31, 2013

  The following are several relatively basic questions regarding Python's 
capabilities.  I am not presently using it myself.  At the moment a number 
of people including myself are comparing it with other programs such as 
XBasic for possible use.


1.  How fast can Python do math calculations compared with other languages 
such as Fortran and fast versions of Basic.  I would have to believe that it 
is much faster than Perl for doing math calculations.


2.  Can Python be used to create CGI programs?  These are the ones that run 
on Internet server computers and process data submitted through Web site 
data entry screens etc.  I know that Perl CGI programs will do that.


3.  If Python can be used for CGI programming, can it draw charts such as 
.png files that will then display on Web pages at a Web site?


4.  How well does Python work for interactive programming.  For example, if 
a Python program is running on a PC and is drawing a chart, can that chart 
be modified by simply pressing a key while the Python program is running.  I 
have Perl and Gnuplot program combinations that can do that.  Their 
interactive speed is not that great.  But it is adequate for my own uses.


5.  Can a running Python program send information to the Windows operating 
system as if it were typed in from the keyboard?  Perl can do that and I 
would imagine that Python probably has that same capability.


--
https://mail.python.org/mailman/listinfo/python-list


Retrieving possible list for use in a subsequent INSERT

2013-10-31 Thread Nick the Gr33k


# if first time for webpage; create new record( primary key is 
automatic, hit is defaulted ), if page exists then update record
cur.execute('''INSERT INTO counters (url) VALUES (%s) ON DUPLICATE KEY 
UPDATE hits = hits + 1''', page )

# get the primary key value of the new added record
cID = cur.lastrowid


# find out if visitor has downloaded torrents in the past
cur.execute('''SELECT torrent FROM files WHERE host = %s''', host )
data = cur.fetchall()

downloads = []
if data:
for torrent in data:
downloads.append( torrent )
else:
downloads.append( 'None Yet' )


# add this visitor entry into database
cur.execute('''INSERT INTO visitors (counterID, refs, host, city, 
useros, browser, visits, downloads) VALUES (%s, %s, %s, %s, %s, %s, %s, 
%s)''', (cID, refs, host, city, useros, browser, visits, downloads) )




Hello,
In my attempt to add as an extra column key the possible downloads of 
the current visitor( based on its hostname to identify him) i have wrote 
the above code to try to do so.


I'am afraid something its not working as i expect it to work.
Where is my mistake?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

2013-10-31 Thread Steven D'Aprano
On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:

> On 10/30/2013 04:22 AM, Steven D'Aprano wrote:

>> Skybuck's experience at programming *is relevant* to the question of
>> whether or not he understands what he is talking about.
> 
> No.  You claimed his proposition "made no sense" based on your analysis
> of it.  

I said absolutely nothing of the sort. You're making that quote up -- not 
just misinterpreting what I said, or taking my words in the worst 
possible way, but completely inventing things I never said. Not only did 
I never say that Skybuck's proposition "made no sense", but I gave an 
example of a language with a loop that does exactly what he wants, and 
explicitly described as making sense:

"There is one sort of loop where it makes sense to have the loop condition
at the end. Python doesn't have such a loop, but Pascal does: the repeat
until loop."

I don't know whether to be more offended for myself, that you would 
invent such a bare-faced falsehood about what I said, or for anyone else 
reading this thread, that you should assume they would fail to notice 
that not only did I not say what you quote me as saying, but that it is 
the *opposite* of what I actually said.

I don't know whether you are deliberately lying, or whether you're just 
such a careless reader that you have attributed words actually written by 
Skybuck to me, but either way I expect an apology from you for putting 
false words into my mouth.

As for the rest of your argument, I am not of the opinion that he is an 
inexperienced programmer because his proposal is "nutty" (YOUR word, not 
mine) since I don't think his proposal is completely nutty. There are use-
cases for putting the loop condition at the end. I think he is an 
inexperienced programmer because of the lack of any sign in his emails 
that he has any meaningful experience in programming.

As for your defence[1] of the ad hominem "Clearly Julie is mistaken, 
she's just a girl, what would she know about programming?", I am not one 
of those cultural relativists who thinks that any belief, no matter how 
stupid, should be judged on how sincere the person expressing it is. 
Regardless of how sincere they might be, they are simply *wrong*, their 
argument is irrational, and it is an ad hominem fallacy. Women, even 
"girls", are capable of having detailed knowledge about programming, and 
there is no logical or factual reason for debating this point, any more 
than we should be debating whether or not people with brown hair or flat 
feet can program.


> (Even if none of the above were true, I would still ask, why shouldn't
> someone's opinion on a programming topic stand on their arguments alone
> without regard to whether they've written code on a physical machine?)

Of course their arguments stand on their merits. But those merits are 
likely to be pretty slim, if their arguments are not grounded in reality. 
We know what happens when "great thinkers" start philosophising without 
any grounding in reality, we get Pliny the Elder who concluded that elks 
have no knees, and Aristotle, who was married twice but apparently never 
thought to look inside either of his wives' mouth, who maintained that 
women have fewer teeth than men. And so we come back to Skybuck, who 
apparently believes that the use of GOTO instead of loops makes code more 
reliable and easier to maintain.




[1] To head off false accusations that I'm misrepresenting you, here for 
the record are your exact words:

[quote]
Secondly, the example ad hominem argument you gave, "Clearly 
Julie is mistaken, she's just a girl, what would she know about
programming?" depends on the non-validity of the logical
implication.  Yet I'm sure you are aware that are some people who
would find that a valid implication and if you could not defend it,
then you would not be able to claim ad hominem. Of course it *is*
easily defendable which is why you used it as an example.
[end quote]

On the contrary, the implication that women cannot program is utterly 
counterfactual and hence is indefensible. It simply isn't and cannot be 
true. Even if there was not a single female programmer in the world -- 
and in reality there are thousands or tens of thousands -- there is 
nothing in biology, chemistry, physics or abstract logic to suggest that 
female Homo sapiens in this world could be inherently incapable of 
programming.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: First day beginner to python, add to counter after nested loop

2013-10-31 Thread rusi
On Thursday, October 31, 2013 2:37:31 AM UTC+5:30, Antoon Pardon wrote:
> Op 30-10-13 21:52, Ned Batchelder schreef:
> > On 10/30/13 3:59 PM, Antoon Pardon wrote:
> >> Op 30-10-13 20:13, Jonas schreef:
> >>> No it isn't...
> >>> The programmers of the tools on either of side will have to adapt.
> >>> I wish it would be Google but it could be a database problem, but what do 
> >>> i know maybe their fucking with you.
> >> Why should people who are using good functioning tools have to adapt to
> >> someone, in this case being you, who is using tools that are behaving 
> >> faulty and as an effect is polluting the news group with hard to read
> >> contributions?
> > Can I suggest that perhaps Jonas is someone best ignored?  It's clear
> > he is not willing to join the community, and does not value much of
> > what we have to say.  In addition, he seems to be above providing details
> > for claims he makes.

> Yes, you can suggest that. I might extend him the benefit of doubt for one
> or two more exchanges, but if I don't notice any appearance of good will by
> then I will in the future mostly ignore him.

Couple of things I wish to say:
1. One of the tragedies of human relations is escalation:
 - I shout at you
 - You hit me
 - I shoot you
 - You bomb me and mine (and not remotely mine) out of existence
 - and so on

If Mark had not been rude to Jonas and explained to him at a little more 
length, maybe he would not be assholing in full-blast.
Or maybe not… Maybe he is just trolling… Just sayin': We dont really know

2. Antoon: I was a bit surprised at your siding with the indentation business. 
As an old-geezer programmer I can think of a number of reasons why,
indentation=structure is a problem. Thats a subject for another thread.

However for a thread whose subject-line says "First day beginner to python…"
I am surprised that you (ie Antoon) participated.
I say this since wrt the Nikos-issue, you seem to be the only sane guy around 
who feels the Nikos-threads are more the problem than Nikos.

3. I am posting this from GG.  And NO hand cut-paste-edit. 
Firefox sends over the text to emacs.
emacs auto-cleans up the GG crap
When I exit emacs Im back in firefox with a clean text
[Thanks Kushal for the tip]

I dont expect Jonas to try or listen but there are thousands of other GG users
And if there is some problem (textual please not political or philosophical!)
I'd appreciate being told.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-31 Thread Mark Lawrence

On 31/10/2013 07:10, Steven D'Aprano wrote:

On Wed, 30 Oct 2013 01:49:28 -0700, wxjmfauth wrote:


The right solution to that is to treat it no differently from other
fuzzy
searches. A good search engine should be tolerant of spelling errors
and
alternative spellings for any letter, not just those with diacritics.
Ideally, a good search engine would successfully match all three of
"naïve", "naive" and "niave", and it shouldn't rely on special handling
of diacritics.


This is a non sense. The purpose of a diacritical mark is to make a
letter a different letter. If a tool is supposed to match an ô, there is
absolutely no reason to match something else.



I'm glad that you know so much better than Google, Bing, Yahoo, and other
search engines. When I search for "mispealled" Google gives me:

 Showing results for misspelled
 Search instead for mispealled


But I see now that this is nonsense and there is *absolutely no reason*
to match something other than the ecaxt wrods I typed.

Perhaps you should submit a bug report to Google:

"When I mistype a word, Google correctly gives me the search results I
wanted, instead of the wrong results I didn't want."



I'm sorry Steven but you're completely out of your depth here.  Please 
bow down to the superior intellect of jmf, where jm is for Joseph McCarthy.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: trying to strip out non ascii.. or rather convert non ascii

2013-10-31 Thread Steven D'Aprano
On Wed, 30 Oct 2013 01:49:28 -0700, wxjmfauth wrote:

>> The right solution to that is to treat it no differently from other
>> fuzzy
>> searches. A good search engine should be tolerant of spelling errors
>> and
>> alternative spellings for any letter, not just those with diacritics.
>> Ideally, a good search engine would successfully match all three of
>> "naïve", "naive" and "niave", and it shouldn't rely on special handling
>> of diacritics.
> 
> This is a non sense. The purpose of a diacritical mark is to make a
> letter a different letter. If a tool is supposed to match an ô, there is
> absolutely no reason to match something else.


I'm glad that you know so much better than Google, Bing, Yahoo, and other 
search engines. When I search for "mispealled" Google gives me:

Showing results for misspelled
Search instead for mispealled


But I see now that this is nonsense and there is *absolutely no reason* 
to match something other than the ecaxt wrods I typed.

Perhaps you should submit a bug report to Google:

"When I mistype a word, Google correctly gives me the search results I 
wanted, instead of the wrong results I didn't want."



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list