Re: Does hashlib support a file mode?

2011-07-05 Thread Thomas Rachel

Am 06.07.2011 07:54 schrieb Phlip:

Pythonistas:

Consider this hashing code:

   import hashlib
   file = open(path)
   m = hashlib.md5()
   m.update(file.read())
   digest = m.hexdigest()
   file.close()

If the file were huge, the file.read() would allocate a big string and
thrash memory. (Yes, in 2011 that's still a problem, because these
files could be movies and whatnot.)

So if I do the stream trick - read one byte, update one byte, in a
loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit
CPU. So that's the same problem; it would still be slow.


Yes. That is why you should read with a reasonable block size. Not too 
small and not too big.


def filechunks(f, size=8192):
while True:
s = f.read(size)
if not s: break
yield s
#f.close() # maybe...

import hashlib
file = open(path)
m = hashlib.md5()
fc = filechunks(file)
for chunk in fc:
m.update(chunk)
digest = m.hexdigest()
file.close()

So you are reading in 8 kiB chunks. Feel free to modify this - maybe use 
os.stat(file).st_blksize instead (which is AFAIK the recommended 
minimum), or a value of about 1 MiB...




So now I try this:

   sum = os.popen('sha256sum %r' % path).read()


This is not as nice as the above, especially not with a path containing 
strange characters. What about, at least,


def shellquote(*strs):
return " ".join([
"'"+st.replace("'","'\\''")+"'"
for st in strs
])

sum = os.popen('sha256sum %r' % shellquote(path)).read()


or, even better,

import subprocess
sp = subprocess.Popen(['sha256sum', path'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
sp.stdin.close() # generate EOF
sum = sp.stdout.read()
sp.wait()

?



Does hashlib have a file-ready mode, to hide the streaming inside some
clever DMA operations?


AFAIK not.


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


Re: Does hashlib support a file mode?

2011-07-05 Thread Chris Rebert
On Tue, Jul 5, 2011 at 10:54 PM, Phlip  wrote:
> Pythonistas:
>
> Consider this hashing code:
>
>  import hashlib
>  file = open(path)
>  m = hashlib.md5()
>  m.update(file.read())
>  digest = m.hexdigest()
>  file.close()
>
> If the file were huge, the file.read() would allocate a big string and
> thrash memory. (Yes, in 2011 that's still a problem, because these
> files could be movies and whatnot.)
>
> So if I do the stream trick - read one byte, update one byte, in a
> loop, then I'm essentially dragging that movie thru 8 bits of a 64 bit
> CPU. So that's the same problem; it would still be slow.
>
> So now I try this:
>
>  sum = os.popen('sha256sum %r' % path).read()
>
> Those of you who like to lie awake at night thinking of new ways to
> flame abusers of 'eval()' may have a good vent, there.

Indeed (*eyelid twitch*). That one-liner is arguably better written as:
sum = subprocess.check_output(['sha256sum', path])

> Does hashlib have a file-ready mode, to hide the streaming inside some
> clever DMA operations?

Barring undocumented voodoo, no, it doesn't appear to. You could
always read from the file in suitably large chunks instead (rather
than byte-by-byte, which is indeed ridiculous); see
io.DEFAULT_BUFFER_SIZE and/or the os.stat() trick referenced therein
and/or the block_size attribute of hash objects.
http://docs.python.org/library/io.html#io.DEFAULT_BUFFER_SIZE
http://docs.python.org/library/hashlib.html#hashlib.hash.block_size

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-05 Thread Gregory Ewing

rantingrick wrote:


And how do you EXPLICITY quit the application?


Using its "Quit" menu command.

But that's Mac-specific, and not central to the discussion.
On Linux and Windows, an application will usually exit when
its last window is closed. Either way, there is no need for
a privileged main window.

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Gregory Ewing

rantingrick wrote:


What he means is that On Mac, if you close "all" windows, the application is
still running.


Then that is NOT closing windows that is only ICONIFIYING/HIDING them.


No, the windows really are closed. They no longer exist
in any way. The application is still running, though, and
its menu bar will appear if you bring it to the front
(in MacOSX this is done by clicking on its dock icon;
in classic MacOS it was done by selecting from the menu
of running applications that was available in the top right
corner of the screen).

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Waldek M.
Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisał(a):
> Because unless you are extremely disciplined, code and the comments
> describing them get out of sync. [...]
True, but that gets far worse with external docs.
Do you have in mind any better replacement?

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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 3:26 PM, Dennis Lee Bieber  wrote:
> On Wed, 6 Jul 2011 12:31:02 +1000, Chris Angelico 
> declaimed the following in gmane.comp.python.general:
>> Democracy DOES NOT WORK. Plain and simple. You cannot build a
>> programming language democratically.
>>
>        Uhm... COBOL and Ada may be close... They were committee/competition
> where the best (compromise) aspect was selected for inclusion...

And are they what you would call good languages?

A committee isn't the same as democracy, although it is related. If
you have two people making a decision, you potentially pull things in
two directions. If you have two million people making a decision, you
tear it to pieces.

Vision for a language (or any other project) cannot come from a
mandate from the masses. I'm waiting for my aquatic ceremony before I
start building a language.

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


Re: Microsoft GUIs

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 2:53 PM, Andrew Berg  wrote:
>> Let Microsoft play with, and sell, pretty GUIs and pretty apps.
> I completely disagree. MS sucks at making GUIs.
>

I never said they were good at making GUIs. I said they were good at
selling GUIs.

Dan is right about the ugliness of the Windows APIs. There are
innumerable anomalies between otherwise-similar functions, weird
behaviours that may and may not have historical precedent, and enough
hair-pulling fuel to turn you bald in a week. Also, and possibly more
serious, the security features that Windows has mostly seem to have
been monkey-patched in; and there are ridiculous vulnerabilities just
waiting to be exploited. The WM_TIMER message can be sent by any
process to any process, and one of its parameters is the address of a
callback - and voila, other process starts executing code at that
address. And this works even if the program doesn't use timers.

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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Andrew Berg
On 2011.07.06 12:26 AM, Dennis Lee Bieber wrote:
> On Tue, 05 Jul 2011 16:01:57 -0500, Andrew Berg
>  declaimed the following in
> gmane.comp.python.general:
>
> > On 2011.07.05 01:14 PM, sal migondis wrote:
> > > How could a belief be wrong?
> > Beliefs aren't subjective.  One's taste in music, for example, is
> > largely subjective and can't be right or wrong, but a belief (which has
> > to do with facts) certainly can be.
>
>   Pardon
>
>   Most "beliefs" that I've encountered do their best to ignore any
> facts that contradict the belief. "Facts" imply testable evidence,
> hypotheses, eventual theorems...
I didn't say people were objective. A belief is quite similar to a
statement of fact. Whether the statement is true or false or even
objectively reached isn't relevant to the definition.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft GUIs

2011-07-05 Thread Andrew Berg
On 2011.07.06 12:03 AM, Dan Stromberg wrote:
> I disagree.  The stuff endusers tend to use is polished to some
> extent, but the backend is verging on hideous.  If a developer
> complains about the ugly internal structure "yeah, but you say that
> just because you're a computer person / geek."
Admittedly, I haven't tried to do a whole lot of development with the
Windows APIs, and I certainly haven't tried to develop any software
that's heavily tied to the kernel, so I could be wrong in this area.
Could you elaborate?
>
> Yes, the NT kernel still has some
> long standing bugs, but MS has done well with things that matter to
> sysadmins. chkdsk, for example, has been around for ages, but I still
> don't know of anything that really beats it.
>
>
> How about FreeBSD's ability to check a filesystem while it's in use?
Actually, I meant in Windows, as in there aren't any 3rd-party tools
that really trump chkdsk for repairing NTFS volumes. I should've
clarified that. However, that sounds like an awesome feature (though I'm
not going to switch to FreeBSD just for that).
>
> I've only had a small
> amount of experience with it so far, but Powershell seems to be an
> excellent tool for admin scripting since it interfaces with WMI so
> well.
>
>
> I worked with PowerShell for about a year (after an acquisition by
> Microsoft), before eagerly diving back to Python.  Here are some of my
> notes about the problems in PowerShell:
Did you encounter these issues with PowerShell 2? I know MS put a lot of
work into fixing and adding features to PowerShell 1, but like I said, I
haven't had much experience with it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT)

2011-07-05 Thread Dan Stromberg
On Tue, Jul 5, 2011 at 9:13 PM, Andrew Berg wrote:

> On 2011.07.05 09:31 PM, Chris Angelico wrote:
> > I've said for a while that Microsoft could do far worse than to turn
> > Windows into a GUI that sits on top of a Unix-derived kernel. They
> > won't do it, though, because it would be tantamount to admitting both
> > that Unix is superior to Windows, AND that Apple got it right.
>

Supposedly when Microsoft sold Xenix to SCO, Microsoft signed a legal
document that barred them from competing in the *ix space.  I do not know if
it remains in effect now or not.


> In my experience, it's been the GUIs that are awful and the backend
> stuff that's been good in Windows.


I disagree.  The stuff endusers tend to use is polished to some extent, but
the backend is verging on hideous.  If a developer complains about the ugly
internal structure "yeah, but you say that just because you're a computer
person / geek."


> Yes, the NT kernel still has some
> long standing bugs, but MS has done well with things that matter to
> sysadmins. chkdsk, for example, has been around for ages, but I still
> don't know of anything that really beats it.


How about FreeBSD's ability to check a filesystem while it's in use?


> I've only had a small
> amount of experience with it so far, but Powershell seems to be an
> excellent tool for admin scripting since it interfaces with WMI so well.
>

I worked with PowerShell for about a year (after an acquisition by
Microsoft), before eagerly diving back to Python.  Here are some of my notes
about the problems in PowerShell:

1) If you have a script that expects an array, and you don’t declare it as
an array (type declarations are generally optional in PS), things will work
fine until you get an array of length 1.  Then your code breaks.
1.5) If you have a function that returns an array, you must return it with
,@{$a} to make it always be an array in the caller - it's ostensibly novice
friendly, but it seems both novice and sophisticate hostile.
2) Options can be abbreviated, which may cause problems for what-was-working
code on PowerShell upgrades, when something that was unique becomes
ambiguous due to the addition of a new option having a common prefix with
another option.
3) You can throw a string exception in PowerShell; this is disallowed in C#
because it’s considered a poor practice.  They’re deprecated in Python 2.x
too - not sure if they were removed in Python 3.
4) Empty strings and nulls are kind of conflated, which is perhaps simpler
in a way in native powershell stuff, but when you call something like a COM
method that expects the two to be different, you run into problems that
appear to require C# to get around.
5) If you try to invoke an external command having an option with double
quotes and blanks in it, the single option will be converted into n+1
options, where n is the number of blanks inside double quotes.  Granted,
this is probably a problem that PowerShell inherited from one of its
dependencies
6) no generators.  C#, a supposedly lower-level language, has generators,
but generators are a really nice high-level construct
7) Not a big deal, but what's up with the not operator?  You Always seem to
have to parenthesize, whether using ! or -not
8) If you pass an array of arrays, for EG 2x10, from one host to another
using invoke-command, you actually end up with a single 20 element array
9) If you foreach ($foo in $bar), and $bar is empty, you still enter the
script block once for $null
10) Sometimes you need comma separated parameters in parens.  Sometimes you
can't have them.  When you can't have them and you're passing to a function
that accepts multiple arguments, you end up with the 1st having an array of
your arguments, and the 2..nth having $null.  That's pretty far from the
principle of least surprise
11) To pipe a 2-d array, you need to first convert it to a 3-d array, where
the outermost array-ing is a single element - using the comma operator out
front.  Then send it into the pipeline as a 2-d array
12) DarkYellow is white and DarkMagenta is dark bluish.  "It’s a feature.
The default colours used by PowerShell are not in the standard console
palette. To get the desired colours, we redefine DarkYellow and DarkMagenta
and use them instead."
13) “continue” is not really supported for a Foreach-Object loop, but at
least return does what you'd expect continue to do
14) “break” doesn’t do what it looks like it does in a foreach-object.  It’s
ending the script like “continue”.
15) Sometimes foreach is foreach.  Sometimes it's foreach-object.
16) break inside a foreach inside a pipeline breaks the whole pipeline



> When it comes to things that interface with your average idiot, however,
> MS consistently drops the ball. The new interface design they've imposed
> on their office suite and Explorer is not only just plain bad, but it's
> infectious (and it's the reason the Firefox and Thunderbird default GUI
> configurations look horrendous).


H.  Wonder why tha

Re: Microsoft GUIs

2011-07-05 Thread Andrew Berg
On 2011.07.05 11:25 PM, Chris Angelico wrote:
> Suppose I gave you a computer that had GNOME ported to Windows, and
> used the purplish palette that Ubuntu 10.10 uses, and had a Windows
> port of bash as its most convenient terminal. Members of this list
> will doubtless have no problem duck-typing that as a Linux box (to the
> extent of being quite surprised on seeing something that functions
> differently).
I would love to see a fully functional KDE running on Windows (this is
being worked on, but development has been slow and rough). I was talking
about GUI design, though, not just the aesthetics of a window manager
and widgets.
A recent version of bash working on Windows would be nice too, but IMO,
MS should be actively promoting PowerShell. It's not that PowerShell is
a superior scripting language to bash, but that it's integrated with WMI
and is therefore much more convenient for admin stuff.
> What is Microsoft selling? They're a company, which means they need to
> keep selling stuff year after year. What's saleable in Windows? Is it
> the kernel? Maybe, but only by its specs. Far more saleable is the
> user-facing parts of the system. Sell them a pretty new GUI with
> transparent windows. Sell 'em a fancy new Office that looks and feels
> different. Sell a development package that lets programmers use these
> same facilities in their own code.
I think the reason MS has been creating good sysadmin tools lately is
that it's feeling competition from Linux/Unix server solutions. If they
can make a Windows domain admin's job easier, they're more likely to
sell their OS.
As for the end-user side of Windows (and their office suite), AFAICT,
they're still pretty complacent with their market share and only change
things up for the sake of difference. Since the GUI is the most
noticeable part of the software, that's what gets changed.
> Since XP, the Windows kernel has been mostly reliable. I've had
> programs go wrong, and (eventually) managed to kill the process, upon
> which everything cleans up fairly nicely. Not that that's really a
> boast-worthy feature; I'd call it mandatory these days.
I agree.
> Let
> Microsoft play with, and sell, pretty GUIs and pretty apps.
I completely disagree. MS sucks at making GUIs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT)

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 2:13 PM, Andrew Berg  wrote:
> On 2011.07.05 09:31 PM, Chris Angelico wrote:
>> I've said for a while that Microsoft could do far worse than to turn
>> Windows into a GUI that sits on top of a Unix-derived kernel. They
>> won't do it, though, because it would be tantamount to admitting both
>> that Unix is superior to Windows, AND that Apple got it right.
> In my experience, it's been the GUIs that are awful and the backend
> stuff that's been good in Windows.

Suppose I gave you a computer that had GNOME ported to Windows, and
used the purplish palette that Ubuntu 10.10 uses, and had a Windows
port of bash as its most convenient terminal. Members of this list
will doubtless have no problem duck-typing that as a Linux box (to the
extent of being quite surprised on seeing something that functions
differently).

What is Microsoft selling? They're a company, which means they need to
keep selling stuff year after year. What's saleable in Windows? Is it
the kernel? Maybe, but only by its specs. Far more saleable is the
user-facing parts of the system. Sell them a pretty new GUI with
transparent windows. Sell 'em a fancy new Office that looks and feels
different. Sell a development package that lets programmers use these
same facilities in their own code.

(And of course, sell them bug fixes, by declaring end-of-life on older
products and forcing everyone to move up. But that's different.)

Since XP, the Windows kernel has been mostly reliable. I've had
programs go wrong, and (eventually) managed to kill the process, upon
which everything cleans up fairly nicely. Not that that's really a
boast-worthy feature; I'd call it mandatory these days.

The main reason I would recommend unifying kernels is simplicity. Let
Microsoft play with, and sell, pretty GUIs and pretty apps. Let
someone else worry about what's underneath. As an advantage, it would
then become possible to buy a copy of Windows, run it *under Linux*,
and treat it like a VMWare window.

But it's not likely to happen, and I'm not 100% convinced it'd really
be a good idea (see DNS root servers argument from earlier). It would
make cross-compilation a lot easier, though!

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


Microsoft GUIs (was: The end to all language wars and the great unity API to come!) (OT)

2011-07-05 Thread Andrew Berg
On 2011.07.05 09:31 PM, Chris Angelico wrote:
> I've said for a while that Microsoft could do far worse than to turn
> Windows into a GUI that sits on top of a Unix-derived kernel. They
> won't do it, though, because it would be tantamount to admitting both
> that Unix is superior to Windows, AND that Apple got it right.
In my experience, it's been the GUIs that are awful and the backend
stuff that's been good in Windows. Yes, the NT kernel still has some
long standing bugs, but MS has done well with things that matter to
sysadmins. chkdsk, for example, has been around for ages, but I still
don't know of anything that really beats it. It's certainly saved my ass
on several occasions. MS also bought the Sysinternals suite of software,
and those programs continue to be very good. I've only had a small
amount of experience with it so far, but Powershell seems to be an
excellent tool for admin scripting since it interfaces with WMI so well.
When it comes to things that interface with your average idiot, however,
MS consistently drops the ball. The new interface design they've imposed
on their office suite and Explorer is not only just plain bad, but it's
infectious (and it's the reason the Firefox and Thunderbird default GUI
configurations look horrendous). Another area MS fails it is sensible
defaults. They put tons of effort into increasing security in the
kernel, but don't use the security features (I'll try to come up with
more detail on this later). Explorer /still/ hides known extensions by
default, which /still/ makes it easier for bad people to get their
victims to execute malware. What I think is that MS should focus on the
kernel and encourage others to do their GUIs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 1:45 PM, rantingrick  wrote:
>> If you force too much on people, they'll go
>> elsewhere.
>
>  Why all this running away with tail between legs?
>  Do these these people have extremely small eggs?
>  I wish they would stand firm and put up a fight
>  instead they're just cowards spewing more endless tripe.

Standing up and fighting takes effort. It's a lot easier - and a lot
more time-efficient - to ignore idiots and trolls and just get some
work done. I think I'll do that, right now.

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


hai

2011-07-05 Thread http://123maza.com/65/chill155/
http://123maza.com/65/chill155/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread rantingrick
On Jul 5, 9:44 pm, Chris Angelico  wrote:
> On Wed, Jul 6, 2011 at 11:53 AM, rantingrick  wrote:
> > So you would start drivers education class with road construction? Or
> > the history of the internal combustion engine? Who cares about
> > actually *driving* the car.
>
> I believe that starting driver ed with some basics of how an internal
> combustion engine works would be a Good Thing. If you're going to be
> in control of a ton of steel that's capable of moving at a hundred
> kays, you ought to know at least a bit about what provides the kinetic
> energy.

How about kinetic energy itself? If you know *what* produces power to
induce kinetic energy into the vehicle but not *how* the laws of
physics govern kinetic energy; what damn good is that going to do for
you? How about some basics of safe/defensive driving? How about
considering the good of the many instead of the you?

> There's a difference between comprehension and jumping through hoops.

Likewise for priorities and acting aloof.

> If you force too much on people, they'll go
> elsewhere.

 Why all this running away with tail between legs?
 Do these these people have extremely small eggs?
 I wish they would stand firm and put up a fight
 instead they're just cowards spewing more endless tripe.


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


Should ctypes handle mis-matching structure return ABI between mingw and MSVC?

2011-07-05 Thread Just Fill Bugs
According the Bug 36834 of gcc, there is a mis-matching between mingw 
and MSVC when a struct was returned by value from a C function.


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834

Should ctypes handle this situation automatically somehow?

A ctypes discussion on 2009:

http://thread.gmane.org/gmane.comp.python.ctypes.user/4439

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


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 11:53 AM, rantingrick  wrote:
> So you would start drivers education class with road construction? Or
> the history of the internal combustion engine? Who cares about
> actually *driving* the car.
>

I believe that starting driver ed with some basics of how an internal
combustion engine works would be a Good Thing. If you're going to be
in control of a ton of steel that's capable of moving at a hundred
kays, you ought to know at least a bit about what provides the kinetic
energy.

There's a difference between comprehension and jumping through hoops.
In your driver ed example, I don't believe that the accelerator pedal
should be replaced with a flexible fuel-line that the driver squeezes
to control flow to the engine; but on the other hand, I don't think
the brake pedal should be replaced by a single button saying "stop
car" either.

Arrogance is a normal part of designing programming languages (see
Larry Wall's comments regarding Perl, for instance). But arrogance to
the extent of forcing your views on programmers is generally resented,
and with good reason. If you force too much on people, they'll go
elsewhere.

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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 11:07 AM, rantingrick  wrote:
> On Jul 4, 6:24 pm, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> Define "best for all", and try not to make it "what Rick wants".
>
> You want features? And remember i am talking about scripting/glue
> level languages here. Something to replace Python, Ruby, Perl,
> JavaScript, etc, etc not some "pie-in-the-sky",  "single-answer-to-all-
> our-problems" pipe dream language.
>
>  * Intuitive syntax.
Subjective.

>  * Productivity friendly.
Depends heavily on the task at hand. HQ9+ is extremely productivity
friendly if you're trying to write a quine.

>  * Complex enough to solve large problems but simple enough for simple
> problems (that does include extending into C when needed)
Subjective. Any Turing-complete language is technically complex enough
to solve large problems, but would you care to write a web browser in
Ook?

>  * Multi paradigm (problem
?

>  * Promotes a culture of code readability (because people read source;
> not just machines!).
from __future__ import braces # this'll make it more readable for C programmers

>> No, Python is not a monoculture. There are the Stackless, Jython, PyPy and
>> etc etc
>
> Hmm. Just think how far ahead we would be if these folks would stop
> trying to support petty differences and focus on a singular Python
> language?

Imagine how much faster we'd all reach our destinations if whenever I
push my car's accelerator, it moves every car in the world the same
distance in the same direction!

> This problem is far bigger than python. Selfishness infests every
> group of humans on this planet. Why do we need multiple OS's? Just so
> one can say "\" is the proper file path sep and someone else can say
> "/" is the proper one! Are you kidding me?

I've said for a while that Microsoft could do far worse than to turn
Windows into a GUI that sits on top of a Unix-derived kernel. They
won't do it, though, because it would be tantamount to admitting both
that Unix is superior to Windows, AND that Apple got it right.

However, if the entire world moved to one kernel, that would be a
spof. That's why the DNS root servers don't all run the same software;
if a flaw were found in BIND that brought everything down, there would
still be three root servers (two of them anycasted) which would be
unaffected.

There's another good reason for diversity, too. Suppose you know only
one language, and you want to verify that your program is producing
correct results. What do you do? You're forced to do the job manually.
If you have a completely different system, you could verify it against
that - for instance, check your Python program by implementing
equivalent functionality in Lua.

> Look at the multiplicity. Look at the asinine nature of it all and for
> once in your life join the group that is the future of human
> evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello!

You can't know what the future of human evolution is, unless it
involves time travel.

>> Since needs are frequently in opposition (e.g. the speed/memory trade-off),
>> a single "true language" must be a compromise language that leaves nobody
>> happy.
>
> Oh Steven, that's just your fear of unity acting out again. Yes,
> what's good for the group will not *always* be good for you, or me, or
> xah lee! But what matters is progress. Not your selfish needs Steven.

And there you have the nub. Your idea of a perfect language is one
that won't always be good for any particular person. This is where
diversity comes to the fore. I'm currently using Google's V8 engine as
my scripting engine, but I need it to be slightly different - so I
modified it. I have offered the patch back to the community, and it
may or may not end up being accepted, but that is immaterial. Right
here, right now, I am running a modified V8, and it works FOR ME.

What you're saying is that "progress" is more important than any individual...

>> Or some dictator (Rick?) declares that such-and-such a set of
>> features is, by definition, the "perfect" language and those who want
>> something else have to miss out.
>
> I have never held myself out as some sort of dictator. These decisions
> must be made in a democratic manner. This is FUD.

... which is exactly what many dictators have said. However, that is immaterial.

Democracy DOES NOT WORK. Plain and simple. You cannot build a
programming language democratically.

Python has a BDFL. Open Office has had a variety of owners, and when
enough people dislike the current owner, the project forks (eg
LibreOffice). Savoynet is run by Marc Shepherd, who took over in 1998.
All the best commanders listen to people, but ultimately, they make
the decisions. Even in USA politics, where people talk proudly of
living in a democracy, what you actually have is a President who
wields a lot of power.

>> Imagine a world where *every* shop was Walmart. That would be good for
>> Walmart, but terrible for everyone else. That's Rick's plan 

Re: Implicit initialization is EXCELLENT

2011-07-05 Thread rantingrick
On Jul 5, 10:26 am, Steven D'Aprano  wrote:
> This is not strictly Python, although it is peripherally relevant.
>
> Some month or three ago, I read an article or blog post about API design,
> specifically the wrong-headedness of insisting that callers manually
> initialise instances using a separate step after creation.
>
> The argument goes, if your API looks something like this:
>
> instance = Spaminator(extra_truffles=False)
> instance.activate()
> instance.nom_nom_nom()
> => prints "yummy spam, the food of the Gods!!!"
>
> chances are that you are doing it wrong and your users will hate you. Why
> force the user to manually "flip the switch" (so to speak)? It's not like
> they can possibly avoid it:

I completely agree!

> Exceptions to this rule are if the Spaminator has side-effects (e.g. files,
> in which case the user may want finer control in when they are opened and
> closed), or if there are meaningful operations you can perform on an
> inactive Spaminator.

Agreed again!

> It's also relevant to
> tkinter, which will implicitly create a root window for you when needed.

WRONG.
Oh wait,
of course,
you are correct!
YES!
Maybe we should have library modules import only when needed! i mean,
who needs those pesky import statements anyways! Sure it will slow
down run time BUT WHO CARES! My gawd, you just opened my mind to so
many possibilities! Why stop at library modules, if it is not there
just download the source at run time! Guido really dropped the ball on
this one folks.

> Since you can't do anything without a root window, I don't see the benefit
> in forcing the user to do so.

The reason is simple. It's called order. It's called learning from day
one how the order of things exists. Widgets are part of windows, not
the other way around. Saving a few keystrokes is not acceptable if you
jumble the understanding of a new student. To understand and use
Tkinter properly you must understand the order of window->widget.

> When they need to learn about root windows,
> they will in their own good time.

So you would start drivers education class with road construction? Or
the history of the internal combustion engine? Who cares about
actually *driving* the car.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread rantingrick
On Jul 4, 6:24 pm, Steven D'Aprano  wrote:
> rantingrick wrote:

> Some people want to make Python more dynamic. Some want it to be less
> dynamic. Some care about integrating it with Java or .Net, some don't care
> about either. Some are interested in clever optimization tricks, some
> oppose adding any more complexity.
>
> Some want it to be faster, and are happy to throw more memory at it to do
> so. Some want it to use less memory, because on embedded devices and smart
> phones memory is the bottleneck, not time.
>
> Some only program in Python. Some treat Python as merely one language out of
> many that they use.
>
> Some come to Python from the C/C++ community, and their wants are influenced
> by C. Some come to Python from Lisp, Scheme or Haskell, and their wants are
> influenced by functional programming ideas. Some have never programmed
> before, and don't know want they want.

And are any of them getting what they want? No. And they should not.
(stay tuned for the reason "why not")

> Define "best for all", and try not to make it "what Rick wants".

You want features? And remember i am talking about scripting/glue
level languages here. Something to replace Python, Ruby, Perl,
JavaScript, etc, etc not some "pie-in-the-sky",  "single-answer-to-all-
our-problems" pipe dream language.

 * Intuitive syntax.
 * Productivity friendly.
 * Complex enough to solve large problems but simple enough for simple
problems (that does include extending into C when needed)
 * Multi paradigm (problem
 * Promotes a culture of code readability (because people read source;
not just machines!).
 * there is always more.
 * we all know this list steven!

> No, Python is not a monoculture. There are the Stackless, Jython, PyPy and
> IronPython sub-cultures, all with their own needs, wants and desires. There
> are sub-cultures for embedded devices and smart phones, sub-cultures for
> those who use Python as a teaching language, for web development, for GUI
> development, and for system administration. There are the Numpy and Scipy
> sub-cultures, sub-cultures in the fields of linguistics and biology.

Hmm. Just think how far ahead we would be if these folks would stop
trying to support petty differences and focus on a singular Python
language?

But let's not kid ourselves here!

This problem is far bigger than python. Selfishness infests every
group of humans on this planet. Why do we need multiple OS's? Just so
one can say "\" is the proper file path sep and someone else can say
"/" is the proper one! Are you kidding me?

Look at the multiplicity. Look at the asinine nature of it all and for
once in your life join the group that is the future of human
evolution, not the evolutionary dead-end! BTW: Tell Lucy i said hello!


> Nature isn't striving for anything.
> [...]
> what you believe is not new and it is
> not a minority view. It is old, obsolete,

Before you go out babbling about "concepts" you should understand what
these "concepts" are; or at least at the minimum read the freaking
Wiki! My statements are in no way remotely related to "Great Chain of
Being" and this feeble attempt to prove so is obviously another one of
your half stuffed straw-men arguments.

> and the vast majority of people
> with no modern biology education believe something like it.

You sure presume to know quite a lot about "uneducated people". Do you
know these folks personally? Do you chit-chat with them on the subway
or whilst sharing a Frappuccino?

> Since needs are frequently in opposition (e.g. the speed/memory trade-off),
> a single "true language" must be a compromise language that leaves nobody
> happy.

Oh Steven, that's just your fear of unity acting out again. Yes,
what's good for the group will not *always* be good for you, or me, or
xah lee! But what matters is progress. Not your selfish needs Steven.

> Or some dictator (Rick?) declares that such-and-such a set of
> features is, by definition, the "perfect" language and those who want
> something else have to miss out.

I have never held myself out as some sort of dictator. These decisions
must be made in a democratic manner. This is FUD.

> Imagine a world where *every* shop was Walmart. That would be good for
> Walmart, but terrible for everyone else. That's Rick's plan for
> programming.

You know Steven, wal-mart is a very successful company. And wal-mart
meets the needs of the many. Again you fail to see the truth behind
the curtain. If (as you say) wal-mart really is such a bad company and
it's existence is hurting "the many"... then explain to the class (if
you can) why wal mart is the most successful retail chain in the
history of the world?

We are listening...

Do you realize that without customers buying products that wal-mart
could never get to this pinnacle of retail success? If you are
correct, then people buy from wal-mart even though wal-mart is "bad"
for them. Please explain this reversal of reality Steven because i
think you are watching too much MTV and it's ro

Re: web browsing short cut

2011-07-05 Thread Dustin Cheung
Hey,

I am looking into Tkinter. But i am not sure if it will actually work. This
maybe a crazy idea but i was wondering if i can put a web browser in the
frame. I have tried to use Tkinter to resize and place the windows to
certain areas of the screen but that's not working or the way im approaching
this problem is completely wrong. I want to make a program that will have
websites displayed in specific areas of the screen. I was planning on using
the program on the big screen. So is it possible to put the web browser
inside the frame in Tkinter?


On Sat, Jul 2, 2011 at 7:10 PM, Chris Rebert  wrote:

> On Sat, Jul 2, 2011 at 6:21 PM, Dustin Cheung  wrote:
> > Hey guys,
> > I am new to python. I want to make a shortcut that opens my websites
> > and re-sizes them to  display on different areas on the screen. I looked
> > around but i had no luck. Is that possible with python? if so can someone
> > point to to the right direction? Here is what I came up with so far..
>
> The window positioning+resizing bit will likely require using
> platform-specific APIs. Since you appear to be on Windows, the
> relevant library would be pywin32 (http://pypi.python.org/pypi/pywin32
> ). You would use it to invoke some COM API that does window
> positioning+resizing. I am unable to give more details as I'm on a
> Mac.
>
> Sidenote: Have you tried Firefox's "Bookmark All Tabs" feature?
>
> Cheers,
> Chris
>



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


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 7:34 pm, Chris Angelico  wrote:

> Actually, everything you do requires the underlying window manager,
> otherwise you're just painting your own pixels on the screen. And I
> never said that this model was possible in some and not others.
> (Although it's a bit harder with Windows; there's no explicit call to
> finalize windowing, so most likely the application will hold GUI
> memory until termination.)

Ah ha. I think we are getting somewhere now. Everything up to this
point has been mostly exposition :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do twisted and multiprocessing.Process create zombies?

2011-07-05 Thread Stefan Behnel

bitcycle, 05.07.2011 23:52:

In python, using twisted loopingcall, multiprocessing.Process, and 
multiprocessing.Queue; is it possible to create a zombie process. And, if so, 
then how?


I think it's best to consult your local Voodoo master on the matter of 
zombie creation processes.


That being said, there are far too many zombies around already, so please 
don't add to that.


Stefan

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 10:15 AM, rantingrick  wrote:
> On Jul 5, 6:54 pm, Chris Angelico  wrote:
>
>> To do what for me? Close windows? Reclaim memory? Terminate
>> applications? I don't understand your bogglement.
>
> ClaimA: I made claim that Tkinter's window hierarchy is not only
> normal, but justified in modern GUI programming.
>
> ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's
> system of window management was superior and did not need such a
> "window hierarchy" simply because;

I never said "better". I just said that it's possible to create an
application that *to the user* has no main window, even though *to the
system* it does. And I'm also pointing out that in most good toolkits,
there's no "main window", but instead a "main thread".

> 1. You can create a program that twiddles it's thumbs (using very
> little memory) until a message is received.
> 2. Upon receiving a message the program can open a GUI window.
> 3. When the user closes the GUI window (definition of "close" is not
> nailed down yet!) the program will free the GUI memory and start
> twiddling it's thumbs again until the next message arrives.
> 4. rinse and repeat until you are happy.

Again, pointing out that it's possible, not that it's good. (Most
messenger programs will have a means of *sending* messages too, which
makes a good basis for a main window.) It's not efficient to keep
loading up GUI libraries and discarding them again. But it's possible,
and it would mean that you genuinely have multiple equal main windows.

> It's obvious that yours and my claims are contradicting. So with that
> said, at what point does Tkinter or Windows fail in this example you
> provide? Because, i can recreate the exact same functionality on a
> windows box without need of the underlying window manager's help.

Actually, everything you do requires the underlying window manager,
otherwise you're just painting your own pixels on the screen. And I
never said that this model was possible in some and not others.
(Although it's a bit harder with Windows; there's no explicit call to
finalize windowing, so most likely the application will hold GUI
memory until termination.)

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 6:54 pm, Chris Angelico  wrote:

> To do what for me? Close windows? Reclaim memory? Terminate
> applications? I don't understand your bogglement.

ClaimA: I made claim that Tkinter's window hierarchy is not only
normal, but justified in modern GUI programming.

ClaimB: You made a claim ( or supported a rebuttal claim) that Mac's
system of window management was superior and did not need such a
"window hierarchy" simply because;

1. You can create a program that twiddles it's thumbs (using very
little memory) until a message is received.
2. Upon receiving a message the program can open a GUI window.
3. When the user closes the GUI window (definition of "close" is not
nailed down yet!) the program will free the GUI memory and start
twiddling it's thumbs again until the next message arrives.
4. rinse and repeat until you are happy.

It's obvious that yours and my claims are contradicting. So with that
said, at what point does Tkinter or Windows fail in this example you
provide? Because, i can recreate the exact same functionality on a
windows box without need of the underlying window manager's help.

1. What is your point?
2. And how does it prove my position incorrect?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 9:47 AM, rantingrick  wrote:
>> > Then that is NOT closing windows that is only ICONIFIYING/HIDING them.
>> > Let's use the correct lingo people!
>>
>> Actually, it IS closing those windows. Why wouldn't it be?
>> [...]
>> The memory used by that window can be reclaimed. Handles to its
>> objects are no longer valid. The window really is closed. The
>> application might not have terminated, but that window has not been
>> minimized - the *window* is closed.
>
> And you need the OS to that for you!?!? Are you joking?
>

To do what for me? Close windows? Reclaim memory? Terminate
applications? I don't understand your bogglement.

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 6:20 pm, Chris Angelico  wrote:
> On Wed, Jul 6, 2011 at 8:42 AM, rantingrick  wrote:
> [...]
> > On Jul 5, 11:00 am, Web Dreamer  wrote:
> >> What he means is that On Mac, if you close "all" windows, the application 
> >> is
> >> still running.
>
> > Then that is NOT closing windows that is only ICONIFIYING/HIDING them.
> > Let's use the correct lingo people!
>
> Actually, it IS closing those windows. Why wouldn't it be?
> [...]
> The memory used by that window can be reclaimed. Handles to its
> objects are no longer valid. The window really is closed. The
> application might not have terminated, but that window has not been
> minimized - the *window* is closed.

And you need the OS to that for you!?!? Are you joking?

> I could conceivably write a program that sits invisibly in the
> background until a network message arrives. Upon receipt of such a
> message, the program initializes the GUI subsystem and opens a window.
> When the user closes the window, the program flushes all GUI code out
> of memory and waits for the next message. While it's waiting, is there
> any "main window" that exists but has just been hidden? No. But is the
> application still running? Of course! Completely separate.

And so could i using Tkinter and it's "supposedly" flawed window
hierarchy. Remind me again why we are discussing this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx MenuItem - icon is missing

2011-07-05 Thread Philip Semanchuk

On Jul 5, 2011, at 3:32 PM, Laszlo Nagy wrote:

> 
>> 1. Post a complete example that demonstrates the problem so that we don't 
>> have to dummy up a wx app ourselves to try your code.
> 

[code sample snipped]

> 
> Under windows, this displays the icon for the popup menu item. Under GTK it 
> doesn't and there is no error message, no exception.


I get different results than you. 

Under Ubuntu 9.04 w with wx 2.8.9.1, when I right click I see a menu item 
called test with little icon of a calculator or something.

Under OS X 10.6 with wx 2.8.12.0 and Win XP with wx 2.8.10.1, when I right 
click I get this --

Traceback (most recent call last):
  File "x.py", line 46, in onPopupMenu
item = wx.MenuItem(None,-1,u"Test")
  File 
"/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-packages/wx-2.8-mac-unicode/wx/_core.py",
 line 11481, in __init__
_core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed at 
/BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in wxMenuItemBase(): 
menuitem should have a menu

Hope this helps more than it confuses.

Cheers
Philip




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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Tim Chase

On 07/05/2011 05:35 PM, rantingrick wrote:

One thing is for sure, i always get a giggle from your self
defeating posts. You're the best enemy a person could have.
Thank you. *bows*


Every time I see a rantingrick post, it's like watching the Black 
Knight scene from the Holy Grail yet again.  You know what's 
going to happen; you know he has a purposeless fight; you know 
he's going to laughably lose; and you know he's going to *think* 
that he is invincible & has won.


ARTHUR:  What are you going to do, bleed on me?
BLACK KNIGHT:  I'm invincible!
ARTHUR:  You're a looney.

Sigh...ready for an intermission...

-tkc


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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 8:42 AM, rantingrick  wrote:
> Chris are you playing devils advocate (for my team). I am confused? :-)

I say whatever I choose to say. Don't pigeon-hole me into "on your
team" or "not on your team" or "devil's advocate" or whatever. And at
two in the morning, "whatever I choose to say" can be quite random. :)

> On Jul 5, 11:00 am, Web Dreamer  wrote:
>
>> What he means is that On Mac, if you close "all" windows, the application is
>> still running.
>
> Then that is NOT closing windows that is only ICONIFIYING/HIDING them.
> Let's use the correct lingo people!

Actually, it IS closing those windows. Why wouldn't it be?

1) User presses Alt-F4, or clicks the X, or opens the system menu and
chooses 'Close Window'.
2) Windowing manager sends a message to the appropriate thread's queue
(on MS Windows, that's WM_CLOSE; not sure how on Linux as I haven't
bothered to dig that deep - interface layers like Tkinter and GTK
don't count).
2a) Toolkit passes message to application code, if applicable.
3) Application destroys this window, leaving the other windows alive.

The memory used by that window can be reclaimed. Handles to its
objects are no longer valid. The window really is closed. The
application might not have terminated, but that window has not been
minimized - the *window* is closed.

> And how do you EXPLICITY quit the application? Because the interface
> for window management(on windows box) is three buttons "minimize",
> "maximize", and "destroy". If closing the window only "hides" the
> window then you are just "managing" a window's "visibility". We are
> talking about destroying GUI processes here.

Presumably you would right-click it and choose "Exit" or something. Up
to the application. If all else fails, kill -9 it.

The interface for window management does not actually have "destroy",
it has "close". The normal handling of a close message is to destroy
the window; and in many applications, once all windows have been
destroyed, the process terminates. These are three quite separate
concepts. The separation of "close" and "destroy" is most easily seen
in "Are you sure" prompts - you send a Close signal to the window, but
the application queries you before going through with the destruction.
And even once the last window has been destroyed, that has nothing to
do with process termination.

I could conceivably write a program that sits invisibly in the
background until a network message arrives. Upon receipt of such a
message, the program initializes the GUI subsystem and opens a window.
When the user closes the window, the program flushes all GUI code out
of memory and waits for the next message. While it's waiting, is there
any "main window" that exists but has just been hidden? No. But is the
application still running? Of course! Completely separate.

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


Re: wx MenuItem - icon is missing

2011-07-05 Thread Laszlo Nagy



1. Post a complete example that demonstrates the problem so that we don't have 
to dummy up a wx app ourselves to try your code.


import sys
import wx
from wx.lib.embeddedimage import PyEmbeddedImage

img = PyEmbeddedImage(

"iVBORw0KGgoNSUhEUgAAABAQCAYf8/9hBmJLR0QAAAD5Q7t/"

"CXBIWXMAAAsTAAALEwEAmpwYB3RJTUUH1QYGDS8dXc5KpwAAADV0RVh0Q29tbWVudAAo"

"YykgMjAwNCBKYWt1YiBTdGVpbmVyCgpDcmVhdGVkIHdpdGggVGhlIEdJTVCQ2YtvAAAB+klE"

"QVQ4y52TwWpTQRSGvzkzwV7S1pI2CFptC3VhUkjabsSlrxBKF0UQdONW3BsK7sQnUPA9pLos"

"WtskzW3AgopKi6jtxYQSY3LnuEi8pYsidjbD8M98c/7/zJil5dJDoMzZRtksLZf0zt3bZzr9"

"7Olz3N/F5tbLUze2Wkek0wHtdgdrhaGhcywu3AQ4BjSbB6cCPrzfw1ohOmzRbB5x/cZcoiWA"

"mZm5UwFTUzmMMagqxhiMMYlmlpZLGjXbPLh/77/8rz56wqULmX4F3W6P8upjfnU6fVUV/QdA"

"RI4t3FpZ4dXaC7yHi5OTfN3fx/uYkfNjtH5GqPcE6RGMCNHhASKG/g0eFwQBla03XJ2dRVUJ"

"w5B8Po+1ljAMyeVyiAiNRgPFsDhfJJVK0e12qdUrSLvdxsceVU1CAojjGDB0Oh289wB4Vay1"

"6GBOLFyZmuH1+joYw0Q2y85OA+9jxjLjvNvdBVXGMhMoUKvVEkgC+PzpI8VioW+h0SCXu4Zz"

"jnq9znyxiIhQrdZwzlEoFJIqNysbyCB2nHN47/G9HtZanHOISNJ3EQP0S0+lUie7MHl5msrm"

"W8Awns2yXa/jrCU9PMx2GGJUGQoCfg/aPDo6ShRFJ1/i/MICANZa4ulpDGBE0EGARoS9vS98"

"//GNw+hgEHIfUK5WN878nf8AhFzLEABZzNIASUVORK5CYII=")



class MyFrame(wx.Frame):

def __init__(self, parent, id=-1, title='Popup image test',
 pos=wx.DefaultPosition, size=(200, 200),
 style=wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)

lst = wx.ListCtrl(self,-1,style=wx.LC_REPORT)
lst.InsertColumn(0, "Column 01")
for i in range(100):
lst.InsertStringItem(sys.maxint, "Right click me %s"%i)


lst.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onPopupMenu, lst)

self.Bind(wx.EVT_CLOSE, self.OnClose)


def OnClose(self, event):
self.Destroy()

def onPopupMenu(self,evt):
global img
menu = wx.Menu()
item = wx.MenuItem(None,-1,u"Test")
item.SetBitmap(img.GetBitmap())
menu.AppendItem(item)
#menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item)
self.PopupMenu( menu, evt.GetPoint())
menu.Destroy()


app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()

Under windows, this displays the icon for the popup menu item. Under GTK 
it doesn't and there is no error message, no exception.


Thanks

L

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 6:14 am, Gregory Ewing  wrote:
> rantingrick wrote:
> > Most applications consist of one main window
> > (a Tkinter.Tk instance).
>
> You've obviously never used a Macintosh. On the Mac, it's
> perfectly normal for an application to open multiple
> documents, each in its own window, with no one window
> being the "main" window. Any of them can be closed (or
> even *all* of them) and the application continues to run
> until you explicitly quit it.

And how do you EXPLICITY quit the application? Because the interface
for window management(on windows box) is three buttons "minimize",
"maximize", and "destroy". If closing the window only "hides" the
window then you are just "managing" a window's "visibility". We are
talking about destroying GUI processes here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 8:35 AM, rantingrick  wrote:
> You're the
> best enemy a person could have. Thank you. *bows*

Compliments are made to be returned, and this one is particularly well
suited. *bow*

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 3:36 AM, Steven D'Aprano
 wrote:
>
> Because unless you are extremely disciplined, code and the comments
> describing them get out of sync. Quote:
>
> "At Resolver we've found it useful to short-circuit any doubt and just
> refer to comments in code as 'lies'. "
> --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22

And yet, as I have found out by trying to embed V8 (Google's
Javascript engine), those little comments can (a) prove the difference
between a bug and a misfeature, and (b) be all the documentation there
is. Okay, it's not QUITE the latter, but most things are not
documented outside of the source, and I greatly appreciate those
little comments!

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 11:00 am, Web Dreamer  wrote:

> What he means is that On Mac, if you close "all" windows, the application is
> still running.

Then that is NOT closing windows that is only ICONIFIYING/HIDING them.
Let's use the correct lingo people!

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Waldek M.  wrote:
> Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisa?(a):
>> Because those specially-formatted comments are wrong.
>
> ... because?

In my experience, they're wrong because somebody changes the code and
not the comments.

> Not in sarcasm mode; just curious why you don't like them.

There've been too many times when I couldn't trust them.

-- 
Grant Edwards   grant.b.edwardsYow! I'm totally DESPONDENT
  at   over the LIBYAN situation
  gmail.comand the price of CHICKEN
   ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-05 Thread rantingrick
On Jul 5, 10:17 am, Chris Angelico  wrote:

> It's actually quite easy to implement this, even if you _are_ forced
> to have one primary window. You just have an invisible primary whose
> sole purpose is to "be the application", and then everything else is
> secondary windows. Kinda defeats the purpose of forcing applications
> to have one primary window, though.
>
> To my thinking, there will always be one primary *thread*, and GUI
> facilities are secondary to the process, never the other way around.
> When the main thread exits, the process ends.


Chris are you playing devils advocate (for my team). I am confused? :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread rantingrick
On Jul 5, 11:04 am, Corey Richardson  wrote:

> How is giving the sort method a function by which to determine the relative
> value of objects a control structure? Do you know what a control structure is?
> It's something that you use to modify control flow:
>
> if foo <= bar:
>         foo += 1
> else:
>         bar += 1

Interesting, corey. Very interesting. However the fun is yet to come
so stay tuned...

> That's a control structurem the "if-else". I don't know what Ruby calls a
> control structure, but that's what it is. for and while are in there too.
> When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens?

So are you suggesting that a control structure must have at minimum
one of "for", "while", or "if"? Okay, i listening. Go on...

> We'll call that argument srt, here's a sample (naive) implementation:
>
> def sort(key):
>         lst = self.internal_list
>         for n in range(len(self.internal_list) - 1):
>                 for i in range(len(self.internal_list) - 1):
>                         if srt(lst[i], lst[i+1]) < 0:
>                                 lst[i], lst[i+1] = lst[i+1], lst[i]
>
> See what's in there? An if.

Yes there IS and "if" in there and IF you look closely enough you may
see two "for"'s also. So by your own definition this (naive) code
qualifies as a control structure. Interesting Corey, very
interesting.

But wait just a second Corey. My statement has nothing to do with
sort. sort is just the vehicle. My statement is that the cmp argument
to sort IS a user defined control structure (the code block to be
exact). It doesn't matter that the code is contained in a function
object. That's like saying a cake is not a cake because it was
packaged in a shoe box instead of a cake box.

> Sure, WHAT the if does is user-controlled with the
> key,

Well as long as you can admit that fact.

> but that doesn't make that particular if a new control structure,

Oh i see. Change the rules as we go eh?

> and
> it certainly doesn't make the key a control structure. You can pass a key
> to a sort even in C and that certainly doesn't have user defined control
> structures.

What the hell does C have to do with Python Corey? One thing is for
sure, i always get a giggle from your self defeating posts. You're the
best enemy a person could have. Thank you. *bows*

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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 4:14 AM, sal migondis  wrote:
> On Jul 4, 10:31 pm, alex23  wrote:
>> rantingrick  wrote:
>> > What do you think will be the eventual outcome of the human existence
>> > Alex? Since you have no imagination i will tell you, a singular
>> > intelligence.
>
> All from the land of creationism.

I don't see the connection between creationism and a Borg-like
"singularity of intelligence" where we all lose individuality. But
this is now decidedly off-topic for a Python mailing list.

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


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread S.Mandl
> haven't used XSLT, and don't know if there's one in emacs...
>
> it'd be nice if someone actually give a example...
>

Hi Xah, actually I have to correct myself. HTML is not XML. If it
were, you
could use a stylesheet like this:


http://www.w3.org/1999/XSL/Transform";>


  

  



  

  



  

  





which applied to this document:



Just having funwith all the

  
  
  my 2 cats

cats here:
Just fooling around

  
  jamie's cat! Her blog is http://example.com/
jamie/">http://example.com/jamie/



would yield:



Just having funwith all the

  
  
  my 2 cats

cats here:
Just fooling around

  
  jamie's cat! Her blog is http://example.com/jamie/



But well, as you don't have XML as input ... there really was no point
to my remark.

Best,
Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write file

2011-07-05 Thread Benjamin Kaplan
On Jul 5, 2011 2:28 PM, "miguel olivares varela" 
wrote:
>
>
> Hi,
>
> i got a csv file that i need to modify and create a new one,  i have no
problem to read mi 'test.cvs' which is the source file but when i try to
create a new one with the modifications i only got the first row in my
'out.csv' file.  I think there is somethng wrong in my loop because i can't
put into the rest.
>
>

>
> [here my code:]
>
> import sys
> import csv
> import os
> import glob
> import time
>
> dir_cdr = "/tmp"
> #loop to find files csv in a directory and read thoses files
> for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ):
> file_source = open(cdr_files_in, 'r')
> reader = csv.reader(file_source, delimiter=';',
quoting=csv.QUOTE_NONE)
> try:
> for data in reader:
> if data:
> firstname = data[0]
> lastname = data[1]
> date_source = data[2]
> phone = data[3]
> #Date to epoch
>
timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S")))
> fout = open("out.csv", "w")
> print >>fout, lastname, firstname,
timestamp, phone

Do you understand what these next two lines are doing? They are closing the
file and then exiting the program. I'm pretty sure that's not what you want
to do here.

> fout.close()
> sys.exit()
> file_source.close()
> except csv.Error, e:
> print e
> file_source.close()
> sys.exit('file %s, line %d: %s' % (file_source,
reader.line_num, e)
>
> [out.csv]
> Smith John 1296208720 336
>
>
> Could you help me?
>
> Best Regards,
> Miguel
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Ian Kelly
On Tue, Jul 5, 2011 at 2:37 PM, Xah Lee  wrote:
> but in anycase, i can't see how this part would work
> ((?:[^<]|<(?!/p>))+)

It's not that different from the pattern 「alt="[^"]+"」 earlier in the
regex.  The capture group accepts one or more characters that either
aren't '<', or that are '<' but are not immediately followed by '/p>'.
 Thus it stops capturing when it sees exactly '' without consuming
the '<'.  Using my regex with the example that you posted earlier
demonstrates that it works:

>>> import re
>>> s = '''
... 
... jamie's cat! Her blog is http://example.com/
... jamie/">http://example.com/jamie/
... '''
>>> print re.sub(pattern, replace, s)


jamie's cat! Her blog is http://example.com/
jamie/">http://example.com/jamie/


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


RE: write file

2011-07-05 Thread miguel olivares varela



What's date_cdr supposed to be?

It was a mistake  it should be date_source


Is your exception handler doing unusual things with sys.exit?

Not really

Did you try to run this?  When I try to run it, it fails to compile.

it compiles i have no problems with the compilation. The issue is the result 
'out.csv',  what i want is to save all the modified rows from 'test.csv' into 
'out.csv' but i only can save the firs row.   



You might want to try opening your output file once and writing to it 
repeatedly, then close()ing it after all your writes are completed.  Or use 
"with": http://effbot.org/zone/python-with-statement.htm


On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela  
wrote:







Hi,

i got a csv file that i need to modify and create a new one,  i have no problem 
to read mi 'test.cvs' which is the source file but when i try to create a new 
one with the modifications i only got the first row in my 'out.csv' file.  I 
think there is somethng wrong in my loop because i can't  put into the rest.   



this is my an example of source file:
[test.csv]
Name;Lastname;Age;ContractDate;PhoneNumber
John;Smith;20110128 105840;336
Mike;Brown;20110128 105842;336
James;Ryan;20110128 105850;336

Barry;Jackson;20110128 105847;336


[here my code:]

import sys
import csv
import os
import glob
import time

dir_cdr = "/tmp"
#loop to find files csv in a directory and read thoses files

for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ):
file_source = open(cdr_files_in, 'r')
reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE)

try:
for data in reader:
if data:
firstname = data[0]
lastname = data[1]
date_source = data[2]

phone = data[3]
#Date to epoch

timestamp=int(time.mktime(time.strptime(date_source, "%Y%m%d %H%M%S")))
fout = open("out.csv", "w")

print >>fout, lastname, firstname, timestamp, 
phone
fout.close()
sys.exit()
file_source.close()

except csv.Error, e:
print e
file_source.close()
sys.exit('file %s, line %d: %s' % (file_source, 
reader.line_num, e)

[out.csv]
Smith John 1296208720 336



Could you help me?

Best Regards,
Miguel

  

--

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



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


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread John Gordon
In  John Gordon  writes:

> which praised the bendfists of implicit initialization.

Wow, that's quite a typo!  I meant "benefits", of course.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


How do twisted and multiprocessing.Process create zombies?

2011-07-05 Thread bitcycle
In python, using twisted loopingcall, multiprocessing.Process, and 
multiprocessing.Queue; is it possible to create a zombie process. And, if so, 
then how?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write file

2011-07-05 Thread Dan Stromberg
What's date_cdr supposed to be?

Is your exception handler doing unusual things with sys.exit?

Did you try to run this?  When I try to run it, it fails to compile.

You might want to try opening your output file once and writing to it
repeatedly, then close()ing it after all your writes are completed.  Or use
"with": http://effbot.org/zone/python-with-statement.htm

On Tue, Jul 5, 2011 at 2:25 PM, miguel olivares varela <
klica_...@hotmail.com> wrote:

>
> Hi,
>
> i got a csv file that i need to modify and create a new one,  i have no
> problem to read mi 'test.cvs' which is the source file but when i try to
> create a new one with the modifications i only got the first row in my
> 'out.csv' file.  I think there is somethng wrong in my loop because i can't
> put into the rest.
>
>
> this is my an example of source file:
> [test.csv]
> Name;Lastname;Age;ContractDate;PhoneNumber
> John;Smith;20110128 105840;336
> Mike;Brown;20110128 105842;336
> James;Ryan;20110128 105850;336
> Barry;Jackson;20110128 105847;336
>
>
> [here my code:]
>
> import sys
> import csv
> import os
> import glob
> import time
>
> dir_cdr = "/tmp"
> #loop to find files csv in a directory and read thoses files
> for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ):
> file_source = open(cdr_files_in, 'r')
> reader = csv.reader(file_source, delimiter=';',
> quoting=csv.QUOTE_NONE)
> try:
> for data in reader:
> if data:
> firstname = data[0]
> lastname = data[1]
> date_source = data[2]
> phone = data[3]
> #Date to epoch
>
> timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S")))
> fout = open("out.csv", "w")
> print >>fout, lastname, firstname,
> timestamp, phone
> fout.close()
> sys.exit()
> file_source.close()
> except csv.Error, e:
> print e
> file_source.close()
> sys.exit('file %s, line %d: %s' % (file_source,
> reader.line_num, e)
>
> [out.csv]
> Smith John 1296208720 336
>
>
> Could you help me?
>
> Best Regards,
> Miguel
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


write file

2011-07-05 Thread miguel olivares varela


Hi,

i got a csv file that i need to modify and create a new one,  i have no problem 
to read mi 'test.cvs' which is the source file but when i try to create a new 
one with the modifications i only got the first row in my 'out.csv' file.  I 
think there is somethng wrong in my loop because i can't  put into the rest.   


this is my an example of source file:
[test.csv]
Name;Lastname;Age;ContractDate;PhoneNumber
John;Smith;20110128 105840;336
Mike;Brown;20110128 105842;336
James;Ryan;20110128 105850;336
Barry;Jackson;20110128 105847;336


[here my code:]

import sys
import csv
import os
import glob
import time

dir_cdr = "/tmp"
#loop to find files csv in a directory and read thoses files
for cdr_files_in in glob.glob(os.path.join(dir_cdr, '*.csv') ):
file_source = open(cdr_files_in, 'r')
reader = csv.reader(file_source, delimiter=';', quoting=csv.QUOTE_NONE)
try:
for data in reader:
if data:
firstname = data[0]
lastname = data[1]
date_source = data[2]
phone = data[3]
#Date to epoch

timestamp=int(time.mktime(time.strptime(date_cdr, "%Y%m%d %H%M%S")))
fout = open("out.csv", "w")
print >>fout, lastname, firstname, timestamp, 
phone
fout.close()
sys.exit()
file_source.close()
except csv.Error, e:
print e
file_source.close()
sys.exit('file %s, line %d: %s' % (file_source, 
reader.line_num, e)

[out.csv]
Smith John 1296208720 336


Could you help me?

Best Regards,
Miguel

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


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread John Gordon
In  Stefaan Himpe  
writes:

> > Now, I have an ulterior motive in raising this issue... I can't find the
> > original article I read! My google-fu has failed me (again...). I don't
> > suppose anyone can recognise it and can point me at it?

> My sarcasm detector warns me not to add a link, although perhaps it's 
> time for recalibration (after all, summer season started) :-)

He's not asking for a link to the "Implicit initialization is EVIL"
thread; he's asking for a link to the original article he read elsewhere
which praised the bendfists of implicit initialization.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: embedding: how do I redirect print output?

2011-07-05 Thread Andrew Berg
On 2011.07.05 10:20 AM, Chris Angelico wrote:
> You, sir, have a warped and twisted mind.
>
> And I love it!!
>
> Now to secretly put code into some module somewhere and wait for
> people to start tearing their hair out wait, did I say that out
> loud?
from pytroll import print
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Andrew Berg
On 2011.07.05 01:14 PM, sal migondis wrote:
> How could a belief be wrong?
Beliefs aren't subjective.  One's taste in music, for example, is
largely subjective and can't be right or wrong, but a belief (which has
to do with facts) certainly can be.
> > > What do you think will be the eventual outcome of the human existence
> > > Alex? Since you have no imagination i will tell you, a singular
> > > intelligence.
>
> All from the land of creationism.
That's from rantingrick, not alex23.
> > No need to answer that last one, we already know the answer: from the
> > very beginning.
>
> In the beginning was a singularity... and Albert Einstein was a chain-
> smoker.
Either you're taking that statement out of context, or you're making an
esoteric joke. If it's not the latter, I suggest you read the sentence
before it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Xah Lee
On Jul 5, 12:17 pm, Ian Kelly  wrote:
> On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee  wrote:
> > So, a solution by regex is out.
>
> Actually, none of the complications you listed appear to exclude
> regexes.  Here's a possible (untested) solution:
>
> 
> ((?:\s* height="[0-9]+">)+)
> \s*((?:[^<]|<(?!/p>))+)
> \s*
>
> and corresponding replacement string:
>
> 
> \1
> \2
> 
>
> I don't know what dialect Emacs uses for regexes; the above is the
> Python re dialect.  I assume it is translatable.  If not, then the
> above should at least work with other editors, such as Komodo's
> "Find/Replace in Files" command.  I kept the line breaks here for
> readability, but for completeness they should be stripped out of the
> final regex.
>
> The possibility of nested HTML in the caption is allowed for by using
> a negative look-ahead assertion to accept any tag except a closing
> .  It would break if you had nested  tags, but then that would
> be invalid html anyway.
>
> Cheers,
> Ian

emacs regex supports shygroup (the 「(?:…)」) but it doesn't support the
negative assertion 「?!…」 though.

but in anycase, i can't see how this part would work
((?:[^<]|<(?!/p>))+)

?

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


ANN: python-ldap 2.4.1

2011-07-05 Thread Michael Ströder
Find a new release of python-ldap:

  http://pypi.python.org/pypi/python-ldap/2.4.1

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema).

Project's web site:

  http://www.python-ldap.org/

Ciao, Michael.


Released 2.4.1 2011-07-05

Changes since 2.4.0:

Modules:
* New LDAP option OPT_X_TLS_PACKAGE available in OpenLDAP 2.4.26+
  to determine the name of the SSL/TLS package OpenLDAP was
  built with

Lib/
* ldap.modlist.modifyModlist(): New key-word argument
  case_ignore_attr_types used to define attribute types for which
  comparison of old and new values should be case-insensitive
* Minor changes to which data is sent to debug output for various
  trace levels
* Now tag [1] is used in ldap.extop.dds.RefreshResponse in
  compliance with RFC 2589 (fix available for OpenLDAP ITS#6886)
* New sub-module ldap.controls.sessiontrack implements request control
  as described in draft-wahl-ldap-session (needs pyasn1_modules)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Xah Lee
On Jul 5, 12:17 pm, Ian Kelly  wrote:
> On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee  wrote:
> > So, a solution by regex is out.
>
> Actually, none of the complications you listed appear to exclude
> regexes.  Here's a possible (untested) solution:
>
> 
> ((?:\s* height="[0-9]+">)+)
> \s*((?:[^<]|<(?!/p>))+)
> \s*
>
> and corresponding replacement string:
>
> 
> \1
> \2
> 
>
> I don't know what dialect Emacs uses for regexes; the above is the
> Python re dialect.  I assume it is translatable.  If not, then the
> above should at least work with other editors, such as Komodo's
> "Find/Replace in Files" command.  I kept the line breaks here for
> readability, but for completeness they should be stripped out of the
> final regex.
>
> The possibility of nested HTML in the caption is allowed for by using
> a negative look-ahead assertion to accept any tag except a closing
> .  It would break if you had nested  tags, but then that would
> be invalid html anyway.
>
> Cheers,
> Ian

that's fantastic. Thanks! I'll try it out.

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


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Xah Lee
On Jul 4, 12:13 pm, "S.Mandl"  wrote:
> Nice. I guess that XSLT would be another (the official) approach for
> such a task.
> Is there an XSLT-engine for Emacs?
>
> -- Stefan

haven't used XSLT, and don't know if there's one in emacs...

it'd be nice if someone actually give a example...

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


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Stefaan Himpe

Hello,

I agree with the contents of this post.

I see a similar problem with API's requiring to initialize all kinds of 
data using setters/properties instead of receiving it in the initializer 
(or constructor).



Python generally follows this design. Apart from files, I can't easily think
off the top of my head of any types that require a separate
open/start/activate call before they are usable.


database connections, network connections, spawning expensive 
processes/threads, things that benefit from lazy evaluation...



Now, I have an ulterior motive in raising this issue... I can't find the
original article I read! My google-fu has failed me (again...). I don't
suppose anyone can recognise it and can point me at it?


My sarcasm detector warns me not to add a link, although perhaps it's 
time for recalibration (after all, summer season started) :-)


Best regards,
Stefaan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Mel
Steven D'Aprano wrote:
[ ... ]
> Python generally follows this design. Apart from files, I can't easily
> think off the top of my head of any types that require a separate
> open/start/activate call before they are usable. It's also relevant to
> tkinter, which will implicitly create a root window for you when needed.
> Since you can't do anything without a root window, I don't see the benefit
> in forcing the user to do so. When they need to learn about root windows,
> they will in their own good time.

In wx, many of the window classes have Create methods, for filling in 
various attributes in "two-step construction".  I'm not sure why, because it 
works so well to just supply all the details when the class is called and an 
instance is constructed.  Maybe there's some C++ strategy that's being 
supported there.

Mel.

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


Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Ian Kelly
On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee  wrote:
> So, a solution by regex is out.

Actually, none of the complications you listed appear to exclude
regexes.  Here's a possible (untested) solution:


((?:\s*)+)
\s*((?:[^<]|<(?!/p>))+)
\s*

and corresponding replacement string:


\1
\2


I don't know what dialect Emacs uses for regexes; the above is the
Python re dialect.  I assume it is translatable.  If not, then the
above should at least work with other editors, such as Komodo's
"Find/Replace in Files" command.  I kept the line breaks here for
readability, but for completeness they should be stripped out of the
final regex.

The possibility of nested HTML in the caption is allowed for by using
a negative look-ahead assertion to accept any tag except a closing
.  It would break if you had nested  tags, but then that would
be invalid html anyway.

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


Re: Implicit initialization is EXCELLENT

2011-07-05 Thread Michel Claveau - MVP
Hi!

+1

@-salutations
-- 
Michel Claveau 

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


Question about how to get line buffering from paramiko

2011-07-05 Thread Steven W. Orr
I'm writing a program that uses paramiko to run a lot of commands over ssh. 
Some of the commands take time to run and they write to stdout and stderr as a 
normal part of their operation so that we can see progress happening.


I can't seem to get the output from the remote commands (which is input to me) 
to be line buffered. If I run the commands using ssh, they line buffer nicely. 
If I run them through paramiko, they end up fully buffered.


I stole this code I found as a base. The code that I got looked like the 
execute_capture method (below). I added the execute method so that I could 
poll for the result from both stderr and stdout. Note that I am calling 
channel.get_pty, but that doesn't change the fact that the results are not 
line buffered.


Can anyone suggest a way to solve this?

The code I'm using follows:

#! /usr/bin/python

"""
Friendly Python SSH2 interface using paramiko
"""

import os
import sys
import tempfile
import paramiko
import select
from collections import namedtuple

ExecStatus = namedtuple('ExecStatus', 'status stdout stderr')

class Connection(object):
"""
Connects and logs into the specified hostname.
Arguments that are not given are guessed from the environment.
"""
def __init__(self,
 host,
 username = None,
 private_key = None,
 password = None,
 port = 22,
 blocking_cmds = True,
 verbose = False,
 ):
self._sftp_live = False
self._sftp = None
if not username:
username = os.environ['LOGNAME']

# Log to a temporary file if requested.
if verbose:
self.templog = tempfile.mkstemp('.txt', 'ssh-')[1]
paramiko.util.log_to_file(self.templog)
else:
self.templog = False

# Begin the SSH transport.
self._transport = paramiko.Transport((host, port))
self._tranport_live = True
# Authenticate the transport.
if password:
# Using Password.
self._transport.connect(username = username, password = password)
else:
# Use Private Key.
if not private_key:
# Try to use default key.
if os.path.exists(os.path.expanduser('~/.ssh/id_rsa')):
private_key = '~/.ssh/id_rsa'
elif os.path.exists(os.path.expanduser('~/.ssh/id_dsa')):
private_key = '~/.ssh/id_dsa'
else:
raise TypeError, "You have not specified a password or key."

private_key_file = os.path.expanduser(private_key)
rsa_key = paramiko.RSAKey.from_private_key_file(private_key_file)
self._transport.connect(username = username, pkey = rsa_key)

def _sftp_connect(self):
"""Establish the SFTP connection."""
if not self._sftp_live:
self._sftp = paramiko.SFTPClient.from_transport(self._transport)
self._sftp_live = True

def get(self, remotepath, localpath = None):
"""Copies a file between the remote host and the local host."""
if not localpath:
localpath = os.path.split(remotepath)[1]
self._sftp_connect()
self._sftp.get(remotepath, localpath)

def put(self, localpath, remotepath = None):
"""Copies a file between the local host and the remote host."""
if not remotepath:
remotepath = os.path.split(localpath)[1]
self._sftp_connect()
self._sftp.put(localpath, remotepath)

def execute(self, command):
"""
Execute the given commands on a remote machine.
Return value is exit status of the remote command.
"""
# This execute method is similar to execute_capture below. The
# difference is that this method gets the stdout and stderr of
# the runnning command and forwards it on to the correct
# channel within this process.
# To do this, we use the poll(2) system call which comes from
# the select package.

def _write(fd, chan, syschan):
"""
_write internal method to check an fd from the list of fds
for a POLLIN event, read the data that's there, and if there's
anything there, then write it to the correct channel.
Return True if there was something to read.
"""
ret = False
if fd[1] & select.POLLIN:
if fd[0] == chan.channel.fileno():
ss = chan.readline()
ret = len(ss) != 0
if ret:
# No need to strip and then print with a newline.
# because every line is newline terminated.
print >> syschan, ss[:-1]
return ret
# Open a channel of type session. Same as open_channel('session')
ch

Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread sal migondis
On Jul 4, 10:31 pm, alex23  wrote:
> rantingrick  wrote:
> > I believe (unlike most people) that nature is striving for perfection
>
> Your belief is wrong. "Nature" doesn't "strive" for _anything_. Things
> in the world are either fit enough to continue their existence or not.
> As circumstances change, some things that were once suitably fit for
> the environment are no longer so and are replaced. Same with ideas.
> There is no "perfection", there is only "what works best now".

How could a belief be wrong?

> > What do you think will be the eventual outcome of the human existence
> > Alex? Since you have no imagination i will tell you, a singular
> > intelligence.

All from the land of creationism.

> Firstly: cite some kind of evidence that this "will be the eventual
> outcome" or admit you're talking shit.
>
> Secondly: I can imagine humanity evolving into a great many things and
> something as limited as a 'botnet' is certainly nothing to be proud of
> as a species.
>
> > It is selflessness on a grand scale.
>
> I don't really know if you're a troll,

Beats me... I think everybody else does..

> have no self-reflective
> capability, delusionally believe what you're spouting, or are on or
> off medication, but sometimes your hypocrisy is just funny as hell.
>
> >> Because the people who ACTUALLY WROTE THE LANGUAGES wanted to explore
> >> different implementations.
> > Why can they not explore within the hive mind? Why must they hide
> > their explorations from the greater group. SELFISHNESS
>
> You mean like how Guido hid the Python code base and never let anyone
> else touch or influence it in any way?
>
> Rick, you remind me a lot of Bill Hicks yelling, "You are free to do
> as we tell you! YOU ARE FREE TO DO AS WE TELL YOU!!" Using terms like
> "hive mind" kinda shows that I'm wasting my time pushing the value of
> diversity to you.

Now you're taking a troll as an excuse for your own trolling.



> No need to answer that last one, we already know the answer: from the
> very beginning.

In the beginning was a singularity... and Albert Einstein was a chain-
smoker.

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Steven D'Aprano
Waldek M. wrote:

> Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisał(a):
>> Because those specially-formatted comments are wrong.
> 
> ... because?
> Not in sarcasm mode; just curious why you don't like them.

Because unless you are extremely disciplined, code and the comments
describing them get out of sync. Quote:

"At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. "
--Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22




-- 
Steven

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Waldek M.
Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisał(a):
> Because those specially-formatted comments are wrong.

... because?
Not in sarcasm mode; just curious why you don't like them.

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


VIDEOS FOR HOT GUYS

2011-07-05 Thread SAHITHI


FOR GOOD JOBS SITES TO YOU
 http://goodjobssites.blogspot.com/

FOR HOT PHOTO&VIDEOS
 KATRINA KAIF IN BEAUTIFUL RED DRESS
http://southactresstou.blogspot.com/2011/05/katrina-kaif_22.html
GOOD LOOKING DEEPIKA PADUKONE
http://southactresstou.blogspot.com/2011/05/deepika-padukone_22.html
  AISHWARYA RAI UNBELIVABLE PHOTO
http://southactresstou.blogspot.com/2011/05/aishwarya-rai.html
TAPSEE RARE PHOTOS
http://southactresstou.blogspot.com/2011/06/tapsee-rare-photos.html


FOR FAST UPDATES IN TELUGU FILM INDUSTRY
http://allyouwants.blogspot.com



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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Robin Becker

On 05/07/2011 16:33, nn wrote:
..

Ah, I see we have a mainframe programmer among us ... :-)

so long since I manipulated the switches of that old pdp-8
-anciently yrs-
Robin Becker

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


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread Corey Richardson
Excerpts from rantingrick's message of Tue Jul 05 07:42:39 -0400 2011:
>
> I was thinking more about this comment and it occurred to me that
> Python does have user controlled data structures. Just because there
> is no "top level syntax" like ruby does not mean these do not exists.
> You only have to look below the surface. Take the sort methods of
> lists for example...
> 
> >>> lst = [
> (100, 0),
> (25, 2),
> (10,1),
> ]
> >>> lst
> [(100, 0), (25, 2), (10, 1)]
> >>> lst.sort()
> >>> lst
> [(10, 1), (25, 2), (100, 0)]
> >>> lst.sort(lambda x,y: cmp(x[1], y[1]))
> >>> lst
> [(100, 0), (10, 1), (25, 2)]
> 
> ...that looks like a "user defined control" structure to me. So how
> can an anti-feature become part of the language proper? (devils
> advocate here) :)
> 

How is giving the sort method a function by which to determine the relative
value of objects a control structure? Do you know what a control structure is?
It's something that you use to modify control flow:

if foo <= bar:
foo += 1
else:
bar += 1

That's a control structurem the "if-else". I don't know what Ruby calls a 
control structure, but that's what it is. for and while are in there too.
When you run lst.sort(lambda x, y: cmp(x[1], y[1])), what happens?

We'll call that argument srt, here's a sample (naive) implementation:

def sort(key):
lst = self.internal_list
for n in range(len(self.internal_list) - 1):
for i in range(len(self.internal_list) - 1):
if srt(lst[i], lst[i+1]) < 0:
lst[i], lst[i+1] = lst[i+1], lst[i]

Untested, probably doesn't work either. See what's in there? An if. Nothing
"user-defined" at all. Sure, WHAT the if does is user-controlled with the
key, but that doesn't make that particular if a new control structure, and
it certainly doesn't make the key a control structure. You can pass a key
to a sort even in C and that certainly doesn't have user defined control
structures.
-- 
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
 -- Abraham Lincoln


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Tim Johnson  wrote:
> * Ian Kelly  [110704 20:37]:
>> 
>> It sounds like what you really want is to detect the names *exported*
>> by the module, then.  i
>   Yes! 
>> Why not do it the same way Python does it?  If
>> the module defines an "__all__" attribute, then it is taken to be a
>> sequence of strings which are the exported names.  Otherwise, the
>> exported names are taken to be all the names in the module dict that
>> don't begin with an underscore.
>
>  :) Oh here we go again. Another python feature I didn't know about
>   or have forgotten.

You could probably implement at least two more languages using nothing
but Python features I don't know about or have forgotten.  :)

Yet I still manage to get a lot accomplished using Python.

-- 
Grant Edwards   grant.b.edwardsYow! I don't know WHY I
  at   said that ... I think it
  gmail.comcame from the FILLINGS in
   my rear molars ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-05 Thread nn
On Jul 4, 11:35 am, Robin Becker  wrote:
> On 03/07/2011 23:21, Chris Angelico wrote:
> .
>
> > var(0x14205359) x   # Don't forget to provide an address where the
> > object will be located
> > x=42
>
> 
> did you forget to specify the memory bank and computer (and presumably planet
> etc etc)
> -molly-coddled-ly yrs-
> Robin Becker

Ah, I see we have a mainframe programmer among us ... :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Implicit initialization is EXCELLENT

2011-07-05 Thread Steven D'Aprano
This is not strictly Python, although it is peripherally relevant.

Some month or three ago, I read an article or blog post about API design,
specifically the wrong-headedness of insisting that callers manually
initialise instances using a separate step after creation.

The argument goes, if your API looks something like this:

instance = Spaminator(extra_truffles=False)
instance.activate()
instance.nom_nom_nom()
=> prints "yummy spam, the food of the Gods!!!"

chances are that you are doing it wrong and your users will hate you. Why
force the user to manually "flip the switch" (so to speak)? It's not like
they can possibly avoid it:

another_instance = Spaminator(with_extra_cheese=True)
another_instance.nom_nom_nom()
=> raises InactiveInstanceError("you must activate the instance first")

What? No! Just activate yourself!

Exceptions to this rule are if the Spaminator has side-effects (e.g. files,
in which case the user may want finer control in when they are opened and
closed), or if there are meaningful operations you can perform on an
inactive Spaminator.

Python generally follows this design. Apart from files, I can't easily think
off the top of my head of any types that require a separate
open/start/activate call before they are usable. It's also relevant to
tkinter, which will implicitly create a root window for you when needed.
Since you can't do anything without a root window, I don't see the benefit
in forcing the user to do so. When they need to learn about root windows,
they will in their own good time.

Now, I have an ulterior motive in raising this issue... I can't find the
original article I read! My google-fu has failed me (again...). I don't
suppose anyone can recognise it and can point me at it?
 


-- 
Steven

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Tim Johnson
* Ian Kelly  [110704 20:37]:
> 
> It sounds like what you really want is to detect the names *exported*
> by the module, then.  i
  Yes! 
> Why not do it the same way Python does it?  If
> the module defines an "__all__" attribute, then it is taken to be a
> sequence of strings which are the exported names.  Otherwise, the
> exported names are taken to be all the names in the module dict that
> don't begin with an underscore.

  :) Oh here we go again. Another python feature I didn't know about
  or have forgotten.

  Thanks very much for that.
  Good tip
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding: how do I redirect print output?

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 12:36 AM, Steven D'Aprano
 wrote:
 print "Hello world"
> dlrow olleH
>

You, sir, have a warped and twisted mind.

And I love it!!

Now to secretly put code into some module somewhere and wait for
people to start tearing their hair out wait, did I say that out
loud?

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 12:25 AM, Steven D'Aprano
 wrote:
> Gregory Ewing wrote:
>
>> You've obviously never used a Macintosh. On the Mac, it's
>> perfectly normal for an application to open multiple
>> documents, each in its own window, with no one window
>> being the "main" window. Any of them can be closed (or
>> even *all* of them) and the application continues to run
>> until you explicitly quit it.
>
> Or a Linux GUI. I have kwrite running with 15 open windows. The application
> doesn't exit until the last window is closed, and no window is privileged
> over the others.

It's actually quite easy to implement this, even if you _are_ forced
to have one primary window. You just have an invisible primary whose
sole purpose is to "be the application", and then everything else is
secondary windows. Kinda defeats the purpose of forcing applications
to have one primary window, though.

To my thinking, there will always be one primary *thread*, and GUI
facilities are secondary to the process, never the other way around.
When the main thread exits, the process ends.

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


Re: module problem on windows 64bit

2011-07-05 Thread Thomas Jollans
On 06/27/2011 06:59 PM, miamia wrote:
> Hello,
> 
> on 32-bit windows everything works ok but on 64-bit win I am getting
> this error:
> Traceback (most recent call last):
>   File "app.py", line 1040, in do_this_now
>   File "kinterbasdb\__init__.pyc", line 119, in 
>   File "kinterbasdb\_kinterbasdb.pyc", line 12, in 
>   File "kinterbasdb\_kinterbasdb.pyc", line 10, in __load
> ImportError: DLL load failed: This application has failed to start
> because the application configuration is incorrect. Reinstalling the
> application may fix this problem.
> 
> How to get it work on 64bit windows as well? many thanks

A process can only link to a shared library compiled for the same
architecture as the process. In layman's terms: A 32-bit DLL won't work
with a 64-bit program. It looks like this package is attempting to load
a 32-bit DLL. That's not going to work. Either procure a 64-bit version
of the DLL, or use a 32-bit version of Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can I package a distutil based python app in deb?

2011-07-05 Thread Thomas Jollans
On 06/26/2011 07:59 PM, hackingKK wrote:
> Hello all,
> I guess the subject line says it all.
> I want to package a python app to deb.
> I have 3 interesting issues with it.
> 1, I would want it to run on Ubuntu 10.04, Ubuntu 10.10, Ubuntu 11.04
> and Debian 5.
> 2, the package depends on another python package which is also distutil
> based.
> 3, The second package needs to run in a virtual environment.
> This means that I not only have to figure out the dependencies but also
> have the deb to include a script to get the virtual environment script,
> then create one for the package, then download all dependencies (Pylons
> 0.9.7 in this case along with report lab) and finally put the package
> into this virtual environment.
> Is this all possible?

Yes, it is possible. Refer to ,
particularly the New Maintainer's Guide:



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


Re: embedding: how do I redirect print output?

2011-07-05 Thread Steven D'Aprano
Ulrich Eckhardt wrote:

> Hi!
> 
> I'm trying to add some scripting capabilities to an application. Since it
> is a GUI application, I need some way to display output from Python. For
> 3.x, where "print" is a function, I'd just exchange this function with one
> that redirects the output to a log window, right.
> 
> However, I'm using 2.6 here, where that can't work. So, what I was
> thinking was to redirect "sys.stdout" and "sys.stderr" to a log window and
> possibly replace "sys.stdin" with something that causes meaningful errors
> if some code tries to use it, but that last point is just icing on the
> cake.
> 
> What seems cumbersome is that I'll need to write something that supports
> the file interface using C, which is still a bit awkward. I'm wondering,
> isn't there an easier way to achieve this? How would you do it?

Why do you think it needs to be in C? As far as I can tell, so long as it
quacks like a file object (that is, has a write method), it should work.


>>> import StringIO, sys
>>> class Test:
... def __init__(self):
... self.out = sys.stdout
... self.log = StringIO.StringIO()
... def write(self, text):
... self.log.write(text.upper())
... self.out.write(''.join(reversed(text)))
...
>>> fake_out = Test()
>>> sys.stdout = fake_out
>>> print "Hello world"
dlrow olleH
>>> print "Goodbye cruel world!!!"
!!!dlrow leurc eybdooG
>>> sys.stdout = sys.__stdout__
>>> fake_out.log.getvalue()
'HELLO WORLD\nGOODBYE CRUEL WORLD!!!\n'



-- 
Steven

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


Re: from module import * using __import__?

2011-07-05 Thread Thomas Jollans
On 07/02/2011 09:52 PM, Dan Stromberg wrote:
> 
> Is there a decent way of running "from  import *"?  Perhaps
> using __import__?
> 
> Does it mean using the copy module or adding an element to globals()
> somehow?

Yes, exactly. That's what `from x import *` does: Get the module, and
then add all members to the global namespace.

def import_all_from (module_name):
mod = __import__(module_name)
for member_name in dir(mod):
globals()[member_name] = getattr(mod, member_name)

Of course, don't do this, do what Gabriel said.

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Steven D'Aprano
Gregory Ewing wrote:

> rantingrick wrote:
>> Most applications consist of one main window
>> (a Tkinter.Tk instance).
> 
> You've obviously never used a Macintosh. On the Mac, it's
> perfectly normal for an application to open multiple
> documents, each in its own window, with no one window
> being the "main" window. Any of them can be closed (or
> even *all* of them) and the application continues to run
> until you explicitly quit it.

Or a Linux GUI. I have kwrite running with 15 open windows. The application
doesn't exit until the last window is closed, and no window is privileged
over the others.

Even in Windows, the sort of MDI interface Rick seems to be describing is
less common now than it used to be -- possibly even rare.

http://en.wikipedia.org/wiki/Multiple_document_interface


-- 
Steven

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


Re: Compiling Python 3.2 on Cygwin fails

2011-07-05 Thread David Robinow
On Mon, Jul 4, 2011 at 3:49 PM, Aly Tawfik  wrote:
> On Jun 20, 12:44 pm, sewpafly  wrote:
>> I was able to a little further by changing 2 lines in Makefile.pre.in.
>>
>> On line 170, changed:
>>     DLLLIBRARY= @DLLLIBRARY@
>> to:
>>     DLLLIBRARY= libpython$(VERSION).dll
>>
>> On line 509 it had:
>>     $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
>>
>> which I changed to:
>>     $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
>>
>> Compile finishes with:
>> Python build finished, but the necessary bits to build these modules
>> were not found:
>> _gdbm              _sqlite3           _tkinter
>> nis                ossaudiodev        spwd
>> To find the necessary bits, look in setup.py in detect_modules() for
>> the module's name.
>>
>> Failed to build these modules:
>> _curses            _curses_panel
>>
>> But 'make test' returns many errors.
>>
>> I'm thinking I'll try Python 3.1 instead.
>
> I, too, am facing the same problem. Which version of Python 3.1 did
> you install, and did it work? Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 Cygwin is not really a supported platform. Reverting to Python 3.1
won't help at all. Download the 2.6.5 source version (i.e., click the
Src box) using cygwin setup. Apply the included patches [some don't
apply cleanly any more]. That will get you most of the way there.
There are a few other issues the details of which I don't remember.
 I'm not sure why there hasn't been a cygwin distribution lately. You
might ask on the cygwin mailing list. [Ultimately somebody with an
interest in cygwin will need to get active in python development. I've
been meaning to do this but life gets in the way.]
  DR
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Embedding a thin python

2011-07-05 Thread Thomas Jollans
On 07/05/2011 08:28 AM, victor lucio wrote:
> Hi All,
> 
> I would like to remove some modules for embedding a thin python.
> how to do that?
> I would be grateful for your suggestions
> 
> 
> 

Start your favourite file manager and delete them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedding: how do I redirect print output?

2011-07-05 Thread Thomas Jollans
On 07/05/2011 02:50 PM, Ulrich Eckhardt wrote:
> I'm trying to add some scripting capabilities to an application. Since it is 
> a GUI application, I need some way to display output from Python. For 3.x, 
> where "print" is a function, I'd just exchange this function with one that 
> redirects the output to a log window, right.
> 
> However, I'm using 2.6 here, where that can't work. So, what I was thinking 
> was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly 
> replace "sys.stdin" with something that causes meaningful errors if some 
> code tries to use it, but that last point is just icing on the cake.
> 
> What seems cumbersome is that I'll need to write something that supports the 
> file interface using C, which is still a bit awkward. I'm wondering, isn't 
> there an easier way to achieve this? How would you do it?

You can mess with low-level file descriptors. Example:

# create new stdout:
fout = file('out.txt', 'w')

# close stdout (fd 1)
import os
os.close(1)

# use fout as new stdout
os.dup2(fout.fileno(), 1)

# test. This will end up in out.txt
print "Testing."

# do the same for stdin (0) and stderr (2)

# - EOF -

However, I suggest you consider isolating your scripts from you main
program and run them in a separate interpreter. You can provide dummy
modules that communicate with your application via sockets to the
scripts. Setting the standard files in the child process is easy: the
Popen constructor takes stdin/stdout/stderr arguments.

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


Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Chris Angelico  wrote:
> On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson  wrote:

>>>Steven, I'm building a documentation system. I have my own MVC
>>>framework and the goal is to have a documentation module for each
>>>project.
>>
>
> Is there a reason for not using Doxygen / Autodoc / etc, or at least
> something in the same style? They work from specially-formatted
> comments in the source code, rather than the compiled module object.

Because those specially-formatted comments are wrong.

-- 
Grant Edwards   grant.b.edwardsYow! I have many CHARTS
  at   and DIAGRAMS..
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Secure ssl connection with wrap_socket

2011-07-05 Thread Jean-Paul Calderone
On Jul 5, 4:52 am, Andrea Di Mario  wrote:
> Hi, I'm a new python user and I'm writing a small web service with ssl.
> I want use a self-signed certificate like in 
> wiki:http://docs.python.org/dev/library/ssl.html#certificates
> I've used wrap_socket, but if i try to use
> cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error:
>
> urllib2.URLError:  specified for verification of other-side certificates.>
>
> It works only with CERT_NONE (the default) but with this option i
> could access to the service in insicure mode.
>
> Have you some suggestions for my service?
>

Also specify some root certificates to use in verifying the peer's
certificate.  Certificate verification works by proceeding from a
collection of "root" certificates which are explicitly trusted.  These
are used to sign other certificates (which may in turn be used to sign
others, which in turn...).  The process of certificate verification is
the process of following the signatures from the certificate in use by
the server you connect to back up the chain until you reach a root
which you have either decided to trust or not.  If the signatures are
all valid and the root is one you trust, then you have established a
connection to a trusted entity.  If any signature is invalid, or the
root is not one you trust, then you have not.

The root certificates are also called the "ca certificates" or
"certificate authority certificates".  `wrap_socket` accepts a
`ca_certs` argument.  See 
http://docs.python.org/library/ssl.html#ssl-certificates
for details about that argument.

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


Re: wx MenuItem - icon is missing

2011-07-05 Thread Philip Semanchuk

On Jul 5, 2011, at 4:02 AM, Laszlo Nagy wrote:

>def onPopupMenu(self,evt):
>menu = wx.Menu()
>for title,bitmap in self.getPopupMenuItems():
>item = wx.MenuItem(None,-1,title)
>if bitmap:
>item.SetBitmap(bitmap)
>menu.AppendItem(item)
>menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item)
>self.PopupMenu( menu, evt.GetPoint())
>menu.Destroy()
> 
> I have read somewhere that under GTK, I have to assign the bitmap before 
> Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu item 
> icons are not showing up in Ubuntu. On Windows 7, everything is fine. What am 
> I doing wrong?
> 
> System: Ubuntu 11 amd64
> Python: 2.7.1+
> wx.__version__ '2.8.11.0'

Hi Laszlo,
Two suggestions --

1. Post a complete example that demonstrates the problem so that we don't have 
to dummy up a wx app ourselves to try your code.

2. Ask on the wxPython mailing list.

Good luck
Philip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: imp.find_module don't found my module but standard import statement can import this module… why ?

2011-07-05 Thread Stéphane Klein

Le 05/07/2011 15:44, Eric Snow a écrit :

On Tue, Jul 5, 2011 at 1:36 AM, Stéphane Klein  wrote:

Hi,

I would like import some module dynamically.



To import a module dynamically, you can use the built-in __import__ function:

   module = __import__("js")

Even better, use importlib's import_module, which is available in
2.7/3.2.  A backport is available on PyPI.

   module = importlib.import_module("js")



Thanks !

It's work very well.

Regards,
Stephane
--
Stéphane Klein 
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
pro: http://www.is-webdesign.com

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


Re: imp.find_module don't found my module but standard import statement can import this module… why ?

2011-07-05 Thread Eric Snow
On Tue, Jul 5, 2011 at 1:36 AM, Stéphane Klein  wrote:
> Hi,
>
> I would like import some module dynamically.
>

To import a module dynamically, you can use the built-in __import__ function:

  module = __import__("js")

Even better, use importlib's import_module, which is available in
2.7/3.2.  A backport is available on PyPI.

  module = importlib.import_module("js")

-eric

> First, I install "js.jquery"
>
> $ pip install js.jquery
>
> Here, I would like import "js" module.
>
 import imp
 imp.find_module("js")
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named js
 import js

>
> I can't found module with "imp.find_module" but I can import it with
> standard "import" statement.
>
> Where is my mistake ?
>
> Regards,
> Stephane
> --
> Stéphane Klein 
> blog: http://stephane-klein.info
> Twitter: http://twitter.com/klein_stephane
> pro: http://www.is-webdesign.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


embedding: how do I redirect print output?

2011-07-05 Thread Ulrich Eckhardt
Hi!

I'm trying to add some scripting capabilities to an application. Since it is 
a GUI application, I need some way to display output from Python. For 3.x, 
where "print" is a function, I'd just exchange this function with one that 
redirects the output to a log window, right.

However, I'm using 2.6 here, where that can't work. So, what I was thinking 
was to redirect "sys.stdout" and "sys.stderr" to a log window and possibly 
replace "sys.stdin" with something that causes meaningful errors if some 
code tries to use it, but that last point is just icing on the cake.

What seems cumbersome is that I'll need to write something that supports the 
file interface using C, which is still a bit awkward. I'm wondering, isn't 
there an easier way to achieve this? How would you do it?


Thank you!

Uli

-- 
Domino Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: HeaderParseError

2011-07-05 Thread Thomas Guettler
On 04.07.2011 13:20, Peter Otten wrote:
> Thomas Guettler wrote:
> 
>> On 04.07.2011 11:51, Peter Otten wrote:
>>> Thomas Guettler wrote:
>>>
 I get a HeaderParseError during decode_header(), but Thunderbird can
 display the name.

>>> from email.header import decode_header
>>>
>>>

Hi,

I created a ticket: http://bugs.python.org/issue12489

  Thomas Güttler


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The end to all language wars and the great unity API to come!

2011-07-05 Thread rantingrick
On Jul 4, 2:36 am, Gregory Ewing  wrote:

> We have different languages because different people have different
> ideas about what a language should be like. Ruby people like user
> defined control structures; Python people regard user defined
> control structures as an anti-feature. It's fundamentally
> impossible for one language to satisfy both sets of people.

I was thinking more about this comment and it occurred to me that
Python does have user controlled data structures. Just because there
is no "top level syntax" like ruby does not mean these do not exists.
You only have to look below the surface. Take the sort methods of
lists for example...

>>> lst = [
(100, 0),
(25, 2),
(10,1),
]
>>> lst
[(100, 0), (25, 2), (10, 1)]
>>> lst.sort()
>>> lst
[(10, 1), (25, 2), (100, 0)]
>>> lst.sort(lambda x,y: cmp(x[1], y[1]))
>>> lst
[(100, 0), (10, 1), (25, 2)]

...that looks like a "user defined control" structure to me. So how
can an anti-feature become part of the language proper? (devils
advocate here) :)

I leave the discovery of other user defined control structures for the
advanced readers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Implicit initialization is EVIL!

2011-07-05 Thread Gregory Ewing

rantingrick wrote:

Most applications consist of one main window
(a Tkinter.Tk instance).


You've obviously never used a Macintosh. On the Mac, it's
perfectly normal for an application to open multiple
documents, each in its own window, with no one window
being the "main" window. Any of them can be closed (or
even *all* of them) and the application continues to run
until you explicitly quit it.

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Gregory Ewing

rantingrick wrote:


You say "root" windows are bad however any parent-child relationship
has to BEGIN somewhere.


There's no need for *toplevel* windows to be children
of anything, though.


HOWEVER any of the windows ARE in fact
instances of Tk.Toplevel[1]. So they ARE all equal because they all
have the same methods available to them.


No, they're not -- the root window is special, because
if you kill it, the whole application exits. Often that
is inconvenient.

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


Secure ssl connection with wrap_socket

2011-07-05 Thread Andrea Di Mario
Hi, I'm a new python user and I'm writing a small web service with ssl.
I want use a self-signed certificate like in wiki:
http://docs.python.org/dev/library/ssl.html#certificates
I've used wrap_socket, but if i try to use
cert_reqs=ssl.CERT_REQUIRED, it doesn't work with error:

urllib2.URLError: 

It works only with CERT_NONE (the default) but with this option i
could access to the service in insicure mode.

Have you some suggestions for my service?

Thanks. Regards.

-- 
Andrea Di Mario
-- 
http://mail.python.org/mailman/listinfo/python-list


wx MenuItem - icon is missing

2011-07-05 Thread Laszlo Nagy

def onPopupMenu(self,evt):
menu = wx.Menu()
for title,bitmap in self.getPopupMenuItems():
item = wx.MenuItem(None,-1,title)
if bitmap:
item.SetBitmap(bitmap)
menu.AppendItem(item)
menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item)
self.PopupMenu( menu, evt.GetPoint())
menu.Destroy()

I have read somewhere that under GTK, I have to assign the bitmap before 
Append-ing the MenuItem to the Menu. So did I, but it doesn't work. Menu 
item icons are not showing up in Ubuntu. On Windows 7, everything is 
fine. What am I doing wrong?


System: Ubuntu 11 amd64
Python: 2.7.1+
wx.__version__ '2.8.11.0'

Thanks,

   Laszlo

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


Re: Problem!!

2011-07-05 Thread Nobody
On Sun, 03 Jul 2011 16:58:24 -0700, amir chaouki wrote:

> the problem is when i use the seek function on windows it gives me
> false results other then the results on *ux. the file that i work with
> are very large about 10mb.

This is probably an issue with how the underlying C functions behave on
Windows, related to the CRLF<->LF conversions when a file is opened in
text mode.

The Python library documention for the .seek() method says:

> If the file is opened in text mode (without 'b'), only offsets returned
> by tell() are legal. Use of other offsets causes undefined behavior.

IOW, you can't use computed offsets with files opened in text mode
(although in practice this will work for platforms other than Windows). If
you want to use computed offsets, open the file in binary mode and strip
the trailing CRs yourself.

And 10MB isn't "very large"; it's not even "large". You normally only
start running into problems with files which are 2GiB (2,147,483,648
bytes) or more (i.e. if you can't fit the size into a signed 32-bit
integer).

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


Re: Implicit initialization is EVIL!

2011-07-05 Thread Robin Becker

On 03/07/2011 23:21, Chris Angelico wrote:
.


var(0x14205359) x   # Don't forget to provide an address where the
object will be located
x=42


did you forget to specify the memory bank and computer (and presumably planet 
etc etc)

-molly-coddled-ly yrs-
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


imp.find_module don't found my module but standard import statement can import this module… why ?

2011-07-05 Thread Stéphane Klein

Hi,

I would like import some module dynamically.

First, I install "js.jquery"

$ pip install js.jquery

Here, I would like import "js" module.

>>> import imp
>>> imp.find_module("js")
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named js
>>> import js
>>>

I can't found module with "imp.find_module" but I can import it with 
standard "import" statement.


Where is my mistake ?

Regards,
Stephane
--
Stéphane Klein 
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
pro: http://www.is-webdesign.com

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