Re: Python and Cron

2007-09-08 Thread Amit Khemka
On 9/8/07, Greg Lindstrom <[EMAIL PROTECTED]> wrote:

> # run client pricing at 0215 (p) Monday-Friday
> 15 2 * * 1-5 cd /m01/edith/src && /usr/bin/python /m01/edith/src/driver.py
> --paid-date yesterday --jobname professional >>
> /m01/edith/stdout/ecomppo.stdout 2&>1

"2&>1",  Is that a typo ? It should be "2>&1" .

Are you *sure* that the cron job is running ?

cheers,

-- 

Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected behavior: did i create a pointer?

2007-09-08 Thread Peter Otten
Am Sat, 08 Sep 2007 00:32:35 + schrieb Steven D'Aprano:

> On Fri, 07 Sep 2007 15:59:53 +0200, Wildemar Wildenburger wrote:
> 
>> I just thought I'd go along with the analogy the OP created as that was
>> his mindset and it would make things easier to follow if I didn't try to
>> forcibly change that.
> 
> My reaction to somebody trying to reason with the wrong analogy is to 
> teach them the right analogy, not to tell them they got it right when 
> they actually got it wrong.
> 
> "My car won't start -- I must not have stirred the gasoline enough before 
> baking it."
> 
> "Yes, that's right. It's very important to stir the gasoline fully so 
> that all the ingredients are fully mixed."

I think Wildemar is too defensive. The pointer "analogy" is a good first
approximation, not cargo cult.

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


Re: unexpected behavior: did i create a pointer?

2007-09-08 Thread Peter Otten
Am Fri, 07 Sep 2007 13:10:16 + schrieb Grant Edwards:

> On 2007-09-07, Peter Otten <[EMAIL PROTECTED]> wrote:
>> Am Fri, 07 Sep 2007 10:40:47 + schrieb Steven D'Aprano:
>>
>>> Python doesn't have any pointers.
>>
>> Thinking of python variables or "names" as pointers should
>> get you a long way when trying to understand python's behaviour.
> 
> But thinking of them as names bound to objects will get you
> further (and get you there faster). ;)

Understanding a new system in terms of one I already know works for me.
When terminology and the system it describes make a perfect fit that is a
strong indication that you have reached a dead end.

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


python sqlite THREADSAFE?

2007-09-08 Thread EuGeNe Van den Bulke
Hi,

Is the sqlite distributed with Python 2.5 compiled with the 
-DTHREADSAFE=1 flag? My gutt feeling is Windows (yes) MacOS/Linux (no) 
but ...

If it is not on MacOS/Linux, how do I go about replacing the sqlite so 
file with a threadsafe sqlite?

Thanks,

EuGeNe -- http://www.3kwa.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python sqlite THREADSAFE?

2007-09-08 Thread Marc 'BlackJack' Rintsch
On Sat, 08 Sep 2007 10:37:51 +0200, EuGeNe Van den Bulke wrote:

> Is the sqlite distributed with Python 2.5 compiled with the 
> -DTHREADSAFE=1 flag? My gutt feeling is Windows (yes) MacOS/Linux (no) 
> but ...

Take a look at the `threadsafety` attribute of the module.

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


Re: unexpected behavior: did i create a pointer?

2007-09-08 Thread Steven D'Aprano
On Sat, 08 Sep 2007 10:07:14 +0200, Peter Otten wrote:

> Am Fri, 07 Sep 2007 13:10:16 + schrieb Grant Edwards:
> 
>> On 2007-09-07, Peter Otten <[EMAIL PROTECTED]> wrote:
>>> Am Fri, 07 Sep 2007 10:40:47 + schrieb Steven D'Aprano:
>>>
 Python doesn't have any pointers.
>>>
>>> Thinking of python variables or "names" as pointers should get you a
>>> long way when trying to understand python's behaviour.
>> 
>> But thinking of them as names bound to objects will get you further
>> (and get you there faster). ;)
> 
> Understanding a new system in terms of one I already know works for me.
> When terminology and the system it describes make a perfect fit that is
> a strong indication that you have reached a dead end.

Ways that Python objects are not like C pointers:

(1) You don't have to manage memory yourself.

(2) You don't have typecasts. You can't change the type of the object you 
point to.

(3) Python makes no promises about the memory location of objects.

(4) No pointer arithmetic.

(5) No pointers to pointers, and for old-school Mac programmers, no 
handles.

(6) No dangling pointers. Ever.

(7) There's no null pointer. None is an object, just like everything else.

(8) You can't crash your computer by writing the wrong thing to the wrong 
pointer. You're unlikely even to crash your Python session.



Ways that Python objects are like pointers:

(1) ... um... 

Oh yeah, if you bind the _same_ object to two different names, _and_ the 
object is mutable (but not if it is immutable), mutating the object via 
one name will have the same effect on the object -- the same object, 
naturally -- bound to the other name.

You know, maybe because I came to Python with no C experience, I never 
had trouble with the "unexpected behaviour" that so confused the original 
poster. It's just obvious.


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


Re: Generating a unique identifier

2007-09-08 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes:

> Should garbage-collecting 16 million strings really take 20+
> minutes?

It shouldn't.  For testing purposes I've created a set of 16 milion
strings like this:

s = set()
for n in xrange(1600):
  s.add('somerandomprefix' + str(n))  # prefix makes the strings a bit larger

It takes maybe about 20 seconds to create the set.  Quitting Python
takes 4-5 seconds.  This is stock Python 2.5.1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unexpected behavior: did i create a pointer?

2007-09-08 Thread Wildemar Wildenburger
Dennis Lee Bieber wrote:
> On Fri, 07 Sep 2007 12:19:12 -0700, Steve Holden <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
>> Since it's only a matter of time before someone brings up the "post-It" 
>> analogy, let me cavil in advance about it. The thing I don't like about 
>> that particular pedagogic mechanism is that it always "attaches" the 
>> names to the objects.
>>
>   Fine... then visual the namespace as a box... Inside the box are the
> "post-it notes" -- attached to the ends of strings that then run to the
> "physical object" at the other end.

This is getting clearer by the minute. ;)

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


www.cheapestsell.com : nike air max air force one guuci prada lacoste D&G adiads Dior shoes

2007-09-08 Thread 001
Hotmail: cheapestsell#hotmail.com

(www.cheapestsell.com )professionally wholesale sports shoes from
china,main product including:Footwear-sneakers series
(nike,puma,adidas,Jordan 1-24,nike max,nike shox,nike dunk,nike
kobe,nike rift,bapesta,timberland
boot,D&G,dsquqred,LV,prada,icecream,NBA,lacoste shoes,ect).,T-
shirts,jeans,hootdies/clothes series.,Sandal slippers series.,Leather
belt series.,Handbags series.,Purse series.,Sunglasses,the sun hats/
cap series.,etc.In the short several years, the company by the most
preferential price, the first-class quality, the first-class
service,the first-class security transportation, receives the
domestic
and foreign customers welcome. Product best-selling Europe and
America,france, Southeast Asia, Russia, South Africa, country and
area
and so on.
Welcome u coming to business with us !!!
Our msn:cheapestsell#hotmail.com
Our website:
http://www.cheapestsell.com and
wholesale jewelry,watch,mp3,mp4.
wholesale Nike Air Jordan, Nike Air Jordan Retro XI, Nike Air Jordan
shoes
http://www.cheapestsell.com  and
 wholesale Nike Air Jordan Retro Basketball Shoes, Air Jordan I, Air
Jordan
http://www.cheapestsell.com  a
 wholesale Jordan Shoes and Nike Shoes can be found here
http://www.cheapestsell.com
wholesale Nike Jordan, Air Force 1,Dunk,Air max 95,97
http://www.cheapestsell.com
wholesale Jordan Shoes, Nike Air Jordan XI and IV, Retro Michael
Jordan Shoes
(www.cheapestsell.com)
 wholesale Nike Air Jordan original xi 11, Nike Air Jordan xi, Nike
Air
http://www.cheapestsell.com
wholesale New nike air jordan XI/11 shoes/nike shoes/air jordan
shoes/
nike
http://www.cheapestsell.com
wholesale Air Jordan Air Jordan I Air Jordan II Air Jordan III Air
Jordan
(www.cheapestsell.com)
wholesale Nike, Jordan XI Basketball Shoes Review in Basketball Shoes
(www.cheapestsell.com)
wholesale Nike Air Jordan retro 9, Nike Air Jordan retro ix, Nike Air
Jordan retro 9 ix sneakers
(www.cheapestsell.com)
wholesale Jordan Shoes, Nike Air Jordan XI and IV, Retro Michael
Jordan Shoes Jordan shoes
(www.cheapestsell.com)
 wholesale Nike Air Jordan Retro 13 xiii, Nike Air Jordan 13 retro,
Nike Air
(www.cheapestsell.com)
 wholesale Nike Air Jordan, Nike Air Jordan Retro XI, Nike Air Jordan
shoes
(www.cheapestsell.com)
wholesale Nike Air Max Jordan 15 Jordan 16 Jordan 17 Jordan 18 Jordan
19 Jordan 20 Jordan 21
(www.cheapestsell.com)
 Jordan 1.5 Dubzero Jordan 5.5 Jordan 21.5
(www.cheapestsell.com)
)Jordan 3.5 ・ Jordan 6.5 ・ Jordan 9.5 ・ Jordan 17.5. Nike DUNK. DUNK.
Air Force one
(www.cheapestsell.com)
 Wholesale/sell nike air jordan 21/XXI,nike shoes suppliers
(www.cheapestsell.com)
 sell nike air jordan, AF1,dunk,airmax,shox,gucci,timberland,bape
(www.cheapestsell.com)
 sell nike air jordan shoes for low price
(www.cheapestsell.com)
CHINA wholesale Nike Jordan, Air Force 1,Dunk
(www.cheapestsell.com)
Sell Nike Shoes,Nike Air Jordan Shoes
(www.cheapestsell.com)
Sell nike , air jordan, Af1,bape,prada,dunk,evisu jeans,coatsNike
Shox
TL III, Shox (www.cheapestsell.com)
(www.cheapestsell.com)
NZ, Shox TL 123, Shox 2:40 2:45, Shox
nike jordan, air max, nike shox, nike tn, nike rival, nike
(www. cheapestsell . com)
(www.cheapestsell.com)
 nike shoes, nike air max, air max 95, air max 97, airmax 2003
 (www.cheapestsell.com)nike shox, nike shox shoes, nike shox
basketball
shoes, nike shox
(www.cheapestsell.com) nike shox tl/tl2 /tl3 shoes with aaa grade,low
price
(www.cheapestsell.com)nike shox - Offers for nike shox - exporters,
manufacturers
(www.cheapestsell.com) nike air force one, nike shoes, nike shox,
nike
air, nike dunks
(www.cheapestsell.com) trainer shoes - Offers for trainer shoes -
exporters
(www.cheapestsell.com) Sell and buy nike shoes online trade lead,
nike
shoes wholesaler
 (www.cheapestsell.com)wholesale Nike Shoes, Nike air force one 1,
nike
air force ones, nike air forces
(www.cheapestsell.com) Nike air jordan air jordans, Nike basketball
shoes,
nike sneakers, air jordan shoes, jordan sneaker
(www. cheapestsell . com)wholesale NIKE Sneakers | Air Jordan Sneakers
|
AIR
FORCE ONE 1S | Nike
(www.cheapestsell.com) wholesale Nike Air Force 1, Nike Air Force 1
Low,
Nike Air Force 1 One white
(www.cheapestsell.com)wholesale Sell and buy nike shoes online trade
lead,
nike shoes wholesaler
(www.cheapestsell.com) Sell Nike Jordans, Air Maxes, and Clears
Locally
and Online!
(www.cheapestsell.com)wholesale Nike Air Max, Nike Air Max 360, Nike
Air
Max 90, Nike
(www.cheapestsell.com)wholesale Nike Air Force 1, Nike Air Force 1
Low,
Nike Air Force 1 One white
(www.cheapestsell.com) wholesale nike air force one, af1 shoes, nike
jordan shoes, athletic shoes
(www.cheapestsell.com) wholesale Nike Shoes, Nike air force one 1 one
shoes, air jordans, air force
(www.cheapestsell.com) Air Force - Buying Leads for Air Force -
Buyers,
Importers
Nike Air Force One (AF1) Low
nike air force one - Offers for nike air force one - exporters
Wholesale AAA quality Nike Air Force one boot, nike, jordan
Factory Wholesale Supp

ANN: Load binary application into a BasiCard from Python

2007-09-08 Thread hg
Hi,

Based on the already released SCF, the code is there:
http://snakecard.com/Source/Applications/SCF/Load_BC.zip.

hg

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


Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Ricardo Aráoz
Zentrader wrote:
> On Sep 7, 11:30 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> On Fri, 07 Sep 2007 18:49:12 +0200, Jorgen Bodde wrote:
>>> As for why caring if they are bools or not, I write True and False to
>>> the properties, the internal mechanism works like this so I need to
>>> make that distinction.
>> Really?  Can't you just apply the `int()` function?
>>
>> In [52]: map(int, [1, 0, True, False])
>> Out[52]: [1, 0, 1, 0]
>>
>> Ciao,
>> Marc 'BlackJack' Rintsch
> 
> Blackjack's solution would take care of the problem, so this is just
> for general info.  Looks like a "feature" of isinstance() is to
> consider both True and 1 as booleans, but type() distinguishes between
> the two.
 x=True
> ... if type(x) == type(1):
> ...print "int"
> ... else:
> ...print "not int"
> ...
> not int
> 
>  if type(x) == type(True):
> ...print "bool"
> ...
> bool
> 

Or just :

>>> a = True
>>> type(a) == int
False
>>> type(a) == bool
True
>>> a = 'True'
>>> type(a) == bool
False
>>> type(a) == str
True
>>> a = 5
>>> type(a) == bool
False
>>> type(a) == str
False
>>> type(a) == int
True
>>> a = 4.323
>>> type(a) == int
False
>>> type(a) == float
True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does this thread have to do with classical music,

2007-09-08 Thread Art Deco
ah <[EMAIL PROTECTED]> wrote:
>Art Deco wrote:
>> ah <[EMAIL PROTECTED]> wrote:
>>>Art Deco wrote:
 ah <[EMAIL PROTECTED]> wrote:
>Art Deco wrote:
>> ah <[EMAIL PROTECTED]> wrote:
>>>Art Deco wrote:
 ah <[EMAIL PROTECTED]> wrote:
>Art Deco wrote:
>> ah <[EMAIL PROTECTED]> wrote:
>>>Art Deco wrote:
 ah <[EMAIL PROTECTED]> wrote:
>Art Deco wrote:
>> Who wrote?
>> 
>> 
>>>What does that have to do with classical music, snuhwolf?
>> 
>>>What does that have to do with classical music, snuhwolf?
>> 
>> How many more times will you be asking the same tired, lame
>> questions,
>> Tholen?
>
>Till 2056?
 
 At that point, he will have made the Thirty Years Pset War look
 like
 1967 in the Sinai.
>>>
>>>It must have been Hell to keep a garden during those times.
>>>
>>>Did they all eat jerky, or what?
>> 
>> Worse -- worm-laden hardtack.
>
>Luxury!
>
>Why, I remember when I was a lad . . . we used to watch the local
>churls
>across the fences eating that well.
>
>We only had millings (and (occasionally) water) on Tuesdays and
>Fridays.
 
 Grog and hardtack, life is good!
>>>
>>>¡Viva la basura!
>> 
>> Vivat les ordures!
>
>Vivara los trunctiato!
 
 das Leben ist gut!
>>>
>>>de Handel esta disgustipado!
>> 
>> la vita è buona!
>
>que grupo da merda!

het leven is goed!

-- 
Official Overseer of Kooks and Saucerheads for alt.astronomy
Wee Davie Tholen is a grade-school lamer
Trainer and leash holder of:
  Honest "Clockbrain" John
  nightbat "fro0tbat" of alt.astronomy
  Tom "TommY Crackpotter" Potter
  

"Classic erroneous presupposition.  Others developed websites
so that they could have the Last Word, Deco.  In the newsgroups,
I could counter their lies."
  --David Tholen
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating really big lists

2007-09-08 Thread Dr Mephesto
On Sep 8, 3:33 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Fri, 07 Sep 2007 16:16:46 -0300, Dr Mephesto <[EMAIL PROTECTED]>
> escribi?:
>
> > hey, that defaultdict thing looks pretty cool...
>
> > whats the overhead like for using a dictionary in python?
>
> Dictionaries are heavily optimized in Python. Access time is O(1),
> adding/removing elements is amortized O(1) (that is, constant time unless
> it has to grow/shrink some internal structures.)
>
> --
> Gabriel Genellina

well, I want to (maybe) have a dictionary where the value is a list of
5 lists. And I want to add a LOT of data to these lists. 10´s of
millions of pieces of data. Will this be a big problem? I can just try
it out in practice on monday too :)

thanks

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

Re: creating really big lists

2007-09-08 Thread Ricardo Aráoz
Dr Mephesto wrote:
> On Sep 8, 3:33 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
>> En Fri, 07 Sep 2007 16:16:46 -0300, Dr Mephesto <[EMAIL PROTECTED]>
>> escribi?:
>>
>>> hey, that defaultdict thing looks pretty cool...
>>> whats the overhead like for using a dictionary in python?
>> Dictionaries are heavily optimized in Python. Access time is O(1),
>> adding/removing elements is amortized O(1) (that is, constant time unless
>> it has to grow/shrink some internal structures.)
>>
>> --
>> Gabriel Genellina
> 
> well, I want to (maybe) have a dictionary where the value is a list of
> 5 lists. And I want to add a LOT of data to these lists. 10´s of
> millions of pieces of data. Will this be a big problem? I can just try
> it out in practice on monday too :)
> 
> thanks
> 
> 

targetList = myDict[someKey]# This takes normal dict access time
for j in xrange(5) :
for i in xrange(5000) :# Add a LOT of data to targetList
targetList[j].append(i)# This takes normal list access time



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


/dev/null as a file-like object, or logging to nothing

2007-09-08 Thread Torsten Bronger
Hallöchen!

Is there a portable and simply way to direct file-like IO to simply
nothing?  I try to implement some sort of NullLogging by saying

--8<---cut here---start->8---
import logging
if options.logging:
logging.basicConfig(level=logging.DEBUG, filename=options.logfile, 
filemode="w",
format='%(asctime)s %(name)s %(levelname)s   
%(message)s')
else:
# redirect logging to a memory buffer in order to simply ignore it.
import StringIO
logging.basicConfig(stream=StringIO.StringIO())
--8<---cut here---end--->8---

However, this consumes memory.  Is there a better way?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating really big lists

2007-09-08 Thread Paul Rubin
Dr Mephesto <[EMAIL PROTECTED]> writes:
> well, I want to (maybe) have a dictionary where the value is a list of
> 5 lists. And I want to add a LOT of data to these lists. 10´s of
> millions of pieces of data. Will this be a big problem? I can just try
> it out in practice on monday too :)

Yes, that may be a problem both because of the amount of memory
required, and because of how the GC works.  You may want to turn off
the GC while building these list.  Otherwise, think of some other
strategy, like files on disk.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Steven D'Aprano
On Sat, 08 Sep 2007 12:08:16 -0300, Ricardo Aráoz wrote:


>>  if type(x) == type(True):
>> ...print "bool"
>> ...
>> bool
>> 
>> 
> Or just :
> 
 a = True
 type(a) == int
> False

[snip]

You know, one or two examples was probably plenty. The other six or seven 
didn't add anything to your post except length.

Also, type testing by equality is generally not a good idea. For example:

class HexInt(int):
"""Like built-in ints, but print in hex by default."""
def __str__(self):
return hex(self)
__repr__ = __str__

You should be able to use a HexInt anywhere you can use an int. But not 
if your code includes something like this:

if type(value) == int:
do_something()
else:
print "Not an int!"

(What do you mean my HexInt is not an int? Of course it is.)

Better is to use isinstance(value, int). Better still is to do duck-
typing, and avoid type() and isinstance() as much as possible.



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

Re: /dev/null as a file-like object, or logging to nothing

2007-09-08 Thread Carsten Haese
On Sat, 2007-09-08 at 18:52 +0200, Torsten Bronger wrote:
> Hallöchen!
> 
> Is there a portable and simply way to direct file-like IO to simply
> nothing?  I try to implement some sort of NullLogging by saying
> 
> --8<---cut here---start->8---
> import logging
> if options.logging:
> logging.basicConfig(level=logging.DEBUG, filename=options.logfile, 
> filemode="w",
> format='%(asctime)s %(name)s %(levelname)s   
> %(message)s')
> else:
> # redirect logging to a memory buffer in order to simply ignore it.
> import StringIO
> logging.basicConfig(stream=StringIO.StringIO())
> --8<---cut here---end--->8---
> 
> However, this consumes memory.  Is there a better way?

This might work:

class LogSink(object):
def write(self, *args, **kwargs): pass
def flush(self, *args, **kwargs): pass

logging.basicConfig(stream=LogSink())

I haven't tested this thoroughly, so it's possible that there are more
methods that the stream is expected to implement.

HTH,

-- 
Carsten Haese
http://informixdb.sourceforge.net


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


Re: /dev/null as a file-like object, or logging to nothing

2007-09-08 Thread Marc 'BlackJack' Rintsch
On Sat, 08 Sep 2007 18:52:57 +0200, Torsten Bronger wrote:

> Is there a portable and simply way to direct file-like IO to simply
> nothing?  I try to implement some sort of NullLogging by saying

`os.devnull`?

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


Re: wxPython unexpected exit

2007-09-08 Thread Jimmy
On Sep 7, 9:42 pm, [EMAIL PROTECTED] wrote:
> On Sep 7, 3:10 am, Jimmy <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi, wxPython is cool and easy to use, But I ran into a problem
> > recently when I try to write a GUI.
> > The thing is I want to periodically update the content of StatixText
> > object, so after create them, I pack them into a list...the problem
> > comes when I later try to extract them from the list! I don't know
> > why?
> > my code is as following:
>
> > import wx, socket
> > import thread
>
> > class MyFrame(wx.Frame):
>
> > firstrun = 0
> > def __init__(self):
> > wx.Frame.__init__(self, None, -1, 'Notifier')
> > self.panel = wx.Panel(self, -1)
> > self.length = 50
> > self.scale = 0.6
> > self.count = 5
> > self.size = wx.Frame.GetSize(self)
> > self.distance = self.size[1] / self.count
> > self.labellist = []
> > self.gaugelist = []
>
> > def ParseAndDisplay(self, data):
> > print "Successful access to main Frame class"
> > print 'And receive data: ', data
> > if MyFrame.firstrun == 0:
> > print 'First time run'
> > items = 3
> > for i in range(items):
> > 
> > self.labellist.append(wx.StaticText(self.panel, -1, data+str(i),
> > (150, 50+i*20), (300,30)))
> > MyFrame.firstrun = 1
> > else:
> > self.labellist[0].SetLabel('AAA')//PROGRAM WILL 
> > ABORT HERE!!!
> > self.labellist[1].SetLabel("Guo")
> > self.labellist[2].SetLabel("Qiang")
>
> > class NetUdp:
>
> > def __init__(self):
> > self.port = 8081
> > self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> > self.s.bind(("", self.port))
> > print "Listening on port", self.port
>
> > def recvdata(self):
> > data, addr = self.s.recvfrom(1024)
> > return data
>
> > def netThread():
> > netudp = NetUdp()
> > while True:
> > data = netudp.recvdata()
> > frame.ParseAndDisplay(data)
>
> > if __name__ == '__main__':
> > firstrun = 0
> > app = wx.PySimpleApp()
> > frame = MyFrame()
> > frame.Show()
> > # start network thread first
> > id = thread.start_new_thread(netThread, ())
> > # main wxpython loop begins
> > app.MainLoop()
>
> > I know the code is ugly, but can anyone really save me here!
>
> If you use threads that update the GUI, you need to take a look at the
> following wiki page:http://wiki.wxpython.org/LongRunningTasks
>
> I've used the techniques therein and they *just work*. I'm not sure if
> you can set values on items in a list or not. I've tried that sort of
> thing and sometimes it works and sometimes it doesn't.
>
> The wxPython group is probably the best place to ask these questions
> anyway:http://www.wxpython.org/maillist.php
>
> Mike

Thanks for your help! It seems work!
Another question: I create a progress bar, and on creation, it will be
displayed,
How can I invisualize it when later I no longer need it?

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


Re: startswith( prefix[, start[, end]]) Query

2007-09-08 Thread rzed
Duncan Booth <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

I went through your example to get timings for my machine, and I 
ran into an issue I didn't expect.

My bat file did the following 10 times in a row:
(the command line wraps in this post)

call timeit -s "s='abracadabra1'*1000;t='abracadabra2';
startswith=s.startswith" startswith(t)
... giving me these times:

100 loops, best of 3: 0.483 usec per loop
100 loops, best of 3: 0.49 usec per loop
100 loops, best of 3: 0.489 usec per loop
100 loops, best of 3: 0.491 usec per loop
100 loops, best of 3: 0.488 usec per loop
100 loops, best of 3: 0.492 usec per loop
100 loops, best of 3: 0.49 usec per loop
100 loops, best of 3: 0.493 usec per loop
100 loops, best of 3: 0.486 usec per loop
100 loops, best of 3: 0.489 usec per loop

Then I thought that a shorter name for the lookup might affect the 
timings, so I changed the bat file, which now did the following 10 
times in a row:

timeit -s "s='abracadabra1'* 1000;t='abracadabra2';
sw=s.startswith" sw(t)

... giving me these times:
100 loops, best of 3: 0.516 usec per loop
100 loops, best of 3: 0.512 usec per loop
100 loops, best of 3: 0.514 usec per loop
100 loops, best of 3: 0.517 usec per loop
100 loops, best of 3: 0.515 usec per loop
100 loops, best of 3: 0.518 usec per loop
100 loops, best of 3: 0.523 usec per loop
100 loops, best of 3: 0.513 usec per loop
100 loops, best of 3: 0.514 usec per loop
100 loops, best of 3: 0.515 usec per loop

In other words, the shorter name did seem to affect the timings, 
but in a negative way. Why it would actually change at all is 
beyond me, but it is consistently this way on my machine. 

Can anyone explain this?

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


Re: /dev/null as a file-like object, or logging to nothing

2007-09-08 Thread Torsten Bronger
Hallöchen!

Marc 'BlackJack' Rintsch writes:

> On Sat, 08 Sep 2007 18:52:57 +0200, Torsten Bronger wrote:
>
>> Is there a portable and simply way to direct file-like IO to
>> simply nothing?  I try to implement some sort of NullLogging by
>> saying
>
> `os.devnull`?

Yes, but I wasn't really sure how portable it is, in particular, on
Windows.  So does

open(os.devnull, "w").write("Schallalla")

work on Windows like on Unix?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Using struct timeval in python

2007-09-08 Thread sapsi
Hi,
I am using a library (pcapy) that returns a timeval object T=
(seconds,microseconds) where microseconds is always < 1e6.
Is there a Python class that can handle timeval structs? Specifically,
I wish to subtract two T (defined above) objects, taking into account
the large values of T[0] and T[1] (esp T[0])?

At one point, I would have to step in, since T[0] rolls back to zero
(after some time).

Any pointers?
Thanks in advance
Saptarshi

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


Re: Why 'class spam(object)' instead of class spam(Object)' ?

2007-09-08 Thread Sergio Correia
Thanks for the replies, very instructive!

On 9/7/07, Steve Holden <[EMAIL PROTECTED]> wrote:
> Carl Banks wrote:
> > On Fri, 07 Sep 2007 01:30:00 -0500, Sergio Correia wrote:
> >> Hi, I'm kinda new to Python (that means, I'm a total noob here), but
> >> have one doubt which is more about consistency that anything else.
> >>
> >> Why if PEP 8 says that "Almost without exception, class names use the
> >> CapWords convention", does the most basic class, object, is lowercase?
> >
> > It said "almost".  :)
> >
> Indeed it did, and never forget that most of PEP 8 was derived from an
> essay by Guido whose original title was "A Foolish Consistency is the
> Hobgoblin of Little Minds" ...
> >
> >> I found a thread about this:
> >> http://mail.python.org/pipermail/python-list/2007-April/437365.html
> >> where its stated that -object- is actually a type, not a class; but the
> >> idea still doesn't convince me.
> >
> You don't have to be convinced. You just have to do what the PEP says
> yourself and ignore the people who *haven't* done what it says
> (particularly if they are core Python developers).
>
> > There's a false dichotomy there: it's not an either-or situation.  Almost
> > everyone would agree that new-style classes, defined by the Python class
> > statement, are both classes and types.  Some might squabble over whether
> > object is class, but it has nothing to do with why object is spelled in
> > lower-case.
> >
> > The reason why "object" is lower case is because built-in types are
> > spelled in lower-case.  Why are built-in types lower case?  Because many
> > built-in types were originially functions.  For example, "int" and "str"
> > were once functions.  When these symbols became the names of their
> > respective types, they kept the lower-case spelling, and it became
> > convention for built-in types to be spelled lower-case.
> >
> In other words: "Get over it" ;-)
>
> regards
>   Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC/Ltd   http://www.holdenweb.com
> Skype: holdenweb  http://del.icio.us/steve.holden
> --- Asciimercial --
> Get on the web: Blog, lens and tag the Internet
> Many services currently offer free registration
> --- Thank You for Reading -
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /dev/null as a file-like object, or logging to nothing

2007-09-08 Thread Torsten Bronger
Hallöchen!

Carsten Haese writes:

> On Sat, 2007-09-08 at 18:52 +0200, Torsten Bronger wrote:
>
>> Is there a portable and simply way to direct file-like IO to
>> simply nothing?  [...]
>>
>> [...]
>
> This might work:
>
> class LogSink(object):
> def write(self, *args, **kwargs): pass
> def flush(self, *args, **kwargs): pass
>
> logging.basicConfig(stream=LogSink())
>
> I haven't tested this thoroughly, so it's possible that there are
> more methods that the stream is expected to implement.

No, write and flush are enough.  Thank, this works.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


How to insert in a string @ a index

2007-09-08 Thread lolu999
Hi;

I'm trying to insert XYZ before a keyword in a string. The first and
the last occurence of hello in the string t1 (t1="hello world hello.
hello \nwhy world hello") are keywords. So after the insertion of XYZ
in this string, the result should be t1 = "XYZhello world hello. hello
\nwhy world XYZhello"

The python doesn't supports t1[keyword_index]="XYZhello" (string
object assignment is not supported). How do I get to this problem? Any
sugguestions?

-a.m.

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


wxpython automate progress bar

2007-09-08 Thread Jimmy
Hi, I want a progress bar to increase automatically, so I wrote code
like this:
current = 0
while True:
if current == 100:
current = 0
self._gauge.SetValue(current)
time.sleep(0.1)
current = current + 1

I put this in the __init__ section, however, the window will never
show! and there are
error message like this:
** (python:28543): CRITICAL **: clearlooks_style_draw_handle:
assertion `width >= -1' failed

can anyone tell me why this happen?Thanks :)

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


Re: How to insert in a string @ a index

2007-09-08 Thread David
> The python doesn't supports t1[keyword_index]="XYZhello" (string
> object assignment is not supported). How do I get to this problem? Any
> sugguestions?

Build a new string var using slicing. eg:

t1 = t1[:keyword_index] + "XYZhello" + [keyword_index]

Or use string formatting:

t1 = "your text bla bla %s bla bla bla %s bla bla" % (string1, string2)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to insert in a string @ a index

2007-09-08 Thread David
On 9/8/07, David <[EMAIL PROTECTED]> wrote:
> > The python doesn't supports t1[keyword_index]="XYZhello" (string
> > object assignment is not supported). How do I get to this problem? Any
> > sugguestions?
>
> Build a new string var using slicing. eg:
>
> t1 = t1[:keyword_index] + "XYZhello" + [keyword_index]
>

Typo. Missed a colon. Should be:

t1 = t1[:keyword_index] + "XYZhello" + [keyword_index:]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to determine the bool between the strings and ints?

2007-09-08 Thread Ricardo Aráoz
Steven D'Aprano wrote:
...
..
.
> You know, one or two examples was probably plenty. The other six or seven 
> didn't add anything to your post except length.
> 
> Also, type testing by equality is generally not a good idea. For example:
> 
> class HexInt(int):
> """Like built-in ints, but print in hex by default."""
> def __str__(self):
> return hex(self)
> __repr__ = __str__
> 
> You should be able to use a HexInt anywhere you can use an int. But not 
> if your code includes something like this:
> 
> if type(value) == int:
> do_something()
> else:
> print "Not an int!"
> 
> (What do you mean my HexInt is not an int? Of course it is.)
> 
> Better is to use isinstance(value, int). Better still is to do duck-
> typing, and avoid type() and isinstance() as much as possible.

>>> type(a) == HexInt
True

That's what I wanted (though I don't know if that's what the OP wanted).
BTW, sorry for the wasted bandwidth, didn't realize you might have such
a small bandwidth that seven lines would be a hassle. We should also
tell the blokes of the 'music' thread to stop it, I can imagine how mad
that must get you.



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


Re: wxpython automate progress bar

2007-09-08 Thread Chris Mellon
On 9/8/07, Jimmy <[EMAIL PROTECTED]> wrote:
> Hi, I want a progress bar to increase automatically, so I wrote code
> like this:
> current = 0
> while True:
> if current == 100:
> current = 0
> self._gauge.SetValue(current)
> time.sleep(0.1)
> current = current + 1
>
> I put this in the __init__ section, however, the window will never
> show! and there are
> error message like this:
> ** (python:28543): CRITICAL **: clearlooks_style_draw_handle:
> assertion `width >= -1' failed
>
> can anyone tell me why this happen?Thanks :)
>

Because you are blocking the event loop so while you are doing this
your application isn't running and not painting. Use a wx.Timer
instead.

Why are you lying to your users about what you are doing and how long
it is taking anyway?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using struct timeval in python

2007-09-08 Thread David
On 9/8/07, sapsi <[EMAIL PROTECTED]> wrote:
> Hi,
> I am using a library (pcapy) that returns a timeval object T=
> (seconds,microseconds) where microseconds is always < 1e6.
> Is there a Python class that can handle timeval structs? Specifically,
> I wish to subtract two T (defined above) objects, taking into account
> the large values of T[0] and T[1] (esp T[0])?
>
> At one point, I would have to step in, since T[0] rolls back to zero
> (after some time).

The Pythonic way would be to convert directly to a datetime (or
perhaps timedelta) object as soon as you receive your (seconds,
microseconds) tuple. Then you can subtract etc easily and interoperate
nicely with the rest of the standard python library.

But if you want to keep it in tuple format then you will probably need
to roll your own. eg: subclass tuple and override the __sub__ method.
Just make sure you handle negative values correctly (ie, what
(seconds,microseconds) you should end up with when you subtract a
later timval from an earlier timeval).

Alternatively you could convert to and from datetime as you need to
(perhaps subclassing and adding methods for easier conversion), but
that would be more expensive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Organizing Code - Packages

2007-09-08 Thread xkenneth
On Sep 7, 2:04 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
> Paul Rudin wrote:
> > xkenneth <[EMAIL PROTECTED]> writes:
>
> >>> Ah, yes, a couple of things:
> >>> - avoid the 'one-class-per-file' syndrom. It's perfectly ok to have tens
> >> Yes but i find it hard to edit classes easily when I have more than
> >> one class per file.
>
> > Why?
>
> Scroll-Blindness would be a good reason.
>
> It would however be completely rediculous to create a file for every
> 10-liner class you have (and I have found that Python classes tend to be
> rather short).
>
> /

Yes I agree, "Scroll-Blindness" it just gets long and confusing.
Navigating isn't so bad (emacs) here. I have another question for
something I don't quite understand.

How do import statements that are declared at the top of a python
module work?

for instance

from MyModule.Objects import *

class Class:
  def function:
   #here i cannot access the things that should have been
imported from the above statement
   #i printed the dir() function to verify this

This happens when I'm using the Class i just defined from another
python script. I can understand if that statement at the top if not
being executed when I import the above defined class, if so, I need to
access the classes from the other modules, so where do I put the
import statement? Is it proper to put import statements inside of
class function definitions? This solves my problem but seems VERY
incorrect coming from my old C/C++ ways.

Thanks Again!

Regards,
Ken


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


Re: Organizing Code - Packages

2007-09-08 Thread Marc 'BlackJack' Rintsch
On Sat, 08 Sep 2007 12:42:19 -0700, xkenneth wrote:

> How do import statements that are declared at the top of a python
> module work?

They import the module.  ;-)

> for instance
> 
> from MyModule.Objects import *
> 
> class Class:
>   def function:
>#here i cannot access the things that should have been
> imported from the above statement
>#i printed the dir() function to verify this

Sorry I don't believe this.  This doesn't even compile because the method
`function()` lacks the arguments in the definition.  Please post actual
code and actual tracebacks you get.

And `MyModule` is a bad name for a package.

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


Re: Organizing Code - Packages

2007-09-08 Thread David
>
> How do import statements that are declared at the top of a python
> module work?
>
> for instance
>
> from MyModule.Objects import *
>
> class Class:
>   def function:
>#here i cannot access the things that should have been
> imported from the above statement
>#i printed the dir() function to verify this

I have seen this myself (stuff seemingly not imported) when 2 modules
import each other, perhaps indirectly, and try to use elements from
each other (at the global/declaration step, rather than in functions.
Logic that runs later (not during the import phase) still works fine,
however)). This sounds like the problem you're having, but your code
snippet isn't complete enough for me to tell. The way to fix this is
generally to move out stuff used by both modules into a separate
module.

Another reason can be that the imported module should be but isn't
setting the "__all__" variable. (in general the "import *" syntax is
frowned upon, it reduces readability).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using struct timeval in python

2007-09-08 Thread sapsi
The timedelta module did the job just fine.
Thank you


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


Re: Organizing Code - Packages

2007-09-08 Thread David
> How do import statements that are declared at the top of a python
> module work?

http://docs.python.org/tut/node8.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Parsing nested constructs

2007-09-08 Thread tool69
Hi,

I need to parse some source with nested parenthesis, like this :

 >cut-

{
 {item1}
 {
  {item2}
  {item3}
 }
}

 >cut-


In fact I'd like to get all start indexes of items and their end (or 
lenght).

I know regexps are rather limited for this type of problems.
I don't need an external module.

What would you suggest me ?

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


Spell-checking Python source code

2007-09-08 Thread John Zenger
To my horror, someone pointed out to me yesterday that a web app I
wrote has been prominently displaying a misspelled word.  The word was
buried in my code.

Is there a utility out there that will help spell-check literal
strings entered into Python source code?  I don't mean spell-check
strings entered by the user; I mean, go through the .py file, isolate
strings, and tell me when the strings contain misspelled words.  In an
ideal world, my IDE would do this with a red wavy line.

I guess a second-best thing would be an easy technique to open a .py
file and isolate all strings in it.

(I know that the better practice is to isolate user-displayed strings
from the code, but in this case that just didn't happen.)

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


Re: Parsing nested constructs

2007-09-08 Thread David
On 9/8/07, tool69 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to parse some source with nested parenthesis, like this :
>

If this is exactly how your data looks, then how about a loop which
searches for "{item" and the following "}"? You can use the "find"
string method for that.

Otherwise, if the items don't look exactly like "{item", but the
formatting is otherwise exactly the same as above, then look for lines
that have both "{" and "}" on them, then get the string between them.

Otherwise, if { and } and the item aren't always on the same line,
then go through the string character by character, keep track of when
you encounter "{" and "}". When you encounter a "}" and there was a
"{" before (ie, not a "}"), then get the string between the "{" and
the "}"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spell-checking Python source code

2007-09-08 Thread Ricardo Aráoz
John Zenger wrote:
> To my horror, someone pointed out to me yesterday that a web app I
> wrote has been prominently displaying a misspelled word.  The word was
> buried in my code.
> 
> Is there a utility out there that will help spell-check literal
> strings entered into Python source code?  I don't mean spell-check
> strings entered by the user; I mean, go through the .py file, isolate
> strings, and tell me when the strings contain misspelled words.  In an
> ideal world, my IDE would do this with a red wavy line.
> 
> I guess a second-best thing would be an easy technique to open a .py
> file and isolate all strings in it.
> 
> (I know that the better practice is to isolate user-displayed strings
> from the code, but in this case that just didn't happen.)
> 

Use the re module, identify the strings and write them to another file,
then open the file with your spell checker. Program shouldn't be more
than 10 lines.



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


Re: Spell-checking Python source code

2007-09-08 Thread David
> >
> > (I know that the better practice is to isolate user-displayed strings
> > from the code, but in this case that just didn't happen.)
> >
>
> Use the re module, identify the strings and write them to another file,
> then open the file with your spell checker. Program shouldn't be more
> than 10 lines.
>
>

Have a look at the tokenize python module for the regular expressions
for extracting strings (for all possible Python string formats). On a
Debian box you can find it here: /usr/lib/python2.4/tokenize.py

It would probably be simpler to hack a copy of that script so it
writes all the strings in your source to a text file, which you then
spellcheck.

Another method would be to log all the strings your web app writes, to
a text file, then run through your entire site, and then spellcheck
your logfile.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to insert in a string @ a index

2007-09-08 Thread Zentrader
Same solution as above, but if you just want "Hello" and to not
include words containing "Hello", i.e. "Helloing" or "Unhello", then
you want to include a leading and/or trailing space.

lit=" hello"  ## note added space
t1="nothello world hello. hello \nwhy world hello"
start = t1.find(lit)
t2 = t1[:start+1] + " XYZ" + t1[start+1:]
print "t1 =", t1
print "t2 =", t2
start = t2.rfind(lit)
t3 = t2[:start+1] + " XYZ" + t2[start+1:]
print "t3 =", t3

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


Re: How to insert in a string @ a index

2007-09-08 Thread David
On 9/8/07, Zentrader <[EMAIL PROTECTED]> wrote:
> Same solution as above, but if you just want "Hello" and to not
> include words containing "Hello", i.e. "Helloing" or "Unhello", then
> you want to include a leading and/or trailing space.

You can also use the re (regular expression) module to search for
"hello" and make sure it's a complete word. You would use re to search
for something like "\bhello\b". "\b" being regex for an empty string
that only occurs at the start or beginning of a word.

More information on python regexes here: http://www.amk.ca/python/howto/regex/

Here is an example from that page:

>>> p = re.compile(r'\bclass\b')
>>> print p.search('no class at all')

>>> print p.search('the declassified algorithm')
None
>>> print p.search('one subclass is')
None
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing nested constructs

2007-09-08 Thread tool69
David a écrit :
> On 9/8/07, tool69 <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I need to parse some source with nested parenthesis, like this :
>>
> 
> If this is exactly how your data looks, then how about a loop which
> searches for "{item" and the following "}"? You can use the "find"
> string method for that.
> 
> Otherwise, if the items don't look exactly like "{item", but the
> formatting is otherwise exactly the same as above, then look for lines
> that have both "{" and "}" on them, then get the string between them.
> 
> Otherwise, if { and } and the item aren't always on the same line,
> then go through the string character by character, keep track of when
> you encounter "{" and "}". When you encounter a "}" and there was a
> "{" before (ie, not a "}"), then get the string between the "{" and
> the "}"
Hi David,

thanks for answering, I will choose the last one as my strings are not 
on the same line and may contain a lot of stuff inside.

cheers,

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


Re: Spell-checking Python source code

2007-09-08 Thread Ricardo Aráoz
David wrote:
>>> (I know that the better practice is to isolate user-displayed strings
>>> from the code, but in this case that just didn't happen.)
>>>
>> Use the re module, identify the strings and write them to another file,
>> then open the file with your spell checker. Program shouldn't be more
>> than 10 lines.
>>
>>
> 
> Have a look at the tokenize python module for the regular expressions
> for extracting strings (for all possible Python string formats). On a
> Debian box you can find it here: /usr/lib/python2.4/tokenize.py
> 
> It would probably be simpler to hack a copy of that script so it
> writes all the strings in your source to a text file, which you then
> spellcheck.
> 
> Another method would be to log all the strings your web app writes, to
> a text file, then run through your entire site, and then spellcheck
> your logfile.
> 

Nice module :

import tokenize

def processStrings(type, token, (srow, scol), (erow, ecol), line):
if tokenize.tok_name[type] == 'STRING' :
print tokenize.tok_name[type], token, \
  (srow, scol), (erow, ecol), line

file = open("myprogram.py")

tokenize.tokenize(
file.readline,
processStrings
)

How would you go about writing the output to a file? I mean, I would
like to open the file at main level and pass a handle to the file to
processStrings to write to it, finally close output file at main level.
Probably a class with a processString method?


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


help - error when trying to call super class method

2007-09-08 Thread dontknowwhy88

I am trying to extend list class to build a stack class -- see code below---
but I got an error when I try to call len method from list class here.. why?
Thanks in advance!
-

class Stackx(list):
   
  def push(self,x):  
  indx= super.len(x)
  self.insert(my_len+1,x) 
  
  def pop(self):
  return self[-1]
 
def test():

myStack = Stackx([1, 2 ,3 ,4])
print myStack
myStack.push(9)
print myStack
print myStack.pop()


if __name__=='__main__':
test()


'''

Traceback (most recent call last):
  File "C:\Python25\Stack2.py", line 20, in 
test()
  File "C:\Python25\Stack2.py", line 14, in test
myStack.push(9)
  File "C:\Python25\Stack2.py", line 4, in push
indx= super.len(x)
AttributeError: type object 'super' has no attribute 'len'
'''

   
-
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out. -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Organizing Code - Packages

2007-09-08 Thread xkenneth
On Sep 8, 3:35 pm, David <[EMAIL PROTECTED]> wrote:
> > How do import statements that are declared at the top of a python
> > module work?
>
> http://docs.python.org/tut/node8.html

On Sat, 08 Sep 2007 12:42:19 -0700, xkenneth wrote:
> How do import statements that are declared at the top of a python
> module work?

They import the module.  ;-)
> for instance
> from MyModule.Objects import *

> class Class:
>   def function:
>#here i cannot access the things that should have been
> imported from the above statement
>#i printed the dir() function to verify this


Sorry I don't believe this.  This doesn't even compile because the
method
`function()` lacks the arguments in the definition.  Please post
actual
code and actual tracebacks you get.
And `MyModule` is a bad name for a package.

Ciao,
Marc 'BlackJack' Rintsch

Code doesn't compile in python. This is pseudo code anyways.
Can't post actual code and tracebacks because the code is proprietary.
"MyModule" is pseudo code, and i forgot the arguments, the actual code
and errors are unimportant for this question.

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


Re: Parsing nested constructs

2007-09-08 Thread Paul McGuire
On Sep 8, 3:42 pm, tool69 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to parse some source with nested parenthesis, like this :
>
>  >cut-
>
> {
>  {item1}
>  {
>   {item2}
>   {item3}
>  }
>
> }
>
>  >cut-
>
> In fact I'd like to get all start indexes of items and their end (or
> lenght).
>
> I know regexps are rather limited for this type of problems.
> I don't need an external module.
>
> What would you suggest me ?
>
> Thanks.

Well, it is an external module, but pyparsing makes this pretty
straightforward:

from pyparsing import *

data = """
{
 {item1}
 {
  {item2}
  {item3}
 }

}
"""

# define delimiters, but suppress them from the output
LBRACE,RBRACE = map(Suppress,"{}")

# forward define recursive items list
items = Forward()

# items is zero or more words of alphas and numbers, or an embedded
# group enclosed in braces
items << ZeroOrMore( Word(alphanums) | Group( LBRACE + items +
RBRACE ) )

# parse the input string, and print out the results
print items.parseString(data)

"""
prints:
[[['item1'], [['item2'], ['item3'

or:
[
[
['item1'],
[
['item2'],
['item3']
]
]
]
"""

-- Paul

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


Re: Organizing Code - Packages

2007-09-08 Thread Tommy Grav

On Sep 8, 2007, at 8:04 PM, xkenneth wrote:
>
> Code doesn't compile in python. This is pseudo code anyways.
> Can't post actual code and tracebacks because the code is proprietary.
> "MyModule" is pseudo code, and i forgot the arguments, the actual code
> and errors are unimportant for this question.

The code and traceback is important because the behavior you claim
is not easily explained without more information. How are we suppose  
to help
you make your code run, when you can't even properly explain the  
problem?

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


Re: Spell-checking Python source code

2007-09-08 Thread DaveM
On Sat, 08 Sep 2007 14:04:55 -0700, John Zenger <[EMAIL PROTECTED]>
wrote:

> In an ideal world, my IDE would do this with a red wavy line.

I can't help with your problem, but this is the first thing I turn off in
Word. It drives me _mad_. 

Sorry - just had to share that.

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


Re: help - error when trying to call super class method

2007-09-08 Thread Jeff McNeil
You shouldn't even need the call to super in that method, a simple
'len(self)' ought to be sufficient.  Note that using the list object's
append method is going to be much more efficient than handling it yourself
anyways.

There are a few problems in your call to super. First, it's a callable - it
doesn't work like the Java equivalent.  Next, as the superclass of Stackx is
list, and there is no 'len' attribute on list, you'll bomb with an
AttributeError.

Lastly, you'll also generate an AttributeError when you increment 'my_len.'

Here's a quick example using 'super.'

class X(object):
def meth(self):
print "Hello"

class Y(X):
def meth(self):
super(Y, self).meth()

Y().meth()

$ python test.py
Hello

For a bit more information on the use of super, check out
http://docs.python.org/lib/built-in-funcs.html. Lastly, super will only work
with new-style classes (which yours is, due to the subclass of list).

-Jeff


On 9/8/07, dontknowwhy88 <[EMAIL PROTECTED]> wrote:
>
>
> I am trying to extend list class to build a stack class -- see code
> below---
> but I got an error when I try to call len method from list class here..
> why?
> Thanks in advance!
> -
>
> class Stackx(list):
>
>   def push(self,x):
>   indx= super.len(x)
>   self.insert(my_len+1,x)
>
>   def pop(self):
>   return self[-1]
>
> def test():
>
> myStack = Stackx([1, 2 ,3 ,4])
> print myStack
> myStack.push(9)
> print myStack
> print myStack.pop()
>
>
> if __name__=='__main__':
> test()
>
>
> '''
>
> Traceback (most recent call last):
>   File "C:\Python25\Stack2.py", line 20, in 
> test()
>   File "C:\Python25\Stack2.py", line 14, in test
> myStack.push(9)
>   File "C:\Python25\Stack2.py", line 4, in push
> indx= super.len(x)
> AttributeError: type object 'super' has no attribute 'len'
> '''
>
> --
> Be a better Heartthrob. Get better relationship answers
> from
> someone who knows.
> Yahoo! Answers - Check it out.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

include myVar

2007-09-08 Thread Ricardo Aráoz
Is there a way to import a module whose name is in a variable (read from
a configuration file for example)?

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


Re: include myVar

2007-09-08 Thread Richard Jones
Ricardo Aráoz wrote:
> Is there a way to import a module whose name is in a variable (read from
> a configuration file for example)?

pydoc __import__


Richard

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

Re: Spell-checking Python source code

2007-09-08 Thread David Trudgett
John Zenger writes:

> In an ideal world, my IDE would do this with a red wavy line.

You didn't mention which IDE you use; however, if you use Emacs, there
is flyspell-prog-mode which does that for you (checks your spelling
"on the fly", but only within comments and strings).

Regards,
David Trudgett

-- 
These are not the droids you are looking for. Move along.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class design (information hiding)

2007-09-08 Thread Alex Martelli
Gregor Horvath <[EMAIL PROTECTED]> wrote:

> Alexander Eisenhuth schrieb:
> > 
> > I'm wodering how the information hiding in python is ment. As I 
> > understand there  doesn't exist public / protected / private  mechanism,
> > but a '_' and '__' naming convention.
> > 
> > As I figured out there is only public and private possible as speakin in
> > "C++ manner". Are you all happy with it. What does "the zen of python"
> > say to that design? (protected is useless?)
> 
> My favourite thread to this FAQ:
> 
>
> http://groups.google.at/group/comp.lang.python/browse_thread/thread/2c85
> d6412d9e99a4/b977ed1312e10b21#b977ed1312e10b21

Why, thanks for the pointer -- I'm particularly proud of having written
"""
The only really workable way to develop large software projects, just as
the only really workable way to run a large business, is a state of
controlled chaos.
"""
*before* I had read Brown and Eisenhardt's "Competing on the Edge:
Strategy as Structured Chaos" (at that time I had no real-world interest
in strategically managing a large business -- it was based on mere
intellectual curiosity and extrapolation that I wrote "controlled chaos"
where B & E have "structured chaos" so well and clearly explained;-).

BTW, if you want to read my entire post on that Austrian server, the
most direct URL is

...


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


Re: Does shuffle() produce uniform result ?

2007-09-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote:

> Any cryptographer worth his salt (pun intended) would be looking to close
> that vulnerability BEFORE an attack is made public, and not just wait for
> the attack to trickle down from the NSA to the script kiddies.

Except that the NSA's reputation has taken a dent since they failed to
anticipate the attacks on MD5 and SHA-1.
-- 
http://mail.python.org/mailman/listinfo/python-list


APL2007 reminder: early (cheaper) registration ends Thursday 9/13

2007-09-08 Thread Mike Kent
On-line registration is through the OOPSLA registrar

http://www.regmaster.com/conf/oopsla2007.html


APL 2007 home page

http://www.sigapl.org/apl2007.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing nested constructs

2007-09-08 Thread Wildemar Wildenburger
Paul McGuire wrote:
> Well, it is an external module, but pyparsing makes this pretty
> straightforward:
> 
> [snip delightful parsing]
> 
Again pyparsing to the rescue :)

I have to do a parsing project in Java right now and I dearly miss 
pyparsing. I explained it to the guy I'm working for, and he was pretty 
impressed.

Thought that might make you smile.

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


Re: Does shuffle() produce uniform result ?

2007-09-08 Thread Paul Rubin
Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
> Except that the NSA's reputation has taken a dent since they failed to
> anticipate the attacks on MD5 and SHA-1.

NSA had nothing to do with MD5, and it's to NSA's credit that SHA-1
held up for as long as it did.
-- 
http://mail.python.org/mailman/listinfo/python-list


req.in Unix/SQL/Oracle/JAVA - Work Location US

2007-09-08 Thread TechRecruit Consultants
Hi

Greets!

This is sandy,Working in TechRecruit Consultants,Chennai as Head
Operaitons - Recruitment.

Currently we have openning in Unix/SQL/Oracle/JAVA for ISO 9001:2000/
CMM LEVEL 5  Company in US.

About the company:An ISO 9001:2000 /SEI-CMM Level 5 accreditation.

Experience:4 - 7 Years

Positions:Senior Level

JOB LOCATION - US

Candidate must also have experience in Unix, SQL, Oracle, and JAVA.
Experience with Weblogic and scripting is also highly desirable. Must
be a self-starter and have good communication skills. Sound procedures
for debugging, coding and testing of changes is needed due to the
criticality of the applications supported.

Kindly forward your updated profile in Word doc. to
[EMAIL PROTECTED]

Please fill the following details and revertback to me.

Current CTC:
Expected CTC:
Notice Period:
DOB:
Marital Status:
Convenient time for Telephonic Interview:


With Thanks and Regards,

Sandy,
Head Operations - Recruitment
TechRecruit Consultants,
India.

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


Re: Parsing nested constructs

2007-09-08 Thread Paul McGuire
On Sep 8, 10:01 pm, Wildemar Wildenburger
<[EMAIL PROTECTED]> wrote:
>
> Again pyparsing to the rescue :)
>
> I have to do a parsing project in Java right now and I dearly miss
> pyparsing. I explained it to the guy I'm working for, and he was pretty
> impressed.
>
> Thought that might make you smile.
>
> /W

Wildemar -

Thanks for such a glowing testimonial! It really is a boost of
encouragement when I find projects that are using pyparsing, or see
postings on c.l.py or the tutor list (by people other than me!)
recommending using pyparsing in response to someone's post.

I'm glad you find pyparsing so useful in your Python endeavors.

-- Paul

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


Python syntax wart

2007-09-08 Thread Lawrence D'Oliveiro
The one thing I don't like about Python syntax is using backslashes to
continue lines. Yes, you can avoid them if you can include parentheses
somehow, but this isn't always possible.

Possible:

if (
quitting
and
len(client["to_write"]) == 0
and
len(client["read"]) + client["to_read"] == 0
) :
close_client(client, "shutting down")
#end if

Not possible:

for \
Link \
in \
GetEachRecord \
  (
"links",
("from_episode",),
"to_episode = %s",
[EpisodeID],
"order by when_created"
  ) \
:
out.write \
  (
"Back to episode %d\n"
%
(
LinkToMe({"ep" : Link["from_episode"]}),
Link["from_episode"]
)
  )
#end for
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spell-checking Python source code

2007-09-08 Thread Miki
>> In an ideal world, my IDE would do this with a red wavy line.
>
> You didn't mention which IDE you use; however, if you use Emacs, there
> is flyspell-prog-mode which does that for you (checks your spelling
> "on the fly", but only within comments and strings).
Same in Vim (:set spell)

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: Python syntax wart

2007-09-08 Thread Marc 'BlackJack' Rintsch
On Sun, 09 Sep 2007 17:16:05 +1200, Lawrence D'Oliveiro wrote:

> The one thing I don't like about Python syntax is using backslashes to
> continue lines. Yes, you can avoid them if you can include parentheses
> somehow, but this isn't always possible.
> 
> Possible:
>
> […]
> 
> Not possible:
> 
> for \
> Link \
> in \
> GetEachRecord \
>   (
> "links",
> ("from_episode",),
> "to_episode = %s",
> [EpisodeID],
> "order by when_created"
>   ) \
> :
> out.write \
>   (
> "Back to episode %d\n"
> %
> (
> LinkToMe({"ep" : Link["from_episode"]}),
> Link["from_episode"]
> )
>   )
> #end for

What do you mean by not possible!?  This compiles fine for me.

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

Re: Python syntax wart

2007-09-08 Thread Stefan Behnel
Marc 'BlackJack' Rintsch wrote:
> On Sun, 09 Sep 2007 17:16:05 +1200, Lawrence D'Oliveiro wrote:
> 
>> The one thing I don't like about Python syntax is using backslashes to
>> continue lines. Yes, you can avoid them if you can include parentheses
>> somehow, but this isn't always possible.
>>
>> Possible:
>>
>> […]
>>
>> Not possible:
>>
>> for \
>> Link \
>> in \
>> GetEachRecord \
>>   (
>> "links",
>> ("from_episode",),
>> "to_episode = %s",
>> [EpisodeID],
>> "order by when_created"
>>   ) \
>> :
>> out.write \
>>   (
>> "Back to episode %d\n"
>> %
>> (
>> LinkToMe({"ep" : Link["from_episode"]}),
>> Link["from_episode"]
>> )
>>   )
>> #end for
> 
> What do you mean by not possible!?  This compiles fine for me.

He means he has to use backslashes instead of parentheses here.

Which is not true, you could easily rephrase this as:

for link in GetEachRecord(
 "links",
 ):
out.write(
 
 )

See? No backslash!

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

Re: debugging program that uses ctypes

2007-09-08 Thread Miki
Hello Marco,

> hi all, I have a python program that calls a dll through ctypes
> (py2.5). In some (reproducible)
> conditions the program crashes with an error in ctypes module.
> How can I trace down the problem? I have created a debug build of
> python but I also use pyodbc
> and dateutil libraries in my program and I don't know how to make them
> visible to python_d.exe
> Am I using the right approach?
If you are the one compiling the called module, you can add `__asm int
3` somewhere in
the code. When this is reached, the windows debugger will pop up on
the line.

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-08 Thread Miki
>   steps.sort(key = lambda s: s.time)
This is why attrgetter in the operator module was invented.
from operator import attrgetter
...
steps.sort(key=attrgettr("time"))

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: Does shuffle() produce uniform result ?

2007-09-08 Thread Bryan Olson
Paul Rubin wrote:
> Lawrence D'Oliveiro writes:
>> Except that the NSA's reputation has taken a dent since they failed to
>> anticipate the attacks on MD5 and SHA-1.
> 
> NSA had nothing to do with MD5, and it's to NSA's credit that SHA-1
> held up for as long as it did.

I haven't kept up. Has anyone exhibited a SHA-1 collision?


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


Re: Python syntax wart

2007-09-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Stefan Behnel wrote:

> He means he has to use backslashes instead of parentheses here.
> 
> Which is not true, you could easily rephrase this as:
> 
> for link in GetEachRecord(
>  "links",
>  ):
> out.write(
>  
>  )
> 
> See? No backslash!

But then you can no longer use indentation to display the two-dimensional
structure of the statement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does shuffle() produce uniform result ?

2007-09-08 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Paul Rubin wrote:

> Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes:
>
>> Except that the NSA's reputation has taken a dent since they failed to
>> anticipate the attacks on MD5 and SHA-1.
> 
> NSA had nothing to do with MD5 ...

Nevertheless, it was their job to anticipate attacks on it. After all, they
call themselves the "National _Security_ Agency", don't they?

> ... and it's to NSA's credit that SHA-1 held up for as long as it did.

But they have no convincing proposal for a successor. That means the gap
between the classified and non-classified state of the art has shrunk down
to insignificance.

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