Re: A simple-to-use sound file writer

2010-01-15 Thread Steven D'Aprano
On Fri, 15 Jan 2010 05:23:48 +0100, Alf P. Steinbach wrote:

> You're again into innuendo, misleading statements and so forth.
[...]
> [Steve Holden] prefers to spout innuendu, personal attacks and
> misleading statements.

Your constant and repeated accusations that any questioning of you is 
deliberate lying and innuendo (innuendo of what, I wonder?) is getting 
tiresome. You did this to me, accusing me of deliberate lying, and now 
you're doing the same to Steve.

Just because people question the (alleged) facts as you report it doesn't 
mean they're deliberately trying to mislead others. Hasn't it occurred to 
you that perhaps we're not deliberately lying to make you look bad but 
actually think you are mistaken? A difference of opinion is not evidence 
that people are lying.

For somebody who fancies himself a writer teaching beginners to 
programming, your communication skills leave something to be desired. I 
hope your book is better than your posts, because from what I have seen 
your writing in this newsgroup is frequently sloppy and hard to 
understand, you tend to use terms in non-standard ways and then take any 
misunderstandings as a personal affront, and if anyone questions what you 
say, you're likely bristle and start looking for a fight.

I don't know what your problem is, but I wish you'd deal with it in 
private and stop dumping it on the rest of us. You're a smart fellow who 
brings much of value to the community, but dealing with your posts is 
becoming more trouble than they're worth.



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


Re: ctypes error

2010-01-15 Thread Dave Angel

>Gib Bogle wrote:
>>I have a simple demo program (on Windows XP) that uses the ctypes 
module to load a DLL. 
>>This program works as expected with Python 2.5.4, but fails with 
Python 2.6.4 (on a different
>> machine, each machine has only one Python version installed), with 
these messages:


>>File "demo.py", line 37, in 
>>  mydll = windll.LoadLibrary("DEMO.DLL")
>>File "c:\python26\lib\ctypes\__init__.py, line 431, in LoadLibrary
>>  return self._dlltype(name)
>>File "c:\python26\lib\ctypes\__init__.py, line 353, in __init__
>>  self._handle = _dlopen(self._name, mode)
>>WindowsError: [Error 14001] This application has failed to start 
because the application configuration is incorrect.  Reinstalling the 
application may fix this problem

>>
>>It isn't clear to me what the "application" is.  As far as I know I 
didn't install anything except Python 2.6.4.  Is it possible that ctypes 
doesn't work with 2.6.4?



Gib Bogle wrote:
It has 
occurred to me that the error may have nothing to do with ctypes.  The 
DLL was built on one machine and copied to the other (which doesn't 
have the compiler installed).  Although both machines are running 
Windows XP, there might be some subtle differences.


I see that the build machine has XP Professional, Version 2002, 
Service Pack 2, while the machine that fails to load the DLL has XP 
Home Edition, Version 2002, Service Pack 3.  Who knows.




The application is "python.exe".  And usually, when it gives such an 
error, there's a missing DLL, or one of improper version.


I think you want to run Dependency-Walker.  See
   http://msdn.microsoft.com/en-us/library/ms235265.aspx

for a description, and follow its link to
   http://go.microsoft.com/fwlink/?linkid=132640

to download it.

DaveA

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


Re: TypeError: __name__ must be set to a string object

2010-01-15 Thread Frank Millman

"Frank Millman"  wrote in message 
news:hieoq6$4i...@ger.gmane.org...
> Hi all
>
> This problem is similar to one I posted recently regarding the 
> multiprocessing module and unicode.
>
> However, although this one manifests itself while using the 
> multiprocessing module, is caused by Python itself (2.6.2).
>
> At the top of my program I have 'from __future__ import unicode_literals'.
>
> The relevant lines from my program read -
>from multiprocessing.managers import BaseManager
>class MyManager(BaseManager): pass
>MyManager.register('my_function', my_function)
>
> Inside the multiprocessing module, the following lines are executed -
>@classmethod
>def register(cls, typeid, ...)
>[...]
>def temp(...):
>[...]
>temp.__name__ = typeid
>
> At this point, Python raises the exception 'TypeError: __name__ must be 
> set to a string object'.
>
> I can fix it by changing my last line to -
>MyManager.register(str('my_function'), my_function)
>
> Is there any reason why __name__ cannot be a unicode object in Python 2.x? 
> If so, there is probably little chance of this being changed, so it is 
> probably not worth reporting.
>

For the record, I filed a report on January 13th - 


Frank



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


Re: Simple distributed example for learning purposes?

2010-01-15 Thread Tim Golden

On 14/01/2010 18:16, Mike Driscoll wrote:

I think distributed transcoding of hi-def videos would be cool, but I
haven't found much with Google. Still, you might find this useful for
your project:

http://pypi.python.org/pypi/AsynCluster/0.3


Thanks. I suspect that that would be overkill for what I need
but I'm always interested in whatever's out there so thanks
for pointing me that way.


For reasons I don't understand, the home page listed in that link is
blocked here.


Interestingly, it just fails to resolve over here. I'll try Googling
for it later. Fortunately, altho' we do have filtering here at work
via transparent proxy, our tech support guys are quite sane: if you
let them know a page is blocked and they can see it's perfectly ok
they'll just unlock it without hassle.

TJG


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


Re: A simple-to-use sound file writer

2010-01-15 Thread Alf P. Steinbach

* Steven D'Aprano:

On Fri, 15 Jan 2010 05:23:48 +0100, Alf P. Steinbach wrote:


You're again into innuendo, misleading statements and so forth.

[...]

[Steve Holden] prefers to spout innuendu, personal attacks and
misleading statements.


Your constant and repeated accusations that any questioning of you is 
deliberate lying and innuendo (innuendo of what, I wonder?) is getting 
tiresome. You did this to me, accusing me of deliberate lying, and now 
you're doing the same to Steve.


You did lie, that's established. In addition as I recall in the same post you 
went on about my motivations for doing the Terrible Deed that you invented. And 
you named one poor person who'd made a silly mistake, stating that he didn't do 
what the logs clearly showed he did do, and I think that was to force me to 
argue a case against him (but happily he did a superb job after that initial 
mistake, it would have been much harder for me to respond to your egging if not 
for that very good job he did).


And now you're trying to get me to argue a case against another person.

That's not very nice.


Just because people question the (alleged) facts as you report it doesn't 
mean they're deliberately trying to mislead others. Hasn't it occurred to 
you that perhaps we're not deliberately lying to make you look bad but 
actually think you are mistaken? A difference of opinion is not evidence 
that people are lying.


Mostly I assume that people who disagree with me think I'm mistaken, yes.

But when someone writes an article that's mainly or only about me, as has 
happened once earlier in this thread and that now you're doing, then I of course 
assume that it's personal, that the person writing has transferred some 
grievances from the technical domain to the personal domain.



For somebody who fancies himself a writer teaching beginners to 
programming, your communication skills leave something to be desired. I 
hope your book is better than your posts, because from what I have seen 
your writing in this newsgroup is frequently sloppy and hard to 
understand, you tend to use terms in non-standard ways and then take any 
misunderstandings as a personal affront, and if anyone questions what you 
say, you're likely bristle and start looking for a fight.


I'm probably a bad person, he he. :-)


I don't know what your problem is, but I wish you'd deal with it in 
private and stop dumping it on the rest of us. You're a smart fellow who 
brings much of value to the community, but dealing with your posts is 
becoming more trouble than they're worth.


Well please stop posting these silly articles about me, and *please* stop 
dragging other people into it.



Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows drag & drop with win32com and IDropTarget

2010-01-15 Thread Tim Golden

On 15/01/2010 07:20, Greg K wrote:

I'm trying to create a program that will process files dragged into
its window, however I can't seem to get the cursor to change correctly
when something is dragged over the window. I've created an object that
implements the IDropTarget interface, but it seems the value returned
by its DragEnter method is ignored by Windows. No matter what value it
returns, I always get a "create shortcut" cursor when something is
dragged over the window.


This is a segment of my code which works ok:

<... code snippet ...>
  def DragEnter (self, data_object, key_state, point, effect):
ur"""Query the data block for a drag action which is over the dialog.
If we can handle it, indicate that we're ready to accept a drop from
this data.
"""
try:
  data_object.QueryGetData (self._data_format)
except pywintypes.error:
  return shellcon.DROPEFFECT_NONE
else:
  return shellcon.DROPEFFECT_COPY
<... code snippet ...>

The whole code's here if you want:

https://winsys.googlecode.com/svn/trunk/winsys/dialogs.py

It looks as though you're returning an OK *and* the effect
which isn't how the thing is implemented via the pywin32
wrappers.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes error

2010-01-15 Thread Terry Reedy

On 1/15/2010 2:00 AM, Gib Bogle wrote:

It has occurred to me that the error may have nothing to do with ctypes.
  The DLL was built on one machine and copied to the other (which
doesn't have the compiler installed). Although both machines are running
Windows XP, there might be some subtle differences.


Python 2.5 and Python 2.6 are built with different versions of Microsoft 
Visual C. That could be your problem.


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


Re: Writing a string.ishex function

2010-01-15 Thread Duncan Booth
MRAB  wrote:

> Duncan Booth wrote:
>> MRAB  wrote:
>> 
>>> I raise you one character:
>>>
>>> ishex2 = lambda s: not(set(s)-set(string.hexdigits)) # Yours
>>> ishex3 = lambda s: not set(s)-set(string.hexdigits)  # Mine
>>>
>>> I could actually go three better:
>>>
>>> ishex3=lambda s:not set(s)-set(string.hexdigits)
>> 
>> But none of those pass your own "ishex('') should return False" test.
> 
> Neither do the others!

That's true, but since you were the one that pointed out they were all 
broken I would have thought your solution should actually work.

I'm sure you'll agree that a longer solution that works trumps any short 
but broken solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Shed Skin 0.3

2010-01-15 Thread Mark Dufour
Hi all,

I have just released Shed Skin 0.3, an experimental (restricted)
Python-to-C++ compiler. Please see my blog for more details about the
release:

http://shed-skin.blogspot.com/


Thanks,
Mark Dufour.
-- 
"Overdesigning is a SIN. It's the archetypal example of what I call 'bad
taste'" - Linus Torvalds
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Alf P. Steinbach

* Ben Finney:

"Alf P. Steinbach"  writes:


You did lie, that's established. In addition as I recall in the same
post you went on about my motivations for doing the Terrible Deed that
you invented.


None of that matches my (largely disinterested) observations. This is
pure fantasy, as best I can tell.


It's decidedly not kind of you to try to re-open those issues.

Anybody can have a bad day and write something that's untrue or actively 
misleading, whatever.


When it's been dealt with, and it has, it should not be reiterated.



I've tried in private to talk you out of this persecution fantasy;
others have tried in public. It all seems to be in vain.


It's quite normal for people to use ad hominem arguments, especially when they 
have chosen an indefensible position; that's why the technique has a name.


There's no persecution involved in that.

And people are not necessarily bad even when they do that from time to time, as 
you do here: it's human.




You've now passed my twit threshold, so welcome to my kill file.


Goodbye.


Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Author of a Python Success Story Needs a Job!

2010-01-15 Thread Simon Brunning
2010/1/14 Novocastrian_Nomad :
> Why is it so many, so called high tech companies, insist on the 19th
> century practice of demanding an employee's physical presence in a
> specific geographic location.

Pair programming and co-location with your end users both hugely
increase real productivity, in my experience. The programmer-to-code
step is only one of many parts of the process.

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Steve Holden
Alf P. Steinbach wrote:
> * Ben Finney:
>> "Alf P. Steinbach"  writes:
>>
>>> You did lie, that's established. In addition as I recall in the same
>>> post you went on about my motivations for doing the Terrible Deed that
>>> you invented.
>>
>> None of that matches my (largely disinterested) observations. This is
>> pure fantasy, as best I can tell.
> 
> It's decidedly not kind of you to try to re-open those issues.
> 
> Anybody can have a bad day and write something that's untrue or actively
> misleading, whatever.
> 
> When it's been dealt with, and it has, it should not be reiterated.
> 
> 
>> I've tried in private to talk you out of this persecution fantasy;
>> others have tried in public. It all seems to be in vain.
> 
> It's quite normal for people to use ad hominem arguments, especially
> when they have chosen an indefensible position; that's why the technique
> has a name.
> 
> There's no persecution involved in that.
> 
> And people are not necessarily bad even when they do that from time to
> time, as you do here: it's human.
> 
> 
>> You've now passed my twit threshold, so welcome to my kill file.
> 
> Goodbye.
> 
> 
> Cheers & hth.,
> 
> - Alf

How you can possibly hope that helps anyone except you I can't possibly
imagine. It seems that any request to question your own behavior, any
remark about how it might usefully change, is taken to be an ad homime,
attack.

As my wife (who has a colorful Scottish turn of phrase) might say, if
you were chocolate you would eat yourself.

Please, get over this obsession with being "right".

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: force URLencoding script

2010-01-15 Thread João
On Jan 14, 5:58 pm, r0g  wrote:
> João wrote:
> > On Jan 12, 10:07 pm, r0g  wrote:
> >> João wrote:
>
> > for the following data,
> > authentication = "UID=somestring&"
> > message = 'PROBLEM severity High: OperatorX Plat1(locationY) global
> > Succ. : 94.47%'
> > dest_number = 'XXX'
>
> > url_values = urlencode({'M':message})
> > enc_data = authentication + url_values + dest_number
>
> > I'm getting null for
> > full_url = Request(url, enc_data, headers)
>
> > and thus,
> > response = urlopen(full_url).read()
> > returns,
> > TypeError: 
>
> > )
>
> Are you sure it's returning a null and not just some other unexpected
> type?
>
> I think your problem may be that you are passing a urllib2 class to
> urllib(1)'s urlopen. Try using urllib2's urlopen instead e.g.
>
> import urllib2
> request_object = urllib2.Request('http://www.example.com')
> response = urllib2.urlopen(request_object)
> the_page = response.read()
>
> Roger.

Thanks Roger.
I think it's a null because i did a print(full_url) right after the
Request
I tried
request_object = urllib2.Request('http://www.example.com')
print(request_object)

but when printing I get: 

I've read about Python 2.4 not playing well with proxies even with no
proxy activated.
Any sugestion?

Thanks again

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


Re: Windows drag & drop with win32com and IDropTarget

2010-01-15 Thread Greg K
> It looks as though you're returning an OK *and* the effect
> which isn't how the thing is implemented via the pywin32
> wrappers.

Thanks for the reply, however even after I change the return value to
just the effect code, I still have the same problem. There must still
be something else I'm doing wrong... But I can probably figure it out
from looking at your working code (thanks for that).

Greg.

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


Re: A simple-to-use sound file writer

2010-01-15 Thread Alf P. Steinbach

* Steve Holden:

Alf P. Steinbach wrote:

* Ben Finney:

"Alf P. Steinbach"  writes:


You did lie, that's established. In addition as I recall in the same
post you went on about my motivations for doing the Terrible Deed that
you invented.

None of that matches my (largely disinterested) observations. This is
pure fantasy, as best I can tell.

It's decidedly not kind of you to try to re-open those issues.

Anybody can have a bad day and write something that's untrue or actively
misleading, whatever.

When it's been dealt with, and it has, it should not be reiterated.



I've tried in private to talk you out of this persecution fantasy;
others have tried in public. It all seems to be in vain.

It's quite normal for people to use ad hominem arguments, especially
when they have chosen an indefensible position; that's why the technique
has a name.

There's no persecution involved in that.

And people are not necessarily bad even when they do that from time to
time, as you do here: it's human.



You've now passed my twit threshold, so welcome to my kill file.

Goodbye.


Cheers & hth.,

- Alf


How you can possibly hope that helps anyone except you I can't possibly
imagine. It seems that any request to question your own behavior, any
remark about how it might usefully change, is taken to be an ad homime,
attack.

As my wife (who has a colorful Scottish turn of phrase) might say, if
you were chocolate you would eat yourself.

Please, get over this obsession with being "right".


You have (so far) refused to outright admit that you were wrong here, going to 
the extreme half-way measure of using the word "wring" or something, perhaps 
hoping that I'd interpret it one way and most everyone else another way.


I do respond to articles which are technically wrong, especially follow-ups to 
my own articles, as your (at least initial) POV was in this thread: wrong.


That's not an obsession, nor is it a desire to be right, it's the *usual* Usenet 
culture: one is expected to respond and to correct technical issues, and to not 
collect social points at the expense of technical correctness.


And since it's you who brings this up again, and since earlier you wrote ...

  "I herebe retract anything I have said about you that you consider
  innuendo. Feel free to remind me what that was."

... I now feel free to remind you about some of it.

Instead of saying OK or thanks or whatever normal for a simple explanation, you 
pretended that my explanation was some kind of thesis from me and "this is 
merely hand-waving. It looks appealing, but there's no rigor there".


And with our last discussion before this one fresh in mind I told you that that 
was bullshit, using just that single word. But to expand on that: the 
insinuation that the explanation was some kind of thesis from me was bullshit, 
that it was merely "hand-waiving" was bullshit (while informal it was an exact 
algorithm, and later in this thread I posted Python code implementing it), and 
that it had "no rigor" was bullshit since it was an exact algorithm; moreover it 
was a *trivial* algorithm, and as demonstrated, it works.


In short, the insinuation that I was some kind of crank posting a thesis that 
lacked "rigor" and was "hand-waiving" was utter bullshit: it was a trivial and 
exact algorithm, an explanation in response to your own question, and it 
demonstrably works.


In response to someone else you then posted this:



Grant Edwards wrote:
> > On 2010-01-14, Alf P. Steinbach  wrote:
[bogus hand-waving]
>> >> After all, it's the basis of digital representation of sound!
> >
> > Huh?  I've only studied basic DSP, but I've never heard/seen
> > that as the basis of digital represention of sound.  I've also
> > never seen that representation used anywhere.  Can you provide
> > any references?
> >
Of course he can't. And it isn't the basis of analog quantization. And I
suspect Alf has never hear of Shannon's theorem.

But don't listen to me, apparently I'm full of it.

regards
 Steve



* The "of course he can't [provide a reference]"

is the same insinuation you made earlier repeated, that what I posted was 
drivel, when it was a trivial and exact algorithm, one that does work.



* "Isn't the basis of analog quantization"

makes the reader believe I'd written that nonsense "basis of analog 
quantization". I did not write such nonsense but readers get the impression that 
I did. The quote above shows what I wrote instead of the words you put in my mouth.



* "And I suspect Alf has never hear of Shannon's theorem."

is solely about me, an insinuation about my education or competence.


* "But don't listen to me, apparently I'm full of it."

gives the reader the impression that I've written earlier that you're "full of 
it".

I haven't ever written that.

And /nothing/ in that posting was about any technical issue, each and every of 
the four sentences just an ad hominem attack.


I very seldom do ad hominem (it has happened, yes, I'm human too). But th

Re: A simple-to-use sound file writer

2010-01-15 Thread r0g
Alf P. Steinbach wrote:
> But maybe you're simply not able to understand the algorithm, trivial as
> it is.
> 
> So, a Python implementation (note, this program takes some time to run!):
> 
> 
> 
> # Generating a sine wave as a sum of square waves of various amplitudes


Pwned! Good one Alf :)

I think those guys owe you an apology really, but I wouldn't hold your
breath!

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options

2010-01-15 Thread schmeii
On Jan 14, 10:55 pm, epsilon  wrote:
> All:
>
> I've been playing with "Lua" and found something really cool that I'm
> unable to do in "Python". With "Lua", a script can be compiled to byte
> code using "luac" and by adding "#!/usr/bin/lua" at the top of the
> binary, the byte code becomes a single file executable. After I found
> this trick, I ran back to "Python" to give it a try.  Well...  it
> didn't work. Is this possible?

You can't add a string on top of a pyc file but you can add one in a
zipped file. For an example, see http://www.noah.org/wiki/Python_zip_exe

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


remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
hi all,
what's the simplest way to create a webpage with a frame for Python
code to be typed in (as a plain text, or, better, as a highlighted
text or something like scite or any other easy python IDE, capable of
automatic indentations), and then pressing a button to evaluate it
using a remote server?

Thank you in advance, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: force URLencoding script

2010-01-15 Thread r0g
João wrote:
> On Jan 14, 5:58 pm, r0g  wrote:
>> João wrote:
>>> On Jan 12, 10:07 pm, r0g  wrote:
 João wrote:
>>> for the following data,
>>> authentication = "UID=somestring&"
>>> message = 'PROBLEM severity High: OperatorX Plat1(locationY) global
>>> Succ. : 94.47%'
>>> dest_number = 'XXX'
>>> url_values = urlencode({'M':message})
>>> enc_data = authentication + url_values + dest_number
>>> I'm getting null for
>>> full_url = Request(url, enc_data, headers)
>>> and thus,
>>> response = urlopen(full_url).read()
>>> returns,
>>> TypeError: 
>>> )
>> Are you sure it's returning a null and not just some other unexpected
>> type?
>>
>> I think your problem may be that you are passing a urllib2 class to
>> urllib(1)'s urlopen. Try using urllib2's urlopen instead e.g.
>>
>> import urllib2
>> request_object = urllib2.Request('http://www.example.com')
>> response = urllib2.urlopen(request_object)
>> the_page = response.read()
>>
>> Roger.
> 
> Thanks Roger.
> I think it's a null because i did a print(full_url) right after the
> Request
> I tried
> request_object = urllib2.Request('http://www.example.com')
> print(request_object)
> 
> but when printing I get: 

Hi João,

That's exactly what you want, an object that is an instance of the
Request class. That object doesn't do anything by itself, you still need
to a) Connect to the server and request that URL and b) Read the data
from the server.

a) To connect to the web server and initialize the request you need to
call urllib2.urlopen() with the Request object you just created and
assign the result to a name e.g.

>> response = urllib2.urlopen(request_object)


That will give you an object (response) that you can call the .read()
method of to get the web page data.

>> the_page = response.read()



If that doesn't make sense or seem to work for you then please try
reading the following website from top to bottom before taking any
further steps...

http://www.voidspace.org.uk/python/articles/urllib2.shtml


> 
> I've read about Python 2.4 not playing well with proxies even with no
> proxy activated.
> Any sugestion?

I doubt any language can play well with proxies if there are none so I
doubt it's a factor ;)

Good luck,

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Steve Holden
Alf P. Steinbach wrote:
> * Steve Holden:
>> Alf P. Steinbach wrote:
>>> * Ben Finney:
 "Alf P. Steinbach"  writes:

> You did lie, that's established. In addition as I recall in the same
> post you went on about my motivations for doing the Terrible Deed that
> you invented.
 None of that matches my (largely disinterested) observations. This is
 pure fantasy, as best I can tell.
>>> It's decidedly not kind of you to try to re-open those issues.
>>>
>>> Anybody can have a bad day and write something that's untrue or actively
>>> misleading, whatever.
>>>
>>> When it's been dealt with, and it has, it should not be reiterated.
>>>
>>>
 I've tried in private to talk you out of this persecution fantasy;
 others have tried in public. It all seems to be in vain.
>>> It's quite normal for people to use ad hominem arguments, especially
>>> when they have chosen an indefensible position; that's why the technique
>>> has a name.
>>>
>>> There's no persecution involved in that.
>>>
>>> And people are not necessarily bad even when they do that from time to
>>> time, as you do here: it's human.
>>>
>>>
 You've now passed my twit threshold, so welcome to my kill file.
>>> Goodbye.
>>>
>>>
>>> Cheers & hth.,
>>>
>>> - Alf
>>
>> How you can possibly hope that helps anyone except you I can't possibly
>> imagine. It seems that any request to question your own behavior, any
>> remark about how it might usefully change, is taken to be an ad homime,
>> attack.
>>
>> As my wife (who has a colorful Scottish turn of phrase) might say, if
>> you were chocolate you would eat yourself.
>>
>> Please, get over this obsession with being "right".
> 
> You have (so far) refused to outright admit that you were wrong here,
> going to the extreme half-way measure of using the word "wring" or
> something, perhaps hoping that I'd interpret it one way and most
> everyone else another way.
> 
Pardon me if my feeble attempt at humor annoyed you. I would have
thought anyone reading the post would have seen it as a clear admission
that I was wrong, but if you insist on seeing those words in unequivocal
black and white I have no trouble accommodating you. If I couldn't admit
it when I was wrong I shouldn't be arguing in the first place.

For the record, yes, summing any waveforms that can be represented as
Fourier Series will necessarily result in another Fourier series, since
any linear combination of Fourier series must itself, be a Fourier
series, and therefore the representation of the sum of the summed waveforms.

And, by the way, "wring" was a genuine typo, though I admit I chose at
the proof reading stage to leave it in for (as I thought) humorous
effect. If I'm the only person who saw that as the slightest bit amusing
then again, I am sorry.

> I do respond to articles which are technically wrong, especially
> follow-ups to my own articles, as your (at least initial) POV was in
> this thread: wrong.
> 
Wrong, wrong, wrong.

> That's not an obsession, nor is it a desire to be right, it's the
> *usual* Usenet culture: one is expected to respond and to correct
> technical issues, and to not collect social points at the expense of
> technical correctness.
> 
But not to characterize honest disagreements in such discussions as ad
hominem attacks.

> And since it's you who brings this up again, and since earlier you wrote
> ...
> 
>   "I herebe retract anything I have said about you that you consider
>   innuendo. Feel free to remind me what that was."
> 
> ... I now feel free to remind you about some of it.
> 
> Instead of saying OK or thanks or whatever normal for a simple
> explanation, you pretended that my explanation was some kind of thesis
> from me and "this is merely hand-waving. It looks appealing, but there's
> no rigor there".
> 
I did. You provided an explanation I did not understand, and I
arrogantly assumed I had something to teach you about the subject.  You
have shown me the error of my ways, and I am grateful for it.

> And with our last discussion before this one fresh in mind I told you
> that that was bullshit, using just that single word. But to expand on
> that: the insinuation that the explanation was some kind of thesis from
> me was bullshit, that it was merely "hand-waiving" was bullshit (while
> informal it was an exact algorithm, and later in this thread I posted
> Python code implementing it), and that it had "no rigor" was bullshit
> since it was an exact algorithm; moreover it was a *trivial* algorithm,
> and as demonstrated, it works.
> 
I haven't listened to any resulting wav files yet, but yes, you posted code.

> In short, the insinuation that I was some kind of crank posting a thesis
> that lacked "rigor" and was "hand-waiving" was utter bullshit: it was a
> trivial and exact algorithm, an explanation in response to your own
> question, and it demonstrably works.
> 
> In response to someone else you then posted this:
> 
> 
> 
> Grant Edwards wrote:
>> > On 2010-01-14, Alf

Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread Diez B. Roggisch

Am 15.01.10 15:16, schrieb dmitrey:

hi all,
what's the simplest way to create a webpage with a frame for Python
code to be typed in (as a plain text, or, better, as a highlighted
text or something like scite or any other easy python IDE, capable of
automatic indentations), and then pressing a button to evaluate it
using a remote server?

Thank you in advance, D.


http://try-python.mired.org/

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Steve Holden
r0g wrote:
> Alf P. Steinbach wrote:
>> But maybe you're simply not able to understand the algorithm, trivial as
>> it is.
>>
>> So, a Python implementation (note, this program takes some time to run!):
>>
>>
>> 
>> # Generating a sine wave as a sum of square waves of various amplitudes
> 
> 
> Pwned! Good one Alf :)
> 
> I think those guys owe you an apology really, but I wouldn't hold your
> breath!
> 
Well as you can now see at least one of "those guys" doesn't mind
admitting (and apologizing) when he is wrong.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: Executable standalone *.pyc after inserting "#!/usr/bin/python" or other options

2010-01-15 Thread epsilon
On Jan 15, 8:32 am, schmeii  wrote:
> On Jan 14, 10:55 pm, epsilon  wrote:
>
> > All:
>
> > I've been playing with "Lua" and found something really cool that I'm
> > unable to do in "Python". With "Lua", a script can be compiled to byte
> > code using "luac" and by adding "#!/usr/bin/lua" at the top of the
> > binary, the byte code becomes a single file executable. After I found
> > this trick, I ran back to "Python" to give it a try.  Well...  it
> > didn't work. Is this possible?
>
> You can't add a string on top of a pyc file but you can add one in a
> zipped file. For an example, seehttp://www.noah.org/wiki/Python_zip_exe


All:

Thanks again and I'm looking at all the options for different
operating system

Christopher
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ignore leading '>>>' and ellipsis?

2010-01-15 Thread r0g
Javier Collado wrote:
> Hello,
> 
> I think that's exactly what the cpaste magic function does. Type
> 'cpaste?' in your IPython session for more information.
> 
> Best regards,
> Javier
> 
> 2010/1/14 Reckoner :
>> Hi,
>>
>> I am studying some examples in a tutorial where there are a lot of
>> leading >>> characters and ellipsis in the text. This makes it hard to
>> cut and paste into the IPython interpreter since it doesn't like these
>> strings.
>>
>> Is there another interpreter I could use that will appropriately
>> ignore and interpret these leading terms?
>>
>> For example, I cannot paste the following directly into the
>> interpreter:
>>
> d = dict(x.__array_interface__)
> d['shape'] = (3, 2, 5)
> d['strides'] = (20, 20, 4)
> class Arr:
>> ... __array_interface__ = d
>> ... base = x
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>



Or, as a man with a shiny new hammer, you could roll your own processor
in python as a learning exercise...

#!/usr/bin/python
import sys
lines = []
try:
while 1:
l1 = sys.stdin.readline()
l2 = l1.lstrip(">")
if l1<>l2: l2 = l2[1:]
lines.append( l2 )
except KeyboardInterrupt:
print "\n--8<8<8<8<8<"
print ''.join(lines)


10 points for modding it so it automatically recopies the data to the
clipboard

20 points for using a timer to automatically issue a keyboard interrupt
if the buffer has data and no input has been received for half a second

:)

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Grant Edwards
On 2010-01-15, Steve Holden  wrote:

> I will, however, observe that your definition of a square wave is what I
> would have to call a "'square' wave" (and would prefer to call a "pulse
> train"), as I envisage a square wave as a waveform having a 50% duty
> cycle, as in
>
>  ___ ___
> |   |   |   |
> |   |   |   |
> |   |   |   |
> +---+---+---+---+ and so on ad infinitum, (though I might allow you
> |   |   |   |  to adjust the position
> |   |   |   |  of y=0 if you want)
> |___|   |___|

That is a square wave.

> as opposed to your
>
>  _
> | |
> | |
>   __| |__   __
>  | |
>  | |
>  |_|

That isn't.

Arguing to the contrary is just being Humpty Dumpty...

> Or, best of all, you could show me how to synthesize any
> waveform by adding square waves with a 50% duty cycle.  Then I
> *will* be impressed.

Isn't that what he claimed?  He said that his algorithm for
summing square waves demonstrated the converse of the ability
to construct a periodic function (like a square wave) from a
sine-cosine summation.

-- 
Grant Edwards   grante Yow! On the road, ZIPPY
  at   is a pinhead without a
   visi.compurpose, but never without
   a POINT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple distributed example for learning purposes?

2010-01-15 Thread r0g
Tim Golden wrote:
> Nobody wrote:
>> On Sat, 26 Dec 2009 20:06:02 +, Tim Golden wrote:
>>
>>> I'm trying to come up with something which will illustrate
>>> the usefulness of a distributed processing model. Since I
>>> may not be using the term "distributed" exactly, my
>>> criteria are:
>>>
>>> * It should be clear that the application produces results
>>> sooner when run via multiple cooperating computers than when run on one.
>>> * The problem being solved should be broadly comprehensible by
>>> the students. This rules out some abstruse mathematical
>>> calculation which would benefit from multiple processors but
>>> which will fail to engage their interest.
>>
>> Rendering fractals? Easy to parallelise, easy to code, easy to make slow
>> enough that the speed-up is noticeable.
>>
> 
> Thanks. I'll add that to the list of possibilities.
> 
> TJG




Distributed password cracking? It's really simple yet potentially
engaging and could be a good segway into teaching them about
computability and security. All you need is a bunch of password hashes
and a wordlist.

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread dmitrey
Thank you for the link, but I meant what is appropriate soft to be
installed on my server to do things like that.
Also, for my purposes it's better to have some text with possibility
of reexecuting after some minor code changes than python interpreter
command prompt.
Regards, D.

On 15 янв, 16:41, "Diez B. Roggisch"  wrote:
> Am 15.01.10 15:16, schrieb dmitrey:
>
> > hi all,
> > what's the simplest way to create a webpage with a frame for Python
> > code to be typed in (as a plain text, or, better, as a highlighted
> > text or something like scite or any other easy python IDE, capable of
> > automatic indentations), and then pressing a button to evaluate it
> > using a remote server?
>
> > Thank you in advance, D.
>
> http://try-python.mired.org/
>
> Diez

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


Re: Simple distributed example for learning purposes?

2010-01-15 Thread Tim Golden

On 15/01/2010 15:43, r0g wrote:

Distributed password cracking? It's really simple yet potentially
engaging and could be a good segway into teaching them about
computability and security. All you need is a bunch of password hashes
and a wordlist.


At the moment, that's pretty much what my example is. I'm hanging
on to other people's examples in the event that I get the chance
to make use of them. And, yes, I intend to use it as an opportunity
to talk about security issues.

Thanks for confirming that the idea is at least credible.

TJG

(BTW, is segway a conventional way of spelling that where you come
from? I've not seen it written that way before.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: force URLencoding script

2010-01-15 Thread João
On Jan 15, 2:38 pm, r0g  wrote:
> João wrote:
> > On Jan 14, 5:58 pm, r0g  wrote:
> >> João wrote:
> >>> On Jan 12, 10:07 pm, r0g  wrote:
>  João wrote:
> >>> for the following data,
> >>> authentication = "UID=somestring&"
> >>> message = 'PROBLEM severity High: OperatorX Plat1(locationY) global
> >>> Succ. : 94.47%'
> >>> dest_number = 'XXX'
> >>> url_values = urlencode({'M':message})
> >>> enc_data = authentication + url_values + dest_number
> >>> I'm getting null for
> >>> full_url = Request(url, enc_data, headers)
> >>> and thus,
> >>> response = urlopen(full_url).read()
> >>> returns,
> >>> TypeError: 
> >>> )
> >> Are you sure it's returning a null and not just some other unexpected
> >> type?
>
> >> I think your problem may be that you are passing a urllib2 class to
> >> urllib(1)'s urlopen. Try using urllib2's urlopen instead e.g.
>
> >> import urllib2
> >> request_object = urllib2.Request('http://www.example.com')
> >> response = urllib2.urlopen(request_object)
> >> the_page = response.read()
>
> >> Roger.
>
> > Thanks Roger.
> > I think it's a null because i did a print(full_url) right after the
> > Request
> > I tried
> > request_object = urllib2.Request('http://www.example.com')
> > print(request_object)
>
> > but when printing I get: 
>
> Hi João,
>
> That's exactly what you want, an object that is an instance of the
> Request class. That object doesn't do anything by itself, you still need
> to a) Connect to the server and request that URL and b) Read the data
> from the server.
>
> a) To connect to the web server and initialize the request you need to
> call urllib2.urlopen() with the Request object you just created and
> assign the result to a name e.g.
>
> >> response = urllib2.urlopen(request_object)
>
> That will give you an object (response) that you can call the .read()
> method of to get the web page data.
>
> >> the_page = response.read()
>
> If that doesn't make sense or seem to work for you then please try
> reading the following website from top to bottom before taking any
> further steps...
>
> http://www.voidspace.org.uk/python/articles/urllib2.shtml
>
>
>
> > I've read about Python 2.4 not playing well with proxies even with no
> > proxy activated.
> > Any sugestion?
>
> I doubt any language can play well with proxies if there are none so I
> doubt it's a factor ;)
>
> Good luck,
>
> Roger.

lol.
I've expressed myself poorly,
I meant I read about some issues when getting the Request + urlopen
working when there's a proxy involved (like in my case)
even when activating a no_proxy configuration, something like,

proxy_support = urllib.ProxyHandler({})
opener = urllib.build_opener(proxy_support)
urllib.install_opener(opener)

But I don't know how to use it :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webscrapping ringcentral.com using mechanize

2010-01-15 Thread r0g
shrini wrote:
> Hi,
> 
>> You wouldn't be trying to crack their customers account logins would
>> you? Coz it would be highly illegal if you were.
> 
> I am a valid customer of ringcentral.com
> 
> We have multiple accounts and need to automate some actions in
> ringcentral site.
> 
> still no clue on how to scrap ringcentral site.
> 
> need help.
> 
> Thanks.
> Shrinivasan
> 


Your original post has expired on my server but you were having problems
logging in IIRC. Just a hunch but are you following the examples on the
first page of the mechanize web site?..

http://wwwsearch.sourceforge.net/mechanize/

If so, do be aware that the code they show for setting a username and
password is NOT what you need to log into most websites. The method
shown is for "HTTPAuth" which works at the Apache server level, not the
website level.

Most sites implement their own login using standard HTML forms. You need
to find out what the form fields used for login are called (by looking
at the source code), populate them with your username and password then
submit the form. I don't know if mechanize can do all of that by itself,
I understand it is commonly used in conjunction with the BeautifulSoup
library.

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Ben Finney
"Alf P. Steinbach"  writes:

> You did lie, that's established. In addition as I recall in the same
> post you went on about my motivations for doing the Terrible Deed that
> you invented.

None of that matches my (largely disinterested) observations. This is
pure fantasy, as best I can tell.

I've tried in private to talk you out of this persecution fantasy;
others have tried in public. It all seems to be in vain.

You've now passed my twit threshold, so welcome to my kill file.

*plonk*

-- 
 \“Pinky, are you pondering what I'm pondering?” “Umm, I think |
  `\   so, Brain, but three men in a tub? Ooh, that's unsanitary!” |
_o__)   —_Pinky and The Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: webscrapping ringcentral.com using mechanize

2010-01-15 Thread shrini
Hi,

> You wouldn't be trying to crack their customers account logins would
> you? Coz it would be highly illegal if you were.

I am a valid customer of ringcentral.com

We have multiple accounts and need to automate some actions in
ringcentral site.

still no clue on how to scrap ringcentral site.

need help.

Thanks.
Shrinivasan

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


Re: force URLencoding script

2010-01-15 Thread João
EDIT:

About the proxy.
That's why I'm using the '-P' in the POST call.
/usr/bin/POST -P
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a problem with writing a generator

2010-01-15 Thread Paweł Banyś
I would like to thank you for help. With the advice you provided I
managed to complete my program and now it is working as it should.

Regards,

Paweł

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


Re: remote evaluation of Python code typed in html webpage frame

2010-01-15 Thread r0g
dmitrey wrote:
> Thank you for the link, but I meant what is appropriate soft to be
> installed on my server to do things like that.
> Also, for my purposes it's better to have some text with possibility
> of reexecuting after some minor code changes than python interpreter
> command prompt.
> Regards, D.
> 
> On 15 янв, 16:41, "Diez B. Roggisch"  wrote:
>> Am 15.01.10 15:16, schrieb dmitrey:
>>
>>> hi all,
>>> what's the simplest way to create a webpage with a frame for Python
>>> code to be typed in (as a plain text, or, better, as a highlighted
>>> text or something like scite or any other easy python IDE, capable of
>>> automatic indentations), and then pressing a button to evaluate it
>>> using a remote server?
>>> Thank you in advance, D.
>> http://try-python.mired.org/
>>
>> Diez
> 



The Web2py framework works a bit like that, although it's not quite as
simplistic as what you describe. May be worth a look though.

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread r0g
Steve Holden wrote:
> r0g wrote:

>> I think those guys owe you an apology really, but I wouldn't hold your
>> breath!
>>
> Well as you can now see at least one of "those guys" doesn't mind
> admitting (and apologizing) when he is wrong.
> 
> regards
>  Steve


I stand corrected, fair play sir :)

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple distributed example for learning purposes?

2010-01-15 Thread r0g
Tim Golden wrote:
> On 15/01/2010 15:43, r0g wrote:
>> Distributed password cracking? It's really simple yet potentially
>> engaging and could be a good segway into teaching them about
>> computability and security. All you need is a bunch of password hashes
>> and a wordlist.
> 
> At the moment, that's pretty much what my example is. I'm hanging
> on to other people's examples in the event that I get the chance
> to make use of them. And, yes, I intend to use it as an opportunity
> to talk about security issues.
> 
> Thanks for confirming that the idea is at least credible.
> 
> TJG
> 
> (BTW, is segway a conventional way of spelling that where you come
> from? I've not seen it written that way before.)


No, it turns out not. I've never encountered the written form of it
before (until I googled it just now to check!) so I had assumed it was
spelled as per the freaky gyroscopically stabilized scooter things.

Good luck with the course.

Cheers,

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: force URLencoding script

2010-01-15 Thread r0g
João wrote:
> On Jan 15, 2:38 pm, r0g  wrote:
>> João wrote:
>>> On Jan 14, 5:58 pm, r0g  wrote:
 João wrote:
> On Jan 12, 10:07 pm, r0g  wrote:
>> João wrote:
> for the following data,
> authentication = "UID=somestring&"
> message = 'PROBLEM severity High: OperatorX Plat1(locationY) global
> Succ. : 94.47%'
> dest_number = 'XXX'
> url_values = urlencode({'M':message})
> enc_data = authentication + url_values + dest_number
> I'm getting null for
> full_url = Request(url, enc_data, headers)
> and thus,
> response = urlopen(full_url).read()
> returns,
> TypeError: 
> )
 Are you sure it's returning a null and not just some other unexpected
 type?
 I think your problem may be that you are passing a urllib2 class to
 urllib(1)'s urlopen. Try using urllib2's urlopen instead e.g.
 import urllib2
 request_object = urllib2.Request('http://www.example.com')
 response = urllib2.urlopen(request_object)
 the_page = response.read()
 Roger.
>>> Thanks Roger.
>>> I think it's a null because i did a print(full_url) right after the
>>> Request
>>> I tried
>>> request_object = urllib2.Request('http://www.example.com')
>>> print(request_object)
>>> but when printing I get: 
>> Hi João,
>>
>> That's exactly what you want, an object that is an instance of the
>> Request class. That object doesn't do anything by itself, you still need
>> to a) Connect to the server and request that URL and b) Read the data
>> from the server.
>>
>> a) To connect to the web server and initialize the request you need to
>> call urllib2.urlopen() with the Request object you just created and
>> assign the result to a name e.g.
>>
 response = urllib2.urlopen(request_object)
>> That will give you an object (response) that you can call the .read()
>> method of to get the web page data.
>>
 the_page = response.read()
>> If that doesn't make sense or seem to work for you then please try
>> reading the following website from top to bottom before taking any
>> further steps...
>>
>> http://www.voidspace.org.uk/python/articles/urllib2.shtml
>>
>>
>>
>>> I've read about Python 2.4 not playing well with proxies even with no
>>> proxy activated.
>>> Any sugestion?
>> I doubt any language can play well with proxies if there are none so I
>> doubt it's a factor ;)
>>
>> Good luck,
>>
>> Roger.
> 
> lol.
> I've expressed myself poorly,
> I meant I read about some issues when getting the Request + urlopen
> working when there's a proxy involved (like in my case)
> even when activating a no_proxy configuration, something like,
> 
> proxy_support = urllib.ProxyHandler({})
> opener = urllib.build_opener(proxy_support)
> urllib.install_opener(opener)
> 
> But I don't know how to use it :(


That is how you use it IIRC, this installs the proxy handler into urllib
and subsequent objects you subclass from urllib will use the custom handler.

>From what I can tell, you should be using urllib2 though, not urllib.

Lets take a step back. You had the following line...

request_object = urllib2.Request('http://www.example.com')

...You printed it and it showed that you had created a Request object
right. Now what happens when you type...

response = urllib2.urlopen(request_object)
print response

?

Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing var names

2010-01-15 Thread Victor Subervi
Hi;
Well it took me *less than a day* to fix the following problems:
-- bare excepts (accidentally left a couple I think)
-- sql injection attacks
-- recreating tables to make them more reasonable

**
"Programming is an ITERATIVE process."
**
See how easy that was??

Now, I believe someone once mentioned that there is some s/w tool out there
for changing the names of my variables more easily than going through every
script one-by-one. If so, please share with me again what it is. Also, if
anyone has any other suggestions they've been holding back, or had mentioned
earlier, on how to improve my design, please share them with me. Eventually,
I'll get around to converting it from monolithic code to class-based code
(and maybe become a real programmer, God forbid).
beno

-- 
The Logos has come to bear
http://logos.13gems.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a string.ishex function

2010-01-15 Thread Vlastimil Brom
2010/1/15 Duncan Booth :
> MRAB  wrote:
>
>> Duncan Booth wrote:
>>> MRAB  wrote:
>>>
 I raise you one character:

 ishex2 = lambda s: not(set(s)-set(string.hexdigits))     # Yours
 ishex3 = lambda s: not set(s)-set(string.hexdigits)      # Mine

 I could actually go three better:

 ishex3=lambda s:not set(s)-set(string.hexdigits)
>>>
>>> But none of those pass your own "ishex('') should return False" test.
>>
>> Neither do the others!
>
> That's true, but since you were the one that pointed out they were all
> broken I would have thought your solution should actually work.
>
> I'm sure you'll agree that a longer solution that works trumps any short
> but broken solution.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

ishex=lambda s:bool(re.match("[a-fA-F0-9]+$",s))
?
vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a string.ishex function

2010-01-15 Thread MRAB

Duncan Booth wrote:

MRAB  wrote:


Duncan Booth wrote:

MRAB  wrote:


I raise you one character:

ishex2 = lambda s: not(set(s)-set(string.hexdigits)) # Yours
ishex3 = lambda s: not set(s)-set(string.hexdigits)  # Mine

I could actually go three better:

ishex3=lambda s:not set(s)-set(string.hexdigits)

But none of those pass your own "ishex('') should return False" test.

Neither do the others!


That's true, but since you were the one that pointed out they were all 
broken I would have thought your solution should actually work.


I'm sure you'll agree that a longer solution that works trumps any short 
but broken solution.


I believe that the rules of the character-counting game don't require
correctness, only that it's no worse.

A real solution would use 'def', have a docstring, etc, of course.
--
http://mail.python.org/mailman/listinfo/python-list


Blocking code

2010-01-15 Thread eric.frederich
I am trying to write something that will watch directories without
poling them.
This is what FAM is fore.  Gamin is a re-implementation of FAM and it
has python bindings.

The problem is that when I call handle_one_event() it blocks until
there is an event to handle.
Pressing Ctrl-C does nothing here.
This seems to be the behavior of FAM so it was re-implemented in
Gamin.
I looked at another set of bindings for FAM in Java.
It came with an example that watched a directory for changes.  They
basically put the code that blocks in another thread and accepted
input on a second thread waiting for the user to press q and it would
kill the blocking thread.

I don't know how to do something like this in Python, I have never
used threads and I'm not sure if thats the way to go.

Someone else that complained about the blocking behavior of those
calls said that he found a solution since he was using OCaml.
Apparently OCaml has a way to say that you're entering a block of code
that blocks and you can still exit using Ctrl-C.
I don't think anything like this exists in Python does it?

So, my question here is How from Python can I call code that
blocks without losing the ability to use Ctrl-C?

Here is the code that is impenetrable to Ctrl-C.  You need to kill it
with another terminal

#!/usr/bin/env python

import gamin
import sys

directory = sys.argv[1]

def callback(path, event):
print "Got callback: %s, %s" % (path, event)

mon = gamin.WatchMonitor()
mon.watch_directory(directory, callback)
mon.event_pending()

while True:
mon.handle_one_event()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing var names

2010-01-15 Thread Jean-Michel Pichavant

Victor Subervi wrote:

Hi;
Well it took me *less than a day* to fix the following problems:
-- bare excepts (accidentally left a couple I think)
-- sql injection attacks
-- recreating tables to make them more reasonable

**
"Programming is an ITERATIVE process."
**
See how easy that was??

Now, I believe someone once mentioned that there is some s/w tool out 
there for changing the names of my variables more easily than going 
through every script one-by-one. If so, please share with me again 
what it is. Also, if anyone has any other suggestions they've been 
holding back, or had mentioned earlier, on how to improve my design, 
please share them with me. Eventually, I'll get around to converting 
it from monolithic code to class-based code (and maybe become a real 
programmer, God forbid).

beno

--
The Logos has come to bear
http://logos.13gems.com/

under unix/linux, google tells me that:
|grep -lr -e '' * | xargs sed -i 
's///g'|


will do the trick.

To improve your code layout/design, you may want to try pylint.
It requires a little bit of tunning, because the default rules are not 
always that satisfying, but it should give you an idea how your code is 
in bad shape once you'll get those thousands warnings from pylint :o)


JM
--
http://mail.python.org/mailman/listinfo/python-list


chr(12) Form Feed in Notepad

2010-01-15 Thread W. eWatson
I thought I'd put a page break, chr(12), character in a txt file I wrote 
to skip to the top of the page. It doesn't work. Comments?

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


Re: Changing var names

2010-01-15 Thread Victor Subervi
On Fri, Jan 15, 2010 at 2:26 PM, Jean-Michel Pichavant <
jeanmic...@sequans.com> wrote:

> Victor Subervi wrote:
>
>> Hi;
>> Well it took me *less than a day* to fix the following problems:
>> -- bare excepts (accidentally left a couple I think)
>> -- sql injection attacks
>> -- recreating tables to make them more reasonable
>>
>> **
>> "Programming is an ITERATIVE process."
>> **
>> See how easy that was??
>>
>> Now, I believe someone once mentioned that there is some s/w tool out
>> there for changing the names of my variables more easily than going through
>> every script one-by-one. If so, please share with me again what it is. Also,
>> if anyone has any other suggestions they've been holding back, or had
>> mentioned earlier, on how to improve my design, please share them with me.
>> Eventually, I'll get around to converting it from monolithic code to
>> class-based code (and maybe become a real programmer, God forbid).
>> beno
>>
>> --
>> The Logos has come to bear
>> http://logos.13gems.com/
>>
> under unix/linux, google tells me that:
> |grep -lr -e '' * | xargs sed -i
> 's///g'|
>
> will do the trick.
>

Easy money ;) Thanks.


>
> To improve your code layout/design, you may want to try pylint.
> It requires a little bit of tunning, because the default rules are not
> always that satisfying, but it should give you an idea how your code is in
> bad shape once you'll get those thousands warnings from pylint :o)
>

Cool. I'll wait till I (finally!!) get my own computer Wednesday. Been
working half a year on borrowed computers!! Bought a Mac Pro :)
Thanks,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Bad file descriptor" in HTTPServer using Multiprocessing.

2010-01-15 Thread Adam Tauno Williams
On Sun, 2010-01-10 at 14:45 -0500, Adam Tauno Williams wrote:
> I have a Python multiprocessing application where a master process
> starts server sub-processes and communicates with them via Pipes;  that
> works very well.  But one of the subprocesses, in turn, starts a
> collection of HTTPServer 'workers' (almost exactly as demonstrated in
> the docs).  This works perfectly so long as the subprocess that
> starts the HTTPServer workers is the *first* process started by the
> master process.  Otherwise the HTTPServer's serve_forever immediately
> abends with: "(9, 'Bad file descriptor')"

Performing an sys.stdin.close() before the subprocess spawned its
workers seems to have resolved the issue.

> I'm confused why the order of starting the processes matter, especially
> given that the HTTPServer's are start in a subprocess of a subprocess.
> The master doesn't do much of anything between starting each subprocess
> (which it does in a loop;  identify all the subprocesses to start, and
> start them.).
> 
> subprocess
> 
> ..
> self._httpd = HTTPServer((HTTP_HOST, HTTP_PORT), 
> HTTPRequestHandler)
> print 'HTTPServer created.'
> for i in range(10):
> p = multiprocessing.Process(target=serve_forever, 
> args=(self._httpd, i, self))
> self._workers.append(p)
> p.start()
> 
> .
> def serve_forever(server, i, control):
> print 'coils.http starting HTTP worker #{0}'.format(i)
> try:
> server.serve_forever()
> except KeyboardInterrupt:
> pass
> except Exception, e:
> control.log.exception(e)
> print 'coils.http worker #{0} abended with exception.'.format(i)
> print e
> return
> OpenGroupware developer: awill...@whitemice.org
> 
> OpenGroupare & Cyrus IMAPd documenation @
> 



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


Re: chr(12) Form Feed in Notepad

2010-01-15 Thread Duncan Booth
"W. eWatson"  wrote:

> I thought I'd put a page break, chr(12), character in a txt file I wrote 
> to skip to the top of the page. It doesn't work. Comments?
> 
Did you intend to ask a question? If so you might like to read 
http://catb.org/~esr/faqs/smart-questions.html first.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Blocking code

2010-01-15 Thread Adam Tauno Williams
On Fri, 2010-01-15 at 10:12 -0800, eric.frederich wrote:
> I am trying to write something that will watch directories without
> poling them.
> This is what FAM is fore.  Gamin is a re-implementation of FAM and it
> has python bindings.
> The problem is that when I call handle_one_event() it blocks until
> there is an event to handle.
> Pressing Ctrl-C does nothing here.
> This seems to be the behavior of FAM so it was re-implemented in
> Gamin.


Hmmm, I don't know if I believe that.

> I looked at another set of bindings for FAM in Java.
> It came with an example that watched a directory for changes.  They
> basically put the code that blocks in another thread and accepted
> input on a second thread waiting for the user to press q and it would
> kill the blocking thread.

You call is probably doing a select(...) on the file handle that FAM (or
whatever) is going to call back on.  You could probably override that
method and add a timeout.  Then do-whatever... wait-and-listen...
do-whatever.  This works very well in many cases, you won't loose
events, they will still be there when you go back to check.

> I don't know how to do something like this in Python, I have never
> used threads and I'm not sure if thats the way to go.

In Python I'd use multiprocessing rather than threads.




-- 
OpenGroupware developer: awill...@whitemice.org

OpenGroupare & Cyrus IMAPd documenation @


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


Re: Blocking code

2010-01-15 Thread Peter Otten
eric.frederich wrote:

> I am trying to write something that will watch directories without
> poling them.
> This is what FAM is fore.  Gamin is a re-implementation of FAM and it
> has python bindings.
> 
> The problem is that when I call handle_one_event() it blocks until
> there is an event to handle.

What's the purpose of mon.event_pending()? Can you use it to check whether 
an event is due? Example:

import gamin
import sys
import time

directory = sys.argv[1]

def callback(path, event):
print "Got callback: %s, %s" % (path, event)

mon = gamin.WatchMonitor()
mon.watch_directory(directory, callback)

while True:
if mon.event_pending():
mon.handle_one_event()
else:
time.sleep(.1)

I didn't find anything that deserves to be called documentation, but a quick 
test suggests that this at least responds to Ctrl-C:

$ mkdir alpha
$ python gamin_test.py alpha/ &
[1] 9932
$ Got callback: /home/petto/srcx/clpy/alpha, 8
Got callback: /home/petto/srcx/clpy/alpha, 9
touch alpha/beta
$ Got callback: beta, 5
Got callback: beta, 1
mkdir alpha/gamma
$ Got callback: gamma, 5
fg
python gamin_test.py alpha/
^CTraceback (most recent call last):
  File "gamin_test.py", line 19, in 
time.sleep(.1)
KeyboardInterrupt

Peter

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


Re: Changing var names

2010-01-15 Thread Adam Tauno Williams
On Fri, 2010-01-15 at 13:27 -0400, Victor Subervi wrote:
> Hi;
> Well it took me *less than a day* to fix the following problems:
> -- bare excepts (accidentally left a couple I think)
> -- sql injection attacks
> -- recreating tables to make them more reasonable
> Now, I believe someone once mentioned that there is some s/w tool out
> there for changing the names of my variables more easily than going
> through every script one-by-one. If so, please share with me again
> what it is. 

This process is called 'refactoring' [a good term to Google], and every
decent IDE provides some support [if it doesn't, it isn't a "decent"
IDE]

Sadly IDEs for Java and .NET are still pretty far ahead of what is
available for Python.

> Also, if anyone has any other suggestions they've been holding back,
> or had mentioned earlier, on how to improve my design, please share
> them with me. Eventually, I'll get around to converting it from
> monolithic code to class-based code (and maybe become a real
> programmer, God forbid).

-- 
OpenGroupware developer: awill...@whitemice.org

OpenGroupare & Cyrus IMAPd documenation @


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


Efficient Running Median

2010-01-15 Thread Raymond Hettinger
I've updated the running median recipe to use a new algorithm with O
(log n) updates for a large sliding window traversing a data stream.
See http://code.activestate.com/recipes/576930/

The engine is a new collection class called IndexableSkiplist.  It is
like a regular skiplist as detailed at http://en.wikipedia.org/wiki/Skip_list,
but it also records the width of each link field.  That allows values
to be retrieved by their position index in O(log n) time.

The key  operations are:
O(log n) --   sl.insert(value) # add a value to the skiplist,
maintaining sorted order
O(log n) --   s.remove(value)  # remove a value from the skiplist,
maintaining sorted order
O(log n) --   s[i] # retrieve the i-th item
O(n) --   list(sl) # iterate over the skiplist in sorted
order
O(1) --   len(sl)  # number of items in the skiplist

The performance of an IndexableSkiplist is similar to a B+tree but the
implementation in pure python is much simpler.


Raymond

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


Re: chr(12) Form Feed in Notepad

2010-01-15 Thread Grant Edwards
On 2010-01-15, W. eWatson  wrote:

> I thought I'd put a page break, chr(12), character in a txt
> file I wrote to skip to the top of the page. It doesn't work.
> Comments?

Yes, it does work.

-- 
Grant Edwards   grante Yow! ... bleakness
  at   ... desolation ... plastic
   visi.comforks ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.sax parsing elements with the same name

2010-01-15 Thread Adam Tauno Williams
On Mon, 2010-01-11 at 13:24 -0800, amadain wrote:
> On Jan 11, 9:03 pm, John Bokma  wrote:
> > amadain  writes:
> > I was thinking about something like:
> > self.filterIndex = 0
> > in startElement:
> > if name == 'filter':
> >self.filterIndex += 1
> >return
> > if name == 'result' and self.filterIndex == 1:
> >...  = attrs.get('value', '')
> > in EndElement
> >if name == 'filters':
> >   self.filterIndex = 0
> > If you want the result of the first filter in filters
> Thank you. I will try that

If you document is reasonably complex I usually define some modes like:

BPML_BOOTSTRAP_MODE  = 0
BPML_PACKAGE_MODE= 1
BPML_PROCESS_MODE= 2
BPML_CONTEXT_MODE= 3

BPML_EVENT_MODE  = 10
BPML_FAULTS_MODE = 11
BPML_ATTRIBUTES_MODE = 12

- so I can self.mode.append(BPML_PROCESS_MODE) when I enter an element
(startElement) and self.mode = self.mode[:-1] when I leave an element
(endElement).  This provides you with a complete 'stack trace' of how
you got where you are and still lets you efficiently process the stream
[verses using evil document model].  In startElement you can check the
current mode and tag with something like -
...
elif (name == 'event' and self.mode[-1] -- BPML_PROCESS_MODE):
...

-- 
OpenGroupware developer: awill...@whitemice.org

OpenGroupare & Cyrus IMAPd documenation @


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


Re: Changing var names

2010-01-15 Thread Phlip

Adam Tauno Williams wrote:


This process is called 'refactoring' [a good term to Google], and every
decent IDE provides some support [if it doesn't, it isn't a "decent"
IDE]


Way more important than IDE support is developers writing wall-to-wall unit 
tests as they write their features, _before_ refactoring them. [If they don't, 
they aren't "decent" developers, either!;]


Don't even call it "refactoring" without test support!


Sadly IDEs for Java and .NET are still pretty far ahead of what is
available for Python.


That is bizarre and inconceivable, given Python's typing is almost as static as 
thoses's.


(Yes yes yes Python does not force you to declare _every_ type. Just _many_ of 
them...)


http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html


>> Also, if anyone has any other suggestions they've been holding back,
>> or had mentioned earlier, on how to improve my design

Write scads of unit tests!

--
  Phlip
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-15 Thread W. eWatson

Grant Edwards wrote:

On 2010-01-15, W. eWatson  wrote:


I thought I'd put a page break, chr(12), character in a txt
file I wrote to skip to the top of the page. It doesn't work.
Comments?


Yes, it does work.

Apparently not with with my Brother 1440 laser printer. The character in 
NotePad.txt looks like a small rectangle, and on the printed page. Same 
result HP C6180 Photosmart.

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


Re: pyserial: Unexpected Local Echo

2010-01-15 Thread John Nagle

Grant Edwards wrote:

On 2010-01-11, Steven Woody  wrote:


I am using pyserial.  But I always get the local echo after I
write some characters onto serial port


I really doubt you're getting a local echo.  Is the data coming
out the serial port?  Do you get the echo if you disconnect the
serial cable?


and I find no way to disable this behavior. When I say 'local
echo', I mean the next read operation will get characters that
was just write to the same port.


The device to which you're connected is echoing them.  There's
also a chance that your rxd line is floating and there's enough
crosstalk in the cable to "echo" the data, but I'll bet money
it's not being done locally (in the serial driver or port).


I run my program on cygwin (pyserial was also built on the
system from source code) and the serial port i am using is a
USB adapter that simulates a port (COM4 on my XP) because my
laptop don't have a real serial port.  But I checked my COM4
settings, there is no any think like 'local echo'.


You're using what?  Some version of Python built on Cygwin
running on a Windows XP system?   What if you just run a stock
Python built for Windows on Windows XP?  Or run Linux?  That
half-and-half environment may not work right.  pyserial has
special cases in it for Windows and Linux, and it's not
clear what it will do on Cygwin.

That said, if you're getting echo from output back to input,
I'd look at the USB to serial device.  I've used devices with
the Silicon Laboratories CP2102 part, and they work fine.
("http://www.aetherltd.com/connectingusb.html";)

Do you have something plugged into the serial port?  If
so, what?

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing var names

2010-01-15 Thread Victor Subervi
On Fri, Jan 15, 2010 at 3:15 PM, Adam Tauno Williams <
awill...@opengroupware.us> wrote:

> On Fri, 2010-01-15 at 13:27 -0400, Victor Subervi wrote:
> > Hi;
> > Well it took me *less than a day* to fix the following problems:
> > -- bare excepts (accidentally left a couple I think)
> > -- sql injection attacks
> > -- recreating tables to make them more reasonable
> > Now, I believe someone once mentioned that there is some s/w tool out
> > there for changing the names of my variables more easily than going
> > through every script one-by-one. If so, please share with me again
> > what it is.
>
> This process is called 'refactoring' [a good term to Google], and every
> decent IDE provides some support [if it doesn't, it isn't a "decent"
> IDE]
>

Thanks. I'll work with Eric, I guess, once I get my Mac.
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing var names

2010-01-15 Thread Victor Subervi
On Fri, Jan 15, 2010 at 3:45 PM, Phlip  wrote:

> Adam Tauno Williams wrote:
>
>  This process is called 'refactoring' [a good term to Google], and every
>> decent IDE provides some support [if it doesn't, it isn't a "decent"
>> IDE]
>>
>
> Way more important than IDE support is developers writing wall-to-wall unit
> tests as they write their features, _before_ refactoring them. [If they
> don't, they aren't "decent" developers, either!;]
>
> Don't even call it "refactoring" without test support!
>
>
>  Sadly IDEs for Java and .NET are still pretty far ahead of what is
>> available for Python.
>>
>
> That is bizarre and inconceivable, given Python's typing is almost as
> static as thoses's.
>
> (Yes yes yes Python does not force you to declare _every_ type. Just _many_
> of them...)
>
>
> http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html
>
>
>
> >> Also, if anyone has any other suggestions they've been holding back,
> >> or had mentioned earlier, on how to improve my design
>
> Write scads of unit tests!
>

Should I re-write it in classes before testing units? Right now it's very
monolithic.
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-15 Thread Tim Chase

W. eWatson wrote:

Grant Edwards wrote:

On 2010-01-15, W. eWatson  wrote:


I thought I'd put a page break, chr(12), character in a txt
file I wrote to skip to the top of the page. It doesn't work.
Comments?

Yes, it does work.

Apparently not with with my Brother 1440 laser printer. The character in 
NotePad.txt looks like a small rectangle, and on the printed page. Same 
result HP C6180 Photosmart.


But are you sending the raw control codes to the printer, or are 
you sending the image-of-my-text-document to a printer-GDI which 
then renders the as-you-see-it out of the printer?


The pseudo-pipeline comparison would be

  type file.txt > lpt1:

which would send the raw text file to the printer (assuming it's 
set up on LPT1, otherwise, use whatever port it's attached to in 
your printer control panel); or are you using something like


  notepad file.txt
  File -> Print

which renders to an internal image representation and then sends 
that image out to the printer.  If it were a dot-matrix printer, 
you'd here/see the difference in a jiffy -- the raw dump is fast 
and uses the printer's built-in fonts while the render-as-image 
is slow and NOISY.


One alternative is possibly to set up the "Generic Text" printer 
as a device type and attach it to the same port; I've had fair 
fortune with this letting me control the printer more directly if 
I want fast dumps (particularly on dot-matrix printers) rather 
than pretty dumps.


-tkc



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


Re: BeautifulSoup

2010-01-15 Thread John Nagle

   It's just somebody pirating movies.  Ineptly.  Ignore.

John Nagle

yamamoto wrote:

Hi,
I am new to Python. I'd like to extract "a" tag from a website by
using "beautifulsoup" module.
but it doesnt work!

//sample.py

from BeautifulSoup import BeautifulSoup as bs
import urllib
url="http://www.d-addicts.com/forum/torrents.php";
doc=urllib.urlopen(url).read()
soup=bs(doc)
result=soup.findAll("a")
for i in result:
print i


Traceback (most recent call last):
  File "C:\Users\falcon\workspace\p\pyqt\ex1.py", line 8, in 
soup=bs(doc)
  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1499, in
__init__
BeautifulStoneSoup.__init__(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1230, in
__init__
self._feed(isHTML=isHTML)
  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1263, in
_feed
self.builder.feed(markup)
  File "C:\Python26\lib\HTMLParser.py", line 108, in feed
self.goahead(0)
  File "C:\Python26\lib\HTMLParser.py", line 148, in goahead
k = self.parse_starttag(i)
  File "C:\Python26\lib\HTMLParser.py", line 226, in parse_starttag
endpos = self.check_for_whole_start_tag(i)
  File "C:\Python26\lib\HTMLParser.py", line 301, in
check_for_whole_start_tag
self.error("malformed start tag")
  File "C:\Python26\lib\HTMLParser.py", line 115, in error
raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: malformed start tag, at line 276, column 36

any suggestion?
thanks in advance


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


Re: Is python not good enough?

2010-01-15 Thread John Nagle

Terry Reedy wrote:

On 1/12/2010 10:17 AM, Krister Svanlund wrote:
Their goal of 
making Go very fast to compile by machines somewhat conflicts with 
Python's goal of being fast to read by humans.


   Actually, no.  It's quite possible to make a Python implementation that
runs fast.  It's just that CPython, a naive interpreter, is too primitive
to do it.  I was really hoping that Google would put somebody good at
compilers in charge of Python and bring it up to production speed.

   Look at Shed Skin, a hard-code compiler for Python with automatic
type inference.  One guy did that.

   The language is fine, but the CPython implementation is obsolete.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


I really need webbrowser.open('file://') to open a web browser

2010-01-15 Thread Timur Tabi
After reading several web pages and mailing list threads, I've learned
that the webbrowser module does not really support opening local
files, even if I use a file:// URL designator.  In most cases,
webbrowser.open() will indeed open the default web browser, but with
Python 2.6 on my Fedora 10 system, it opens a text editor instead.  On
Python 2.5, it opens the default web browser.

This is a problem because my Python script creates a local HTML file
and I want it displayed on the web browser.

So is there any way to force webbrowser.open() to always use an actual
web browser?

-- 
Timur Tabi
Linux kernel developer at Freescale
-- 
http://mail.python.org/mailman/listinfo/python-list


setattr() oddness

2010-01-15 Thread Sean DiZazzo
Should the following be legal?

>>> class TEST(object): pass
...
>>> t = TEST()
>>> setattr(t, "", "123")
>>> getattr(t, "")
'123'

~Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing var names

2010-01-15 Thread Phlip

Victor Subervi wrote:

> Should I re-write it in classes before testing units? Right now it's
> very monolithic.

The "Unit" in unit tests is a misnomer. It refers to an old QA concept, for 
high-end projects, that the failure of any test should implicate only one unit.


We only need "developer tests". They help, when we change the code, to avoid 
excessive debugging. And to test a given method you must be able to access it, 
so tests force your code to be decoupled. But a test may call as many functions 
as it needs, regardless what "unit" they live in.


If you don't have tests yet, then sometimes a rewrite is indicated (and 
sometimes it's very easy and will produce _very_ clear code!). But in most cases 
like yours the best advice is to write your next feature using "test driven 
development". Write the test first, get it to fail, then change the code as 
little as possible to get it to pass. Repeat until done, occasionally refactoring.


If old code now works, just leave it alone. Until it needs a new feature, and 
then wham! it has tests.


--
  Phlip
  http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1
--
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup

2010-01-15 Thread Brian J Mingus
On Wed, Jan 13, 2010 at 5:46 AM, yamamoto  wrote:
> Hi,
> I am new to Python. I'd like to extract "a" tag from a website by
> using "beautifulsoup" module.
> but it doesnt work!
>
> //sample.py
>
> from BeautifulSoup import BeautifulSoup as bs
> import urllib
> url="http://www.d-addicts.com/forum/torrents.php";
> doc=urllib.urlopen(url).read()
> soup=bs(doc)
> result=soup.findAll("a")
> for i in result:
>print i
>
>
> Traceback (most recent call last):
>  File "C:\Users\falcon\workspace\p\pyqt\ex1.py", line 8, in 
>soup=bs(doc)
>  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1499, in
> __init__
>BeautifulStoneSoup.__init__(self, *args, **kwargs)
>  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1230, in
> __init__
>self._feed(isHTML=isHTML)
>  File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 1263, in
> _feed
>self.builder.feed(markup)
>  File "C:\Python26\lib\HTMLParser.py", line 108, in feed
>self.goahead(0)
>  File "C:\Python26\lib\HTMLParser.py", line 148, in goahead
>k = self.parse_starttag(i)
>  File "C:\Python26\lib\HTMLParser.py", line 226, in parse_starttag
>endpos = self.check_for_whole_start_tag(i)
>  File "C:\Python26\lib\HTMLParser.py", line 301, in
> check_for_whole_start_tag
>self.error("malformed start tag")
>  File "C:\Python26\lib\HTMLParser.py", line 115, in error
>raise HTMLParseError(message, self.getpos())
> HTMLParser.HTMLParseError: malformed start tag, at line 276, column 36
>
> any suggestion?
> thanks in advance
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

BeautifulSoup is overkill for this anyways.

 *#!/bin/python*from urllib import urlopen
html = urlopen("http://www.d-addicts.com/forum/torrents.php";).read()links
= set([link.split('"')[0] *for* link in html.split('href="')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread W. eWatson

Tim Chase wrote:

W. eWatson wrote:

Grant Edwards wrote:

On 2010-01-15, W. eWatson  wrote:


I thought I'd put a page break, chr(12), character in a txt
file I wrote to skip to the top of the page. It doesn't work.
Comments?

Yes, it does work.

Apparently not with with my Brother 1440 laser printer. The character 
in NotePad.txt looks like a small rectangle, and on the printed page. 
Same result HP C6180 Photosmart.


But are you sending the raw control codes to the printer, or are you 
sending the image-of-my-text-document to a printer-GDI which then 
renders the as-you-see-it out of the printer?


The pseudo-pipeline comparison would be

  type file.txt > lpt1:

which would send the raw text file to the printer (assuming it's set up 
on LPT1, otherwise, use whatever port it's attached to in your printer 
control panel); or are you using something like


  notepad file.txt
  File -> Print

which renders to an internal image representation and then sends that 
image out to the printer.  If it were a dot-matrix printer, you'd 
here/see the difference in a jiffy -- the raw dump is fast and uses the 
printer's built-in fonts while the render-as-image is slow and NOISY.


One alternative is possibly to set up the "Generic Text" printer as a 
device type and attach it to the same port; I've had fair fortune with 
this letting me control the printer more directly if I want fast dumps 
(particularly on dot-matrix printers) rather than pretty dumps.


-tkc



I should mention I'm using Windows. I just put chr(12) right in the txt. 
It's the first character in the next line of the txt file where I want 
to page forward. Not acquainted with GDI. Maybe I need some sequence of 
such characters?

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


Problem with wsgiref.headers.Headers

2010-01-15 Thread Phil
I am having an issue with wsgiref.headers.Headers.

For example, if I do this...

from wsgiref.headers import Headers
list = []
wrapper = Headers(list)
wrapper['content-type'] = "text/html"
print(list)
print(wrapper)

I get an empty list printed, and then the correct result for wrapper
printed.

Am I misunderstanding the documentation?

class wsgiref.headers.Headers(headers)
Create a mapping-like object wrapping headers, which must be a list of
header name/value tuples as described in PEP 333. Any changes made to
the new Headers object will directly update the headers list it was
created with.

Thanks for any help,

Phil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with wsgiref.headers.Headers

2010-01-15 Thread Phil
I left one crucial detail out. My concern was the fact that the
original headers list being wrapped ('list' in my example) is not
being updated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup

2010-01-15 Thread John Bokma
yamamoto  writes:

> Hi,
> I am new to Python. I'd like to extract "a" tag from a website by
> using "beautifulsoup" module.
> but it doesnt work!

[..]

> check_for_whole_start_tag
> self.error("malformed start tag")
>   File "C:\Python26\lib\HTMLParser.py", line 115, in error
> raise HTMLParseError(message, self.getpos())
> HTMLParser.HTMLParseError: malformed start tag, at line 276, column 36
>
> any suggestion?

I guess you're using 3.1.0. If yes, see:
http://www.crummy.com/software/BeautifulSoup/3.1-problems.html

You might want to do:

sudo easy_install -U "BeautifulSoup==3.0.7a"

and try again. 

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup

2010-01-15 Thread John Bokma
John Nagle  writes:

>It's just somebody pirating movies.  Ineptly.  Ignore.

Wow, what a childish reply. You should've followed your own advice and
ignored the OP instead of replying with a top post + full quote (!).

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BeautifulSoup

2010-01-15 Thread John Bokma
John Bokma  writes:

> yamamoto  writes:
>
>> Hi,
>> I am new to Python. I'd like to extract "a" tag from a website by
>> using "beautifulsoup" module.
>> but it doesnt work!
>
> [..]
>
>> check_for_whole_start_tag
>> self.error("malformed start tag")
>>   File "C:\Python26\lib\HTMLParser.py", line 115, in error
>> raise HTMLParseError(message, self.getpos())
>> HTMLParser.HTMLParseError: malformed start tag, at line 276, column 36
>>
>> any suggestion?
>
> I guess you're using 3.1.0. If yes, see:
> http://www.crummy.com/software/BeautifulSoup/3.1-problems.html
>
> You might want to do:
>
> sudo easy_install -U "BeautifulSoup==3.0.7a"
>
> and try again. 

Forgot to add, see also:
http://johnbokma.com/mexit/2009/09/26/python-downgrading-beatifulsoup.html

-- 
John Bokma   j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setattr() oddness

2010-01-15 Thread Terry Reedy

On 1/15/2010 3:37 PM, Sean DiZazzo wrote:

Should the following be legal?


class TEST(object): pass

...

t = TEST()
setattr(t, "", "123")
getattr(t, "")

'123'


Different people have different opinions as to whether setattr (and 
correspondingly getattr) should be strict or permissive as to whether or 
not the 'name' string is a legal name. CPython is permissive. The 
rationale is that checking would take time and prevent possible 
legitimate use cases.


CPython is actually looser than this. Try

t.__dict__[1] = 2

Now there is an 'attribute' whose 'name' is an int! -- and which can 
only be accessed via the same trick of delving into the internals. This 
is, however, implementation behavior that would go away if an 
implementation used string-key-only dicts to store attributes.


Terry Jan Reedy

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


Re: which data structure should I use?

2010-01-15 Thread Gabriel Genellina
En Fri, 15 Jan 2010 01:56:24 -0300, Eknath Venkataramani  
 escribió:



I have a txt file in the following format:



[code]
"confident" => {
  count => 4,
  trans => {
 "ashahvasahta" => 0.74918568,
"atahmavaishahvaasa" => 0.09095465,
"pahraaram\.nbha" => 0.06990729,
 "mailatae" => 0.02856427,
   "utanai" => 0.01929341,
 "anaa" => 0.01578552,
 "uthaanae" => 0.01403157,
 "jaitanae" => 0.01227762,
},
},
"consumers" => {
  count => 4,
  trans => {
"upabhaokahtaa" => 0.75144362,
...



and I need to extract "confident" , "ashahvasahta" from the first
record, "consumers",  "upabhaokahtaa" from the second record...
i.e. "word in english" and the "first word in the probable-translations"


The most robust way would be to write a specific parser for such format.  
Should be easy using pyparsing http://pyparsing.wikispaces.com/


If you can guarantee certain properties (e.g. lines like "confident",  
"consumers" are always in a separate line; translations appear one per  
line; no line breaks before/after the => sign, etc.) then you could  
process the file line by line, looking at those separators. But only do  
that is you are completely sure the format is fixed (e.g. the file is  
computer-generated, not human-written). Anyway, it isn't much easier than  
writing a real parser, and the latter is a lot more reliable. Learning how  
to use a tool like pyparsing is in no way a waste of time.


--
Gabriel Genellina

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


Re: setattr() oddness

2010-01-15 Thread Steve Holden
Terry Reedy wrote:
> On 1/15/2010 3:37 PM, Sean DiZazzo wrote:
>> Should the following be legal?
>>
> class TEST(object): pass
>> ...
> t = TEST()
> setattr(t, "", "123")
> getattr(t, "")
>> '123'
> 
> Different people have different opinions as to whether setattr (and
> correspondingly getattr) should be strict or permissive as to whether or
> not the 'name' string is a legal name. CPython is permissive. The
> rationale is that checking would take time and prevent possible
> legitimate use cases.
> 
> CPython is actually looser than this. Try
> 
> t.__dict__[1] = 2
> 
> Now there is an 'attribute' whose 'name' is an int! -- and which can
> only be accessed via the same trick of delving into the internals. This
> is, however, implementation behavior that would go away if an
> implementation used string-key-only dicts to store attributes.
> 
Good question, great answer!

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: setattr() oddness

2010-01-15 Thread Sean DiZazzo
On Jan 15, 2:22 pm, Terry Reedy  wrote:
> On 1/15/2010 3:37 PM, Sean DiZazzo wrote:
>
> > Should the following be legal?
>
>  class TEST(object): pass
> > ...
>  t = TEST()
>  setattr(t, "", "123")
>  getattr(t, "")
> > '123'
>
> Different people have different opinions as to whether setattr (and
> correspondingly getattr) should be strict or permissive as to whether or
> not the 'name' string is a legal name. CPython is permissive. The
> rationale is that checking would take time and prevent possible
> legitimate use cases.
>
> CPython is actually looser than this. Try
>
> t.__dict__[1] = 2
>
> Now there is an 'attribute' whose 'name' is an int! -- and which can
> only be accessed via the same trick of delving into the internals. This
> is, however, implementation behavior that would go away if an
> implementation used string-key-only dicts to store attributes.
>
> Terry Jan Reedy

Interesting.  I can understand the "would take time" argument, but I
don't see any legitimate use case for an attribute only accessible via
getattr().  Well, at least not a pythonic use case.

Thanks for the info!

~Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread Tim Chase

W. eWatson wrote:

Tim Chase wrote:

The pseudo-pipeline comparison would be

  type file.txt > lpt1:

which would send the raw text file to the printer (assuming it's set up 
on LPT1, otherwise, use whatever port it's attached to in your printer 
control panel); or are you using something like


  notepad file.txt
  File -> Print


I should mention I'm using Windows. I just put chr(12) right in the txt. 
It's the first character in the next line of the txt file where I want 
to page forward. Not acquainted with GDI. Maybe I need some sequence of 
such characters?


It's not a matter of you controlling the GDI stuff.  Unless 
you're writing directly to the printer device, printing on 
Windows is done (whether by Notepad, gvim, Word, Excel, whatever) 
into a graphical representation which is then shipped off to the 
printer.  So if you're printing from Notepad, it's going to print 
what you see (the little square), because Notepad renders to this 
graphical representation to print.  If you send the file 
*directly* to the printer device (bypassing the Win32 printing 
layer), it will send the ^L directly and should eject a new page 
on most printers.


-tkc


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


import data structure

2010-01-15 Thread monkeys paw

I want to store data in a file like show below. Then
i want to import the data in, but am having trouble.
I'm trying:

import sfdata

for x in author_list:
print x



FILE: sfdata.py (i'm trying to import it)
==

author_list = {
 '829337' : {
   'author_name' : 'Carter, John',
   'count' : 49,
   'c2' : '0.102040816326531',
   'author_party' : 'R',
   'f1' : '0.102040816326531',
   'f2' : '0.102040816326531',
   'author_entry_name' : 'Carter',
   'c1' : '0.122448979591837'
 },
 '825522' : {
   'author_name' : 'Stark, Fortney',
   'count' : 171,
   'c2' : '0.0116959064327485',
   'author_party' : 'D',
   'f1' : '0.0233918128654971',
   'f2' : '0.0116959064327485',
   'author_entry_name' : 'Stark',
   'c1' : '0.0233918128654971'
 },
}
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a string.ishex function

2010-01-15 Thread Steven D'Aprano
On Fri, 15 Jan 2010 00:53:51 +, Steven D'Aprano wrote:

> On Thu, 14 Jan 2010 18:36:12 +, MRAB wrote:

>> BTW, ishex('') should return False.
> 
> 
> Only if you want to be inconsistent with other isFoo string functions:
> 
 ''.isalpha()
> False

I said what???

Sorry MRAB, what I wrote there was obvious nonsense. I should be agreeing 
with you, not disagreeing!



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


Re: import data structure

2010-01-15 Thread Gary Herron

monkeys paw wrote:

I want to store data in a file like show below. Then
i want to import the data in, but am having trouble.
I'm trying:

import sfdata

for x in author_list:
print x


Either

  import sfdata
 for x in sfdata.author_list:   # Access list as an attribute of 
the module

 print x

or

 from sfdata import author_list  # Import individual attribute from 
module.

 for x in author_list:
 print x


Gary Herron






FILE: sfdata.py (i'm trying to import it)
==

author_list = {
 '829337' : {
   'author_name' : 'Carter, John',
   'count' : 49,
   'c2' : '0.102040816326531',
   'author_party' : 'R',
   'f1' : '0.102040816326531',
   'f2' : '0.102040816326531',
   'author_entry_name' : 'Carter',
   'c1' : '0.122448979591837'
 },
 '825522' : {
   'author_name' : 'Stark, Fortney',
   'count' : 171,
   'c2' : '0.0116959064327485',
   'author_party' : 'D',
   'f1' : '0.0233918128654971',
   'f2' : '0.0116959064327485',
   'author_entry_name' : 'Stark',
   'c1' : '0.0233918128654971'
 },
}


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


Re: BeautifulSoup

2010-01-15 Thread Phlip

John Bokma wrote:


John Nagle writes:


   It's just somebody pirating movies.  Ineptly.  Ignore.


Wow, what a childish reply. You should've followed your own advice and
ignored the OP instead of replying with a top post + full quote (!).


Mr Manners reminds the Gentle Poster(s) that...

A> as Google vs China shows, all programmers should resist hacking, no
matter how inept it may be, by any means necessary

B> John should not have attempted to leave a dead trail in the archives.
Searches for BeautifulSoup should always return answered questions.

--
  Phlip
--
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes error

2010-01-15 Thread Gib Bogle

Gib Bogle wrote:
It has occurred to me that the error may have nothing to do with 
ctypes.  The DLL was built on one machine and copied to the other (which 
doesn't have the compiler installed).  Although both machines are 
running Windows XP, there might be some subtle differences.


I see that the build machine has XP Professional, Version 2002, Service 
Pack 2, while the machine that fails to load the DLL has XP Home 
Edition, Version 2002, Service Pack 3.  Who knows.


I'm a bit embarrassed to report that the problem has nothing to do with Python. 
 My DLL was built with dynamic library linking, and apparently there are some 
differences between the various Intel DLLs used on the two machines.  Following 
advice from the Intel Fortran forum, I created the DLL with static library 
linking, and now all works as expected.  Sorry to waste your time.

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread W. eWatson

Tim Chase wrote:

W. eWatson wrote:

Tim Chase wrote:

The pseudo-pipeline comparison would be

  type file.txt > lpt1:

which would send the raw text file to the printer (assuming it's set 
up on LPT1, otherwise, use whatever port it's attached to in your 
printer control panel); or are you using something like


  notepad file.txt
  File -> Print


I should mention I'm using Windows. I just put chr(12) right in the 
txt. It's the first character in the next line of the txt file where I 
want to page forward. Not acquainted with GDI. Maybe I need some 
sequence of such characters?


It's not a matter of you controlling the GDI stuff.  Unless you're 
writing directly to the printer device, printing on Windows is done 
(whether by Notepad, gvim, Word, Excel, whatever) into a graphical 
representation which is then shipped off to the printer.  So if you're 
printing from Notepad, it's going to print what you see (the little 
square), because Notepad renders to this graphical representation to 
print.  If you send the file *directly* to the printer device (bypassing 
the Win32 printing layer), it will send the ^L directly and should eject 
a new page on most printers.


-tkc


I am writing a txt file. It's up to the user to print it using Notepad 
or some other tool.  I have no idea how to send it directly to the 
printer, but I really don't want to furnish that capability in the 
program. From Google, The Graphics Device Interface (GDI).

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


Re: A simple-to-use sound file writer

2010-01-15 Thread Alf P. Steinbach

* Steve Holden:


For the record, yes, summing any waveforms that can be represented as
Fourier Series will necessarily result in another Fourier series, since
any linear combination of Fourier series must itself, be a Fourier
series, and therefore the representation of the sum of the summed waveforms.


As it is I do not know whether the above represents what I've written, or might 
perhaps be /misprepresenting/ the conclusions of this thread.


If I knew a lot more about Fourier series (it's been a long time since college! 
lots forgotten) I might agree or disagree with the above as it applies to 
constructing a sine wave from square waves.


I just note that representing a sine wave as square waves, forming it from 
square waves, in the practical sense works (demonstrated here), even though it's 
totally impractical :-), but just in answer to your original question.


And I note that in the mathematematical sense when n goes to infinity and 
vanishingly thin pulses result from sums of square waves, like *impulse* waves, 
then one is over in some regime where it is not at all clear to me that it is 
valid to talk about Fourier series any more. Perhaps it's valid if the term 
"Fourier series" does not necessarily imply sum of sine waves. I don't know.


I'm guessing that applying the Fourier series view for that is like actually 
dividing by zero to maintain the running product of a collection of numbers when 
an instance of 0 is removed from the collection.


It's no practical problem to maintain a running product (for programmers it's 
interesting to note that polar representation complex numbers can do the job), 
and it's well-defined also mathematically, with any /reasonable/ approach. But 
the simple-minded direct way, just dividing the current product by the number 
removed from the collection, is then invalid. And some people might take that 
limited applicability of the direct simple way as evidence that it's impossible 
to remove numbers, failing to see any of the trivial practical solutions. ;-)



Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread Mensanator
On Jan 15, 6:40 pm, "W. eWatson"  wrote:
> Tim Chase wrote:
> > W. eWatson wrote:
> >> Tim Chase wrote:
> >>> The pseudo-pipeline comparison would be
>
> >>>   type file.txt > lpt1:
>
> >>> which would send the raw text file to the printer (assuming it's set
> >>> up on LPT1, otherwise, use whatever port it's attached to in your
> >>> printer control panel); or are you using something like
>
> >>>   notepad file.txt
> >>>   File -> Print
>
> >> I should mention I'm using Windows. I just put chr(12) right in the
> >> txt. It's the first character in the next line of the txt file where I
> >> want to page forward. Not acquainted with GDI. Maybe I need some
> >> sequence of such characters?
>
> > It's not a matter of you controlling the GDI stuff.  Unless you're
> > writing directly to the printer device, printing on Windows is done
> > (whether by Notepad, gvim, Word, Excel, whatever) into a graphical
> > representation which is then shipped off to the printer.  So if you're
> > printing from Notepad, it's going to print what you see (the little
> > square), because Notepad renders to this graphical representation to
> > print.  If you send the file *directly* to the printer device (bypassing
> > the Win32 printing layer), it will send the ^L directly and should eject
> > a new page on most printers.
>
> > -tkc
>
> I am writing a txt file. It's up to the user to print it using Notepad
> or some other tool.  I have no idea how to send it directly to the
> printer, but I really don't want to furnish that capability in the
> program. From Google, The Graphics Device Interface (GDI).

Have you considered the possibility that your printer can't print
raw text files? I had one that would ONLY print Postscript. Embedding
a chr(12) would accomplish nothing, you HAD to use a driver that
would translate chr(12) into the appropriate Postcript codes.

What you're doing MIGHT work for others with different printers.


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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread Neil Hodgson
W. eWatson wrote:

> I am writing a txt file. It's up to the user to print it using Notepad
> or some other tool.  

   WordPad will interpret chr(12) as you want.

   Neil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python not good enough?

2010-01-15 Thread Nobody
On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:

> Actually, no.  It's quite possible to make a Python implementation that
> runs fast.  It's just that CPython, a naive interpreter, is too primitive
> to do it.  I was really hoping that Google would put somebody good at
> compilers in charge of Python and bring it up to production speed.
> 
> Look at Shed Skin, a hard-code compiler for Python

A hard-code compiler for the subset of Python which can easily be compiled.

Shed Skin has so many restrictions that it isn't really accurate to
describe the language which it supports as "Python".

Hardly any real-world Python code can be compiled with Shed Skin. Some of
it could be changed without too much effort, although most of that is the
kind of code which wouldn't look any different if it was implemented in
C++ or Java.

The monomorphism restriction is likely to be particularly onerous: the
type of a variable must be known at compile time; instances of subclasses
are allowed, but you can only call methods which are defined in the
compile-time class.

If you're writing code which makes extensive use of Python's dynamicity,
making it work with Shed Skin would require as much effort as re-writing
it in e.g. Java, and would largely defeat the point of using Python in the
first place.

http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html

If you want a language to have comparable performance to C++ or Java, you
have to allow some things to be fixed at compile-time. There's a reason
why C++ and Java support both virtual and non-virtual ("final") methods.

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


Re: setattr() oddness

2010-01-15 Thread Terry Reedy

On 1/15/2010 6:10 PM, Sean DiZazzo wrote:

On Jan 15, 2:22 pm, Terry Reedy  wrote:

On 1/15/2010 3:37 PM, Sean DiZazzo wrote:


Should the following be legal?



class TEST(object): pass

...

t = TEST()
setattr(t, "", "123")
getattr(t, "")

'123'


Different people have different opinions as to whether setattr (and
correspondingly getattr) should be strict or permissive as to whether or
not the 'name' string is a legal name. CPython is permissive. The
rationale is that checking would take time and prevent possible
legitimate use cases.

CPython is actually looser than this. Try

t.__dict__[1] = 2

Now there is an 'attribute' whose 'name' is an int! -- and which can
only be accessed via the same trick of delving into the internals. This
is, however, implementation behavior that would go away if an
implementation used string-key-only dicts to store attributes.

Terry Jan Reedy


Interesting.  I can understand the "would take time" argument, but I
don't see any legitimate use case for an attribute only accessible via
getattr().  Well, at least not a pythonic use case.


That was my first thought, but one thing I thought of would be a proxy 
object for remote objects coded in a language with different name rules, 
or any situation where 'names' and values come over the wire to be 
stored and later retrieved, so that all 'foreign' attribute access was 
done with set/get/del/attr.


I expect that creative Python programmers have found other uses too.

Terry Jan Reedy


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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread W. eWatson

Mensanator wrote:

On Jan 15, 6:40 pm, "W. eWatson"  wrote:

Tim Chase wrote:

W. eWatson wrote:

Tim Chase wrote:

...

program. From Google, The Graphics Device Interface (GDI).


Have you considered the possibility that your printer can't print
raw text files? I had one that would ONLY print Postscript. Embedding
a chr(12) would accomplish nothing, you HAD to use a driver that
would translate chr(12) into the appropriate Postcript codes.

What you're doing MIGHT work for others with different printers.


Could be, but I have no way of easily knowing. In any case, I was trying 
to write a simple report that could be printed with titles at the top of 
each page. If there's another "common" format that I can write in to 
produce the file, that's fine. It may be this is so difficult to be 
impossible. Long, long ago this was no problem. :-)


I suppose I could copy the txt file into wordpad, and print it there.
--
http://mail.python.org/mailman/listinfo/python-list


Re: chr(12) Form Feed in Notepad

2010-01-15 Thread Nobody
On Fri, 15 Jan 2010 10:42:43 -0800, W. eWatson wrote:

> I thought I'd put a page break, chr(12), character in a txt file I wrote 
> to skip to the top of the page. It doesn't work. Comments?

The 1970's are over, and neither Notepad nor your printer attempts to
maintain compatibility with a Teletype model 37.

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread W. eWatson

Neil Hodgson wrote:

W. eWatson wrote:


I am writing a txt file. It's up to the user to print it using Notepad
or some other tool.  


   WordPad will interpret chr(12) as you want.

   Neil


That may be the solution. Just tell the end user to copy the file into 
it, and print it there.


I just tried it in Wordpad, and it works, but my --- underlines are 
pushed together. Maybe tabs instead of spaces. The columns past Seq # in 
WordPad may suffer from the characters not being fixed width. Well, a 
little work with WordPad might be enough for users to get it right. 
"Copy txt file into wordpad. Select all the text, and set format to 
fixed (if that's possible.).


Here's what a txt sample looks like. It has line wrap here, and the page 
feed


Date/Time &Station UTC  Seq # Frames Time Span Pix 
Dst Pix/Sec
--- -- ---  - -- - 
--- ---
2008/11/12 17:38:58 WW 2008/11/13 01:38:58  1   Noise data.  Short 
track.
2008/11/12 17:39:24 WW 2008/11/13 01:39:24  2   Noise data.  Short 
track.



  <-PAGE FEED
Date/Time &Station UTC  Seq # Frames Time Span Pix 
Dst Pix/Sec
--- -- ---  - -- - 
--- ---
2008/11/17 22:29:54 WW 2008/11/18 06:29:54 21   Noise data.  Short 
track.
2008/11/18 01:51:36 WW 2008/11/18 09:51:36 22   Noise data.  Short 
track.
2008/11/18 04:05:03 WW 2008/11/18 12:05:03 23   Noise data.  Short 
track.
2008/11/18 17:40:42 WW 2008/11/19 01:40:42 2495  3.17 
48.17   15.21

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


Re: chr(12) Form Feed in Notepad (Windows)

2010-01-15 Thread D'Arcy J.M. Cain
On Fri, 15 Jan 2010 20:17:35 -0800
"W. eWatson"  wrote:
> Could be, but I have no way of easily knowing. In any case, I was trying 
> to write a simple report that could be printed with titles at the top of 
> each page. If there's another "common" format that I can write in to 
> produce the file, that's fine. It may be this is so difficult to be 
> impossible. Long, long ago this was no problem. :-)

Why not generate a PostScript or PDF file in the first place?  Check
out reportlab.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Using invalid.com email addresses

2010-01-15 Thread D'Arcy J.M. Cain
Damn!  I missed the @invalid.com in the address.  I'm not sure why I
just didn't do this before but @invalid.com just went into my
blacklist.

Does anyone else think that that behaviour is just rude, not to mention
in violation of the RFCs?

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A simple-to-use sound file writer

2010-01-15 Thread Alf P. Steinbach

* Grant Edwards:

On 2010-01-15, Steve Holden  wrote:


I will, however, observe that your definition of a square wave is what I
would have to call a "'square' wave" (and would prefer to call a "pulse
train"), as I envisage a square wave as a waveform having a 50% duty
cycle, as in

 ___ ___
|   |   |   |
|   |   |   |
|   |   |   |
+---+---+---+---+ and so on ad infinitum, (though I might allow you
|   |   |   |  to adjust the position
|   |   |   |  of y=0 if you want)
|___|   |___|


That is a square wave.


as opposed to your

 _
| |
| |
  __| |__   __
 | |
 | |
 |_|


That isn't.

Arguing to the contrary is just being Humpty Dumpty...


Neither I nor Steve has called that latter wave a square wave.

Steve, quoted above, has written that I defined a square wave that way. I have 
not. So Steve's statement is a misrepresentation (I described it as a sum of two 
square waves, which it is), whatever the reason for that misrepresentation.




Or, best of all, you could show me how to synthesize any
waveform by adding square waves with a 50% duty cycle.  Then I
*will* be impressed.


Isn't that what he claimed?  He said that his algorithm for
summing square waves demonstrated the converse of the ability
to construct a periodic function (like a square wave) from a
sine-cosine summation.


Not by itself, no: it just synthesizes a sine.

For the more general case read e.g. the PS in my reply to your earlier (single) 
article in this thread.


For information about what the algorithm does, what you refer to as a "claim" 
(but note that a Python implementation has been posted to this thread, and that 
it works, and that besides the algorithm is trivial so that "claim" is a rather 
meaningless word here), read the article that you then responded to.



Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using invalid.com email addresses

2010-01-15 Thread Alf P. Steinbach

* D'Arcy J.M. Cain:

Damn!  I missed the @invalid.com in the address.  I'm not sure why I
just didn't do this before but @invalid.com just went into my
blacklist.

Does anyone else think that that behaviour is just rude, not to mention
in violation of the RFCs?


In RFC violation yes.



   To safely satisfy these needs, four domain names are reserved as
   listed and described below.

   .test
.example
.invalid
  .localhost

  ".test" is recommended for use in testing of current or new DNS
  related code.

  ".example" is recommended for use in documentation or as examples.

  ".invalid" is intended for use in online construction of domain
  names that are sure to be invalid and which it is obvious at a
  glance are invalid.

  The ".localhost" TLD has traditionally been statically defined in
  host DNS implementations as having an A record pointing to the
  loop back IP address and is reserved for such use.  Any other use
  would conflict with widely deployed code which assumes this use.



Rude, no, it's probably someone who thought that /including/ the word "invalid" 
was the way to do it.



Cheers, just my 3 øre,

- Alf

PS: in the same way, not including "OT" in the subject line here might be 
considered rude. But then, if I were to add it, some newsreader might split the 
thread. So it's difficult to please everyone! :-)

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


Re: Is python not good enough?

2010-01-15 Thread hackingKK

On Saturday 16 January 2010 08:01 AM, Nobody wrote:

On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:

   

 Actually, no.  It's quite possible to make a Python implementation that
runs fast.  It's just that CPython, a naive interpreter, is too primitive
to do it.  I was really hoping that Google would put somebody good at
compilers in charge of Python and bring it up to production speed.
"production"?
 




 Look at Shed Skin, a hard-code compiler for Python
 

A hard-code compiler for the subset of Python which can easily be compiled.

Shed Skin has so many restrictions that it isn't really accurate to
describe the language which it supports as "Python".
+1
   




Hardly any real-world Python code can be compiled with Shed Skin. Some of
it could be changed without too much effort, although most of that is the
kind of code which wouldn't look any different if it was implemented in
C++ or Java.
   



Happy hacking.
Krishnakant.

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


Re: Using invalid.com email addresses

2010-01-15 Thread Stephen Hansen
On Fri, Jan 15, 2010 at 10:13 PM, D'Arcy J.M. Cain  wrote:

> Damn!  I missed the @invalid.com in the address.  I'm not sure why I
> just didn't do this before but @invalid.com just went into my
> blacklist.
>
> Does anyone else think that that behaviour is just rude, not to mention
> in violation of the RFCs?
>

It may or may not be in violation of the RFCs, but the modern reality of the
internet makes certain "rules" of the RFC's meaningless.

Spam is a major issue for some people; and some people do not want their
email address to be trivially harvested, and usenet exposes that address
very easy. You will frequently see people mutate their address, sometimes
they'll do so in such a way that if you look at it you'll know that if you
remove parts you will get a real address-- these people allow for personal
direct communication. Others don't really want to receive any email at all
based on their newsgroup posting, and want all of your messages to go to the
group instead-- they generally provide an email address which is utterly
meaningless.

It may or may not violate certain RFC's, but there's nothing rude about it.
Its people trying to engage a community and yet hold some measure of control
over how they engage that community. They have every right, IMHO, regardless
of what an RFC may say.

People who may use an invalid.com address simply don't want to be contacted
individually and directly. Why is that rude? They post to a public forum,
and they simply want to communicate solely in that public forum. They have
no moral obligation to provide a means for personal or direct communication,
in my mind at least. To me, demanding a real address from people in the
usenet medium which has nothing even vaguely like privacy protection is
rude. If someone chooses to provide it, great. If not, just as fine. One is
obligated only to share with us what they wish, and all power to them in
whatever capacity they wish to share.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict's as dict's key.

2010-01-15 Thread Lie Ryan
On 01/14/10 05:33, Albert van der Horst wrote:
> (I encountered this before. A dictionary is a natural for a
> boardgame position, i.e. chess. Now we want to look up chess
> positions.)

or use collections.namedtuple
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using invalid.com email addresses

2010-01-15 Thread Ben Finney
"D'Arcy J.M. Cain"  writes:

> Does anyone else think that that behaviour is just rude, not to
> mention in violation of the RFCs?

Yes, it violates RFCs. It also ignores the fact that the domain is
currently registered until 2010-08-03, and is therefore not available
for anyone else's use, unless they happen to have an arrangement for its
use with the registrant.

It also ignores the reserved names in RFC 2606 which would avoid these
problems http://tools.ietf.org/html/rfc2606>.

-- 
 \ “Nature hath given men one tongue but two ears, that we may |
  `\  hear from others twice as much as we speak.” —Epictetus, |
_o__)  _Fragments_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list