Re: Can I use python for this .. ??

2006-05-04 Thread Terry Reedy

"placid" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
.)
>
> When you hibernate/boot up/hibernate for a long time without a clean
> reboot, Windows becomes unstable...

This seems to depend on the system.  I have gone at least a week, maybe 
two, with nightly hibernations and no problems.  Maybe you meant much 
longer than that.  But installs and updates often require reboots anyway.

tjr



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


Re: Can I use python for this .. ??

2006-05-04 Thread placid

Petr Jakes wrote:
> Why using Python?
> What about?
> 1. Open Power Options in Control Panel. (Click Start, click Control
> Panel, and then double-click Power Options.)
> 2.Click the Hibernate tab, select the Enable hibernate support check
> box, and then click Apply.
> (If the Hibernate tab is unavailable, your computer does not support
> this feature.)

When you hibernate/boot up/hibernate for a long time without a clean
reboot, Windows becomes unstable...


>
> then:
> 1:  Click Start and Shut Down,
> 2: Point the standby button and maintain the shift key pushed,
> 3: A new hibernation button appears: click it while still holding the
> shift key: voila your PC will hibernate (it mens computer will save
> your current setting and will switch off).
> 
> Petr Jakes

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


Re: Swaying A Coder Away From Python

2006-05-04 Thread Terry Reedy

"Tim Williams" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> idea how large its user-base is.   As I said,  the email was forwarded
> to someone who thought I would be interested.

Well, it got Fredrik to post the link to a really nice intro to Django, 
which I had not seen before.  So thanks to you both ;-)

tjr



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


Re: Tuple assignment and generators?

2006-05-04 Thread Carl Banks

Larry Bates wrote:
> You must be careful with this as they all point to
> exactly the same object.  Example:
>
> >>> q = r = s = t = u = v = 0
> >>> id(q)
> 3301924
> >>> id(r)
> 3301924
> >>> id(s)
> 3301924

But:

>>> q = 0
>>> r = 0
>>> s = 0
>>> id(q)
134536636
>>> id(r)
134536636
>>> id(s)
134536636


[snip]
> My rule, don't do it unless you know exactly why you
> want to do it.  It will trip you up at some point and
> be VERY hard to find.

It's ok to do it with constant objects, really.


Carl Banks

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


Re: Using time.sleep() in 2 threads causes lockup when hyper-threading is enabled

2006-05-04 Thread Tim Peters
[Tim Peters]
>> I didn't run it for hours ;-)

[EMAIL PROTECTED]
> Please try.

OK, I let the first test program run for over 24 hours by now.  It
never hung.  Overnight, the box did go into sleep mode, but the test
woke itself up after sleep mode ended, and the threads reported they
were sleeping for about 8 hours then.

I did this under a debug build of Python, so that if it did hang I'd
have _some_chance of getting useful info from the VC 7.1 debugger. 
It's possible (but unlikely) that using a debug-build Python prevented
a hang that would have occurred had I used a release-build Python.

> The sleep statement does not return!  And this should not happen.  The
> code above does nothing special or unusual.  The problem only occurs if
> 2 threads use the sleep statement and hyper-threading is enabled.
>
> We discovered this bug perhaps a year ago.  The only solution was to
> tell our customers to disable hyper-threading (you can imagine they did
> not like our "solution" very much).  It then took many days of hard
> work to isolate the problem down to the code I posted above.

As before, since Python merely calls the Win32 API Sleep() function,
it's extremely unlikely that the problem is due to Python.

It's quite possible that the problem is due to a tiny timing hole in
MS's implementation of Sleep().  Since I don't have the source code
for that, and disassembling is prohibited by my license ;-), I can't
pursue that.

I've seen software with honest-to-God thread-race bugs that were never
reported across years of heavy production use, until a user tried the
code on a hyper-threaded or multi-core box.  Tiny timing holes can be
_extremely_ shy, and running on a box with true, or even just
finer-grained (like HT), concurrency can make them much more likely to
appear.  I've never seen a software failure with (eventually) known
cause occur on an HT box that could not have happened on a non-HT box.
 The statistics of extremely unlikely events aren't a natural fit to
the unabused human mind ;-)

> ...
> Once the application locks up (getting stuck in a sleep statement) all
> comes back to live if I pull the network cable out.  So perhaps the
> socket thread returns from the sleep statement and other threads return
> to live because they were waiting for the socket thread.

That's peculiar.  time.sleep() called from a thread other than the
main thread on Windows is non-interruptable (because the Windows
Sleep() function is non-interruptable).  time.sleep() called from the
main thread on Windows _is_ interruptable:  the main thread uses the
Win32 API WaitForSingleObject() instead, passing a handle to a custom
interrupt event; the _intent_ is so that a time.sleep() in the main
thread can be aborted by a keyboard interrupt.  But it shouldn't be
possible for anything other than a keyboard interrupt or a normal
(timeout) return to knock that loose.

So if unplugging the cable knocks things lose, that just points even
stronger at a bug in the Windows kernel.

> Our software runs on both Windows and Linux.  We are not sure if the
> problem also happens on Linux.

Well, I ran your test for a day on my Windows box -- you try running
it for a week on your Linux box ;-)

> ...
> We have searched the Internet far and wide and were not able to find
> any information that indicates that someone else has reported a similar
> problem (neither Python nor Windows Sleep related).

I'm pretty sure I would have known about it if anyone reported such a
Python bug in the last 15 years.  But this is the first time I've
heard it.  I don't keep up with Microsoft bug reports at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross platform libraries

2006-05-04 Thread Ravi Teja
No! That's not the way things work. Such code needs to run locally (in
this case, Windows). You can run this program as a daemon on Windows
with some nice simple remote interface (Eg: xmlrpc) and send a message
to trigger the shutdown.

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


Re: Newbie question on code vetting

2006-05-04 Thread Edward Elliott
I have no deep connections to any open source projects.  I do however know
quite a few engineers.  Bear that in mind.


[EMAIL PROTECTED] wrote:
> It seems to me that Open Source generally would be more pervasive if there
> was more transparency with respect to the practices observed within the
> projects.  What possible harm could there be in letting the world know how 
> decisions to incorporate code are reached? 

I don't think it's a question of transparency but effort.  Documenting the
processes takes time which many probably feel is better spent on functional
aspects of the project.  And for what benefit?  Are open source projects
more concerned about approval or quality?  Besdies, most commercial
products have zero transparency in their development processes and it
doesn't hinder their market acceptance.


> The goal of collaborative 
> development is to build a body of code with many minds that is better than
> the body of code that could be built by any subset of them. The same
> principle could be applied to identification of best practices for
> committers across projects. 

If those practices are identifiable and repeatable, then sure, maybe
projects could be more productive following a "best practices" approach. 
OTOH if successful projects function more as little fiefdoms run by 
benevolent dictators, the reasons for success may be too idiosyncratic and
happenstance to translate to other projects.  

Note I said more productive, as in allow the code to improve quicker.  My
impression is most engineers don't want to invest time on IP rules and hate
when legal shenanigans impinge on their development.  They're generally
good at providing attribution and avoiding intentional misuses, but won't
go out of their way to check sources.  Nor should they, as 1) that's not
their job and 2) it's a very difficult task (unless you know of some master
database containing all the world's code).  Hence IP verification "best
practices" are likely to be summarily ignored as a foolish waste of time.

Closed commercial projects fare no better, indeed they may be even worse
since the risk of getting caught is lower.  Google for the number of times
unlicensed GPLed code turned up in some commercial product.


> To me, being unable to reach an understanding
> of the practices is analogous to being unable to see and run the JUnit
> suites on a bunch of classes - being in the position of assuming that
> there is coverage, but not being able to understand how much or how
> thorough.

Transparency can be valuable to an outsider, but I don't see how most
projects would have the time, resources, or inclination to provide it.


> I think it is obvious that if every consumer of the code who has an
> interest in controlling risk has to reinvent the wheel, there will be a
> lot of effort wasted on redundant work. 

Sure, but this task is better handled by vendors like Red Hat than by
individual projects.  IP verification is no easy matter to handle, and
vendors have a financial incentive to perform the checks.  Vendors can also
offer indemnity, which individual projects can't.


> Why not have the project publish a 
> document that says "here are the practices by which we manage our code
> base - take it or leave it". Just as most licenses are variations on a few
> (GPL, LGPL, CPL, etc.), it seems to me that very quickly, a set of common
> management practices would evolve if most projects published, perhaps with
> a few variations.

I suspect part of the reason you have trouble finding answers about IP
issues is that there are none to give.  I doubt most projects follow
anything resembling a formal process for verifying sources.  It's more
likely left up to individual contributors, and probably runs along the
lines of "if it doesn't look obviously ripped-off, then it's ok".

 
> With regard to the issue of trust, how can I either trust or decide not to
> trust in an information vacuum?

By looking at indirect sources of evidence.  How much trust do others put in
this project?  (Google for one uses python heavily.)  How do most open
source projects function?  How do most engineers handle IP issues?  Can I
hire an auditor to sample a representative portion of the code base for IP
issues?  Has anyone else already done so?  How often are open source
projects accused of IP violations?  How serious are they and what are the
outcomes?  Do closed projects handle things any differently?  What
assurances do they really provide?

Risk analysis means there's risk.  Unknowns are inherent.  Work around them
the best you can.


> I may be splitting hairs, but my 
> understanding is that belief despite absence of evidence is faith, not
> trust. Trust is the result of observation, and I want to be able to
> observe.

Faith is a belief that something is true without evidence.  Trust is relying
on something/someone to perform a certain way.  Blindly believing a project
to be free of IP issues is faith.  Expecting the committers to take the sam

Re: Using time.sleep() in 2 threads causes lockup when hyper-threading is enabled

2006-05-04 Thread OlafMeding
Marc

> IIRC it was something like an NTP daemon that caused the clock to "jump" a 
> little and (Window's) sleep was confused.

The problem is not a "jump" but a permanet lockup of the sleep
statement.

To all others, is there nobody out there that could run the test code
at the beginning of this post on a hyper-threading CPU?

Olaf

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


Re: using urllib with ftp?

2006-05-04 Thread John Salerno
Fredrik Lundh wrote:
> John Salerno wrote:
> 
>> I've tried this already and it seems to work, but I'm curious if it's
>> okay to use urllib when trying to access a url that begins with ftp://
>> instead of http://. Does this matter? It's only a text file, so it's not
>>   really an FTP server I'm accessing, I don't think. I wasn't sure if
>> using ftplib would be overkill in this case, or if you even could use it
>> at all if you just want to get the page itself (the txt file).
> 
> from the urllib documentation:
> 
> Currently, only the following protocols are supported: HTTP,
> (versions 0.9 and 1.0), Gopher (but not Gopher-+), FTP, and
> local files.

Thanks. So the ftp:// is something different than actually using ftplib 
to connect to an FTP server, right? I've used both urllib and ftplib, so 
I know what they do, I just was a little unclear about whether they can 
sometimes do each other's work as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question on code vetting

2006-05-04 Thread Ben Finney
<[EMAIL PROTECTED]> writes:

> I hope the following message will not result in scorn being heaped
> upon me.

We try to heap scorn not upon individuals, but upon scorn-worthy ideas.

Also, we heap scorn upon people who heap their responses on top of the
quoted material. Please don't top-post.

> It seems to me that Open Source generally would be more pervasive if
> there was more transparency with respect to the practices observed
> within the projects.

You mean like publicly-accessible and archived developer discussion
forums? Bug tracking systems which anyone can submit to? Source code
with copyright statements and license grants directly in the files for
anyone to examine?

Who is it that needs to improve their transparency, again?

I would love for all software vendors to be held to this standard. Are
you suggesting your organisation expects some higher level of
transparency from free software, when it happily accepts a far lower
level of transparency from proprietary vendors?

(good sigmonster, have a biscuit)

-- 
 \"The right to search for truth implies also a duty; one must |
  `\ not conceal any part of what one has recognized to be true."  |
_o__)   -- Albert Einstein |
Ben Finney

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


Re: Tuple assignment and generators?

2006-05-04 Thread Ben Finney
[EMAIL PROTECTED] writes:

> There is only one zero in Python!  It can never change!

+0.5 QOTW

-- 
 \"Madness is rare in individuals, but in groups, parties, |
  `\ nations and ages it is the rule."  -- Friedrich Nietzsche |
_o__)  |
Ben Finney

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


Re: Gettings subdirectories

2006-05-04 Thread alex23
Florian Lindner wrote:
> how can I get all subdirectories of a given directories?

If you're not adverse to a solution outside of the standard lib, I
highly recommend the 'path' module:

>>> from path import path
>>> c = path("C:\\")
>>> c.dirs()
[path(u'C:\\cmdcons'), path(u'C:\\Config.Msi'), path(u'C:\\Logon'),
path(u'C:\\Program Files'), path(u'C:\\Python24'),
path(u'C:\\RECYCLER'), path(u'C:\\System Volume Information'),
path(u'C:\\WINDOWS'), path(u'C:\\WINSRC')]

http://www.jorendorff.com/articles/python/path/

Hope this helps.

- alex23

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


RE: Newbie question on code vetting

2006-05-04 Thread Delaney, Timothy (Tim)
[EMAIL PROTECTED] wrote:

> It seems to me that Open Source generally would be more pervasive if
> there was more transparency with respect to the practices observed
> within the projects.

You mean something like: http://www.python.org/dev/

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


whois info from Python?

2006-05-04 Thread skip
I'm looking to get whois information for a given domain from Python.  I'm
mostly interested in record update and creation dates at the moment, but
eventually might want more.  I stumbled upon a couple modules/programs:
rwhois.py and whois.py but neither seems to work.  I can clearly issue a
whois command directly, but I'm hoping there's some module out there that
will do the domain-to-whoisserver mapping and all the output parsing for me.
Any candidates other than the two I've found so far?

Thx,

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


Re: Swaying A Coder Away From Python

2006-05-04 Thread Russ Salsbury
Adam Jones: """
User error, evidently. Sometimes the interface is more intelligent than
its user, and every time this happens the interface is the one that
gets the bad rap.
"""

Well that certainly explains my problems with Eclipse.

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


Re: Newbie question on code vetting

2006-05-04 Thread william.boquist
All,

I hope the following message will not result in scorn being heaped upon me.
I know this is not a particularly fascinating topic for developers, but I
believe it is worth pursuing.

It seems to me that Open Source generally would be more pervasive if there
was more transparency with respect to the practices observed within the
projects. What possible harm could there be in letting the world know how
decisions to incorporate code are reached? The goal of collaborative
development is to build a body of code with many minds that is better than
the body of code that could be built by any subset of them. The same
principle could be applied to identification of best practices for
committers across projects. Just as the code must be available so that it
can be inspected, improved and extended, so should the practices, for
essentially the same reason. To me, being unable to reach an understanding
of the practices is analogous to being unable to see and run the JUnit
suites on a bunch of classes - being in the position of assuming that there
is coverage, but not being able to understand how much or how thorough.

I think it is obvious that if every consumer of the code who has an interest
in controlling risk has to reinvent the wheel, there will be a lot of effort
wasted on redundant work. Why not have the project publish a document that
says "here are the practices by which we manage our code base - take it or
leave it". Just as most licenses are variations on a few (GPL, LGPL, CPL,
etc.), it seems to me that very quickly, a set of common management
practices would evolve if most projects published, perhaps with a few
variations.

With regard to the issue of trust, how can I either trust or decide not to
trust in an information vacuum? I may be splitting hairs, but my
understanding is that belief despite absence of evidence is faith, not
trust. Trust is the result of observation, and I want to be able to observe.

Thanks for the info on the Cheese Shop. That helps.

If there is any interest in learning about it within this group, I can
supply some related info from the Eclipse project.

Regards,
Bill

"Robert Kern" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
> > Hi.
> >
> > I have visited the Python web site and read some information on who the
> > commiters are and how to go about submitting code to them, but I have
not
> > been able to locate any information regarding the process for vetting
the
> > code to identify any possible IP infringement before it is committed.
How do
> > the committers ascertain the originality of the code before it becomes
part
> > of the base?
>
> They tell themselves very sternly not to commit code that isn't
appropriately
> licensed.
>
> > Is there any use of tools like BlackDuck ProtexIP or the
> > competing Palamida product to scan for matches to code that is already
> > licensed elsewhere?
>
> No.
>
> > Also, is the same or a different standard of IP assurance practiced for
the
> > Cheese Shop?
>
> There is no vetting for the Cheese Shop. Anyone can post packages there.
If some
> illegal-to-redistribute code is discovered, it will probably be removed by
the
> administrators. This hasn't come up, yet, I don't think.
>
> If you want the code to be vetted, you have to do it yourself. Besides, if
you
> don't trust the commiters and the package authors not to infringe on other
> peoples' IP, why do you trust them to report infringement?
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
enigma
>  that is made terrible by our own mad attempt to interpret it as though it
had
>  an underlying truth."
>   -- Umberto Eco
>


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


Re: Tuple assignment and generators?

2006-05-04 Thread jemfinch
> Zero, in particular, is the same variable all throughout a Python interpreter.

For the sake of accuracy let me note that I ought to have said, "is the
same *value* all throughout a Python interpreter."

Jeremy

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


Re: Tuple assignment and generators?

2006-05-04 Thread jemfinch

Larry Bates wrote:
> Just wrote:
> > In article <[EMAIL PROTECTED]>,
> >  Larry Bates <[EMAIL PROTECTED]> wrote:
> >
> >> While I have never needed anything like this in my 5 years of Python
> >> programming, here is a way:
> >>
> >> a,b,c = 3*[0]
> >> q,r,s,t,u,v = 6*[0]
> >
> > This is (IMO) fairly idiomatic:
> >
> >a = b = c = 0
> >q = r = s = t = u = v = 0
> >
> > Just
>
> You must be careful with this as they all point to
> exactly the same object.  Example:
>
> >>> q = r = s = t = u = v = 0
> >>> id(q)
> 3301924
> >>> id(r)
> 3301924
> >>> id(s)
> 3301924
> >>>
>
> Notice that all of them point to exactly the same object,
> not 6 copies of zero which is "probably" what the poster
> was thinking.

Numbers are immutable.  They're never copied.  Zero, in particular, is
the same variable all throughout a Python interpreter.

> Most of the time when I see this, it is because people are
> thinking of variables having values which is mostly a
> carry-over from old Fortran/Cobol/Basic programming ideas.

Most of the time when I see it, it's written by someone who's used
Python for quite some time.  It's a standard Python idiom.  You'll find
it all over the standard library.  It's not a carry-over from
Fortran/Cobol/Basic at all.

> In python variables are pointers to objects.  Objects could
> be values, but they are not placeholders where you store
> stuff.

And all immutable objects are indistinguishable from values.  Immutable
objects include ints, longs, strings, unicode objects, tuples,
frozensets, and perhaps some others that I'm forgetting.

> I read on this list (quite frequently) that people
> think they are getting 6 separate variables each with
> a zero stored in them.

That's because they are.  They're getting 6 different pointers
(bindings) to zero.  If you change one, the others remain pointed at
(bound to) zero.

> They are not.  They are getting
> six pointers that all point to an integer zero

Six *different* pointers.  Six *different* bindings.

> (IMHO it
> would be a rather odd application for a programmer
> to want this).

No, it wouldn't be.  It's exactly how a person works with immutable
(value) objects.

>  Here is where multiple assignments
> causes problems for beginners:
>
> >>> a=[]
> >>> b=c=a
> >>> a.append(6)
> >>> b
> [6]

Yes, that does sometimes trouble beginners to programming.  But so do
regular expressions.  Programmers ought not to restrict themselves by
what beginners will have no difficulty learning.

> What??  'b' should contain an empty list, right?  Nope.
> a, b, and c all point to the SAME list just like the
> poster's  q, r, s, t, u, v all point to the SAME zero.

There is only one zero in Python!  It can never change!

> What they meant to write was:
>
> c=a[:]  # Shallow copy of list
> b=a[:]
>
> My rule, don't do it unless you know exactly why you
> want to do it.  It will trip you up at some point and
> be VERY hard to find.

Your rule should only be followed by people who obstinately refuse
either to understand the way variable bindings work in Python, or by
people who refuse to know or care whether a given kind of object is
immutable.  And that group of people doesn't seem to include any of the
good Python programmers I know.

Jeremy

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


Re: Can I use python for this .. ??

2006-05-04 Thread Martin P. Hellwig
san wrote:
> Hi
> 
> I am using windows xp and have installed python and win32. I am
> familiar with basic Python. I wanted to control some of the
> applications via python script.
> 
> I would like to write a python script to say:
> 1. Open firefox and log on to gmail
> 2. Another firefox window to visit slickdeals
> 3. Open winamp and tune in to a shoutcast station
> 4. Open groupwise ...
> etc ..
> 
> These are the task I do every day whenever I log on my computer .. it
> just seems repetitive and hence probably can be coded in python.
> 
> Can I do this in python? Where do I find the COM objects/interfaces for
> all these different programs? Are there any sample codes ?
> 
> Thanks.
> Santosh.
> 

What you want looks like a way to automate the windows gui using python.
Since I never done this myself I gave google a try with this query:
http://www.google.com/search?hl=en&q=windows+gui+automation+python&btnG=Google+Search

It looks like pywinauto seems to be a good candidate.

hth

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


Re: Can I use python for this .. ??

2006-05-04 Thread BartlebyScrivener
san,

Take a look at this thread which features some smart and helpful people
and good links.

http://tinyurl.com/ggn5e

I'm wagering you'll make more sense of it than I did. I have my hands
full just making my way through tutorials and books at the moment.

rick

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


Re: __init__.py, __path__ and packaging

2006-05-04 Thread Sandro Dentella
In comp.lang.python, hai scritto:
> Sandro Dentella wrote:
>> The structure of my package:
>> 
>> python/
>> `-- dbg/
>>|-- __init__.py
>>`-- lib
>>|-- __init__.py
>>|-- debug.py
>>`-- gtk_dbg.py
>> 
>> my sys.path includes 'python' and I wanted that the content of debug.py was
>> simply included by: 'import dbg', so I wrote dbg/__init__.py as follows:
>> 
>> import os
>> Dir = os.path.dirname(__file__)
>> __path__ = [os.path.join(Dir, 'lib')]
>> from debug import *
>
> What you probably want in python/dbg/__init__.py to get values is:
>
>  from dbg.lib.debug import *

This does not work:

   Traceback (most recent call last):
 File "", line 1, in ?
 File "dbg/__init__.py", line 8, in ?
   from dbg.lib.debug import *
   ImportError: No module named lib.debug



>
>> BUT, if I set some variables they are not correctly seen:
>> import dbg
>> dbg.DBG = 1
>> function test included in debug.py raises NameError:
>> def test():
>> print DBG
>> NameError: global name 'DBG' is not defined`
>> 
>> What's happening? DBG seems to be set, as shown by dir(dbg)... any hints?
> You misunderstand modules and python variables.  Each module has a
> dictionary associating the names of its globals and their current
> values.  After:
>  import dbg.lib.debug, dbg.lib.gtk_dbg
> you have four modules:
>  dbg # Corresponds to python/dbg/__init__.py
>  dbg.lib # Corresponds to python/dbg/lib/__init__.py
>  dbg.lib.debug   # Corresponds to python/dbg/lib/debug.py
>  dbg.lib.gtk_dbg # Corresponds to python/dbg/lib/gtk_dbg.py
> Each has its own globals.
> after:
>  dbg.DBG = 1
> the dbg module's global dictionary contains an entry mapping 'DBG' to 1
> after:
>  dbg.DBG = 1+2
> the dbg module's global dictionary contains an entry mapping 'DBG' to 3
>
> In no case will an assignment to a global in dbg cause an assignment to
> anything in dbg.lib.debug.  The "from dbg.lib.debug import *" statement
> can be seen as a module import followed by a fancy multiple assignment,
> where module dbg.lib.debug is first imported, then its globals are
> assigned to globals of the same names in module dbg.

This confirms to me that I'm seriously confused... so I started with a very
simple setup:
$ cat dbg.py
DBG = 1
def test():
global DBG
print DBG

def set():
global DBG
DBG = 3


$ cat m.py
from  dbg import *

test()
#dbg.DBG = 2   ## does not work, no way to assign in module dbg
set()  # this acts in dbg module and sets 'DBG = 3'
test() # test the value of DBG
print DBG


$ python m.py
1
3  # changed by 'set' that was 'imported'
1  # value of local DBG

isn't this contraddicting you words:

> can be seen as a module import followed by a fancy multiple assignment,
> where module dbg.lib.debug is first imported, then its globals are
> assigned to globals of the same names in module dbg.

So: which is the way I can change a value of a package 'imported', only with
a function that sets it? is there a way to assign the value directly?
is there any way to make some introspection of what is really there (in
dbg)?

Thanks angain for any possible hint.

sandro
*:-)



-- 
Sandro Dentella  *:-)
http://www.tksql.orgTkSQL Home page - My GPL work
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does built-in set not take keyword arguments?

2006-05-04 Thread Serge Orlov

Jack Diederich wrote:
> On Thu, May 04, 2006 at 02:08:30PM -0400, Steven Watanabe wrote:
> > I'm trying to do something like this in Python 2.4.3:
> >
> > class NamedSet(set):
> >   def __init__(self, items=(), name=''):
> > set.__init__(self, items)
> > self.name = name
> >
> > class NamedList(list):
> >   def __init__(self, items=(), name=''):
> > list.__init__(self, items)
> > self.name = name
> >
> > I can do:
> >
> > >>> mylist = NamedList(name='foo')
> >
> > but I can't do:
> >
> > >>> myset = NamedSet(name='bar')
> > TypeError: set() does not take keyword arguments
> >
> > How come? How would I achieve what I'm trying to do?
>
> setobject.c checks for keyword arguments in it's __new__ instead
> of its __init__.  I can't think of a good reason other to enforce
> inheriters to be maximally set-like.  We're all adults here so
> I'd call it a bug.  bufferobect, rangeobject, and sliceobject all
> do this too, but classmethod and staticmethod both check in tp_init.
> Go figure.
>
> As a work around use a function to make the set-alike.
>
> class NamedSet(set): pass
>
> def make_namedset(vals, name):
>   ob = NamedSet(vals)
>   ob.name = name
>   return ob
>
> Then make_namedset as a constructor in place of NamedSet(vals, name)

Or use this work around:

class NamedSet(set):
def __new__(cls, iterable=(), name=""):
return super(NamedSet, cls).__new__(cls)

def __init__(self, iterable=(), name=""):
super(NamedSet, self).__init__(iterable)
self.name = name

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


Re: Why does built-in set not take keyword arguments?

2006-05-04 Thread Jack Diederich
On Thu, May 04, 2006 at 02:08:30PM -0400, Steven Watanabe wrote:
> I'm trying to do something like this in Python 2.4.3:
> 
> class NamedSet(set):
>   def __init__(self, items=(), name=''):
> set.__init__(self, items)
> self.name = name
> 
> class NamedList(list):
>   def __init__(self, items=(), name=''):
> list.__init__(self, items)
> self.name = name
> 
> I can do:
> 
> >>> mylist = NamedList(name='foo')
> 
> but I can't do:
> 
> >>> myset = NamedSet(name='bar')
> TypeError: set() does not take keyword arguments
> 
> How come? How would I achieve what I'm trying to do?

setobject.c checks for keyword arguments in it's __new__ instead 
of its __init__.  I can't think of a good reason other to enforce
inheriters to be maximally set-like.  We're all adults here so 
I'd call it a bug.  bufferobect, rangeobject, and sliceobject all 
do this too, but classmethod and staticmethod both check in tp_init.
Go figure.

As a work around use a function to make the set-alike.

class NamedSet(set): pass

def make_namedset(vals, name):
  ob = NamedSet(vals)
  ob.name = name
  return ob

Then make_namedset as a constructor in place of NamedSet(vals, name)

-Jack


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


Re: scope of variables

2006-05-04 Thread Gary Wessle
thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can I use python for this .. ??

2006-05-04 Thread san
Petr I dont want hibernation .. its more like starting a list of
programs when i want to have fun time on my pc...

but thanx for ur reply ..

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


Re: Can I use python for this .. ??

2006-05-04 Thread Petr Jakes
Why using Python?
What about?
1. Open Power Options in Control Panel. (Click Start, click Control
Panel, and then double-click Power Options.)
2.Click the Hibernate tab, select the Enable hibernate support check
box, and then click Apply.
(If the Hibernate tab is unavailable, your computer does not support
this feature.)

then:
1:  Click Start and Shut Down,
2: Point the standby button and maintain the shift key pushed,
3: A new hibernation button appears: click it while still holding the
shift key: voila your PC will hibernate (it mens computer will save
your current setting and will switch off).

Petr Jakes

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


Re: Python 2.4.2 to 2.4.3 transition issue

2006-05-04 Thread Panos Laganakos
Heh, Frederic,
It seems that its Lilypond's (www.lilypond.org) fault.

It registered its bin directory in the PATH variable, which seems to
contain a python.exe too.
So the result of:
>>>import sys; sys.executable
'D:\\Program Files\\LilyPond\\usr\\bin\\python.exe'

As for the instances of python24.dll, there are two:
one in system32 and one in inkscape's directory.

I 'fixed' it, by defining python's directory ahead of lilypond's. Now
the right executable is called.

Is there any other way instead of positioning in the PATH variable?

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


Re: Using time.sleep() in 2 threads causes lockup when hyper-threading is enabled

2006-05-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Grant Edwards wrote:

> On 2006-05-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> The sleep statement does not return!
> 
> Never, or does it just take a long time?
> 
>> And this should not happen.
> 
> Dude, it's MS Windows.
> 
> It does all _sorts_ of stuff that it shouldn't.
> 
> Having sleep() take orders of magnitude longer than it should
> is not an uncommon complaint for MS Windows users.  There was a
> fairly extensive thread in this group about that problem just a
> few weeks ago.  IIRC, disabling some other program or service
> fixed it for one MS victem.

IIRC it was something like an NTP daemon that caused the clock to "jump"
a little and (Window's) sleep was confused.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: using urllib with ftp?

2006-05-04 Thread Fredrik Lundh
John Salerno wrote:

> I've tried this already and it seems to work, but I'm curious if it's
> okay to use urllib when trying to access a url that begins with ftp://
> instead of http://. Does this matter? It's only a text file, so it's not
>   really an FTP server I'm accessing, I don't think. I wasn't sure if
> using ftplib would be overkill in this case, or if you even could use it
> at all if you just want to get the page itself (the txt file).

from the urllib documentation:

Currently, only the following protocols are supported: HTTP,
(versions 0.9 and 1.0), Gopher (but not Gopher-+), FTP, and
local files.





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


Re: Python sample code for PLSQL REF CURSORS

2006-05-04 Thread A.M
Exactly what I was looking for.

Thanks alot


"Gerhard Häring" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> A.M wrote:
>> Hi,
>>
>> I am having hard time to find a sample that shows me how to return an OUT 
>> REF CURSOR from my oracle stored procedure to my python program. [...]
>
> import cx_Oracle
>
> con = cx_Oracle.connect("me/[EMAIL PROTECTED]")
> cur = con.cursor()
> outcur = con.cursor()
> cur.execute("""
> BEGIN
> MyPkg.MyProc(:cur);
> END;""", cur=outcur)
>
> for row in out_cur:
> print row
>
> HTH,
>
> -- Gerhard 


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

Re: Can I use python for this .. ??

2006-05-04 Thread BartlebyScrivener
For starters, you need the os and webbrowser modules

import os
import webbrowser

webbrowser.open("http://mail.google.com/mail";)

# need to know the shell keyword for starting the app
os.system('start ' + 'Winword')

# the equivalent of double-clicking on the doc or file
os.startfile("c:/MyFiles/MyTextFile.txt")

If you actually want to log onto password-protected sites it gets
gnarly fast (beyond me). You can read about by perusing the urllib2
module or search this list at groups.google.com/group/comp.lang.python

Hope this helps.

rick

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


Unable to use py2app

2006-05-04 Thread Pierre Thibault
Hello,

I am unable to use py2app. I have an error when I try to import it:

ImportError: No module named py2app

I have installed pyobjc-1.3.7. I am on Mac OS 10.4.6.

It does not work. It does not work with python 2.4 and it does not work
with python 2.3.

Is it working with someone else?

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


Re: Can I use python for this .. ??

2006-05-04 Thread san
btw i got the firefox to open and access some webpage and winamp
running ..

code below
--
import os
import os.path
import subprocess

# Web pages
ffox_exe = r'C:\Program Files\Mozilla Firefox\firefox.exe'
assert os.path.exists(ffox_exe)
# open gmail
url = "http://www.gmail.com";
child = subprocess.Popen( (ffox_exe, url), executable = ffox_exe)
rc = child.wait()

# Winamp
wamp_exe = r'C:\Program Files\Winamp\winamp.exe'
assert os.path.exists(wamp_exe)
url = "http://64.236.34.97:80/stream/1040";
child = subprocess.Popen( (wamp_exe, url), executable = wamp_exe)



now is there anyway i can enter user name and password and then click
okay .. (not for gmail but for other similar webpages which require
loggin) .. ??

how to open pages in tabs .. ?? 

San

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


using urllib with ftp?

2006-05-04 Thread John Salerno
I've tried this already and it seems to work, but I'm curious if it's 
okay to use urllib when trying to access a url that begins with ftp:// 
instead of http://. Does this matter? It's only a text file, so it's not 
  really an FTP server I'm accessing, I don't think. I wasn't sure if 
using ftplib would be overkill in this case, or if you even could use it 
at all if you just want to get the page itself (the txt file).

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


Re: Python 2.4.2 to 2.4.3 transition issue

2006-05-04 Thread Fredrik Lundh
Panos Laganakos wrote:

> OS: Windows XP + SP1
>
> On this particular box, I hadn't moved to 2.4.3 yet.
> So, earlier today, I uninstalled Python2.4.2 and installed 2.4.3 using
> the .msi installer.
>
> It seems though everything looked great, that when I invoke 'python'
> from the command line, I get Python2.4.2 (as the header states),
> instead of 2.4.3.
>
> I looked at the registry and at the PATH variables of both system and
> current user, but they are just stating 'C:\Python24\'.
>
> When I explicitly call C:\Python24\python.exe though, 2.4.3 comes up.
>
> Any ideas what seems to be the problem here?

in your python 2.4.2 interpreter, what does

>>> import sys
>>> sys.executable

say ?

if you do a global search for "python24.dll", how many instances do
you find ?





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


Re: Swaying A Coder Away From Python

2006-05-04 Thread Stormcoder
I usually refer to it as "VILE!". As in what Vile thing do I have
before me. 

Emacs all the way baby!

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


Why does built-in set not take keyword arguments?

2006-05-04 Thread Steven Watanabe
I'm trying to do something like this in Python 2.4.3:

class NamedSet(set):
  def __init__(self, items=(), name=''):
set.__init__(self, items)
self.name = name

class NamedList(list):
  def __init__(self, items=(), name=''):
list.__init__(self, items)
self.name = name

I can do:

>>> mylist = NamedList(name='foo')

but I can't do:

>>> myset = NamedSet(name='bar')
TypeError: set() does not take keyword arguments

How come? How would I achieve what I'm trying to do?
Thanks.
--
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.4.2 to 2.4.3 transition issue

2006-05-04 Thread Panos Laganakos
OS: Windows XP + SP1

On this particular box, I hadn't moved to 2.4.3 yet.
So, earlier today, I uninstalled Python2.4.2 and installed 2.4.3 using
the .msi installer.

It seems though everything looked great, that when I invoke 'python'
from the command line, I get Python2.4.2 (as the header states),
instead of 2.4.3.

I looked at the registry and at the PATH variables of both system and
current user, but they are just stating 'C:\Python24\'.

When I explicitly call C:\Python24\python.exe though, 2.4.3 comes up.

Any ideas what seems to be the problem here?

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


Re: CRC calculation

2006-05-04 Thread Stormcoder
Check out http://docs.python.org/lib/module-zlib.html comes with a CRC
function.

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


Re: Swaying A Coder Away From Python

2006-05-04 Thread Fredrik Lundh
Rony Steelandt wrote:

> What s wrong with VI ???  :)

it's spelled "vim".





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


CRC calculation

2006-05-04 Thread mike7411
Does anyone know where I can get python code to perform a CRC
calculation on an IP packet?

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


Can I use python for this .. ??

2006-05-04 Thread san
Hi

I am using windows xp and have installed python and win32. I am
familiar with basic Python. I wanted to control some of the
applications via python script.

I would like to write a python script to say:
1. Open firefox and log on to gmail
2. Another firefox window to visit slickdeals
3. Open winamp and tune in to a shoutcast station
4. Open groupwise ...
etc ..

These are the task I do every day whenever I log on my computer .. it
just seems repetitive and hence probably can be coded in python.

Can I do this in python? Where do I find the COM objects/interfaces for
all these different programs? Are there any sample codes ?

Thanks.
Santosh.

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


regex to exctract informations

2006-05-04 Thread Bob
Dears,

I am trying to search and replace strings with regex.

The string is identified by a keyword :

IDImage("1M234567");
DescriptionImage("Desc of the Image 1");

I want to exctract the IDImage (1M234567 ) and the Description.

The ID are characters and numbers, the description too.

Thx,

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


Re: Tuple assignment and generators?

2006-05-04 Thread Tim Chase
> I don't think he was explicitly wanting to initialize
> things to zero, but rather unpack an arbitrary sequence
> into a tuple (could perhaps be the fibonnacci sequence
> for example).

Ant is correct here...Fibonnaci, digits of pi, the constant
42, an incrementing counter, a series of squares, whatever. 
  That was my original intent in the matter.  Zeros just 
happened to be a nice sort of place to start my exercise.

> How about:
> 
> 
def zeros(count):
> 
> ... for i in range(count):
> ... yield 0

One of the things I was trying to avoid was having to know 
(and maintain) the count of items initialized.  In the 
theoretical world of my example, one could do something like

def counter():
counter = 0
while 1:
yield counter
counter += 1

and then initialize several variables, such as

 >>> a,b,c,d,e,f,g = counter()
 >>> a,b,c,d,e,f,g
(0,1,2,3,4,5,6)

It's similar to C's auto-numbering of enum values...If I 
want to add another entry to a C enum, I just put it there, 
and let the language take care of matters.  With most of the 
provided solutions, I also have to increment the count each 
time I add an item to the list.

Diez provided an elegant solution with a decorator 
(employing an incredibly ugly sort of hack involving 
sniffing the opcode stack behind the scenes) that does what 
I was looking for.

I was hoping that there was just some __foo__ property I was 
missing that would have been called in the process of tuple 
unpacking that would allow for a more elegant solution such 
as a generator (or generator method on some object) rather 
than stooping to disassembling opcodes. :)

Ah well.

-tkc




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


[HOST] - Flexible Project Hosting with Python (similar to Assembla Breakout)

2006-05-04 Thread lazaridis_com
For a larger scale project, a collaboration infrastructure and toolset
should be selected.

More information about the overall project:

http://lazaridis.com/pj

The actually active system is a Dedicated Server (with Trac & SVN).

A Project Host Candidate which comes close to the needed system is
Assembla ( http://assembla.com ), but currently it does not comply
fully to the Basic Requirements.

You can find the actual selection case here:

http://case.lazaridis.com/host

Are there any other Python-Centric Project Hosts available (which could
comply to the stated requirements)?

Any suggestions are very welcome.

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


Re: Tuple assignment and generators?

2006-05-04 Thread Larry Bates
Just wrote:
> In article <[EMAIL PROTECTED]>,
>  Larry Bates <[EMAIL PROTECTED]> wrote:
> 
>> While I have never needed anything like this in my 5 years of Python
>> programming, here is a way:
>>
>> a,b,c = 3*[0]
>> q,r,s,t,u,v = 6*[0]
> 
> This is (IMO) fairly idiomatic:
> 
>a = b = c = 0
>q = r = s = t = u = v = 0
> 
> Just

You must be careful with this as they all point to
exactly the same object.  Example:

>>> q = r = s = t = u = v = 0
>>> id(q)
3301924
>>> id(r)
3301924
>>> id(s)
3301924
>>>

Notice that all of them point to exactly the same object,
not 6 copies of zero which is "probably" what the poster
was thinking.

Most of the time when I see this, it is because people are
thinking of variables having values which is mostly a
carry-over from old Fortran/Cobol/Basic programming ideas.
In python variables are pointers to objects.  Objects could
be values, but they are not placeholders where you store
stuff.

I read on this list (quite frequently) that people
think they are getting 6 separate variables each with
a zero stored in them.  They are not.  They are getting
six pointers that all point to an integer zero (IMHO it
would be a rather odd application for a programmer
to want this).  Here is where multiple assignments
causes problems for beginners:

>>> a=[]
>>> b=c=a
>>> a.append(6)
>>> b
[6]

What??  'b' should contain an empty list, right?  Nope.
a, b, and c all point to the SAME list just like the
poster's  q, r, s, t, u, v all point to the SAME zero.

What they meant to write was:

c=a[:]  # Shallow copy of list
b=a[:]

My rule, don't do it unless you know exactly why you
want to do it.  It will trip you up at some point and
be VERY hard to find.

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


Re: Possible constant assignment operators ":=" and "::=" for Python

2006-05-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Yes, I know that "constant" A will also be modified as the b[0] points
> to A. Obviously the [] should be marked as immutable, as A is declared
> to be constant thus immutable. If somebody tries to modify this
> immutable object an error would occur.
> 
> When I further thought about this problem with constant objects (and
> values), I run into this scenario: What if I want to use a constant
> object/value as a template (or predefined value/class) for a variable:
> 
> constant A = ['1'] # let's declare A as immutable constant value/object
> b = A # let's assign b some default value
> b.append('2') # and let's play with b, but I wouldn't want to change A

def A():
   return ['1']

b = A()
b.append('2')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible constant assignment operators ":=" and "::=" for Python

2006-05-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> Bruno Desthuilliers wrote:
> 
>>[EMAIL PROTECTED] a écrit :
>>
>>>Hi Pythonians,
>>>
>>>To begin with I'd like to apologize that I am not very experienced
>>>Python programmer so please forgive me if the following text does not
>>>make any sense.
>>>
>>>I have been missing constants in Python language.
>>
>>Why so ?
>>
>>I guess you're talking about named (symbolic) constants ? If so, just
>>follow the convention : a name in ALL_UPPERCASE is a constant (or at
>>least will be treated as such by anyone not wanting to mess with your
>>package's implementation). No need to add extra syntax here IMHO.
> 
> 
> Hi Bruno,
> 
> For example:
> 
> 
A = []  # let's declare a "constant" here

Uh ? That's the strangest idea I've ever seen - I mean, using an empty 
list as a constant... If you need your constant to be a sequence (while 
I can't imagine any reason to do so), use a tuple.

(snip)

> As you can see, the "constant" A can be modified this easily. But if
> there were an intuitive mechanism to declare a symbol to be immutable,

Don't worry about the symbol, use an immutable type !-)
-- 
http://mail.python.org/mailman/listinfo/python-list


how Can I programater in python similar to Delphi

2006-05-04 Thread Tomás Rodriguez Orta



Hello, friends.
I can programter in python similar to delphi, 
enveloper form for capture ther data from user.
some help.
 
sincerely TOMAS-
Este correo fue escaneado en busca de virus con el MDaemon Antivirus 2.27
en el dominio de correo angerona.cult.cu  y no se encontro ninguna coincidencia.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question on code vetting

2006-05-04 Thread Edward Elliott
[EMAIL PROTECTED] wrote:
> I agree with your point, which is why I asked the question. Risk cannot be
> eliminated, but it can be understood and managed so that useful work can
> still be done. If there is any way I can find out what the commiters do
> prior to reaching a decision to accept or reject a particular submission,
> I would like to know about it.

If committers make no checks on submitted code, that doesn't have to be an
automatic showstopper, even for a risk-averse company.  How many of the
alternatives perform more stringent checks on their code?  How much
misappropriated code is floating around in closed commercial products,
where the privacy of the source may encourage more liberal borrowing? 
Anyone can say they check their IP, but how many organizations put their
money where their mouth is and provide indemnity?  How visible will your
company and your Python projects be?

You can always try to make the case that even without ip checks python makes
your company 1) no more vulnerable than the other software they already
rely on, and 2) unlikely to be targetted for their use anyway.  And if you
can show the financial gains from using it are highger than the potential
liability, you're golden.

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


Re: __getattr__ for global namespace?

2006-05-04 Thread Bruno Desthuilliers
Harold Fellermann a écrit :
> Hi,
> 
> I am writing an application that initializes the global namespace, and
> afterwards, leaves the user with the python prompt. Now, I want to
> catch NameErrors in user input like e.g.
> 
> 
some_name
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> NameError: name 'some_name' is not defined
> 
> For classes, there are the __getattr__ and __getattribute__ functions.
> I wonder if there is some related function for (failed) global
> attribute
> lookup that is invoked with name as its argument instead.
> 
> I consulted the docs, but could not find anything. Any ideas?

http://docs.python.org/lib/module-sys.html

"""
excepthook( type, value, traceback)
 This function prints out a given traceback and exception to sys.stderr.

 When an exception is raised and uncaught, the interpreter calls 
sys.excepthook with three arguments, the exception class, exception 
instance, and a traceback object. In an interactive session this happens 
just before control is returned to the prompt; in a Python program this 
happens just before the program exits. The handling of such top-level 
exceptions can be customized by assigning another three-argument 
function to sys.excepthook.
"""

>>> import sys
>>> def myhook(type, value, tb):
... print "got ", type, value, tb
...
...
>>> sys.excepthook = myhook
>>> toto
got  exceptions.NameError name 'toto' is not defined 
>>>

HTH

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


Re: Subclassing array

2006-05-04 Thread Bruno Desthuilliers
Sion Arrowsmith a écrit :
> Alex Martelli <[EMAIL PROTECTED]> wrote:
> 
>>TG <[EMAIL PROTECTED]> wrote:
>>
>>>When I call Vector.__init__() in Stimulus, doesn't it also call __new__
>>>? I don't understand the detail of callings to __new__ and __init__ in
>>>python inheritance ...
>>
>>Calling a (new-style) class does __new__ first, THEN calls the class's
>>__init__ on the resulting instance -- and the arguments you're passing
>>when calling the class go to both __new__ and __init__.
> 
> 
> ... so you might want something like:
> 
> class Vector(array):
> def __new__(cls,*args):
> return super(Vector,cls).__new__(cls,'f')
> 
And if you want to support named arguments:

class Vector(array):
 def __new__(cls,*args, **kw):
 return super(Vector,cls).__new__(cls,'f')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: noob question: "TypeError" wrong number of args

2006-05-04 Thread Edward Elliott
bruno at modulix wrote:
> Edward Elliott wrote:
>> Ah, well then, there's no need for a full-blown parser.  It should
>> suffice to recognize a class definition and modify the parameter list of
>> every def indented one level further than that.
> 
> won't do :
> 
> class CounterExample(object):
>   if compute_some_const_according_to_phase_of_moon():
> def meth(...):
>   do_something(self, 42)

Uuunn, you got me pardner.  (cough, cough) my hands, they're so cold. 
bruno?  where'd you go, bruno?  i can't see you anymore.  are we back on
the farm?  tell ma i love her.  (clunk)

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


Re: Possible constant assignment operators ":=" and "::=" for Python

2006-05-04 Thread Edward Elliott
Michele Simionato wrote:
>> >>> A = []  # let's declare a "constant" here
>> >>> b = A   # and let's assign the constant here
>> >>> b.append('1') # OOPS!
> 
> But it makes no sense to use a mutable object for a constant!
> The user should use a tuple, 

Sure.  Now show me the builtin immutable equivalent of a dict.

> or a custom list-like type where 
> all methods with side effects are removed, so it effectively acts
> as a tuple.

Ugh, not worth the trouble imo.


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


Re: Python for Perl programmers

2006-05-04 Thread Paddy
I found this version of the phrasebook:
 http://wiki.python.org/moin/PerlPhrasebook
its been edited recently but I didn't check for how current it is.

-- Pad.

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


Re: Python for Perl programmers

2006-05-04 Thread Andrew Gwozdziewycz

On May 4, 2006, at 12:36 PM, Aahz wrote:

> In article <[EMAIL PROTECTED]>,
> A.M <[EMAIL PROTECTED]> wrote:
>>
>> Is there any efficient online resource or book that help  
>> experienced Perl
>> programmers to Python?

I'd recommend http://www.diveintopython.org since you know how to  
program already. It's free!


---
Andrew Gwozdziewycz
[EMAIL PROTECTED]
http://ihadagreatview.org
http://and.rovir.us


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


Re: Python for Perl programmers

2006-05-04 Thread John J. Lee
"A.M" <[EMAIL PROTECTED]> writes:

> Is there any efficient online resource or book that help experienced Perl 
> programmers to Python?

Worry instead about how you're going to keep maintaining your Perl
code after you've developed an allergic response to it.

<0.5 wink>


John

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


Re: Python & SSL

2006-05-04 Thread John J. Lee
Sybren Stuvel <[EMAIL PROTECTED]> writes:

> John J. Lee enlightened us with:
> > Of course, remembering that the first thing to ask in response to
> > "is it secure?"  is "against what?", for lots of purposes it just
> > doesn't matter that it ignores certificates.
> 
> I'm curious. Can you give me an example? AFAIK you need to know who
> you're talking to before transmitting sensitive information, otherwise
> you could be talking to anybody - and that's just what you wanted to
> prevent with the encryption, right?

If Edward hadn't answered I would have said something along the lines
of what he said too, but more than that I just had in mind situations
where, when fetching a web page, the risk (probability and
consequences) of a man-in-the-middle attack doesn't feature much
higher than the risk of getting hit by a piece of debris from outer
space that day.  Surprisingly often, it so happens that the people
setting up the web site used https, even though as a user of the site
I don't really care about the encryption or authentication.

That doesn't mean proper certificate handling wouldn't be good to have
(it would), just that installing m2crypto and finding the right docs
isn't necessarily worth the bother.

BTW, I assume the reason the OP (I forgot who that was) didn't have
https support compiled in was just that they didn't have OpenSSL
installed when they typed ./configure (since the Python build process
on unix uses autoconf).  Either that or they installed a system
package to get Python (e.g. an .rpm) and the SSL support is is a
separate package (seems unlikely).


John

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


Re: Problem building extension under Cygwin (ImportError: Bad address)

2006-05-04 Thread Lars
Great!
Thanks for the advice.

Lars

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


Re: Multiple Version Install?

2006-05-04 Thread Tim Peters
[David C.Ullrich]
> Would there be issues (registry settings, environment
> variables, whatever) if a person tried to install
> versions 1.x and 2.x simultaneously on one Windows
> system? Windows 98, if it matters.
>
> (I can handle the file associations with no problem.)

There are generally no issues beyond file associations.  On Windows,
Python versions i.j.k and i'.j'.k' coexist happily so long as i != i'
or j != j'.  For example, I currently have the python.org-released
Pythons 2.2.3, 2.3.5, and 2.4.3 installed on my Windows box.  It would
be a challenge only if I wanted, say, 2.4.2 and 2.4.3 installed
simultaneously.

Another possible issue is that whenever the major or minor version
numbers (i or j) change on Windows, you also need to install matching
versions of any 3rd party extensions you want.  The major and minor
version numbers appear in the _name_ of the core Python DLL (like
python23.dll and python24.dll), and extensions with C code must be
compiled to link with the correct version of the Python DLL.

> If anyone feels like pointing out that there's simply
> no reason to want to keep 1.x after installing the
> current version: By all means talk me into that!

If you've been using extensions with 1.j.k, then as above they have no
chance of working with 2.j'.k' bejore you install 2.j' versions of
those extensions.  That's a good reason to keep an old version.

There have been thousands of bugfixes and language enhancements since
1.j.k too, and not all are 100% backward-compatible.

In all, best advice is to keep the old version around until you're
sure you no longer need it.

> The problem is not that I'm concerned about backwards
> compatibility of Python code. The problem is that I
> use Python embedded in various Delphi programs,
> including a "DIDE" that I use really a lot, via
> a certain set of Delphi "components". These components
> don't seem to work with 2.x. Presumably the PyDelphi
> people have new versions of the components that do
> work with Python 2.x. These presumably use much
> newer versions of Delphi than what I have. A new
> version of Delphi is not free... If I could use
> Python 2.x when I need to while continuing to
> use 1.x the way I have been for things that
> don't need 2.x that would be convenient.

That should work fine.  I don't know about PyDelphi, but found what
appears to be a still-active discussion list:

http://groups.yahoo.com/group/pythonfordelphi/

The theoretical joy of open source is that if they _don't_ support the
Python+Delphi combo you have, you can fix that yourself ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


pyuno and PDF output

2006-05-04 Thread Sells, Fred
I can use java to output a PDF file using uno, but when I try to do it in
python, I get an IO Exception with no added information.   The relevant code
snippet follows:

from com.sun.star.beans import PropertyValue
PDF= PropertyValue( "FilterName" , 0 , "writer_pdf_Export", 0 )
doc2.storeAsURL("file:///C:/alleclipse/OpenOffice/test2.pdf", (PDF,) )

if I don't specify any properties, it writes an "odt" file just fine, but
when I specify (PDF,) it breaks.





Traceback (most recent call last):
  File "oomerge.py", line 137, in ?
test1()
  File "oomerge.py", line 74, in test1
doc2.storeAsURL("file:///C:/alleclipse/OpenOffice/test2.pdf", (PDF,) )
__main__.com.sun.star.task.ErrorCodeIOException

---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-04 Thread Just
In article <[EMAIL PROTECTED]>,
 Larry Bates <[EMAIL PROTECTED]> wrote:

> While I have never needed anything like this in my 5 years of Python
> programming, here is a way:
> 
> a,b,c = 3*[0]
> q,r,s,t,u,v = 6*[0]

This is (IMO) fairly idiomatic:

   a = b = c = 0
   q = r = s = t = u = v = 0

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


Re: Python & SSL

2006-05-04 Thread Sybren Stuvel
Edward Elliott enlightened us with:
> Encryption has multiple meanings.  In the general sense, it
> encompasses all of cryptography and the information security
> properties crypto provides. 

And if you already know who'll get the message, it's secure. I get it
:)

Thanks for the nice read ;-)

> Of course if you control the server and serve a small clientele who
> already trust you, you can have clients import your own cert so they
> really can be sure who they're talking to -- as long as your master
> key remains secret. 

I'm used to using it like that. My own graduation project uses SSL to
thoroughly check the identity of both parties, without a web of trust.

> The moral of this story is: computer security is an ugly, complex
> business.

Yup.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


cross platform libraries

2006-05-04 Thread diffuser78
I am using python on a linux terminal.

I want to shutdown a remote windows box. I found a script which does
something like this. My question is can we use windows libraries in
linux as follows 

import win32api
import win32con
import win32netcon
import win32security
import win32wnet

def shutdown(parameters):
OTHER CODE HERE

Every help is appreciated.

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


Re: problem with reload(sys) (doing reload on the sys module)

2006-05-04 Thread nick
Looks like a bug (probably in IDLE): when I start IDLE from the command
line, it pops up its interaction window and here is what it says about
stdout:

IDLE 1.1.2  
>>> import sys
>>> sys.stdout


Then I try the reload and I get no output in the interaction
window:

>>> reload(sys)
>>> sys.stdout
>>> 

After the reload, stdout has been changed to the terminal from which
IDLE got started, so I see the messages there:


', mode 'w' at 0xb7b67068>

As you can see, stdout has been redefined (back to the way it would be if
you started Python from the command line, with no IDLE involved).
-- 
nick  (nicholas dot dokos at hp dot com)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Perl programmers

2006-05-04 Thread Aahz
In article <[EMAIL PROTECTED]>,
A.M <[EMAIL PROTECTED]> wrote:
>
>Is there any efficient online resource or book that help experienced Perl 
>programmers to Python?

Don't use the Martin Brown book, whatever you do.  The Perl/Python
Phrasebook isn't bad, but it's ten years out of date.  Really, your best
bet is to just dive into the Python tutorial.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple assignment and generators?

2006-05-04 Thread Ant
I don't think he was explicitly wanting to initialize things to zero,
but rather unpack an arbitrary sequence into a tuple (could perhaps be
the fibonnacci sequence for example).

How about:

>>> def zeros(count):
... for i in range(count):
... yield 0
...
>>> a,b,c = zeros(3)
>>> a
0
>>> b
0
>>> c
0

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


Re: Mutable String

2006-05-04 Thread Pierre Thibault
Ok,

That will do the job. Thank you.

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


Re: Tuple assignment and generators?

2006-05-04 Thread Larry Bates

Tim Chase wrote:
> Just as a pedantic exercise to try and understand Python a bit better, I
> decided to try to make a generator or class that would allow me to
> unpack an arbitrary number of calculatible values.  In this case, just
> zeros (though I just to prove whatever ends up working, having a
> counting generator would be nice).  The target syntax would be something
> like
> 
 a,b,c = zeros()
 q,r,s,t,u,v = zeros()
> 
> where "zeros()" returns an appropriately sized tuple/list of zeros.
> 
> I've tried a bit of googling, but all my attempts have just ended up
> pointing to pages that blithly describe tuple assignment, not the
> details of what methods are called on an object in the process.
> 
> My first thought was to get it to use a generator:
> 
> def zeros():
> while 1: yield 0
> 
> However, I get back a "ValueError: too many values to unpack" result.
> 
> As a second attempt, I tried a couple of attempts at classes (I started
> with the following example class, only derived from "object" rather than
> "list", but it didn't have any better luck):
> 
 class zeros(list):
> ... def __getitem__(self,i):
> ... return 0
> ...
 z = zeros()
 a,b,c = z
> Traceback (most recent call last):
>   File "", line 1, in ?
> ValueError: need more than 0 values to unpack
> 
> 
> It looks like I need to have a pre-defined length, but I'm having
> trouble figuring out what sorts of things need to be overridden.  It
> seems like I sorta need a
> 
> def __len__(self):
> return INFINITY
> 
> so it doesn't choke on it.  However, how to dupe the interpreter into
> really believing that the object has the desired elements is escaping
> me.  Alternatively if there was a "doYouHaveThisManyElements"
> pseudo-function that was called, I could lie and always return true.
> 
> Any hints on what I'm missing?
> 
> Thanks,
> 
> -tkc
> 
> 
While I have never needed anything like this in my 5 years of Python
programming, here is a way:

a,b,c = 3*[0]
q,r,s,t,u,v = 6*[0]

of if you like:

def zeros(num):
return num*[0]

a,b,c = zeros(3)
q,r,s,t,u,v = zeros(6)

I think the reason I don't every use anything like this is that
you don't need to initialize variables in Python to zero and I would
probably use a list instead of individual variables like q,r,s,t,u,v.

-Larry Bates

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


Re: Progamming python without a keyboard

2006-05-04 Thread Philippe Martin
That reminds me a session in an R&D lab a long time ago

One of the guys kept talking to himself, commenting code, bugs . he
drove me nuts

Eventually (weeks later) another guy silently stood up, went to the first
guy, and without a word attempted to strangle him.

He got stopped ... but did not get fired (I guess even the management was
tired of the first guy rambling)

We should be aware of all types of RSI.

(I'm still laughing)

Philippe





Rony Steelandt wrote:

> http://www.newscientisttech.com/article/dn9066
> 
> To nice to be true ?
> 
> R_
> 
> --
> ---
> Rony Steelandt
> BuCodi
> rony dot steelandt (at) bucodi dot com
> 
> Visit the python blog at http://360.yahoo.com/bucodi

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


Python for Perl programmers

2006-05-04 Thread A.M
Hi,



Is there any efficient online resource or book that help experienced Perl 
programmers to Python?



Thank you,

Alan


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


Re: Calling superclass

2006-05-04 Thread Diez B. Roggisch
Florian Lindner wrote:

> Hello,
> I try to call the superclass of the ConfigParser object:
> 
> class CustomizedConfParser(ConfigParser.SafeConfigParser):
> def get(self, section, attribute):
> try:
> return super(CustomizedConfParser, self).get(section,
> attribute)
> # [...]
> 
> 
> but that gives only
> 
> return super(CustomizedConfParser, self).get(section, attribute)
> TypeError: super() argument 1 must be type, not classobj
> 
> I don't really understand the error message.


super works only for newstyle-classes. So additionally extend
CustomizedConfParser from object.

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


Re: Swaying A Coder Away From Python

2006-05-04 Thread Adam Jones

Rony Steelandt wrote:
> 
> "One problem is that python tools suck," he wrote. Wallace compared the
> various IDEs and other developer tools available to Microsoft's freely
> available Visual Studio Express and called them "toys."
>
> 
>
> What s wrong with VI ???  :)

User error, evidently. Sometimes the interface is more intelligent than
its user, and every time this happens the interface is the one that
gets the bad rap.

Sorry for the snarky comment, but python dev tools do not suck, they
are just generally different from visual studio. There are any number
of good editing platforms for python, visual studio is just not really
one of them.

>
> R_
>
> >> On 4 May 2006 05:24:40 -0700, BartlebyScrivener <[EMAIL PROTECTED]> wrote:
> >>> I'm picking this up via clp on Google Groups. I can't tell what Mr.
> >>> Lundh is referring to. The first line of his post is: "Tim Williams
> >>> wrote" but there's nothing that comes before.
> >
> > Similarly, I'm reading this via comp.lang.python and the original
> > article hasn't shown up at this site.
> >
> > Tim Williams <[EMAIL PROTECTED]> wrote:
> >> I found the web version at.
> >>
>
>
> >> http://www.devwebpro.co.uk/devwebprouk-46-20060503SwayingACoderAwayFromPython.html
> >
> > Wherein we find:
> >
> > He also listed a few reasons why C# appeals to him over Python or Java:
> > * anonymous functions (delegates)
> > * a python-like yield statement
> > * a nice type system with generics
> > * interfaces
> > * properties (Yay!!)
> >
> > So that's two of the five Python has, one explicitly acknowledged,
> > plus the combination of lambda and functions-as-first-class-objects
> > is as good as (or better than) "anonymous functions (delegates)".
> > And then we get onto personal preferences as to how to do type
> > systems. That's not a great deal with which to sway someone.
>
>
> --
> ---
> Rony Steelandt
> BuCodi
> rony dot steelandt (at) bucodi dot com
> 
> Visit the python blog at http://360.yahoo.com/bucodi

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


Re: Tuple assignment and generators?

2006-05-04 Thread Diez B. Roggisch
Tim Chase wrote:

> Just as a pedantic exercise to try and understand Python a
> bit better, I decided to try to make a generator or class
> that would allow me to unpack an arbitrary number of
> calculatible values.  In this case, just zeros (though I
> just to prove whatever ends up working, having a counting
> generator would be nice).  The target syntax would be
> something like



By using this:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/284742


I came up with a small decorator doing that:

import inspect, dis

def expecting():
"""Return how many values the caller is expecting"""
f = inspect.currentframe()
f = f.f_back.f_back
c = f.f_code
i = f.f_lasti
bytecode = c.co_code
instruction = ord(bytecode[i+3])
if instruction == dis.opmap['UNPACK_SEQUENCE']:
howmany = ord(bytecode[i+4])
return howmany
elif instruction == dis.opmap['POP_TOP']:
return 0
return 1

def variably_unpack(f):
def d(*args, **kwargs):
r = f(*args, **kwargs)
exp = expecting()
if exp < 2:
return exp
return (r.next() for i in xrange(exp))
return d

@variably_unpack
def test():
def gen():
i = 0
while True:
yield i
i += 1
return gen()



a, b, c = test()

print a,b,c

a, b, c, d = test()

print a,b,c, d



Diez


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


Calling superclass

2006-05-04 Thread Florian Lindner
Hello,
I try to call the superclass of the ConfigParser object:

class CustomizedConfParser(ConfigParser.SafeConfigParser):
def get(self, section, attribute):
try:
return super(CustomizedConfParser, self).get(section, attribute)
# [...]


but that gives only

return super(CustomizedConfParser, self).get(section, attribute)
TypeError: super() argument 1 must be type, not classobj

I don't really understand the error message.

Thanks,

Florian

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


Progamming python without a keyboard

2006-05-04 Thread Rony Steelandt
http://www.newscientisttech.com/article/dn9066

To nice to be true ?

R_

-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: Problem building extension under Cygwin (ImportError: Bad address)

2006-05-04 Thread Jason Tishler
On Thu, May 04, 2006 at 06:23:23AM -0700, Lars wrote:
> But first compiling hello.c with gcc, then linking it with gnu-ld just
> won't work. I only really need to compile one C-file to a shared
> library so it doesn't matter so much for me. But bigger projects will
> have a problem..

No, it works if you drive it from gcc:

$ gcc -I/usr/include/python2.4 -c hello.c
$ gcc -shared -o hello.dll hello.o -L/usr/lib/python2.4/config -lpython2.4
$ python hellouse.py 
Hello, C
Hello, module /tmp/examples/PP2E/Integrate/Extend/Hello/hello.dll
Hello, 0
Hello, 1
Hello, 2

BTW, if you use Distutils, then it will just work...

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swaying A Coder Away From Python

2006-05-04 Thread Rony Steelandt

"One problem is that python tools suck," he wrote. Wallace compared the 
various IDEs and other developer tools available to Microsoft's freely 
available Visual Studio Express and called them "toys."



What s wrong with VI ???  :)

R_

>> On 4 May 2006 05:24:40 -0700, BartlebyScrivener <[EMAIL PROTECTED]> wrote:
>>> I'm picking this up via clp on Google Groups. I can't tell what Mr.
>>> Lundh is referring to. The first line of his post is: "Tim Williams
>>> wrote" but there's nothing that comes before.
>
> Similarly, I'm reading this via comp.lang.python and the original
> article hasn't shown up at this site.
>
> Tim Williams <[EMAIL PROTECTED]> wrote:
>> I found the web version at.
>> 


>> http://www.devwebpro.co.uk/devwebprouk-46-20060503SwayingACoderAwayFromPython.html
>
> Wherein we find:
>
> He also listed a few reasons why C# appeals to him over Python or Java: 
> * anonymous functions (delegates)
> * a python-like yield statement
> * a nice type system with generics
> * interfaces 
> * properties (Yay!!)
>
> So that's two of the five Python has, one explicitly acknowledged,
> plus the combination of lambda and functions-as-first-class-objects
> is as good as (or better than) "anonymous functions (delegates)".
> And then we get onto personal preferences as to how to do type
> systems. That's not a great deal with which to sway someone.


-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: Subclassing array

2006-05-04 Thread Sion Arrowsmith
Alex Martelli <[EMAIL PROTECTED]> wrote:
>TG <[EMAIL PROTECTED]> wrote:
>> When I call Vector.__init__() in Stimulus, doesn't it also call __new__
>> ? I don't understand the detail of callings to __new__ and __init__ in
>> python inheritance ...
>Calling a (new-style) class does __new__ first, THEN calls the class's
>__init__ on the resulting instance -- and the arguments you're passing
>when calling the class go to both __new__ and __init__.

... so you might want something like:

class Vector(array):
def __new__(cls,*args):
return super(Vector,cls).__new__(cls,'f')

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

pyuno and oootools with OpenOffice 2.0

2006-05-04 Thread Sells, Fred
I'm using windows xp and OpenOffice 2.0 and doing my first project with
pyuno.

I've got the basics to work,.  An example I googled at
http://blogs.nuxeo.com/sections/aggregators/openoffice_org/blogaggregator_vi
ew?b_start:int=0 imported an ootools module.  When I try to import it, it
does not exist,  

Does anyone know where this exists, or why I cannot import it.  

---
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swaying A Coder Away From Python

2006-05-04 Thread Sion Arrowsmith
>On 4 May 2006 05:24:40 -0700, BartlebyScrivener <[EMAIL PROTECTED]> wrote:
>> I'm picking this up via clp on Google Groups. I can't tell what Mr.
>> Lundh is referring to. The first line of his post is: "Tim Williams
>> wrote" but there's nothing that comes before.

Similarly, I'm reading this via comp.lang.python and the original
article hasn't shown up at this site.

Tim Williams <[EMAIL PROTECTED]> wrote:
>I found the web version at.
>
>http://www.devwebpro.co.uk/devwebprouk-46-20060503SwayingACoderAwayFromPython.html

Wherein we find:

He also listed a few reasons why C# appeals to him over Python or Java: 
* anonymous functions (delegates)
* a python-like yield statement
* a nice type system with generics
* interfaces 
* properties (Yay!!)

So that's two of the five Python has, one explicitly acknowledged,
plus the combination of lambda and functions-as-first-class-objects
is as good as (or better than) "anonymous functions (delegates)".
And then we get onto personal preferences as to how to do type
systems. That's not a great deal with which to sway someone.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Wake on LAN and Shutdown for Windows and Linux

2006-05-04 Thread diffuser78
Any help is appreciated

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


Re: Multiple Version Install?

2006-05-04 Thread David C.Ullrich
On Thu, 4 May 2006 16:17:57 +0200, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:

>David C.Ullrich wrote:
>
>> Would there be issues (registry settings, environment
>> variables, whatever) if a person tried to install
>> versions 1.x and 2.x simultaneously on one Windows
>> system? Windows 98, if it matters.
>>
>> (I can handle the file associations with no problem.)
>
>in general, no.

Excellent. Thanks.

>(I usually have about a dozen Python's, or more, on most of my
>windows boxes)
>
>however, applications that look in the registry may only find the
>last one you've installed.
>
> 
>
>




David C. Ullrich
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode code has no method float() ?

2006-05-04 Thread Rony Steelandt
Works, thank you


> Le 04-05-2006, Rony <[EMAIL PROTECTED]> nous disait:
>> How can I get the value of a Unicode object ?
>> 
>> When I do myobject.float() I get the error message that it doesn't have 
>> a float() attribute
>
> Try to use the float builtin function, as in: float(myobject) instead of
> a method. 


-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: Python function returns:

2006-05-04 Thread Sion Arrowsmith
Michael Yanowitz <[EMAIL PROTECTED]> wrote:
>  In Python, there does not seem to be an easy way to have functions return
>multiple values except it can return a list such as:
>strHostname, nPortNumber, status = get_network_info (strIpAddress,
>strHostname,
> nPortNumber)
>  Am I missing something obvious? Is there a better, or more standard way
>to return values from functions?

I'm kind of repeating what other people have said, but there
isn't a better way. Not just in Python, but in any language.
If your function is returning multiple values, why should you
have to split them into one privileged "return value" plus a
bunch of Out (or InOut) parameters? That's a historical mis-
feature of older languages, and one which more newer languages
would do well to fix.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: stripping unwanted chars from string

2006-05-04 Thread Alex Martelli
Edward Elliott <[EMAIL PROTECTED]> wrote:

> I'm looking for the "best" way to strip a large set of chars from a filename
> string (my definition of best usually means succinct and readable).   I
> only want to allow alphanumeric chars, dashes, and periods.  This is what I
> would write in Perl (bless me father, for I have sinned...):
> 
> $filename =~ tr/\w.-//cd, or equivalently 
> $filename =~ s/[^\w.-]//
> 
> I could just use re.sub like the second example, but that's a bit overkill.
> I'm trying to figure out if there's a good way to do the same thing with
> string methods.  string.translate seems to do what I want, the problem is
> specifying the set of chars to remove.  Obviously hardcoding them all is a
> non-starter.

(untested code, but, the general idea shd be correct)...:

class KeepOnly(object):
allchars = ''.join(chr(i) for i in xrange(256))
identity = string.maketrans('', '')

def __init__(self, chars_to_keep):
self.chars_to_delete = self.allchars.translate(
self.identity, chars_to_keep)

def __call__(self, some_string):
return some_string.translate(self.identity,
self.chars_to_delete)


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


Tuple assignment and generators?

2006-05-04 Thread Tim Chase
Just as a pedantic exercise to try and understand Python a 
bit better, I decided to try to make a generator or class 
that would allow me to unpack an arbitrary number of 
calculatible values.  In this case, just zeros (though I 
just to prove whatever ends up working, having a counting 
generator would be nice).  The target syntax would be 
something like

 >>> a,b,c = zeros()
 >>> q,r,s,t,u,v = zeros()

where "zeros()" returns an appropriately sized tuple/list of 
zeros.

I've tried a bit of googling, but all my attempts have just 
ended up pointing to pages that blithly describe tuple 
assignment, not the details of what methods are called on an 
object in the process.

My first thought was to get it to use a generator:

def zeros():
while 1: yield 0

However, I get back a "ValueError: too many values to 
unpack" result.

As a second attempt, I tried a couple of attempts at classes 
(I started with the following example class, only derived 
from "object" rather than "list", but it didn't have any 
better luck):

 >>> class zeros(list):
... def __getitem__(self,i):
... return 0
...
 >>> z = zeros()
 >>> a,b,c = z
Traceback (most recent call last):
   File "", line 1, in ?
ValueError: need more than 0 values to unpack


It looks like I need to have a pre-defined length, but I'm 
having trouble figuring out what sorts of things need to be 
overridden.  It seems like I sorta need a

def __len__(self):
return INFINITY

so it doesn't choke on it.  However, how to dupe the 
interpreter into really believing that the object has the 
desired elements is escaping me.  Alternatively if there was 
a "doYouHaveThisManyElements" pseudo-function that was 
called, I could lie and always return true.

Any hints on what I'm missing?

Thanks,

-tkc








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


Re: Subclassing array

2006-05-04 Thread Alex Martelli
TG <[EMAIL PROTECTED]> wrote:
   ...
> When I call Vector.__init__() in Stimulus, doesn't it also call __new__
> ? I don't understand the detail of callings to __new__ and __init__ in
> python inheritance ...

Calling a (new-style) class does __new__ first, THEN calls the class's
__init__ on the resulting instance -- and the arguments you're passing
when calling the class go to both __new__ and __init__.


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


Re: Unicode code has no method float() ?

2006-05-04 Thread Alexandre Fayolle
Le 04-05-2006, Rony <[EMAIL PROTECTED]> nous disait:
> How can I get the value of a Unicode object ?
>
> When I do myobject.float() I get the error message that it doesn't have 
> a float() attribute

Try to use the float builtin function, as in: float(myobject) instead of
a method. 


-- 
Alexandre Fayolle  LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:   http://www.logilab.fr/services
Python et calcul scientifique:   http://www.logilab.fr/science
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode code has no method float() ?

2006-05-04 Thread Rony Steelandt
How can I get the value of a Unicode object ?

When I do myobject.float() I get the error message that it doesn't have 
a float() attribute

tia

R_

-- 
---
Rony Steelandt
BuCodi
rony dot steelandt (at) bucodi dot com

Visit the python blog at http://360.yahoo.com/bucodi


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


Re: python strings

2006-05-04 Thread Sion Arrowsmith
Bryan  <[EMAIL PROTECTED]> wrote:
> >>> s = '\x00'
> >>> s[0] == chr(0)
>True

That's a little excessive when:

>>> s = '\0'
>>> s[0] == chr(0)
True

Oh, and to reassure the OP that that null really is *in* the string:

>>> len(s)
1

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Calling a Postgres Function using CGI written in Python

2006-05-04 Thread Fuzzydave
cheers :)

thats what i wanted to know :)

David

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


Re: simultaneous assignment

2006-05-04 Thread Paul Rubin
Dave Hansen <[EMAIL PROTECTED]> writes:
> Well, if you want something minimalist, you could try
> 
>def truth_test(seq):
>   return sum(1 for item in seq if item) == 1

def truth_test(seq):
   return sum(map(bool, seq)) == 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous assignment

2006-05-04 Thread Dave Hansen
On Tue, 02 May 2006 18:52:48 GMT in comp.lang.python, John Salerno
<[EMAIL PROTECTED]> wrote:

[...]
>
>Yeah, after trying some crazy things, I just wrote it this way:
>
>def truth_test(seq):
> truth = 0
> for item in seq:
> if item:
> truth += 1
> if truth == 1:
> return True
> else:
> return False

You could replace those last four lines with

  return truth == 1

>
>Not sure I like having to keep a counter though, but the other stuff I 

Well, if you want something minimalist, you could try

   def truth_test(seq):
  return sum(1 for item in seq if item) == 1

Though I'm not sure it's really any clearer...

>did was really convoluted, like checking to see if the first item was 
>True, and if it was, popping it from the list and iterating over the 
>rest of the items (needless to say, the in-place change wasn't helpful).

Perhaps something like

   def truth_test(seq):
  found = False
  for item in seq:
 if item:
if found:
   return False
found = True
  return found

Gets you an early exit, anyway...

All code untested.  Regards,
-=Dave

-- 
Change is inevitable, progress is not.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Because of multithreading semantics, this is not reliable.

2006-05-04 Thread Christophe
[EMAIL PROTECTED] a écrit :
> Christophe
> 
> 
>>Same reason that there is a warning in the "os.access" manual
> 
> 
> I understand the if file exists open it code.
> 
> I looked at the os.access documentation and see no "warning" or "not
> reliable" wording there.
>   6.1.4 Files and Directories
>   access(path, mode)
> 
> 
> Olaf
> 

6.1.4 Files and Directories

access( path, mode)

Use the real uid/gid to test for access to path. Note that most 
operations will use the effective uid/gid, therefore this routine can be 
used in a suid/sgid environment to test if the invoking user has the 
specified access to path. mode should be F_OK to test the existence of 
path, or it can be the inclusive OR of one or more of R_OK, W_OK, and 
X_OK to test permissions. Return True if access is allowed, False if 
not. See the Unix man page access(2) for more information. Availability: 
Macintosh, Unix, Windows.
Note: Using access() to check if a user is authorized to e.g. open a 
file before actually doing so using open() creates a security hole, 
because the user might exploit the short time interval between checking 
and opening the file to manipulate it.



I call that note a warning.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting a list of dictionaries by dictionary key

2006-05-04 Thread Alex Martelli
Tim Chase <[EMAIL PROTECTED]> wrote:

> > assuming that DateTime returns something that compares correctly, you can
> > do something like:
> > 
> > def sortkey(item):
> > return item.get("from_datetime")
> > 
> > data.sort(key=sortkey)
> > 
> > (assuming Python 2.4 or later)
> 
> Building on Fredrik's solution, for 2.3 (or earlier?), you 
> can use
> 
> data.sort(lambda a,b: cmp(a['from_datetime'], 
> b['from_datetime']))

...and get a potentially very slow sort, if the list is long.  Much
faster:

_aux = [ (d['from_datetime'], i, d) for (i, d) in enumerate(data) ]
_aux.sort()
data[:] = [ t[-1] for t in _aux ]


Google Search for DSU or [Decorate Sort Undecorate] ...


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


Re: Multiple Version Install?

2006-05-04 Thread Fredrik Lundh
David C.Ullrich wrote:

> Would there be issues (registry settings, environment
> variables, whatever) if a person tried to install
> versions 1.x and 2.x simultaneously on one Windows
> system? Windows 98, if it matters.
>
> (I can handle the file associations with no problem.)

in general, no.

(I usually have about a dozen Python's, or more, on most of my
windows boxes)

however, applications that look in the registry may only find the
last one you've installed.

 



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


Re: pleac

2006-05-04 Thread Thomas Guettler
Am Thu, 04 May 2006 04:05:49 -0700 schrieb jonas:

> Hi,
> 
> I'm new to python.
> After a search on
> http://pleac.sourceforge.net/pleac_python/index.html
> why python have a low %?

Python has the highest percentage of all languages at pleac.

For those who don't know pleac:

"""Following the great Perl Cookbook (by Tom Christiansen & Nathan
Torkington, published by O'Reilly; you can freely browse an excerpt of the
book here) which presents a suite of common programming problems solved in
the Perl language, this project aims to gather fans of programming, in
order to implement the solutions in other programming languages.

If successful, this project may become a primary resource for quick, handy
and free reference to solve most common programming problems using
higher-level programming languages, and for comparison on ease-of-use and
power/efficiency of these languages.
"""

-- 
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: [EMAIL PROTECTED]

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


Re: Because of multithreading semantics, this is not reliable.

2006-05-04 Thread OlafMeding
Christophe

> Same reason that there is a warning in the "os.access" manual

I understand the if file exists open it code.

I looked at the os.access documentation and see no "warning" or "not
reliable" wording there.
  6.1.4 Files and Directories
  access(path, mode)


Olaf

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


Re: Python sample code for PLSQL REF CURSORS

2006-05-04 Thread Gerhard Häring
A.M wrote:
> Hi,
> 
> I am having hard time to find a sample that shows me how to return an OUT 
> REF CURSOR from my oracle stored procedure to my python program. [...]

import cx_Oracle

con = cx_Oracle.connect("me/[EMAIL PROTECTED]")
cur = con.cursor()
outcur = con.cursor()
cur.execute("""
 BEGIN
 MyPkg.MyProc(:cur);
 END;""", cur=outcur)

for row in out_cur:
 print row

HTH,

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


  1   2   >