magic names in python

2007-06-03 Thread per9000
Hi,

I recently started working a lot more in python than I have done in
the past. And I discovered something that totally removed the pretty
pink clouds of beautifulness that had surrounded my previous python
experiences: magic names (I felt almost as sad as when I discovered
the strange pink worms that eat you in nethack, not to mention the
mind flayers - I really hate them).

I guess all programming languages have magic names to some extent
(f.x. classes in the "C-family" have constructors that must have the
same name as the class (foo::foo) instead of foo.__init__).

I just used a search engine a little on this topic and I found no
comprehensive list of magic names in python.

So my questions:
 * is there a comprehensive list of magic names in python (so far i
know of __init__ and __repr__)?
 * are these lists complete or can magic names be added over time (to
the python "core")?
 * are magic names the same in different python versions?

I also tried (selected parts of(?)) the unittest package for use in
Zope and it seemed functions that I created for my test with the magic
prefix "test" were magic, other functions were not.

So another question emerges:
 * is the use of magic names encouraged and/or part of good coding
practice.

Live long and prosper,
Per

--

Per Erik Strandberg
home: www.pererikstrandberg.se
work: www.incf.org
also: www.spongswedencare.se

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


Re: subexpressions (OT: math)

2007-06-03 Thread Wildemar Wildenburger
Gary Herron wrote:
>> The radian is defined as the ratio of an arc of circumfence of a circle 
>> to the radius of the circle and is therefore *dimensionless*. End of story.
>> http://en.wikipedia.org/wiki/Radian  and esp.
>> http://en.wikipedia.org/wiki/Radian#Dimensional_analysis
>>
>>   
>> 
>
> The arguments to sine and cosine must have an associated unit so you
> know whether to interpret sin(1.2) as sine of an angle measured in
> degrees or radians (or whatever else).
>   

Touché. :)

Yes, I think we can all agree on that.

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


Re: excel library without COM

2007-06-03 Thread yuce

i think this one works pretty nice: http://www.python.org/pypi/xlrd

Happy hacking,

Yuce


On Jun 4, 3:59 am, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> is there any library to help me write excel files without using win
> com? because i'll be working on linux platform. At the same time I
> could want to perform some formatting, merging of cells. adding sheets
> and etc ...
>
> Thanks
> james


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


Re: `yield` in a `try/finally` block, pre-Python 2.5

2007-06-03 Thread yuce

I had the same problem, you can see: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/130004
for a solution.

Happy hacking,

Yuce

On Jun 4, 8:23 am, Adam Atlas <[EMAIL PROTECTED]> wrote:
> I'm trying to emulate the Python 2.5 behaviour (PEP 342) of generator
> functions where the `yield` statement is in a `try/finally` block.
> Basically, where the `finally` block is guaranteed to run even if the
> generator doesn't finish running: it simply runs when the generator is
> garbage-collected. Does anyone know a good way of doing this? I'm
> looking to see if there's a way to bring about an exception in another
> frame in pure Python, but I haven't found anything yet.


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


`yield` in a `try/finally` block, pre-Python 2.5

2007-06-03 Thread Adam Atlas
I'm trying to emulate the Python 2.5 behaviour (PEP 342) of generator
functions where the `yield` statement is in a `try/finally` block.
Basically, where the `finally` block is guaranteed to run even if the
generator doesn't finish running: it simply runs when the generator is
garbage-collected. Does anyone know a good way of doing this? I'm
looking to see if there's a way to bring about an exception in another
frame in pure Python, but I haven't found anything yet.

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


Re: excel library without COM

2007-06-03 Thread Waldemar Osuch
On Jun 3, 6:59 pm, james_027 <[EMAIL PROTECTED]> wrote:

> is there any library to help me write excel files without using win
> com?

One option is:
https://secure.simplistix.co.uk/svn/xlwt/trunk


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


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-03 Thread Steve Howell

--- Ross Ridge <[EMAIL PROTECTED]>
wrote:
> >Asia:
> >
> >   Python should be *completely* internationalized
> for
> >Mandarin, Japanese, and possibly Hindi and Korean. 
> >Not just identifiers.  I'm talking the entire
> >language, keywords and all.
> 
> 
> btw. Mandarin is a spoken dialect Chinese, what
> you're actually asking
> for is a Simplified-Chinese version of Python.
> 

I'm just trying to divide-and-conquer the problem of
promoting Python literacy in the world.   To the
extent that you have a billion people in the world who
all speak/write a mostly common language, I wonder if
you wouldn't try to go even further than PEP 3131 and
truly translate Python to Chinese, whatever that
means.

I'm wondering if all the English keywords in Python
would present too high a barrier for most Chinese
people--def, if, while, for, sys, os, etc.  So you
might need to go even further than simply allowing
identifiers to be written in Simplified-Chinese.





 

Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: example: 40286 -> 68204

2007-06-03 Thread attn . steven . kuo
On Jun 3, 5:23 pm, Shihpin <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> Is there a fuction that reverse the digits of a number?
>
> Many thanks,
>
> Shihpin Lin


One can use int, str and a slice:

print int(str(40286)[::-1])

--
Hope this helps,
Steven

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


Re: can this be implemented?

2007-06-03 Thread Gabriel Genellina
En Sat, 02 Jun 2007 20:54:29 -0300, greenflame <[EMAIL PROTECTED]>  
escribió:

> When I first learned about programming, I started with BASIC, QBASIC
> to  be more accurate. While I was at that stage, I learned about the
> INPUT command. I used it abundantly.
>
> Ok so now for the actual issue.
>
> I would like to implement something like the INPUT command from BASIC.
> I failed to find something on the python website documentation for
> beginners.

This BASIC program:

INPUT "Your name"; z$
PRINT "Hello, "; z$

would be this in Python:

name = raw_input("Your name? ")
print "Hello,", name

raw_input is a built-in function, see  
http://docs.python.org/lib/built-in-funcs.html#l2h-59

-- 
Gabriel Genellina

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


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-03 Thread Ross Ridge
Steve Howell  <[EMAIL PROTECTED]> wrote:
>about Japan:
>major linguistic influences: Chinese, English,
>Dutch

English and Dutch are minor linguistic influences.

>kanji = Chinese characters
>hiragana and katakana -- syllabic scripts
>Latin alphabet often used in modern Japanese (see
>wikipedia)

The Latin alphabet is generally only used for western or westernized
names, like Sony.

>Asia:
>
>   Python should be *completely* internationalized for
>Mandarin, Japanese, and possibly Hindi and Korean. 
>Not just identifiers.  I'm talking the entire
>language, keywords and all.

This would be more convincing if it came from someone who spoke Mandarin,
Japanese, Hindi or Korean.

btw. Mandarin is a spoken dialect Chinese, what you're actually asking
for is a Simplified-Chinese version of Python.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: excel library without COM

2007-06-03 Thread kyosohma
On Jun 3, 7:59 pm, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> is there any library to help me write excel files without using win
> com? because i'll be working on linux platform. At the same time I
> could want to perform some formatting, merging of cells. adding sheets
> and etc ...
>
> Thanks
> james

I'm not aware of any modules. However, this thread is on the same
topic and it mentions using html or txt files as possibilities:

http://mail.python.org/pipermail/python-list/2002-April/138748.html

I would also think that you could write some kind of custom XML parser/
creator that you could use to create the Excel sheet's structure and
then interface with COM later.

Mike

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


Third PyConBrasil takes place in August 2007

2007-06-03 Thread Rodrigo Senra

 We are glad to announce the Third PyConBrasil organised by the
 Brazilian Python Community.

 The event will take place from 2007-08-30 to 2007-09-01 at
 Joinville city in Santa Catarina State (SC) in the
 Brazil's south region. 

 The event home page is http://pyconbrasil.com.br/
 We apologize but the site's content is only available 
 in Brazilian Portuguese Language (pt-br) for the time being.

 The call for speeches is open until 2007-06-30.

 I'd like to thank the python developers and the python community
 in general for outstanding tools, culture and community.

 best regards,
 Rod Senra

 III PyConBrasil 
 http://pyconbrasil.com.br
 [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error message if there is a space in the source directory

2007-06-03 Thread lukefrancomusic
Wow, great!!  That worked like a charm.  Sorry about the excessive
commenting, when looking it over I could see how that would be
annoying.  Thank you Peter!

Luke

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


Re: example: 40286 -> 68204

2007-06-03 Thread Shihpin
Brian,

Thanks! I will try it when I come home,

> > Shihpin Lin
>
> This does it:
>
>  def reversed_int(i):
> > ... return int(''.join(reversed(str(i
> > ...
>  reversed_int(12345)
> > 54321
>
> Best,
>
> Brian vdB


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


Re: c[:]()

2007-06-03 Thread Terry Reedy

"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|| Warren Stringer wanted to call the functions just for the side effects
| without interest in the return values.  So building a list of return
| values which is immediately thrown away is a waste of time and memory.

Also unnecessary: for f in callables: f()

tjr



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


Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell

--- Alex Martelli <[EMAIL PROTECTED]> wrote:
> 
> I blame the
> Babylonians for that
> confusion just as much as for the clunky base-60
> that intrudes in our
> ordinary time reckoning...!
> 

I apologize for helping to start this whole ridiculous
thread, although I hope some people have been
entertained by it.  I have been!




  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


Python, Dutch, English, Chinese, Japanese, etc.

2007-06-03 Thread Steve Howell
The never-ending debate about PEP 3131 got me thinking
about natural languages with respect to Python, and I
have a bunch of mostly simple observations (some
factual, some anecdotal).  I present these mostly as
food for thought, but I do make my own
continent-by-continent recommendations at the bottom
of the email.   (My own linguistic biases are also
disclosed at the bottom of the email.)

Nationality of various technologists who use English
to some degree (keywords in their languages, etc.):

   van Rossum -- Dutch-born, now lives in California
   Wall -- American
   Matz -- Japanese
   Ritchie -- American
   Stroustroup -- Danish-born, lives in Texas
   Gosling -- Canadian
   McCarthy -- American
   Torvalds -- Finnish-born (but family spoke
Swedish), lives in Oregon
   Stallman -- American
   Berners-Lee -- English-born, did major work in
Geneva

A sampling of largish countries where English is
fairly widely known:

   United States (82% of inhabitants speak it at
home), Canada, United Kingdom, Australia, South
Africa, India

about China:
largest country in the world by population
Mandarin Chinese has 850 million speakers
written Chinese dates back 4000 years, employs
5000 characters

about India:

   second largest country in the world by population
   official languages: Hindi, English, and 21 others
   major software outsourcing center (anecdotal)
   Hindi is Indo-European language with distinctively
different alphabet from English

about Japan:
10th largest population
world leader in robotics
Japanese language mostly spoken in Japan
major linguistic influences: Chinese, English,
Dutch
kanji = Chinese characters
hiragana and katakana -- syllabic scripts
Latin alphabet often used in modern Japanese (see
wikipedia)

some European alphabets:

   Spanish -- accented, includes digraphs ch and ll
   German -- accented
   French -- accented
   Italian -- accented, no J/K/W/X/Y

Bringing Python to the world (all opinion here):

   Even in English-speaking countries, Python is
greatly underutilized.

   Even in environments where programmers commonly use
ASCII encoding, Python is greatly underutilized.

   Any focus on the current English/ASCII bias of
Python should mostly concern Asia, due its large
population, the 80/20 rule, the prevalence of
different writing systems in large Asian countries,
Asia's influence on technology in general, etc. (not
to mention Ruby!)

Asia:

   Python should be *completely* internationalized for
Mandarin, Japanese, and possibly Hindi and Korean. 
Not just identifiers.  I'm talking the entire
language, keywords and all.

Europe:

   Lobby EU for more funding for PyPy.  Promote
cultural acceptance of English-ized spelling in the
context of writing software programs.

North America:

   Marketing, marketing, marketing.

South America:

   Focus first on translating Python documents, books,
etc. to Spanish.

Africa:

   write Python code for the XO-1 (aka $100 laptop)

Australia:

   no worries

Antartica:

   more Penguins than people

My linguistic biases:

1) I speak American English natively.
2) I live in a very multilingual city.
3) I took 6 years of French in high school, but I
get very little exposure to the language in my
day-to-day life.
4) I hear a LOT of Spanish in day-to-day life, and
I have first semester literacy.
5) I have never learned Arabic, Mandarin,
Japanese, just to name a few major world languages.
6) I have written software that has been
translated from English to other languages, but I only
once been the primary person to do the actual
internationalization, and it was a small project.
7) Lots of U.S.-based programmers that I have
worked with speak English as their second or third
language.



 






   

Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Joe Salmeri
> Please understand that it is *extremely* tedious to follow your
> messages. It would have been much better if they had been short and
> to the point.

Sometimes it seems that it is impossible to please people.

When messages are short then people complain that they did not get 
sufficient details, or examples.

I provide details and tests so that anyone could easily attempt to duplicate 
exactly what I said was happening and you complain that they are too long.

Baring any typo mistakes on  my part, performing the tests should produce 
the exact results that I stated were happening.

> That is very hard to believe. CVS and backup programs use the UTC time
> stamp, and completely ignore the timezone. So when you agree that the
> UTC time stamp did not change, CVS and the backup programs will work
> just fine.

The CVS problems were mentioned in the article I linked to and were 
discussed by people involved in CVS development.  Whether you choose to 
believe all those people or not is up to you.

See my reply to Terry, from the end user perspective, the Windows behavior 
does not make sense.

Short enough?








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


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Joe Salmeri

> | > You are misinterpreting what you are seeing. Windows is not claiming
> | > that the modification time changes when DST starts. Instead, it is
> | > claiming that the *same* time now has a *different* textual
> | > representation, because the computer now has moved to a different
> | > time zone.
>
> Joe, read the last sentence again.  Most of your reply shows that you have
> missed this basic point.

My reply specifically indicated that I was referring to the textual 
presentation that Windows is showing.

I understand that a DST change and a timezone change produce the same 
results on the offset from GMT but I don't consider them the same thing.

As I attempted to describe the issue with the timestamps changing when DST 
starts/ends is not my *opinion* it is behavior that Microsoft (and others) 
have documented (and I agree with).

Consider this situation from the end user perspective.

I create a file on 01/02/2007 at 07:00 PM

Windows shows the last write time as 01/02/2007 07:00 PM

I never make any changes to the file.

Fast forward in time and it is now 06/03/2007.

When I do a directory on the file Windows now shows the last write time as 
01/02/2007 08:00 PM.

I understand WHY this is happening, but like many others do not agree with 
the behavior.

The reason Windows does this is because although my timeszone did not change 
(as far as I am concerned) DST has started (a timezone change as far as you 
are concerned) so it now shows the time as 1 hour more than it used to 
because the GMT offset has changed.

>From the end user perspective it appears this file has now been modified an 
hour later than it showed it was modifed before DST started.

Now let's look at another common user activity.

I watch this TV show on 01/02/2007 at 07:00 PM.  It comes on every day at 
07:00 PM

Fast forward in time it is now 06/03/2007.

When I watch that same show it comes on at 07:00 PM (even though DST has 
started) and if I look the TV listings it still shows that the older show on 
01/02/2007 came on at 07:00 PM.  It did not show the older show now on as 
08:00 PM which is what Windows is doing with the timestamp.

When you compare those two situations it does not make sense that Windows 
shows a different timestamp.

I would recommend reading the links in the articles where Microsoft 
documents the situation and developers for the CVS project discuss having to 
deal with the problems.

Here's a clip from the article:

This behaviour is responsible for a flood of questions to the 
various support lists for CVS, following the first Sunday in April and the 
last Sunday in October, with
scores of people complaining that CVS now reports erroneously that 
their files have been modified. This is commonly known as the "red file bug" 
because the
WinCVS shell uses red icons to indicate modified files.




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


Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote:

> No, not end-of-story.  Neither of us are being precise enough here.  To
> quote from your second link:
> "Although the radian is a unit of measure, it is a dimensionless
> quantity."
> 
> But NOTE: Radians and degrees *are* units of measure., however those
> units are dimensionless quantities , i.e., not a length or a time etc.

They're both "unit of measure" in some general sense, I suppose, but 
only one is dimensionless.  pi/2 rad = pi/2.  90 deg != 90.  Of the 
plane angles, only radians are dimensionless, and of the solid angles, 
only steradians are dimensionless.  This is because they're defined as 
the ratio of two quantities with similar dimensions (length for radians 
and area for steradians).

> The arguments to sine and cosine must have an associated unit so you
> know whether to interpret sin(1.2) as sine of an angle measured in
> degrees or radians (or whatever else).

The problem with this reasoning is when angular-dimensioned quantities 
pop out of trigonometric functions, which happens routinely in the world 
of calculus.  When that happens, you use radians (or steradians) or 
you're screwed.

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   There never was a good war or a bad peace.
-- Benjamin Franklin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote:

> Of course not!  Angles have units, commonly either degrees or radians.
...
> I don't know of any name for the units of "sqrt of angle", but that
> doesn't invalidate the claim that the value *is* a dimensioned
> quantity.  In lieu of a name, we'd have to label such a quantity as
> "sqrt of degrees" or "sqrt of radians".  After all, we do the same
> thing for measures of area.  We have some units of area like "acre", but
> usually we label areas with units like  "meters squared" or "square
> meters".That's really no stranger than labeling a quantity as "sqrt
> of degrees".

What he (probably) means is that the only proper unit of angle is 
dimensionless, i.e., the radian.  All the rest are different ways of 
measuring things that technically violate rules of dimensional analysis.

In practice, it doesn't much matter, since angles are usually nicely 
stuffed inside trigonometric functions, e.g., r = A sin theta.  The 
problem occurs when, via calculus, angles get pulled out of 
trigonometric substitution.  This can happen via the chain rule easily 
enough.  For the example r(t) = A sin theta(t) with A constant, the 
derivative

v(t) = dr/dt = A (d/dt) sin theta(t) = A dtheta/dt cos theta.

dtheta/dt is the time rate of change of an angle, and since it appears 
outside of a trigonometric function, must be expressed in units of 
radians per unit time or you'll get the wrong answers for v(t).  Using 
alternate units (deg, grad, gon, rev, etc.) for expressing the angle 
here is not an option; you must use radians, which are technically just 
another name for a dimensionless figure.

The radian is defined as the length of the subtended arc divided by the 
length of the radius, which is a length divided by a length, and thus 
dimensionless.  (Like in a lot of dimensional analysis, you write "rad" 
when desired to give a helpful hint, not because it's necessary; the 
radian has the same units as 1.)

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   There never was a good war or a bad peace.
-- Benjamin Franklin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: another thread on Python threading

2007-06-03 Thread Josiah Carlson
[EMAIL PROTECTED] wrote:
> I've recently been working on an application[1] which does quite a bit
> of searching through large data structures and string matching, and I
> was thinking that it would help to put some of this CPU-intensive work
> in another thread, but of course this won't work because of Python's
> GIL.

If you are doing string searching, implement the algorithm in C, and 
call out to the C (remembering to release the GIL).

> There's a lot of past discussion on this, and I want to bring it up
> again because with the work on Python 3000, I think it is worth trying
> to take a look at what can be done to address portions of the problem
> through language changes.

Not going to happen.  All Python 3000 PEPs had a due-date at least a 
month ago (possibly even 2), so you are too late to get *any* 
substantial change in.

> I remember reading (though I can't find it now) one person's attempt
> at true multithreaded programming involved adding a mutex to all
> object access.  The obvious question though is - why don't other true
> multithreaded languages like Java need to lock an object when making
> changes?

 From what I understand, the Java runtime uses fine-grained locking on 
all objects.  You just don't notice it because you don't need to write 
the acquire()/release() calls.  It is done for you.  (in a similar 
fashion to Python's GIL acquisition/release when switching threads) 
They also have a nice little decorator-like thingy (I'm not a Java guy, 
so I don't know the name exactly) called 'synchronize', which locks and 
unlocks the object when accessing it through a method.


  - Josiah



> == Why hasn't __slots__ been successful? ==
> 
> I very rarely see Python code use __slots__.  I think there are
> several reasons for this.  The first is that a lot of programs don't
> need to optimize on this level.  The second is that it's annoying to
> use, because it means you have to type your member variables *another*
> time (in addition to __init__ for example), which feels very un-
> Pythonic.
> 
> == Defining object attributes ==
> 
> In my Python code, one restriction I try to follow is to set all the
> attributes I use for an object in __init__.   You could do this as
> class member variables, but often I want to set them in __init__
> anyways from constructor arguments, so "defining" them in __init__
> means I only type them once, not twice.
> 
> One random idea is to for Python 3000, make the equivalent of
> __slots__ the default, *but* instead gather
> the set of attributes from all member variables set in __init__.  For
> example, if I write:
> 
> class Foo(object):
>   def __init__(self, bar=None):
> self.__baz = 20
> if bar:
>   self.__bar = bar
> else:
>   self.__bar = time.time()
> 
> f = Foo()
> f.otherattr = 40  # this would be an error!  Can't add random
> attributes not defined in __init__
> 
> I would argue that the current Python default of supporting adding
> random attributes is almost never what you really want.  If you *do*
> want to set random attributes, you almost certainly want to be using a
> dictionary or a subclass of one, not an object.  What's nice about the
> current Python is that you don't need to redundantly type things, and
> we should preserve that while still allowing more efficient
> implementation strategies.
> 
> = Limited threading =
> 
> Now, I realize there are a ton of other things the GIL protects other
> than object dictionaries; with true threading you would have to touch
> the importer, the garbage collector, verify all the C extension
> modules, etc.  Obviously non-trivial.  What if as an initial push
> towards real threading, Python had support for "restricted threads".
> Essentially, restricted threads would be limited to a subset of the
> standard library that had been verified for thread safety, would not
> be able to import new modules, etc.
> 
> Something like this:
> 
> def datasearcher(list, queue):
>   for item in list:
> if item.startswith('foo'):
>   queue.put(item)
>   queue.done()
> 
> vals = ['foo', 'bar']
> queue = queue.Queue()
> threading.start_restricted_thread(datasearcher, vals, queue)
> def print_item(item):
>   print item
> queue.set_callback(print_item)
> 
> Making up some API above I know, but the point here is "datasearcher"
> could pretty easily run in a true thread and touch very little of the
> interpreter; only support for atomic reference counting and a
> concurrent garbage collector would be needed.
> 
> Thoughts?
> 
> [1] http://submind.verbum.org/hotwire/wiki
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: monitoring the filesystem for changes

2007-06-03 Thread momobear
> You could use the ReadDirectoryChangesW in overlapped
> mode. I've never tried it, so I don't know how
> robust it would be. Why is it a problem to have
> "multiple programs" running? And is that simply
> multiple threads, or multiple processes?
I used overlapped in my program, it runs about 1 week, seems no
problems now.
FILE_LIST_DIRECTORY = 0x0001
hDir = None

def __init__(self, directory):
self.hDir = win32file.CreateFile (
directory,
self.FILE_LIST_DIRECTORY,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None,
win32con.OPEN_EXISTING,
win32con.FILE_FLAG_BACKUP_SEMANTICS|
win32con.FILE_FLAG_OVERLAPPED,
None
)
but I didn't try use multiple program do the same action. I think only
one thread to do directory monitor is enough. other thread and process
can communicate with it use thread or process communication.

Wang Wei


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


excel library without COM

2007-06-03 Thread james_027
Hi,

is there any library to help me write excel files without using win
com? because i'll be working on linux platform. At the same time I
could want to perform some formatting, merging of cells. adding sheets
and etc ...

Thanks
james

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


Re: Roundup, smtplib, TLS and MS Exchange

2007-06-03 Thread carlistixx
Thanks for your response. I tried modifying the Roundup code as suggested:

class SMTPConnection(smtplib.SMTP):
''' Open an SMTP connection to the mailhost specified in the config
'''
def __init__(self, config):

smtplib.SMTP.__init__(self, config.MAILHOST)
self.set_debuglevel(1)
# start the TLS if requested
if config["MAIL_TLS"]:
self.ehlo()
self.starttls(config["MAIL_TLS_KEYFILE"],
config["MAIL_TLS_CERTFILE"])
self.ehlo()

# ok, now do we also need to log in?
mailuser = config["MAIL_USERNAME"]
if mailuser:
self.login(mailuser, config["MAIL_PASSWORD"])

I've inserted a call to ehlo() before and after the call to
starttls(). Adding the first call to ehlo() does help - I don't get so
many complaints from the server. But it still doesn't work- it seems
like the server stops responding after the call to starttls().

I have not specified a keyfile or certfile in the Roundup
configuration, but as I understand it these are optional, so I presume
this is not causing the problem.

[EMAIL PROTECTED] tracker]$ roundup-server -p 8081
roundup=/home/foobar/roundup/tracker
Roundup server started on :8081
send: 'ehlo moe.foobar.local\r\n'
reply: '250-smtpx15.msoutlookonline.net Hello [202.173.131.223]\r\n'
reply: '250-SIZE 31457280\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-STARTTLS\r\n'
reply: '250-AUTH LOGIN\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250 CHUNKING\r\n'
reply: retcode (250); Msg: smtpx15.msoutlookonline.net Hello [202.173.131.223]
SIZE 31457280
PIPELINING
ENHANCEDSTATUSCODES
STARTTLS
AUTH LOGIN
8BITMIME
BINARYMIME
CHUNKING
send: 'STARTTLS\r\n'
reply: '220 2.0.0 SMTP server ready\r\n'
reply: retcode (220); Msg: 2.0.0 SMTP server ready
send: 'ehlo moe.foobar.local\r\n'
send: 'ehlo moe.foobar.local\r\n'
reply: '250-smtpx15.msoutlookonline.net Hello [202.173.131.223]\r\n'
reply: '250-SIZE 31457280\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-STARTTLS\r\n'
reply: '250-AUTH LOGIN\r\n'
reply: '250-8BITMIME\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250 CHUNKING\r\n'
reply: retcode (250); Msg: smtpx15.msoutlookonline.net Hello [202.173.131.223]
SIZE 31457280
PIPELINING
ENHANCEDSTATUSCODES
STARTTLS
AUTH LOGIN
8BITMIME
BINARYMIME
CHUNKING
send: 'STARTTLS\r\n'
reply: '220 2.0.0 SMTP server ready\r\n'
reply: retcode (220); Msg: 2.0.0 SMTP server ready
send: 'ehlo moe.foobar.local\r\n'
192.168.100.68 - - [04/Jun/2007 10:43:24] "POST /roundup/issue1638
HTTP/1.1" 400 -
EXCEPTION AT Mon Jun  4 10:43:24 2007
Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/roundup/scripts/roundup_server.py",
line 106, in run_cgi
self.inner_run_cgi()
  File "/usr/lib/python2.3/site-packages/roundup/scripts/roundup_server.py",
line 266, in inner_run_cgi
tracker.Client(tracker, self, env).main()
  File "/usr/lib/python2.3/site-packages/roundup/cgi/client.py", line
196, in main
self.inner_main()
  File "/usr/lib/python2.3/site-packages/roundup/cgi/client.py", line
314, in inner_main
self.mailer.exception_message()
  File "/usr/lib/python2.3/site-packages/roundup/mailer.py", line 153,
in exception_message
self.standard_message(to, subject, content)
  File "/usr/lib/python2.3/site-packages/roundup/mailer.py", line 93,
in standard_message
self.smtp_send(to, message)
  File "/usr/lib/python2.3/site-packages/roundup/mailer.py", line 173,
in smtp_send
smtp = SMTPConnection(self.config)
  File "/usr/lib/python2.3/site-packages/roundup/mailer.py", line 194,
in __init__
self.ehlo()
  File "/usr/lib/python2.3/smtplib.py", line 390, in ehlo
(code,msg)=self.getreply()
  File "/usr/lib/python2.3/smtplib.py", line 344, in getreply
line = self.file.readline()
  File "/usr/lib/python2.3/smtplib.py", line 159, in readline
chr = self.sslobj.read(1)
sslerror: The read operation timed out





On 6/1/07, Tijs <[EMAIL PROTECTED]> wrote:
> carlistixx wrote:
>
> > [EMAIL PROTECTED] tracker]$ roundup-server -p 8081
> > roundup=/home/foobar/roundup/tracker
> > Roundup server started on :8081
> > send: 'STARTTLS\r\n'
> > reply: '503 5.5.2 Send hello first\r\n'
> > reply: retcode (503); Msg: 5.5.2 Send hello first
>
> I think this must be an issue with roundup, issuing commands in the wrong
> order. The correct order should (according to the rfc and the python docs)
> be:
> * ehlo()
> * starttls()
> * ehlo()
> * login()
> ...
>
> --
>
> Regards,
> Tijs
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple inheritence for exceptions?

2007-06-03 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote:

> Useful or a bad idea?
> 
> I have a module that defines a number of exceptions which inherit from
> various built-ins like KeyError, ValueError etc. I'm considering defining
> an abstract module exception like MyModuleError, and having all my real
> exceptions inherit from it as well, but I don't recall seeing that done
> before and I was wondering if it were a bad idea for some reason.

I often do exactly what you propose, and I believe I have suggested it
in the Nutshell 2nd edition.  I have never observed bad effects.


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


Re: *Naming Conventions*

2007-06-03 Thread Michael Hoffman
Michael Hoffman wrote:
> Thorsten Kampe wrote:
> 
>> for validanswer in validanswers:
>> if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
>> MyOptions['style'] = validanswer
> 
> I usually try to avoid using "my" because I find it obscures a better 
> understanding of what is really going

...on.

Whoops, sorry about missing the last word of that message.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *Naming Conventions*

2007-06-03 Thread Michael Hoffman
Thorsten Kampe wrote:

> for validanswer in validanswers:
> if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
> MyOptions['style'] = validanswer

I usually try to avoid using "my" because I find it obscures a better 
understanding of what is really going

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


Re: subexpressions (OT: math)

2007-06-03 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> On 3, 22:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> >
> > angle is a ratio of two length and
> >dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_ang
> >les
> >
> > only dimensionless values can be a argument of a sine and exponent!
> > Are you discordant?
> 
> if you are discordant read more :P :
> sine is a dimensionless value.
> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
> etc.
> you can see that sin can be dimensionless only if x is dimensionless
> too.
> 
> I am a professional physicist and a know about what I talk

Lots of people are confused by the concept of "degrees" -- your Taylor
series, of course, intrinsically assumes x is "in radians" (which of
course IS how angles "truly are").  I blame the Babylonians for that
confusion just as much as for the clunky base-60 that intrudes in our
ordinary time reckoning...!


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


Re: int vs long

2007-06-03 Thread Alex Martelli
Paul Rubin  wrote:

> Dan Bishop <[EMAIL PROTECTED]> writes:
> > If you ever do, it's trivial to write your own enumerate():
> > def enumerate(seq):
> > index = 0
> > for item in seq:
> > yield (index, item)
> > index += 1
> 
> That's a heck of a lot slower than the builtin, and if you're running it
> often enough for sys.maxint to be an issue, you may care about the speed.

Perhaps itertools.izip(itertools.count(), seq) might be faster (haven't
timed it, but itertools tends to be quite fast).


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


Re: Check for descriptors (in C)

2007-06-03 Thread Alex Martelli
Gabriel Genellina <[EMAIL PROTECTED]> wrote:

> For most types, there are macros like PyXxxx_Check and
> PyXxxx_CheckExact. But not for descriptors, and I want to test if a
> certain object is a descriptor or not. May I define
> PyMethodDescr_Check, by example, along the lines of similar checks, or
> the fact that they are not already defined implies that they should
> not be tested that way?

"Being a descriptor" == "belonging to a type having a __get__ method",
more or less. There is NO relationship among such types, just a
commonality of methods they make available. Descriptor is a protocol,
common to a family of otherwise unrelated types, not a type. All of the
PyXXX_Check macros are instead based on *types*, not protocols.

> My actual use case: I want to check if an object (instance of a class
> that inherits from file) still uses the original write method or has
> overriden it.

I'd check for identity between type(o).write and file.write -- seems a
more direct expression of that thought (and implementable with the C-API
just as well as with pure Python).


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


Re: example: 40286 -> 68204

2007-06-03 Thread Yongjian Xu

Don't think there is one in builtin for that and might have to convert str
<-> int to do that too, such as int(str(i)[::-1]) ...

Jim

On 6/3/07, Shihpin <[EMAIL PROTECTED]> wrote:


Hi all,

Is there a fuction that reverse the digits of a number?

Many thanks,

Shihpin Lin

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

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

Re: example: 40286 -> 68204

2007-06-03 Thread Brian van den Broek
Shihpin said unto the world upon 06/03/2007 08:23 PM:
> Hi all,
> 
> Is there a fuction that reverse the digits of a number?
> 
> Many thanks,
> 
> Shihpin Lin
> 

This does it:

 def reversed_int(i):
> ... return int(''.join(reversed(str(i
> ... 
 reversed_int(12345)
> 54321
 
> 

Best,

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


Re: subexpressions (OT: math)

2007-06-03 Thread Lloyd Zusman
"Steven D'Aprano" <[EMAIL PROTECTED]> writes:

> On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote:
>
>> if you are discordant read more :P :
>> sine is a dimensionless value.
>> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
>> etc.
>> you can see that sin can be dimensionless only if x is dimensionless
>> too.
>> 
>> I am a professional physicist and a know about what I talk
>
> I am confused why you get different results for the square root of an
> angle depending on whether you use degrees or radians:
>
> sqrt(25°) = 5° = 0.087266462599716474 radians
> sqrt(25*pi/180) = 0.66055454960100179 radians
>
> If angles are dimensionless numbers, then:
>
> degrees_to_radians(sqrt(25°)) 
>
> should equal 
>
> sqrt(degrees_to_radians(25°))
>
> but they don't.

That's because for arbitrary functions f and g, 

  f(g(x)) is not equivalent to g(f(x))

This has nothing to do with whether or not x is a dimensionless number.

(replace "f" with "degrees_to_radians" and "g" with "sqrt")


-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.

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


example: 40286 -> 68204

2007-06-03 Thread Shihpin
Hi all,

Is there a fuction that reverse the digits of a number?

Many thanks,

Shihpin Lin

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


Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
Wildemar Wildenburger wrote:
> Gary Herron wrote:
>   
>> Of course not!  Angles have units, commonly either degrees or radians.
>>
>> However, sines and cosines, being ratios of two lengths, are unit-less.
>>   
>> 
>>> To understand it: sin() can't have dimensioned argument. It is can't
>>> to be - sin(meters)
>>>   
>>> 
>>>   
>> No it's sin(radians) or sin(degrees). 
>>   
>> 
>
> NO!
> The radian is defined as the ratio of an arc of circumfence of a circle 
> to the radius of the circle and is therefore *dimensionless*. End of story.
> http://en.wikipedia.org/wiki/Radian  and esp.
> http://en.wikipedia.org/wiki/Radian#Dimensional_analysis
>
> *grunt*
>   
No, not end-of-story.  Neither of us are being precise enough here.  To
quote from your second link:
"Although the radian is a unit of measure, it is a dimensionless
quantity."

But NOTE: Radians and degrees *are* units of measure., however those
units are dimensionless quantities , i.e., not a length or a time etc.

The arguments to sine and cosine must have an associated unit so you
know whether to interpret sin(1.2) as sine of an angle measured in
degrees or radians (or whatever else).

Gary Herron



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


RE: c[:]()

2007-06-03 Thread Warren Stringer

> Anyway, the code below defines a simple "callable" list; it just calls
> each contained item in turn. Don't bother to use [:], it won't work.
> 
> py> class CallableList(list):
> ...   def __call__(self):
> ... for item in self:
> ...   item()
> ...
> py> def a(): print "a"
> ...
> py> def b(): return 4
> ...
> py> def c(): pass
> ...
> py> def d():
> ...   global z
> ...   z = 1
> ...
> py> z="A"
> py> x = CallableList([a,b,c,d])
> py> x()
> a
> py> z
> 1
 
I just ran this example. I think the class is simpler than Mikael's example:

class CallableList(list):
def __call__(self,*args,**kwargs):
return [f(*args,**kwargs) for f in self]

def a(): return 'a called'
def b(): return 'b called'
c = CallableList([a,b])()

Though Mikael's returns a list containing all the returns of each item,
which comes in handy for some use cases. So, your examples with Mikael's
CallableList, yields a list [None,4,None,None]

Mikael's shows how such a construct could simplify homogenous lists. Yours
shows how it might obfuscate heterogeneous lists. 

Your example is less of an edge condition than ["string", func], as these
are all funcs. It best shows why supporting a general case of c[:]() might
lead to more obscure code.
 
My use case is very homogenous. I am porting a C++ parsed script that
contain 1000's of calls with no return value. So, I'll probably be using a
cross between your version and Mikael's. 

There is another incentive for a callable list. Much of my script has deep
nested namespaces, like a.b.c.d(). In C++, deep nesting is cheap, but in
python, it is expensive because each dot is, in its own right, a function
call to __getattr__. Collecting all the calls into list preprocesses all of
the dots.

Thanks for the example

> I begin to think you are some kind of Eliza experiment with Python
> pseudo-knowledge injected.

BTW, my favorite Eliza implementation of all time is the one written by
Strout, Eppler, and Higgins ... in Python, of course.

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


Re: *Naming Conventions*

2007-06-03 Thread Steve Howell

--- Dan Bishop <[EMAIL PROTECTED]> wrote:
> 
> * Loop indices often have single-letter names
> (typically i/j/k or x/
> y), or names that are the singular form of the list
> name (e.g., "for
> ballot in self._ballots").  For iterating over
> files, I use "line".
>

You are in good company with "i" and "line."  They are
among the 15 most used tokens in the Python standard
library, which includes reserved words if, def,
return, in, not, else, and for.

16610 self
7347 if
5222 def
4686 return
2818 None
2235 in
1799 not
1723 else
1637 name
1499 i
1226 os
1224 line
1203 for
1183 data
1181 path
 
I sampled /usr/local/lib/python2.5 with tokenizer.



   

Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *Naming Conventions*

2007-06-03 Thread Dan Bishop
On Jun 3, 11:03 pm, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> Okay,
>
> I hear you saying 'not another naming conventions thread'. I've read
> through Google and the 'naming conventions' threads were rather
> *spelling conventions* threads.
>
> I'm not interested in camelCase versus camel_case or anything
> mentioned in  'PEP 8 -- Style Guide for Python Code'. What I'm looking
> for is hints or ideas how to name your variables and especially how to
> name functions, methods and classes.

In my code:

* The most common form of a function/method name is verb_noun.  Other
common patterns are adjective_noun, noun_to_noun or noun2noun (for
conversions), and noun_of_noun.

* Classes nearly always have AdjectiveNoun names.

* Loop indices often have single-letter names (typically i/j/k or x/
y), or names that are the singular form of the list name (e.g., "for
ballot in self._ballots").  For iterating over files, I use "line".

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


Re: subexpressions (OT: math)

2007-06-03 Thread Wildemar Wildenburger
Gary Herron wrote:
> Of course not!  Angles have units, commonly either degrees or radians.
>
> However, sines and cosines, being ratios of two lengths, are unit-less.
>   
>> To understand it: sin() can't have dimensioned argument. It is can't
>> to be - sin(meters)
>>   
>> 
> No it's sin(radians) or sin(degrees). 
>   

NO!
The radian is defined as the ratio of an arc of circumfence of a circle 
to the radius of the circle and is therefore *dimensionless*. End of story.
http://en.wikipedia.org/wiki/Radian  and esp.
http://en.wikipedia.org/wiki/Radian#Dimensional_analysis

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


Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote:

> if you are discordant read more :P :
> sine is a dimensionless value.
> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
> etc.
> you can see that sin can be dimensionless only if x is dimensionless
> too.
> 
> I am a professional physicist and a know about what I talk

I am confused why you get different results for the square root of an
angle depending on whether you use degrees or radians:

sqrt(25°) = 5° = 0.087266462599716474 radians
sqrt(25*pi/180) = 0.66055454960100179 radians

If angles are dimensionless numbers, then:

degrees_to_radians(sqrt(25°)) 

should equal 

sqrt(degrees_to_radians(25°))

but they don't.

How do you interpret the square root of an angle? What does it mean?


-- 
Steven.

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


Dict naming, global vs local imports, etc. [was Re: *Naming Conventions*]

2007-06-03 Thread George Sakkis
On Jun 3, 4:32 pm, Steve Howell <[EMAIL PROTECTED]> wrote:

> I also still waste brain cycles on naming
> dictionaries.  Sometimes I name the dictionary after
> the values it stores, sometimes after the keys it
> uses, and sometimes after both.

I was in the same boat but now I've pretty much settled to the
convention `key2value`, e.g.:

name2func = {
  'sum' : sum,
  'avg' : lambda values: sum(values) / float(len(values))
  'product' : lambda values: reduce(operator.mul,values,1),
}

word2positions = {
  'dog' : [3, 45, 79, 840],
  'cat' : [56, 97, 810],
}

At some point I was torn between this and the plural form, i.e.
`keys2values`, but that's ambiguous in cases where each key or value
is a collection, such as the 'positions' above.

While we're at it, although it's not strictly a naming convention
issue I still waste brain cycles on where to put the import statements
that are used only once or twice in a module. Should
(1) all imports be at the global scope at the top of the module, or
(2) be imported in the function or method they are actually used ?

Reasons for (1)
---
- PEP-8 compatible.
- Easy to see all external dependencies in one place.

Reasons for (2)
---
- Point of import closer to point of use; easy to notice if a given
import is not used any more after refactoring.
- Less name pollution.
- Faster name lookup in locals (might make a difference for tight
loops).

I usually go for (1), at least until the number of global imports in
the top remains in single digits. After some point though I often
localize the standard library imports that are used only once or twice
(the third-party and local application imports are almost always
global). Any others that are not strictly PEP-8 compliant on this ?

George

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


Re: *Naming Conventions*

2007-06-03 Thread Ninereeds
On Jun 4, 5:03 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:

> for validanswer in validanswers:
> if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
> MyOptions['style'] = validanswer

First, for small loops with loop variables whose meaning is obvious
from context, the most readable name is usually something like 'i' or
'j'. It avoids unnecessary duplication and clutter. Of course, just as
physically turning your head to look in the rear view mirror is
necessary in a driving test but stupid for real driving, you are
likely to be penalised for this if you do it in an educational setting
or somewhere else where daft coding conventions are strictly enforced
(I once worked in a company that had library constants 'Zero' and
'One' defined because the coding conventions insisted on absolutely no
unnamed 'magic numbers' - spelling the numbers using letters
apparently didn't count).

Second, when naming a member, you should take into account that
references will already be specifying what the whole class describes.
That is, provide new information where possible, and avoid unnecessary
repetition.

Since Python is dynamically typed, it can be useful for names to
describe the datatype of the content at times (though not to the
Hungarian notation extreme that is common is C code, esp. for
Windows). And while most variable names are nouns, sometimes
adjectives are most appropriate - esp where the noun is already clear
from context.

Based on this, your code might become something like...

  for i in validanswers:
if myAnswers.current in myAnswers.validList [i]:
  MyOptions['style'] = i

  'i'
  Its obviously a validanswer since it is one of
  the validanswers.

  'myAnswers.current'
  I know its related to myAnswers, but the
  adjective 'current' tells me more about this
  specific member.

  'myAnswers.validList'
  'valid' on its own is useful extra information,
  but suggests a flag field. validList is better
  since it avoids that confusion.

Depending on what myAnswers.myanswer actually holds, it might
alternately be renamed something like myAnswers.uid or myAnswers.id (a
[unique] identifier code identifying the answer) or myAnswers.text
(the text of the answer).

It is also often useful to use a convention where a prefix identifies
whether a name is a (p)arameter, (l)ocal variable, or (m)ember
variable - no prefix for functions, usually. For example, a simple
setter method may logically use the same name for the parameter
specifying the value to write, the member variable to write to, and
(barring a prefix along the lines of 'Set') the method name.

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


Re: another thread on Python threading

2007-06-03 Thread [EMAIL PROTECTED]
On Jun 3, 5:52 pm, Steve Howell <[EMAIL PROTECTED]> wrote:

> The pitfall here is that to reduce code duplication,
> you might initialize certain variables in a method
> called by __init__, because your object might want to
> return to its initial state.

This is a good point.  I was thinking that this analysis would
occur during module loading; i.e. it would be the equivalent of Java's
classloading.

What if the startup code analysis just extended to methods called
during __init__?
That seems like a relatively straightforward extension.  Remember we
aren't actually *executing*
the startup code in my proposal; we are just analyzing it for all
possible execution paths which cause
a member variable assignment.

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


Re: another thread on Python threading

2007-06-03 Thread Steve Howell

--- "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> One random idea is to for Python 3000, make the
> equivalent of
> __slots__ the default, *but* instead gather
> the set of attributes from all member variables set
> in __init__.  

Are you suggesting to do this at startup time or
runtime?

The pitfall here is that to reduce code duplication,
you might initialize certain variables in a method
called by __init__, because your object might want to
return to its initial state.  An example might be an
object that flipflops between waiting for headers and
waiting for payloads.  You might have code like this:

class MessageReader:
def __init__(self, incoming_port):
self.incoming_port = incoming_port
self.start_waiting_for_headers()

def start_waiting_for_headers(self):
self.waiting_for_headers = ''
self.header = ''
self.payload = ''

def handle_payload(self):
self.do_something_with(self.payload)
self.start_waiting_for_headers()

# ...





   

Looking for a deal? Find great prices on flights and hotels with Yahoo! 
FareChase.
http://farechase.yahoo.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


another thread on Python threading

2007-06-03 Thread [EMAIL PROTECTED]
Hi,

I've recently been working on an application[1] which does quite a bit
of searching through large data structures and string matching, and I
was thinking that it would help to put some of this CPU-intensive work
in another thread, but of course this won't work because of Python's
GIL.

There's a lot of past discussion on this, and I want to bring it up
again because with the work on Python 3000, I think it is worth trying
to take a look at what can be done to address portions of the problem
through language changes.

Also, the recent hardware trend towards multicore processors is
another reason I think it is worth taking a look at the problem again.

= dynamic objects, locking and __slots__ =

I remember reading (though I can't find it now) one person's attempt
at true multithreaded programming involved adding a mutex to all
object access.  The obvious question though is - why don't other true
multithreaded languages like Java need to lock an object when making
changes?  The answer is that they don't support adding random
attributes to objects; in other words, they default to the equivalent
of __slots__.

== Why hasn't __slots__ been successful? ==

I very rarely see Python code use __slots__.  I think there are
several reasons for this.  The first is that a lot of programs don't
need to optimize on this level.  The second is that it's annoying to
use, because it means you have to type your member variables *another*
time (in addition to __init__ for example), which feels very un-
Pythonic.

== Defining object attributes ==

In my Python code, one restriction I try to follow is to set all the
attributes I use for an object in __init__.   You could do this as
class member variables, but often I want to set them in __init__
anyways from constructor arguments, so "defining" them in __init__
means I only type them once, not twice.

One random idea is to for Python 3000, make the equivalent of
__slots__ the default, *but* instead gather
the set of attributes from all member variables set in __init__.  For
example, if I write:

class Foo(object):
  def __init__(self, bar=None):
self.__baz = 20
if bar:
  self.__bar = bar
else:
  self.__bar = time.time()

f = Foo()
f.otherattr = 40  # this would be an error!  Can't add random
attributes not defined in __init__

I would argue that the current Python default of supporting adding
random attributes is almost never what you really want.  If you *do*
want to set random attributes, you almost certainly want to be using a
dictionary or a subclass of one, not an object.  What's nice about the
current Python is that you don't need to redundantly type things, and
we should preserve that while still allowing more efficient
implementation strategies.

= Limited threading =

Now, I realize there are a ton of other things the GIL protects other
than object dictionaries; with true threading you would have to touch
the importer, the garbage collector, verify all the C extension
modules, etc.  Obviously non-trivial.  What if as an initial push
towards real threading, Python had support for "restricted threads".
Essentially, restricted threads would be limited to a subset of the
standard library that had been verified for thread safety, would not
be able to import new modules, etc.

Something like this:

def datasearcher(list, queue):
  for item in list:
if item.startswith('foo'):
  queue.put(item)
  queue.done()

vals = ['foo', 'bar']
queue = queue.Queue()
threading.start_restricted_thread(datasearcher, vals, queue)
def print_item(item):
  print item
queue.set_callback(print_item)

Making up some API above I know, but the point here is "datasearcher"
could pretty easily run in a true thread and touch very little of the
interpreter; only support for atomic reference counting and a
concurrent garbage collector would be needed.

Thoughts?

[1] http://submind.verbum.org/hotwire/wiki

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


Re: Is 1 large Regex faster than 3 smaller ones?

2007-06-03 Thread John Machin
On Jun 4, 4:52 am, erikcw <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to match 3 small strings in a small text file (about 200 words
> of text).
>
> Would it be faster to write 1 compiled regex that matches all 3
> substrings in one go, or to use 3 separate regular expressions to do
> the same job?
>

Taking your question literally: we have no idea how long it might take
you to write alternative versions of source code.

Guessing that you mean "Which would run faster?": both should run over
a 200-word text file in imperceptibly different time (unless of course
you make a mistake), and the time should be tiny compared to the time
required to open the file (again unless of course you make a mistake).

I'd suggest that as a learning exercise you do both, check the
accuracy of both (text e.g. matching only 2 out of 3, sought strings
in different orders, etc), and then and only then worry about the time
it takes.

HTH,
John

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


Re: Is 1 large Regex faster than 3 smaller ones?

2007-06-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 erikcw <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I need to match 3 small strings in a small text file (about 200 words
> of text).
> 
> Would it be faster to write 1 compiled regex that matches all 3
> substrings in one go, or to use 3 separate regular expressions to do
> the same job?
> 
> Thanks!
> Erik

For a classic regex, the answer is one big one.  Matching against a regex 
takes time proportional to the number of characters of input.  One big 
regex will probably consume more memory, and may be slower to compile, but 
it should run faster.

On the other hand, there are a lot of things that pattern maching libraries 
accept these days under the guise of being a "regex" which are not strictly 
regexes in the classic sense.

>From a purely practical point of view, if your input is only 200 words, 
it's likely that the search time will be insignificant no matter what you 
do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
What's the square root of -1 radians? :)




  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


WSGI/wsgiref: modifying output on windows ?

2007-06-03 Thread [EMAIL PROTECTED]
Hi,

I am currently trying to port my web software AFoC 
to Windows and have hit a strange problem: it seams that binary files
(PNG images in this case) get distorted by wsgiref. (I have tried both
the CGIHandler with both Xitami and Apache2 and WSGIServer). My
application is returning a list of one item (the image as a string).
The image is intact at that point. (tested by writing it to disk and
comparing); The client gets a version with a few added \r characters
and something missing at the end, but of the same overall length. Here
are specific examples:

>>> f1 = file('afoc_bak', 'rb')
>>> f2 = file('box_top.png', 'rb')
>>> s1 = f1.read()
>>> s2 = f2.read()
>>> s1 == s2
False
>>> s1
"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR
\x00\x00\x00\x96\x00\x00\x00\x14\x08\x06\x00
\x00\x00oy\xc41\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d
\x88\x00\x00\x00\x19tEX
tSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00\x01\x95IDATh\x81\xed
\xd9?K#A\
[EMAIL PROTECTED])*\xda\xd9(v\xd7+r
\xb6\x82\xef\xc3
[EMAIL PROTECTED]
\x8d1\x9a8\x16\x93\
x80\xc4F]u\x89\xfc>\xcd\xb0\x0fS<\xc5\x8fyfw\x8d\xb5\x16\x91\x8f
\xe6\xa5\xdd\x80
|O\n\x96|\n\x05K>\x85\x01\x06\xd2nB\xda\xc6\xe3\xb3\xb5\x06<\x00Uk\xed}
\xeb\xc6\
x00\xf8\xf1\x85\x8dI{\xab7\xd6f\xb0\xee\x81\xaa1\xa6\x02\x94\xad
\xb5\x95\xe6\xc6
\x00\x9dX\xf2zU\xc0\xc7\x05\xac\xd6x\xbe\x03n\x81\xd8\x18s\x03\\Yk\xeb:
\xb1\xe4-
n\x80\x08\x17\xac\x07\\\xb0n\x812\x90\x05B\xc07\xc6\x94\x82\xf9\xa5\xad
\xb5\xd4\
xda\x94\xb6\xe0y\xbe\x0fP*\xfe?>\xc9\xef\x15J\xc5\x7f\x97\xb81x
\x87\x0bUL#T\xb8{
\xbb5\xab\xeb\x07\xfaB*oR)\x17\xce\x8f\x0e\xb7w\xf3\xc7;\x7f\x81k
\xe0\n(\x01\x97
@\x11\xb8\xf0'g76S\xecQ\xdaP&\xccu\xfc\x1c\\\x98\n\xa3n\xef\xect\xbf
\xd0([\xdc\x
a5\xbe\x0e\xd4\xf4\x1dK\xdem\xf4\xd7\xca\xc2\xc8\xf8\xf24\xd0\x05t
\x02\x1d\xb8\x
b1\x18+X\xf2n\xc6xfbf}\x11\x17\xa8,\xeeb\x1f\x01\xa1\x82%
\x89\xc4\xb9\xfe\x9e\xb
1\xc9?\x11\xee2_\xc7\x8dC\xab`IbC\xc3\xbf\xe7p\xa3\xb0\xf9f\xa8\x7f
\x85\x92\\\x9
4\xed\xedk\xad)X\x92X&\xcc\xf5\xb6\xd6\x14,I,\x08\xe2\x9e\xd6\x9a\x82%
\x89y~&\xf
b\xa2\x96F#\xf2\xfd=\x01\x19c^\xe3KN&\x89\x00\x00\x00\x00IEND\xaeB`
\x82"
>>> s2
"\x89PNG\r\r\n\x1a\r\n\x00\x00\x00\rIHDR
\x00\x00\x00\x96\x00\x00\x00\x14\x08\x06
\x00\x00\x00oy\xc41\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d
\x88\x00\x00\x00\x1
9tEXtSoftware\x00www.inkscape.org\x9b\xee<\x1a\x00\x00\x01\x95IDATh
\x81\xed\xd9?
[EMAIL PROTECTED])*\xda\xd9(v\xd7+r
\xb6\x82\xef
[EMAIL PROTECTED]
\x8d1\x9a8\x16\
x93\x80\xc4F]u\x89\xfc>\xcd\xb0\x0fS<\xc5\x8fyfw\x8d\xb5\x16\x91\x8f
\xe6\xa5\xdd
\x80|O\r\n\x96|\r\n\x05K>\x85\x01\x06\xd2nB\xda\xc6\xe3\xb3\xb5\x06<
\x00Uk\xed}\
xeb\xc6\x00\xf8\xf1\x85\x8dI{\xab7\xd6f\xb0\xee
\x81\xaa1\xa6\x02\x94\xad\xb5\x95
\xe6\xc6\x00\x9dX\xf2zU\xc0\xc7\x05\xac\xd6x\xbe\x03n\x81\xd8\x18s\x03\
\Yk\xeb:\
xb1\xe4-n\x80\x08\x17\xac\x07\\\xb0n\x812\x90\x05B
\xc07\xc6\x94\x82\xf9\xa5\xad\
xb5\xd4\xda\x94\xb6\xe0y\xbe\x0fP*\xfe?>\xc9\xef\x15J\xc5\x7f\x97\xb81x
\x87\x0bU
L#T\xb8{\xbb5\xab\xeb\x07\xfaB*oR)\x17\xce\x8f\x0e\xb7w\xf3\xc7;\x7f
\x81k\xe0\r\
n([EMAIL PROTECTED]'g76S\xecQ\xdaP&\xccu\xfc\x1c\\\x98\r\n\xa3n\xef
\xect\xbf
\xd0([\xdc\xa5\xbe\x0e\xd4\xf4\x1dK\xdem\xf4\xd7\xca
\xc2\xc8\xf8\xf24\xd0\x05t\x
02\x1d\xb8\xb1\x18+X\xf2n\xc6xfbf}\x11\x17\xa8,\xeeb\x1f\x01\xa1\x82%
\x89\xc4\xb
9\xfe\x9e\xb1\xc9?\x11\xee2_\xc7\x8dC\xab`IbC\xc3\xbf\xe7p\xa3\xb0\xf9f
\xa8\x7f\
x85\x92\\\x94\xed\xedk\xad)X\x92X&\xcc\xf5\xb6\xd6\x14,I,\x08\xe2\x9e
\xd6\x9a\x8
2%\x89y~&\xfb\xa2\x96F#\xf2\xfd=\x01\x19c^\xe3KN&
\x89\x00\x00\x00\x00IE"
>>>

a thought that springs to mind is that this may be related to the
barmy DOS relic of binary/ASCII file destinction; however, this should
not be a problem if I understand PEP 333 correctly:

"""The server or gateway should treat the yielded strings as binary
byte sequences: in particular, it should ensure that line endings are
not altered."""

Might this be a bug in wsgiref ? I will hopefully be able to do some
more testing, e.g. with the FLUP FastCGI back-end, in the next few
days.

Kind regards,

Thomas Jollans

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


Re: subexpressions (OT: math)

2007-06-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Leonhard Vogt  <[EMAIL PROTECTED]> wrote:
>>> Yes, I understand that, but what is the geometrical
>>> meaning of the square root of an arc length?  
>> 
>> That's a different question to your original question, which was asking
>> about the square root of an angle.
>> 
>>> And what would the units be?  
>> 
>> Angles are a ratio of two lengths, and are therefore dimensionless units.
>> So the square root of an angle is just another angle, in the same units,
>> and it requires no special geometric interpretation: the square root of 25
>> degrees (just an angle) is 5 degrees (just another angle). 
>
>But sqrt(25°) = sqrt(25/180*pi) = 5*sqrt(180/pi) != 5°
>
>Leonhard

Yes it is; that is, if you're willing to countenance the square root
of an angle at all, then there should be no problem swallowing

sqrt(pi radians / 180) = 1 sqrt(degree)

so that

sqrt(25 degrees) = sqrt(25) * sqrt(pi radians / 180)
 
 = 5 * sqrt(degree)

If it helps, we can call

zilth := sqrt(pi radians / 180)

Measured in square-roots of a degree, a zilth is numerically 1.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: *Naming Conventions*

2007-06-03 Thread Steve Howell

--- Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> 
> for validanswer in validanswers:
> if myAnswers.myanswer in
> myAnswers.validAnswers[validanswer]:
> MyOptions['style'] = validanswer
> 

I can at least sympathize with your problem, although
I don't have a great solution for you.  I often have
trios of variables like this:

   answer_dct
   answers
   answer

English mostly pluralizes with an "s," but I sometimes
resort to bad English to keep the convention going:

   mouse_dct
   mouses (not mice)
   mouse

I also still waste brain cycles on naming
dictionaries.  Sometimes I name the dictionary after
the values it stores, sometimes after the keys it
uses, and sometimes after both.




  

Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: *Naming Conventions*

2007-06-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Thorsten Kampe wrote:

> Recently I wrote this code and noticed that I was completely lost in 
> giving these objects names to describe and distinguish them:
> 
> for validanswer in validanswers:
> if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
> MyOptions['style'] = validanswer

Wow, I know you don't want to talk about "spelling conventions" but here
you are mixing many of them.  :-)

I don't know if it makes sense for your code, but maybe you can move the
``if`` condition into the class of `myAnswer` as overloaded ``in``
operator.  Then this can be written as:

for valid_answer in valid_answers:
if valid_answer in my_answers:
my_options['style'] = valid_answer

> The 'tips' I got through some postings or articles on the net are: if 
> a function simply tests something and returns a boolean call it
> 
> def is_():
>  pass

The other typical boolean test prefix is 'has_'.

> like 'is_even'.
> 
> Makes sense. The other thing I captured was to use something like
> 
> def get_values():
> 
> ... Makes sense, too, but aren't all functions getting something?

So you may reduce this to just `values()`.  On the other hand there is the
convention to name functions and methods as verbs that are "doing"
something.

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


Re: c[:]()

2007-06-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
>>> [using `map()`]
>> And has the same issue as a list comprehension if all you want is the side
>> effect of the calls: a useless temporary list full of `None`\s is build.
> 
> functoins can return a values, and you get it. I don't think that it
> is bad side effect.

I don't either.  By definition it's not a side effect at all. Side effects
are the "things that happen" besides the return values.

Warren Stringer wanted to call the functions just for the side effects
without interest in the return values.  So building a list of return
values which is immediately thrown away is a waste of time and memory.

> When you write simple
 def a(): print "From Russia with love."
 a()
> you have side effect too - returning "None".

No, the side effect is the printing of 'From Russia with love.'

IMHO there's a difference between this single `None` that can't be
prevented and abusing a list comprehension or `map()` just for side
effects and not for building a list with meaningful content.

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


*Naming Conventions*

2007-06-03 Thread Thorsten Kampe
Okay,

I hear you saying 'not another naming conventions thread'. I've read 
through Google and the 'naming conventions' threads were rather 
*spelling conventions* threads.

I'm not interested in camelCase versus camel_case or anything 
mentioned in  'PEP 8 -- Style Guide for Python Code'. What I'm looking 
for is hints or ideas how to name your variables and especially how to 
name functions, methods and classes.

I know this depends on what the function is doing. If I know what it 
is doing I should be able to give them a desciptive name. But actually 
I'm often not able. Especially when the task is quite similar to 
another function or Class.

Recently I wrote this code and noticed that I was completely lost in 
giving these objects names to describe and distinguish them:

for validanswer in validanswers:
if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
MyOptions['style'] = validanswer

The 'tips' I got through some postings or articles on the net are: if 
a function simply tests something and returns a boolean call it

def is_():
 pass

like 'is_even'.

Makes sense. The other thing I captured was to use something like

def get_values():

... Makes sense, too, but aren't all functions getting something?

So if someone had a similar dilemma to mine and could tell me how he 
dealt with that, I'd be grateful...


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


Re: how can I get the name of a method inside it?

2007-06-03 Thread Alex Martelli
"Sébastien Vincent"  wrote:

> I would like to know if it's possible to retrieve the name of a method when
> you're inside it. For example, in the following script, I would like to
> assign _s so that it prints "you are in method1".
> 
> 
> ***
> class Obj1:
> def __init__(self):
> ...
> 
> def method1(self):
> _s = ???
> print "you are in %s" % _s

For debugging purposes,

  _s = sys._getframe(0).f_code.co_name

should work (after you've done an "import sys" somewhere appropriate, of
course;-).  The _ in front of _getframe, as well as the klunkiness of it
all, are all indications that this is _not_ recommended for "production
use" -- like most of Python's introspection features, it IS chiefly
meant for debugging purposes.


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


Re: how can I get the name of a method inside it?

2007-06-03 Thread montyphyton
> I would like to know if it's possible to retrieve the name of a method when
> you're inside it. For example, in the following script, I would like to
> assign _s so that it prints "you are in method1".
>
>
> ***
> class Obj1:
> def __init__(self):
> ...
>
> def method1(self):
> _s = ???
> print "you are in %s" % _s
>
> x = Obj1()
> x.method1()

i'm no expert on the subject, but AFAIK, there's no way to do this.
why not just print "you are in method1"?
what are you exactly trying to do?

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


Re: Detecting an active exception

2007-06-03 Thread Nick Craig-Wood
NeBlackCat <[EMAIL PROTECTED]> wrote:
>  I've now also looked at this from a traceback and stack frame walking 
>  perspective as well and it seems impossible, ie. it see,s impossible to 
>  create a function AmIHandlingAnException() which would behave as follows:
> 
>try:
>a=a+1
>except:
>pass
> 
>try:
>AmIHandlingAnException()# returns FALSE
>b = b + 1
>except:
>AmIHandlingAnException()# returns TRUE
>try:
>AmIHandlingAnException()# returns TRUE
>except:
>pass
>
>AmIHandlingAnException()# returns FALSE
>
>  The only way I can see to do it is to use something like the 'inspect' 
>  module to walk up the stack and, for each frame, walk lines of code 
>  backwards to determine whether or not you're in an except: block. Of 
>  course that would be horribly inefficient.
> 
>  I'm rather stunned by this (this was the 'easy' bit that I left to 
>  last!).

Why don't you tell us what you are actually trying to achieve and we
can see if we can come up with a more pythonic solution?  The fact
that you are running into limits of the language like this as a new
python programmer probably means you aren't thinking in python yet.

-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


how can I get the name of a method inside it?

2007-06-03 Thread \"S�bastien Vincent\"
I would like to know if it's possible to retrieve the name of a method when 
you're inside it. For example, in the following script, I would like to 
assign _s so that it prints "you are in method1".


***
class Obj1:
def __init__(self):
...

def method1(self):
_s = ???
print "you are in %s" % _s

x = Obj1()
x.method1() 


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


Re: monitoring the filesystem for changes

2007-06-03 Thread Tim Golden
rohit wrote:
> hello
> well in my implementation of readdirectorychangesw i am using
> threading that is multiple programs run simultaneously each program
> monitoring one drive for changes.
> is their a way around this...one program for all drives?
> thanks

You could use the ReadDirectoryChangesW in overlapped
mode. I've never tried it, so I don't know how
robust it would be. Why is it a problem to have
"multiple programs" running? And is that simply
multiple threads, or multiple processes?

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


MoinMoin configuration

2007-06-03 Thread kyosohma
Hi,

I am working on a new site about Python to help document some of the
modules that don't have much for documentation. Anyway, I chose to use
MoinMoin because it has very easy-to-use code display with line
numbers that toggle on and off.

The question I have is how do I configure MoinMoin to force users to
login before making changes and still allow the user to choose if he/
she wants to sign the edit or not? It looks like Python.org has that
kind of thing in place.

I have read through the ACL instructions on MoinMoin's site, but I
don't understand how to make it work. See 
http://moinmoin.wikiwikiweb.de/HelpOnAccessControlLists

To me it seems to be saying that you have to create a page before you
can set the ACL for it. I don't want a bunch of pages where some have
ACL's and some don't.

If you can clear up my confusion, that would be great. Thanks!

Mike

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


Re: iterblocks cookbook example

2007-06-03 Thread Steve Howell
--- Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> ISTM, this is a common mailing list problem because
> it is fun
> to solve, not because people actually need it on a
> day-to-day basis.
>

It comes up in the real world for me once very couple
months or so.  It's usually when I need to manipulate
data, but I also use the technique to write quick and
dirty tools to analyze code.
 
> In that spirit, it would be fun to compare several
> different
> approaches to the same problem using re.finditer,
> itertools.groupby,
> or the tokenize module.  To get the ball rolling,
> here is one variant:
> 
> from itertools import groupby
> 
> def blocks(s, start, end):
> def classify(c, ingroup=[0], delim={start:2,
> end:3}):
> result = delim.get(c, ingroup[0])
> ingroup[0] = result in (1, 2)
> return result
> return [tuple(g) for k, g in groupby(s,
> classify) if k == 1]
> 

Neat.  I like the way you persist ingroup[0] from call
to call.

 
> One observation is that groupby() is an enormously
> flexible tool.
> Given a well crafted key= function, it makes short
> work of almost
> any data partitioning problem.
> 

Definitely.



   

Be a better Heartthrob. Get better relationship answers from someone who knows. 
Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: monitoring the filesystem for changes

2007-06-03 Thread rohit
hello
well in my implementation of readdirectorychangesw i am using
threading that is multiple programs run simultaneously each program
monitoring one drive for changes.
is their a way around this...one program for all drives?
thanks
rohit

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


Is 1 large Regex faster than 3 smaller ones?

2007-06-03 Thread erikcw
Hi,

I need to match 3 small strings in a small text file (about 200 words
of text).

Would it be faster to write 1 compiled regex that matches all 3
substrings in one go, or to use 3 separate regular expressions to do
the same job?

Thanks!
Erik

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


Re: int vs long

2007-06-03 Thread Paul Rubin
Dan Bishop <[EMAIL PROTECTED]> writes:
> If you ever do, it's trivial to write your own enumerate():
> def enumerate(seq):
> index = 0
> for item in seq:
> yield (index, item)
> index += 1

That's a heck of a lot slower than the builtin, and if you're running it
often enough for sys.maxint to be an issue, you may care about the speed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: int vs long

2007-06-03 Thread Dan Bishop
On Jun 2, 11:55 pm, kaens <[EMAIL PROTECTED]> wrote:
> On 02 Jun 2007 20:18:02 -0700, Paul Rubin
>
> <"http://phr.cx"@nospam.invalid> wrote:
> > Dan Bishop <[EMAIL PROTECTED]> writes:
> > > Note that recent versions of Python automatically promote the results
> > > of integer arithmetic to long if necessary, so the distinction is less
> > > relevant than it used to be.
>
> > Note however that even in recent versions, there are still parts of
> > Python that get stuck at sys.maxint, for example the enumerate function.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> I didn't know that - I'll keep it in mind though. I can imagine that
> causing some pretty nasty annoyances if you ran into it unexpectedly

If you ever do, it's trivial to write your own enumerate():

def enumerate(seq):
index = 0
for item in seq:
yield (index, item)
index += 1

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


Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 22:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> angle is a ratio of two length and 
> dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_angles
>
> only dimensionless values can be a argument of a sine and exponent!
> Are you discordant?

if you are discordant read more :P :
sine is a dimensionless value.
if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120
etc.
you can see that sin can be dimensionless only if x is dimensionless
too.

I am a professional physicist and a know about what I talk

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


Check for descriptors (in C)

2007-06-03 Thread Gabriel Genellina
For most types, there are macros like PyXxxx_Check and
PyXxxx_CheckExact. But not for descriptors, and I want to test if a
certain object is a descriptor or not. May I define
PyMethodDescr_Check, by example, along the lines of similar checks, or
the fact that they are not already defined implies that they should
not be tested that way?

My actual use case: I want to check if an object (instance of a class
that inherits from file) still uses the original write method or has
overriden it.

--
Gabriel Genellina

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


Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 21:43, Gary Herron <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
> > angle is dimensionless unit.
>
> Of course not!  Angles have units, commonly either degrees or radians.
>
> However, sines and cosines, being ratios of two lengths, are unit-less.> To 
> understand it: sin() can't have dimensioned argument. It is can't
> > to be - sin(meters)
>
> No it's sin(radians) or sin(degrees).> it is difficult to invent what is a 
> "sqrt from a angle" but it can be.
>
> I don't know of any name for the units of "sqrt of angle", but that
> doesn't invalidate the claim that the value *is* a dimensioned
> quantity.  In lieu of a name, we'd have to label such a quantity as
> "sqrt of degrees" or "sqrt of radians".  After all, we do the same
> thing for measures of area.  We have some units of area like "acre", but
> usually we label areas with units like  "meters squared" or "square
> meters".That's really no stranger than labeling a quantity as "sqrt
> of degrees".
>
> Gary Herron, PhD.
> Department of Computer Science
> DigiPen Institute of Technology

angle is a ratio of two length and dimensionless.
http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_angles


only dimensionless values can be a argument of a sine and exponent!
Are you discordant?

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


Re: Cookie: Not understanding again

2007-06-03 Thread mosscliffe
On 2 Jun, 11:50, David Wahler <[EMAIL PROTECTED]> wrote:
> On Jun 2, 9:32 am, mosscliffe <[EMAIL PROTECTED]> wrote:
>
> > David,
>
> > Thanks for your help.
>
> > I spent all last night trying to get it to work, but I can not work
> > out how to force mycookieinto the response header.  The most
> > annoying part is on one occasion it did and thecookiesat there until
> > I killed the session.  By the time I discovered 'pageinfo' add-in for
> > firefox, thecookiehad gone.
>
> Your CGI script needs to produce output of the form:
>
> Header-1: ...
> Header-2: ...
>
> response data goes here...
>
> Each line before the blank line is an HTTP header. To send cookies to
> the browser, you need to generate a header of the form:
>
> Set-Cookie: name=value
>
> Printing the SimpleCookie object does this for you.
>
> > I have read a lot about cookies, but the grey matter is very slow at
> > absorbing nowadays.  I was wondering if I should add the 'path=/' to
> > mycookie, as I am using a host that has numbers for the IP address
> > and my domain name when used, is via a frame.  Although the python bit
> > to display the contents (when it did work), did not show any value for
> > 'path'.
>
> If you specify a path attribute, then the browser will only send thecookieon 
> requests that begin with that path. If you don't, it
> defaults to the URL of the page that generates thecookie. For a
> single test script like this, there's no need to bother with it, but
> you can set it like this:
>
> >>>cookie["someCookieName"]["path"] = "/path/to/whatever"
> > Could I create the response header in python and get it executed as
> > part of my form submission ?
>
> > Obviously, still struggling.
>
> Here's a simple, complete example to get you started, based loosely on
> your original code:
>
> ##
>
> importCookie, os
> import cgitb; cgitb.enable()
>
> def getCookie():
> c =Cookie.SimpleCookie()
> if 'HTTP_COOKIE' in os.environ:
> c.load(os.environ['HTTP_COOKIE'])
>
> if os.environ['QUERY_STRING'] == 'reset' or 'mysession' not in c:
> c['mysession'] = 0
> else:
> c['mysession'] = int(c['mysession'].value) + 1
>
> return c
>
> if __name__ == '__main__':
>
> print "Content-type: text/html"
> myCookie = getCookie()
> print myCookie
>
> if os.environ['QUERY_STRING'] == 'reset':
> print "Status: 302 Moved"
> print "Location:", os.environ['SCRIPT_NAME']
> print
> else:
> print
> print 'Current Value: ', myCookie['mysession'].value
> print 'Reset Counter'
>
> ##
>
> Hope this helps!
>
> -- David

David,

Thank you very much for your detailed reply.  As soon as I get a
chance to try it all out, I will let you know how I get on.

Thanks again

Richard

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


Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
[EMAIL PROTECTED] wrote:
> On 3, 14:05, Steven D'Aprano <[EMAIL PROTECTED]>
> wrote:
>   
>> On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote:
>> 
 bla-bla
 
>> Hmmm... perhaps that's why the author of the "units" program doesn't
>> treat angles as dimensionless when taking square roots.
>>
>> Given that, I withdraw my claim that the sqrt of an angle is just an
>> angle. I can't quite see why it shouldn't be, but the evidence is fairly
>> solid that it isn't.
>>
>> --
>> Steven
>> 
>
> angle is dimensionless unit.
>   
Of course not!  Angles have units, commonly either degrees or radians.

However, sines and cosines, being ratios of two lengths, are unit-less.
> To understand it: sin() can't have dimensioned argument. It is can't
> to be - sin(meters)
>   
No it's sin(radians) or sin(degrees). 
> it is difficult to invent what is a "sqrt from a angle" but it can be.
>   
I don't know of any name for the units of "sqrt of angle", but that
doesn't invalidate the claim that the value *is* a dimensioned
quantity.  In lieu of a name, we'd have to label such a quantity as
"sqrt of degrees" or "sqrt of radians".  After all, we do the same
thing for measures of area.  We have some units of area like "acre", but
usually we label areas with units like  "meters squared" or "square
meters".That's really no stranger than labeling a quantity as "sqrt
of degrees".

Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology



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


Re: int vs long

2007-06-03 Thread jay
Hi Dan, Paul, and Kaens,

Thanks  very much for replying to my question.  I appreciate you all  
taking the time to answer this for me!

Jay


> On 02 Jun 2007 20:18:02 -0700, Paul Rubin
> <"http://phr.cx"@nospam.invalid> wrote:
>> Dan Bishop <[EMAIL PROTECTED]> writes:
>> > Note that recent versions of Python automatically promote the  
>> results
>> > of integer arithmetic to long if necessary, so the distinction  
>> is less
>> > relevant than it used to be.
>>
>> Note however that even in recent versions, there are still parts of
>> Python that get stuck at sys.maxint, for example the enumerate  
>> function.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> I didn't know that - I'll keep it in mind though. I can imagine that
> causing some pretty nasty annoyances if you ran into it unexpectedly

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


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Martin v. Löwis
> It appears that you may have missed part of my tests.  Sorry it was such a 
> long reply but I was trying to provide a lot of detail so that others had a 
> clear understanding of what was going on.

Please understand that it is *extremely* tedious to follow your
messages. It would have been much better if they had been short and
to the point.

> Changing the timezone will defintely change the "textual representation" of 
> all timestamps just as you say (even though the actual UTC value has *not* 
> changed), however, when DST starts/ends the "textual representation" of the 
> timestamps on some files WILL ALSO CHANGE when the automatically adjust for 
> DST setting is turned on.

Right, and that's because switching to DST means that YOU MOVE TO A
DIFFERENT TIME ZONE.

EST != EDT.

> While it is true that I did change the timezone in the first part of the 
> test (to establish the baseline), in the second part of the tests where the 
> difference you are referring to occured, the timezone was *not* changed, the 
> only thng that occured was that DST started.

And that meant that the time zone *did* change.

> When the date progressed to a point after DST had started Windows now 
> reports the timestamp on that *unmodified* file now is 01/01/2007 08:00 PM.
> 
> I did not change the timezone, the only thing that occurred was DST started.

So you did change the timezone.

> Over the years this issue has caused all sorts of problems for backup 
> programs and CVS (greatly detailed in the article I provided the link for).

That is very hard to believe. CVS and backup programs use the UTC time
stamp, and completely ignore the timezone. So when you agree that the
UTC time stamp did not change, CVS and the backup programs will work
just fine.

There was a long-standing problem with changing time-stamps ON FAT.
On a FAT file system, the actual UTC time stamps change when the
timezone changes (including the change to and from DST). *That*
was a big problem for backup programs and CVS, and is now fixed
with NTFS.

> You mixed up my tests, in that case as shown above the timezone did *not* 
> change, the only thing that changed was that DST started and the file was 
> created during a time when DST was not in effect.

Right, so the timezone did change.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Terry Reedy

"Joe Salmeri" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| ""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message
| news:[EMAIL PROTECTED]
| >> The short explaination of this issue is that the timestamp shown when
| >> you do a dir on a file that is on an NTFS volume changes by an hour
| >> when DST starts and also when DST ends, even though the file has NOT
| >> been modified!!!  Note that this only happens if you have the setting
| >> turned on to automatically adjust for DST (this is the default in
| >> Windows).
| >
| > You are misinterpreting what you are seeing. Windows is not claiming
| > that the modification time changes when DST starts. Instead, it is
| > claiming that the *same* time now has a *different* textual
| > representation, because the computer now has moved to a different
| > time zone.

Joe, read the last sentence again.  Most of your reply shows that you have 
missed this basic point.

A 'time zone', as far as the math (and Windows) is concerned, *IS* an 
offset from GMT.The shift from 'standard' to 'daylight' time is a 
one-hour change in the offset.  That has the same effect as moving to the 
standard time zone one hour to the east.  So Eastern Daylight Time is the 
same as Atlantic Standard Time (or whatever Canadians call the next zone 
for their maritime provinces).  Similarly, 'Central Daylight Time' is an 
alias for 'Eastern Standard Time'.  CDT and EST both translate to -5 (I 
believe) in Windows timezone lookup dictionary.  Because there are multiple 
names and abbreviations for most or all timezones, Windows has to 
separately keep track of which one the user expects to see.

[In my opinion, the Congressional mandate that we pretend to live somewhere 
to the east for over half the year is as arrogant and stupid as would be a 
mandate that we use 'adjusted Fahrenheit' (F - 10 degrees) during the 
summer so that temperatures 'seemed' lower. ;-]

| > When you explicitly change the time zone of your computer, you will
| > notice that all file time stamps immediately change also.

What Martin meant, of course, is the presented text representation thereof.

| It appears that you may have missed part of my tests.  Sorry it was such 
a
| long reply but I was trying to provide a lot of detail so that others had 
a
| clear understanding of what was going on.
|
| I understand that the actual UTC time value for the file has *not* 
changed.
|
| That local textual representation of the modification timestamp is what
| people and programs look at and work with and is what is displayed by the
| dir command and what Explorer displays.

And without a timezone attached, that 'local representation' is as 
ambiguous as any measurement without units.  Is 45 hot or cool?

| Changing the timezone will defintely change the "textual representation" 
of
| all timestamps just as you say (even though the actual UTC value has 
*not*
| changed), however, when DST starts/ends the "textual representation" of 
the
| timestamps on some files WILL ALSO CHANGE when the automatically adjust 
for
| DST setting is turned on.

To repeat, turning DST on *IS* a timezone change.  So you are talking about 
the *same* thing.

| In the following comments I am referring to the textual representation of
| the timestamp that the user is working with (I understand that the 
interal
| UTC timestamp for the file has *not* changed).
|
| The issue occurs when the timestamp for the file is in a period when DST 
was
| not in effect and DST is in effect for the current time OR when the
| timestamp for the file is in a period when DST was in effect and DST is 
not
| in effect for the current time.

Because the timezones change.  Geographically, UTC+X is the area where the 
relevant authorities mandate that clocks be set to offset X from UTC.  When 
the clocks jump, those areas jump!  In the US, at least, the UTC-6 area, 
for instance, jumps from where it was to what was previously the UTC-7 
area.  This spring, when there were different jump dates around the world, 
the overall configuration of zones (which areas had the same time) changed. 
Yes, a mess

| While it is true that I did change the timezone in the first part of the
| test (to establish the baseline), in the second part of the tests where 
the
| difference you are referring to occured, the timezone was *not* changed, 
the
| only thng that occured was that DST started.

Which *is* a timezone change.

| In that test the file had a timestamp of 01/01/2007 07:00 PM as shown by 
the
| dir command results.

As Martin said, that is not a timestamp.  It is an information-stripped 
representation thereof.

| When the date progressed to a point after DST had started Windows now
| reports the timestamp on that *unmodified* file now is 01/01/2007 08:00 
PM.

Because Windows changed the timezone offset by one hour.  Again, not a 
timestamp but an alternate info-deleted representation thereof.

| I did not change the timezone, the only thing that occurred was

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 14:05, Steven D'Aprano <[EMAIL PROTECTED]>
wrote:
> On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote:
> >> bla-bla
>
> Hmmm... perhaps that's why the author of the "units" program doesn't
> treat angles as dimensionless when taking square roots.
>
> Given that, I withdraw my claim that the sqrt of an angle is just an
> angle. I can't quite see why it shouldn't be, but the evidence is fairly
> solid that it isn't.
>
> --
> Steven

angle is dimensionless unit.
To understand it: sin() can't have dimensioned argument. It is can't
to be - sin(meters)

it is difficult to invent what is a "sqrt from a angle" but it can be.

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


Re: getting rid of leading zeros in float expotential

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 11:47, [EMAIL PROTECTED] wrote:
> Hi! I'm wondering whether there's an easy way to remove unnecessary
> leading zeros from my floating point number.
>
> realS = float(-1.25e-5)
> imgS = float(-7.6e4)
>
> print complex(realS, imgS)
>
>  >> (-1.25e-005-76000j)
>
> I would like it to look like (-1.25e-5-76000j)

why?
For printing?
try to process it as a string

>>>def my_func(a):
   return my_del_zeros_func(str(a))

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


Re: Why Python?

2007-06-03 Thread Arsham Shirvani





What is it about Python that makes it such a suitable language for 
you?  For instance, why would you use it over something similarly 
portable as Java, or PHP?


I know personally, in my small exposure to Python, I can see it as a 
great learning tool for a basic introduction to programming and even 
OOP.  It's wonderful how your .py file can simply start making 
expressions without any overhead, import/using statements, class 
declarations, etc.


--
Chris Stewart
[EMAIL PROTECTED] 
http://www.compiledmonkey.com 

For me is its simplicity and usability
Python forces you to write clean codes
There are a lot of modules available in web-wide that you can use

IMO Python is a powerful language and a fast-develop one.

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

Python 2.5 and stdin

2007-06-03 Thread hg
Hi,

I have upgraded to 2.5 and one of my program no longre functions:

In a thread run function, I attempts to get a "raw_input('')" and get the
error
***
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 460, in __bootstrap
self.run()
  File "/usr/local/games/RealTimeBattle/Robots/pyrobot.py", line 89, in run
l_res = raw_input('')
IOError: [Errno 11] Resource temporarily unavailable
***

The full source code is here: http://snakecard.com/rtb/


Any clue ?

Thanks,

hg




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


Re: Python rocks

2007-06-03 Thread George Sakkis
On Jun 2, 4:58 pm, [EMAIL PROTECTED] (Aahz) wrote:

> In article <[EMAIL PROTECTED]>,
> George Sakkis  <[EMAIL PROTECTED]> wrote:
>
>
>
> >I had probably stumbled on many/most of the common pitfalls usually
> >mentioned (e.g.http://www.ferg.org/projects/python_gotchas.html,
> >http://zephyrfalcon.org/labs/python_pitfalls.html) while learning, but
> >picked them up easily after the first or second time. Off the top of
> >my head, two errors that keep coming back even years after are:
> >- Comparing instances of (semantically) incomparable types (http://
> >www.ibm.com/developerworks/library/l-python-elegance-1.html).
> >Thankfully this will be fixed in Py3k.
> >- Strings being iterable; unfortunately this will stay in Py3K.
>
> I'll repeat the comment I made on python-3000:
>
> "...string iteration isn't about treating strings as sequences of
> strings, it's about treating strings as sequences of characters.  The
> fact that characters are also strings is the reason we have problems,
> but characters are strings for other good reasons."

No, the reason we have problems is that far more often than not
strings are treated as atomic values, not sequences of smaller strings
or characters. A classic example is flatten(), where most people are
surprised if flatten([1, (3.14, 'hello')]) returns [1, 3.14, 'h', 'e',
'l', 'l', 'o'].

> Thing is, the fact that you can e.g. slice strings just like other
> sequence types creates the consequence that you can also iterate over
> strings -- moreover, some of us actually do iterate over strings (though
> of course we could if necessary create lists/tuples of characters).  In
> the grand scheme of things, I rarely see people running into problems
> with iterating over strings.

One class of problems is functions such as flatten() that expect "a
collection or an atom", with strings being typically considered
atomic. A second common pitfall are functions that expect file-like
objects but are given file names instead:

def process_file(input_file):
for line in input_file:
do_stuff(line)


process_file('/home/george/.bashrc')  # oops

I now try to remember to write such functions as:

def process_file(input_file):
if isinstance(input_file, basestring):
input_file = open(input_file)
for line in input_file:
...

It's not a huge impediment by any means but it's certainly a gotcha.

George

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


Re: Why Python?

2007-06-03 Thread Mohammad Tayseer
Why you should use Python
http://spellcoder.com/blogs/tayseer/archive/2007/04/08/why_you_should_use_python.aspx

Chris Stewart <[EMAIL PROTECTED]> wrote: What is it about Python that makes it 
such a suitable language for you?  For instance, why would you use it over 
something similarly portable as Java, or PHP?

I know personally, in my small exposure to Python, I can see it as a great 
learning tool for a basic introduction to programming and even OOP.  It's 
wonderful how your .py file can simply start making expressions without any 
overhead, import/using statements, class declarations, etc. 

-- 
Chris Stewart
[EMAIL PROTECTED]
http://www.compiledmonkey.com -- 
http://mail.python.org/mailman/listinfo/python-list


Mohammad Tayseer
http://spellcoder.com/blogs/tayseer

  
-
Park yourself in front of a world of choices in alternative vehicles.
Visit the Yahoo! Auto Green Center.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python rocks

2007-06-03 Thread Alex Martelli
Mark Carter <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > Mark Carter <[EMAIL PROTECTED]> wrote:
> 
> > Yes, GMP is a pain to compile (especially on Mac OS X), but I believe
> 
> > Just mentioning this in case you want to give Scheme another chance
> 
> Thanks. I'll take a look at it.

You're welcome.

> I think I've decided to finish off my little in project in Python first,
> though. I'd like to actually get it done (!). I may well decide to 
> reimplement bits in either Scheme, or I might try my hand at Forth. My
> app will be small enough to permit re-writes.

Excellent situation to play around with many languages, then.  If your
app can run on dotNET or Mono, you might also want to try Boo, a
language somewhat inspired by Python but with a different approach to
typing (based on type-inferencing, with an explicit 'duck' type for
those rare cases in which you really _want_ a single variable to take on
values of heterogeneous types during execution).

> I had actually done a small 3-month Java project professionally about 7
> years ago. Can't say I was too impressed. IMO, it was too verbose, I'm
> not an OO fanatic, and some immutable strings turned out to be not quite
> as immutable as I expected.

Nolo contendere on the verbosity and the need to stuff _every_thing into
a class,  but the non-immutable-strings looks like a serious bug in
whatever JVM you were using at the time.  Anyway, what's impressive with
Java today is not the language (maybe a bit better than it was 7 years
ago but still substantially Java:-), it's the array of excellent tools,
libraries and frameworks grown around it; Java's standard library has
arguably surpassed Python's, and third-party offerings for Java are
really great.

 
> I had a brief toy around with Java using Xcode very recently, and I was

Not the best IDE for Java, btw -- Apple doesn't seem to like Java all
that much any more, and it looks to me like it's backpedaling on Java's
integration in MacOSX (in favor of Python, Ruby, etc).  BTW, ObjectiveC
is another language worth trying (though its non-Apple implementations
lag far, far behind, alas).  Eclipse is probably "the" Java IDE nowadays
(and it's free, cross-platform, and all).

> able to figure out how to download webpages easy enough (I do this to
> scrape stock quotes). I felt fairly confident that I could achieve what
> I wanted in Java, even though I'm fairly raw with it. I started from a
> default project using Xcode, and it seemed to generate a lot of base 
> code. I quickly abandoned the Java idea, as I'm not gunning to be a Java
> developer, and Python seems to do what I want without fuss.
> 
> I think that's the key to Python. You can do what you want without fuss,
> and it's copiously documented.

Yes, excellent points.  Although I have a long-time fascination with
many programming languages, Python does still stand out from the crowd
in enabling me to get any given app done "without fuss"!-)


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


Re: Python rocks

2007-06-03 Thread Alex Martelli
Mark Carter <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > Josiah Carlson <[EMAIL PROTECTED]> wrote:
> > 
> >>> pitfall of Python is knowing whether an operation is destructive or not.
> >> If it returns None, it probably changes the content of an object.
> > 
> > A reasonable heuristic, but with lots of exceptions, alas:
> > somedict.get(somekey)
> > will often return None without performing any change, while
> > somelist.pop()
> > does modify somelist but typically returns non-None.
> > 
> > The use of trailing-exclamation-point (by convention) to indicate
> > "mutating methods" is a nice plus in languages that allow it.
> 
> Actually, that'd be nice to have in Python. And whilst we're about it,
> might as well go the whole hog and allow hyphens in names, too.

Hyphens look the same as minus signs, so that allowing them in names in
a language with infix operator syntax is far from a clear win.  Right
now, in Python and all cognate languages, a-b means a minus b; the
tectonic shift to having it be a 3-character identifier instead, in
addition to breaking millions of lines of existing code, would rightly
produce extreme resistance in anybody whose main programming experience
comes from Basic, C, Java, Fortran, C++, PL/I, Perl, C#, and Python
itself (and dozens of other languages, too, of course).

I noticed this effect when I was playing with Dylan (never did anything
"serious" with it, but I did like many aspects of the language): I kept
writing a-b (and for that matter a+b, etc) and getting weird syntax
errors because I had not interposed all needed spaces.  (If a-b is not
allowed as an expression, it makes sense that a+b isn't either).  

Despite substantial previous experience with Lisp, Scheme, and Forth, in
all of which a-b would "of course" be an identifier, that experience
just didn't guide my fingers -- in those languages operator are prefix
(Lisp, Scheme) or suffix (Forth), so it's "natural" that sticking an
operator sign "between" sequences of letters means nothing special...
but moving to an infix language just shifts my brain in a different
gear.  Cobol has preferably-prefix notation too, i.e., the natural way
to express the difference would be "SUBTRACT C FROM B", and the
alternative "algebraic" (infix) notation is and feels very "bolted-on",
so it's kind of an intermediate case, where hyphens are still OK.

Not only is the cost of making a-b an identifier extremely high, but the
gains are tiny: what conventional difference is there supposed to be
between a-b and a_b?  Looks like nothing but one more category of easily
confusable identifiers.  Big pain, little gain == not so great an idea.

Allowing a trailing ! in method names has no such cost, because in no
language I know is ! used as a "postfix unary operator"; the gain in the
convention "mutators end with !" is not huge, but substantial.  So, the
tradeoffs are different: small pain, substantial gain == not a bad idea.

However, this is all quite theoretical, because no more PEPs will be
accepted for Python 3000, so any language change like this would have to
wait for Python 4000, which is no doubt quite a distant prospect:-).


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


Re: c[:]()

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 18:44, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
> In <[EMAIL PROTECTED]>,
>
> >bla-bla-bla
> > it is easy to read and understandable.
>
> And has the same issue as a list comprehension if all you want is the side
> effect of the calls: a useless temporary list full of `None`\s is build.
>
> Ciao,
> Marc 'BlackJack' Rintsch

functoins can return a values, and you get it. I don't think that it
is bad side effect.
When you write simple
>>> def a(): print "From Russia with love."
>>> a()
you have side effect too - returning "None".

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


Why Python?

2007-06-03 Thread Chris Stewart

What is it about Python that makes it such a suitable language for you?  For
instance, why would you use it over something similarly portable as Java, or
PHP?

I know personally, in my small exposure to Python, I can see it as a great
learning tool for a basic introduction to programming and even OOP.  It's
wonderful how your .py file can simply start making expressions without any
overhead, import/using statements, class declarations, etc.

--
Chris Stewart
[EMAIL PROTECTED]
http://www.compiledmonkey.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: c[:]()

2007-06-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> On 30, 22:48, "Warren Stringer" <[EMAIL PROTECTED]> wrote:
>> I want to call every object in a tupple, like so:
>>
>> #--
>> def a: print 'a'
>> def b: print 'b'
>> c = (a,b)
>>
>> >>>c[:]()  # i wanna
>>
>>  TypeError: 'tupple' object is not callable
>>
>> >>>c[0]()  # expected
>> a
>> >>>c[:][0] # huh?
>> a
>> >>> [i() for i in c] # too long and ...huh?
>>
>> a
>> b
>> [None,None]
>> #--
>>
>> bla-bla-bla..
> 
> 
> you can write:
 map(lambda x: x(), c)
> 
> I think that it is good idea to use "map()" function for doing
> somethimg with each element of a sequence, if the order of a actions
> not important.
> 
> it is easy to read and understandable.

And has the same issue as a list comprehension if all you want is the side
effect of the calls: a useless temporary list full of `None`\s is build.

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


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Joe Salmeri
""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>> The short explaination of this issue is that the timestamp shown when
>> you do a dir on a file that is on an NTFS volume changes by an hour
>> when DST starts and also when DST ends, even though the file has NOT
>> been modified!!!  Note that this only happens if you have the setting
>> turned on to automatically adjust for DST (this is the default in
>> Windows).
>
> You are misinterpreting what you are seeing. Windows is not claiming
> that the modification time changes when DST starts. Instead, it is
> claiming that the *same* time now has a *different* textual
> representation, because the computer now has moved to a different
> time zone.
>
> When you explicitly change the time zone of your computer, you will
> notice that all file time stamps immediately change also.

It appears that you may have missed part of my tests.  Sorry it was such a 
long reply but I was trying to provide a lot of detail so that others had a 
clear understanding of what was going on.

I understand that the actual UTC time value for the file has *not* changed.

That local textual representation of the modification timestamp is what 
people and programs look at and work with and is what is displayed by the 
dir command and what Explorer displays.

Changing the timezone will defintely change the "textual representation" of 
all timestamps just as you say (even though the actual UTC value has *not* 
changed), however, when DST starts/ends the "textual representation" of the 
timestamps on some files WILL ALSO CHANGE when the automatically adjust for 
DST setting is turned on.

That is *not* my opinion or interpretation, it is clearly documented by 
Microsoft and is also documented in the long article that I provided the 
link for in my reply yesterday.  It was also demonstrated in the second test 
I provided yesterday and is also demonstrated in the article I provided the 
link to.

In the following comments I am referring to the textual representation of 
the timestamp that the user is working with (I understand that the interal 
UTC timestamp for the file has *not* changed).

The issue occurs when the timestamp for the file is in a period when DST was 
not in effect and DST is in effect for the current time OR when the 
timestamp for the file is in a period when DST was in effect and DST is not 
in effect for the current time.

While it is true that I did change the timezone in the first part of the 
test (to establish the baseline), in the second part of the tests where the 
difference you are referring to occured, the timezone was *not* changed, the 
only thng that occured was that DST started.

In that test the file had a timestamp of 01/01/2007 07:00 PM as shown by the 
dir command results.

When the date progressed to a point after DST had started Windows now 
reports the timestamp on that *unmodified* file now is 01/01/2007 08:00 PM.

I did not change the timezone, the only thing that occurred was DST started.

The internal UTC timestamp did NOT change, the issue is in Windows textual 
representation of that UTC timestamp to my local timezone and DST values, 
Windows now reports that the modification timestamp on the file as 1 hour 
later (again the actual UTC timestamp did *not* change).

To the end user the file "appears" to have been modified an hour later than 
it was the day before even though it was not changed.

Over the years this issue has caused all sorts of problems for backup 
programs and CVS (greatly detailed in the article I provided the link for).

>> Even though Python 2.5.1 is correct this presents a NEW problem
>> because it differs from what XP SP 2 (wrongly) reports.  I am sure
>> this will cause a lot of confusion for people as it already appears
>> that others have stumbled on this difference.
>
> However, please understand that the problem is *not* caused by the
> results returned from os.stat. Instead, the difference comes from
> your choice of calling localtime() to break down the timestamp
> to day, hour, and minute. If you write a different function
> windows_localtime, that behaves the same way that the Windows
> rendering behaves, you will get the same results.
>
>> To the end user it appears the file was modifed when in fact it was
>> not.
>
> That's because the user is misinterpreting the data that Windows
> reports. Windows isn't saying the file changed, Windows says that
> the timezone changed.

You mixed up my tests, in that case as shown above the timezone did *not* 
change, the only thing that changed was that DST started and the file was 
created during a time when DST was not in effect.

>> Having this difference between Python and Windows makes it difficult
>> to write code that depends on those values being in sync.
>
> No. Just write a windows_localtime function, and be done.

For those that are interested here is a function that you can use in place 
of time.localtime that will return values tha

Re: c[:]()

2007-06-03 Thread [EMAIL PROTECTED]
On 30, 22:48, "Warren Stringer" <[EMAIL PROTECTED]> wrote:
> I want to call every object in a tupple, like so:
>
> #--
> def a: print 'a'
> def b: print 'b'
> c = (a,b)
>
> >>>c[:]()  # i wanna
>
>  TypeError: 'tupple' object is not callable
>
> >>>c[0]()  # expected
> a
> >>>c[:][0] # huh?
> a
> >>> [i() for i in c] # too long and ...huh?
>
> a
> b
> [None,None]
> #--
>
> bla-bla-bla..


you can write:
>>> map(lambda x: x(), c)

I think that it is good idea to use "map()" function for doing
somethimg with each element of a sequence, if the order of a actions
not important.

it is easy to read and understandable.

P.S. sorry my bad English

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


Lindsay Lohan jessica Alba Scarlett Johansson

2007-06-03 Thread Christina Aguilera
Lindsay Lohan  jessica  Alba  Scarlett Johansson Christina Aguilera 



www.alphasearch.gr-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to control the creation of an instance?

2007-06-03 Thread KingMax
On Jun 3, 2:17 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Jun 2, 10:31 pm, lialie <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > suppose i have a free_object list[Sample1, Smaple2]. when create a
> > new object sample(*args, **kwds), if free_object_list isn't empty, just
> > pop one from free_object_list instead of creating a new instance.
>
> > any way to do this?
>
> > I do some work as follows:
>
> > class Sample(object):
> > used_object = []
> > free_object = []
>
> > def __init__(self, *args, **kwds):
> > pass
>
> > def __new__(self, *args, **kwds):
> > if Sample.free_object:
> > obj = Sample.free_object.pop(0)
> > else:
> > obj = object.__new__(Sample, *args, **kwds)
> > Sample.used_object.append(obj)
> > return obj
>
> >  still get a new instance :(
>
> > def Release(self):
> > Sample.used_object.remove(self)
> > Sample.free_object.append(self)
> > return True
>
> This seems to work for me:
>
> import collections
>
> class Sample(object):
>
> free_objects = collections.deque()
> used_objects = []
>
> def __new__(cls, *args, **kwds):
> if not Sample.free_objects:
> temp = object.__new__(Sample, args, kwds)
> Sample.used_objects.append(temp)
> return temp
> else:
> return Sample.free_objects.popleft()
>
> def __init__(self, *args, **kwds):
> self.args = args
> self.kwds = kwds
>
> def release(self):
> Sample.used_objects.remove(self)
> Sample.free_objects.append(self)
>
> s1 = Sample(10, name="Bob")
> print s1
> print s1.args
> print s1.kwds
>
> s2 = Sample("red", name="Bill")
> print s2
> print s2.args
> print s2.kwds
>
> s1.release()
> s3 = Sample("blue", name="Tim")
> print s3
> print s3.args
> print s3.kwds

Thank you.
> def __new__(cls, *args, **kwds):
> if not Sample.free_objects:
> temp = object.__new__(Sample, args, kwds)
> Sample.used_objects.append(temp)
> return temp
> else:
> return Sample.free_objects.popleft() # Here you may lost one 
> object :)

The free_objects list doesn't have orders. My sample code seems to
work. But follows may create a new instance:

class Sample(wx.Image):
free_objects = []
used_objects
def __int__(self, *args, **kwds):
wx.Image.__init__(self, *args, **kwds)  play tricks with
me :)
pass

def __new__(cls, *args, **kwds):
# The same

wx.Image always create a new instance. It seems that I have to avoid
wx.Image.__init__.

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


ANN: eric4 4.0.0 release

2007-06-03 Thread Detlev Offenbach
Hi,

I am proud to announce the availability of the first official release of
eric4. eric4 is the successor of the well known eric3 Python development
environment.

What is eric4?
--
eric4 is an Integrated Development Environment for the Python (and Ruby)
language. It comes with all batteries included. It has too many features
to list here. For details please visit

http://www.die-offenbachs.de/eric/index.html

Regards,
Detlev
-- 
Detlev Offenbach
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote:


>> Angles are a ratio of two lengths, and are therefore dimensionless units.
>> So the square root of an angle is just another angle, in the same units,
>> and it requires no special geometric interpretation: the square root of 25
>> degrees (just an angle) is 5 degrees (just another angle). 
> 
> But sqrt(25°) = sqrt(25/180*pi) = 5*sqrt(180/pi) != 5°

Hmmm... perhaps that's why the author of the "units" program doesn't
treat angles as dimensionless when taking square roots.

Given that, I withdraw my claim that the sqrt of an angle is just an
angle. I can't quite see why it shouldn't be, but the evidence is fairly
solid that it isn't.



-- 
Steven

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


Re: Trouble killing a process on windows

2007-06-03 Thread Tim Golden
Thomas Nelson wrote:

[... re Access Denied error on trying to TerminateProcess ...]

[Tim Golden]
>> I suppose you might have to adjust your token privs to include,
>> say the Debug priv. This is designed to let you take control
>> of any process (and terminate it, or whatever). If it looks
>> like you need to do that, post back and I -- or someone else --
>> can try to run up an example.

[Thomas Nelson]
> I Tried the PID method, and the Taskkill method, and neither worked.
> This is what I get for trying to work on a windows machine.  If you
> could explain how to add the debug privilege, that would be great.

OK, this being Windows security, there's a couple
of hoops to jump through, but nothing too bad.


import win32api
import win32security as sec

#
# This function is merely window-dressing
# to make it easier to see whether the
# code has worked or not.
#
def priv_status (hToken, priv):
   for p, status in sec.GetTokenInformation (
 hToken,
 sec.TokenPrivileges
   ):
 if p == priv:
   if status == 0:
 return "disabled"
   else:
 return "enabled"
   else:
 return "disabled"

process = win32api.GetCurrentProcess ()
token_access_flags = sec.TOKEN_ADJUST_PRIVILEGES | sec.TOKEN_QUERY
hToken = sec.OpenProcessToken (process, token_access_flags)
debug_priv = sec.LookupPrivilegeValue (None, sec.SE_DEBUG_NAME)

print "Debug is", priv_status (hToken, debug_priv)

privs = [(debug_priv, sec.SE_PRIVILEGE_ENABLED)]
sec.AdjustTokenPrivileges (hToken, 0, privs)

print "Debug is", priv_status (hToken, debug_priv)



> Just out of curiosity, is there a reason a python module like os
> couldn't have a universal terminateProcess type function, that works
> on all systems?  Something like os.listdir seems to work really well
> everywhere.  Maybe killing processes is too complicated for this?

Not to say that there could never be one, but I suspect
that the difference of APis and the number of corner
cases makes it a daunting task for maintenance. The
code would have to work on every platform Python works
on -- which is no small number -- and would have to be
maintained across the many and varied changes on each
of those platforms.

Still, if you think you're in with a chance, go ahead
and offer :)

Let us know if the DEBUG priv thing works or not.

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


Re: Python rocks

2007-06-03 Thread Mark Carter
Alex Martelli wrote:
> Josiah Carlson <[EMAIL PROTECTED]> wrote:
> 
>>> pitfall of Python is knowing whether an operation is destructive or not.
>> If it returns None, it probably changes the content of an object.
> 
> A reasonable heuristic, but with lots of exceptions, alas:
> somedict.get(somekey)
> will often return None without performing any change, while
> somelist.pop()
> does modify somelist but typically returns non-None.
> 
> The use of trailing-exclamation-point (by convention) to indicate
> "mutating methods" is a nice plus in languages that allow it.

Actually, that'd be nice to have in Python. And whilst we're about it, 
might as well go the whole hog and allow hyphens in names, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-03 Thread Mark Carter
Alex Martelli wrote:
> Mark Carter <[EMAIL PROTECTED]> wrote:

> Yes, GMP is a pain to compile (especially on Mac OS X), but I believe

> Just mentioning this in case you want to give Scheme another chance

Thanks. I'll take a look at it.

I think I've decided to finish off my little in project in Python first, 
though. I'd like to actually get it done (!). I may well decide to 
reimplement bits in either Scheme, or I might try my hand at Forth. My 
app will be small enough to permit re-writes.

I had actually done a small 3-month Java project professionally about 7 
years ago. Can't say I was too impressed. IMO, it was too verbose, I'm 
not an OO fanatic, and some immutable strings turned out to be not quite 
as immutable as I expected.

I had a brief toy around with Java using Xcode very recently, and I was 
able to figure out how to download webpages easy enough (I do this to 
scrape stock quotes). I felt fairly confident that I could achieve what 
I wanted in Java, even though I'm fairly raw with it. I started from a 
default project using Xcode, and it seemed to generate a lot of base 
code. I quickly abandoned the Java idea, as I'm not gunning to be a Java 
developer, and Python seems to do what I want without fuss.

I think that's the key to Python. You can do what you want without fuss, 
and it's copiously documented.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python rocks

2007-06-03 Thread Hendrik van Rooyen
 "Mark Carter" <[EMAIL PROTECTED]> wrote:


> Josiah Carlson wrote:

> >  What kind of scoping did you desire?
>
> Well, I had in mind so that if you defined a function, but wanted to
> access a global var, that you didn't have to use the global keyword. Not
> much of a biggie, I guess.

You can access them without the global keyword - for "reading" .

You only need global if you are assigning to it - else you get a new function
local:

>>> x = 7
>>> def rubbish():
print x

>>> rubbish()
7
>>> def more_rubbish():
x = x+1
print x

>>> more_rubbish()
Traceback (most recent call last):
  File "", line 1, in ?
more_rubbish()
  File "", line 2, in more_rubbish
x = x+1
UnboundLocalError: local variable 'x' referenced before assignment

>>>def other_rubbish():
y = x+1
print y

>>> other_rubbish()
8
>>> x
7
>>> def global_rubbish():
global x
x = x + 1
print x

>>> global_rubbish()
8
>>> print x
8
>>>

- Hendrik

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


Re: Python 2.5.1 broken os.stat module

2007-06-03 Thread Martin v. Löwis
> The short explaination of this issue is that the timestamp shown when
> you do a dir on a file that is on an NTFS volume changes by an hour
> when DST starts and also when DST ends, even though the file has NOT
> been modified!!!  Note that this only happens if you have the setting
> turned on to automatically adjust for DST (this is the default in
> Windows).

You are misinterpreting what you are seeing. Windows is not claiming
that the modification time changes when DST starts. Instead, it is
claiming that the *same* time now has a *different* textual
representation, because the computer now has moved to a different
time zone.

When you explicitly change the time zone of your computer, you will
notice that all file time stamps immediately change also.

> Even though Python 2.5.1 is correct this presents a NEW problem
> because it differs from what XP SP 2 (wrongly) reports.  I am sure
> this will cause a lot of confusion for people as it already appears
> that others have stumbled on this difference.

However, please understand that the problem is *not* caused by the
results returned from os.stat. Instead, the difference comes from
your choice of calling localtime() to break down the timestamp
to day, hour, and minute. If you write a different function
windows_localtime, that behaves the same way that the Windows
rendering behaves, you will get the same results.

> To the end user it appears the file was modifed when in fact it was
> not.

That's because the user is misinterpreting the data that Windows
reports. Windows isn't saying the file changed, Windows says that
the timezone changed.

To understand this, you have to truly grasp the notion of absolute
time. June 2, 2007, 9:40 is *not* a point in time. Instead, you
have to provide a timezone also to make it point in time. So Windows
is incorrect not giving the time zone; otherwise, it is correct.

>   This file was originally created01/02/2007 12:00 AM GMT
>   which is the same locally as01/01/2007 07:00 PM EST
>   but now everything EXCEPT Python 2.51
>   is reporting that the file changed on   01/01/2007 08:00 PM EST

Not true. Everything else is reporting that the time stamp is

01/01/2007 08:00 PM EDT

(where EDT is the Eastern Daylight Time).

> Having this difference between Python and Windows makes it difficult
> to write code that depends on those values being in sync.

No. Just write a windows_localtime function, and be done.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: M2Crypto-0.17 blocks python threads?

2007-06-03 Thread John Nagle
Heikki Toivonen wrote:
> [EMAIL PROTECTED] wrote:
> 
>>I am having a problem with python threads and M2Crypto.  It appears
>>the M2Crypto used in multi-thread application blocks other threads
>>from running:
> 
> 
> This turned into https://bugzilla.osafoundation.org/show_bug.cgi?id=9401
> 
> Thanks for the report!

That helps.  I've been getting occasional stalls and timeouts in
a multithreaded program that can have several M2Crypto operations
going, and this is probably the explaination.

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


getting rid of leading zeros in float expotential

2007-06-03 Thread tom
Hi! I'm wondering whether there's an easy way to remove unnecessary 
leading zeros from my floating point number.

realS = float(-1.25e-5)
imgS = float(-7.6e4)

print complex(realS, imgS)

 >> (-1.25e-005-76000j)

I would like it to look like (-1.25e-5-76000j)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to control the creation of an instance?

2007-06-03 Thread 7stud
On Jun 3, 12:50 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Sat, 02 Jun 2007 23:25:49 -0700, 7stud wrote:
> > Oops.  This line:
>
> >> temp = object.__new__(Sample, args, kwds)
>
> > should be:
>
> > temp = object.__new__(cls, args, kwds)
>
> > although it would seem that cls is always going to be Sample, so I'm
> > not sure what practical difference that makes.
>
> What if you are calling it from a sub-class?
>
> --
> Steven.

cls it is!

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


Re: subexpressions (OT: math)

2007-06-03 Thread Leonhard Vogt
>> Yes, I understand that, but what is the geometrical
>> meaning of the square root of an arc length?  
> 
> That's a different question to your original question, which was asking
> about the square root of an angle.
> 
>> And what would the units be?  
> 
> Angles are a ratio of two lengths, and are therefore dimensionless units.
> So the square root of an angle is just another angle, in the same units,
> and it requires no special geometric interpretation: the square root of 25
> degrees (just an angle) is 5 degrees (just another angle). 

But sqrt(25°) = sqrt(25/180*pi) = 5*sqrt(180/pi) != 5°

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


  1   2   >