re module help

2012-01-09 Thread Ganesh Kumar
Hi Guys, I have created regular expression with os modules, I have created file sdptool to match the regular expression pattern, will print the result. I want without creating file how to get required output, I tried but i didn't get output correctly, over stream. #! /usr/bin/python import os,re

Re: [BangPypers] re module help

2012-01-09 Thread Noufal Ibrahim
Ganesh Kumar writes: > Hi Guys, > > I have created regular expression with os modules, I have created file > sdptool to match the regular expression pattern, will print the result. > I want without creating file how to get required output, I tried but i > didn't get output correctly, over stream.

how to install lxml in window xp?

2012-01-09 Thread 水静流深
in my xp ,python26,easy_install installed. i want to install lxml in window xp 1.c:\python26\scripts\easy_install lxml what i get is: Reading http://codespeak.net/lxml Best match: lxml 2.3.3 Downloading http://lxml.de/files/lxml-2.3.3.tgz Processing lxml-2.3.3.tgz Running lxml-2.3.3\setup.p

Re: how to install lxml in window xp?

2012-01-09 Thread Stefan Behnel
水静流深, 09.01.2012 10:18: > in my xp ,python26,easy_install installed. > i want to install lxml in window xp > 1.c:\python26\scripts\easy_install lxml > > what i get is: > > Reading http://codespeak.net/lxml > Best match: lxml 2.3.3 > Downloading http://lxml.de/files/lxml-2.3.3.tgz > Processi

Re: python philosophical question - strong vs duck typing

2012-01-09 Thread Robert Kern
On 1/9/12 5:35 AM, John Nagle wrote: Python has some serious problems that preclude optimization. Basically, the language is designed to be run by a naive (non-optimizing) interpreter, and allows things that are easy for such an implementation but very tough to optimize. An example is the abilit

THE EXPANSION OF THE UNIVERSE IN THE QURAN !!!!!!!!!!!!!!

2012-01-09 Thread BV
THE EXPANSION OF THE UNIVERSE IN THE QURAN What you are about to read might sound unusual but it could be very enlightened In 1929, in the California Mount Wilson observatory, an American astronomer by the name of Edwin Hubble made one of the greatest discoveries in the history of astronomy. Whi

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Lie Ryan
On 01/09/2012 09:03 AM, Eelco wrote: i havnt read every post in great detail, but it doesnt seem like your actual question has been answered, so ill give it a try. AFAIK, changing __dict__ to be an ordereddict is fundamentally impossible in python 2. __dict__ is a builtin language construct hard

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 13:10, schrieb Lie Ryan: I was just suggesting that what the OP thinks he wants is quite likely not what he actually wants. Rest assured that the OP has a rather good idea of what he wants and why, the latter being something you don't know, because he never bothered to explain

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Roy Smith
In article , Ian Kelly wrote: > Randomizing the order is not a bad idea, but you also need to be able > to run the tests in a consistent order, from a specific random seed. > In the real world, test conflicts and dependencies do happen, and if > we observe a failure, make a change, rerun the tes

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Neil Cerutti
On 2012-01-09, Roy Smith wrote: > If somebody (i.e. the classic "consenting adult" of the Python > world) wants to take advantage of that to write a test suite > where the tests *do* depend on each other, and have to be run > in a certain order, there's nothing wrong with that. As long > as they

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ulrich Eckhardt
Am 09.01.2012 15:35, schrieb Roy Smith: The classic unittest philosophy says that tests should be independent of each other, which means they should be able to be run in arbitrary order. Some people advocate that the test framework should intentionally randomize the order, to flush out inter-tes

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 9:59 AM, Ulrich Eckhardt wrote: > There is another dependency and that I'd call a logical dependency. This > occurs when e.g. test X tests for an API presence and test Y tests the API > behaviour. In other words, Y has no chance to succeed if X already failed. > Unfortunatel

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Νικόλαος Κούρας
Can you please explain me what the [0] in host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) instead? what is the need of [0] ? -- http://mail.python.org/mailman/listinfo/python-list

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Dominic Binks
On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote: Can you please explain me what the [0] in host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) instead? what is the need of [0] ? The address database can h

classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Hello, I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary. >>> class Parse_Nagios_Header: ... def __init__(self): ... self.keylist = [] ... self.d = {} ...

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Νικόλαος Κούρας
On 10 Ιαν, 00:35, Dominic Binks wrote: > On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote: > > > Can you please explain me what the [0] in host = > > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? > > > Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) > > inst

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Chris Angelico
On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks wrote: > The address database can have multiple names for the same IP address so > gethostbyaddr returns a list - [0] being the first item in the list (and > usually considered the canonical name) Point to note: The inverse operation, getting IP addr

Re: classes and __iter__

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 2:51 PM, david.gar...@gmail.com wrote: class Parse_Nagios_Header: > ... def __init__(self): > ... self.keylist = [] > ... self.d = {} > ... def __iter__(self): > ... return iter(self.keylist, self.d) No idea what you're expecting this

Re: classes and __iter__

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 3:51 PM, david.gar...@gmail.com wrote: > ... def __iter__(self): > ... return iter(self.keylist, self.d) This method is incorrect. The 2-argument form of iter() is very different from the 1-argument form. Whereas the 1-argument form takes an iterable, the 2-ar

Explanation about for

2012-01-09 Thread Νικόλαος Κούρας
dataset = cursor.fetchall() for row in dataset: print ( "" ) for item in row: print ( " %s " % item ) and this: dataset = cursor.fetchall() for host, hits, agent, date in dataset:

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Chris, Both a list and dict are both iterable. I get a python dictionary object of both iterables.;) It is nice... but I don't know if this is good form? Should I be asking the duck question here? >>> print helo.__dict__ {'keylist': [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20,

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Nick Dokos
Chris Angelico wrote: > On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks wrote: > > The address database can have multiple names for the same IP address so > > gethostbyaddr returns a list - [0] being the first item in the list (and > > usually considered the canonical name) > > Point to note: Th

Re: Explanation about for

2012-01-09 Thread Ian Kelly
2012/1/9 Νικόλαος Κούρας : > > dataset = cursor.fetchall() > > for row in dataset: >    print ( "" ) > >    for item in row: >        print ( " %s " % item ) > > > and this: > > > dataset = cursor.fet

Re: classes and __iter__

2012-01-09 Thread Ian Kelly
On Mon, Jan 9, 2012 at 4:30 PM, david.gar...@gmail.com wrote: > Chris, > > Both a list and dict are both iterable.  I get a python dictionary object of > both iterables.;) It is nice... but I don't know if this is good form? > Should I be asking the duck question here? print helo.__dict__ [SN

Re: Explanation about for

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 3:23 PM, Νικόλαος Κούρας wrote: > > dataset = cursor.fetchall() > > for row in dataset: >    print ( "" ) > >    for item in row: >        print ( " %s " % item ) > > > and this: > Your second snippet makes u

Re: classes and __iter__

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com wrote: > Chris, > > Both a list and dict are both iterable.  I get a python dictionary object of > both iterables.;) No, you get a Python object with both iterables as instance variables. Instance variables happen to be stored using a dict (w

Re: Explanation about for

2012-01-09 Thread Νικόλαος Κούρας
Στις 10 Ιανουαρίου 2012 1:42 π.μ., ο χρήστης Ian Kelly < ian.g.ke...@gmail.com> έγραψε: > > > b) In the 2nd example we have for 'host, hits, agent, date in > > dataset'. How does these 4 variables take their values out of dataset? > > How dataset is being splitted? > > The second example works the

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Thanks Ian & Chris for the conversation... On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com > wrote: > > Chris, > > > > Both a list and dict are both iterable. I get a python dictionary > object of > > both iterables.;) > > No, you

codecs in a chroot / without fs access

2012-01-09 Thread Philipp Hagemeister
I want to forbid my application to access the filesystem. The easiest way seems to be chrooting and droping privileges. However, surprisingly, python loads the codecs from the filesystem on-demand, which makes my program crash: >>> import os >>> os.getuid() 0 >>> os.chroot('/tmp') >>> ''.decode('r

Re: classes and __iter__

2012-01-09 Thread MRAB
On 09/01/2012 22:51, david.gar...@gmail.com wrote: Hello, I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary. >>> class Parse_Nagios_Header: ... def __init__(self): ...

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Roy Smith
In article <11jrt8-l32@satorlaser.homedns.org>, Ulrich Eckhardt wrote: > > Some people advocate that the test framework should > > intentionally randomize the order, to flush out inter-test dependencies > > that the author didn't realize existed (or intend). > > If you now > happen to infl

Re: Explanation about for

2012-01-09 Thread Ian Kelly
2012/1/9 Νικόλαος Κούρας : > if the MySQL query was: > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin = > %s ORDER BY date DESC''', pin ) > > can you help me imagine how the mysql database cursor that holds the query > results would look like? I must somehow visualize i

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
I see your meaning for __iter__ method.;) On Mon, Jan 9, 2012 at 4:57 PM, david.gar...@gmail.com < david.gar...@gmail.com> wrote: > Thanks Ian & Chris for the conversation... > > > > > On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > >> On Mon, Jan 9, 2012 at 3:30 PM, david.gar...@gmail.com

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
*Here is a good tutorial: http://shutupandship.com/articles/iterators/index.html * On Mon, Jan 9, 2012 at 5:22 PM, david.gar...@gmail.com < david.gar...@gmail.com> wrote: > I see your meaning for __iter__ method.;) > > > On Mon, Jan 9, 2012 at 4:57 PM, david.gar...@gmail.com < > david.gar...@gmai

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Chris Angelico
On Tue, Jan 10, 2012 at 10:32 AM, Nick Dokos wrote: > Chris Angelico wrote: >> Point to note: The inverse operation, getting IP addresses from names, > > so socket.gethostbyaddr(os.environ['REMOTE_ADDR'])[0] is the 0th element > of the tuple, i.e. the *name* that is returned. Correct, I was draw

Re: classes and __iter__

2012-01-09 Thread david.gar...@gmail.com
Many thanks mrabarnett for the code critic... On Mon, Jan 9, 2012 at 5:08 PM, MRAB wrote: > On 09/01/2012 22:51, david.gar...@gmail.com wrote: > >> Hello, >> >> I have a class and i return both a key list and dictionary from the >> class. Is it good form to do this? The print helo.__dict__ sho

function problem

2012-01-09 Thread contro opinion
code1: def FirstDeco(func): print 'haha' y=func() return y print y @FirstDeco def test(): print 'asdf' return 7 result : haha asdf code2: def FirstDeco(func): print 'haha' y=func() #return y print y @FirstDeco def test(): print 'asdf' return 7 result : h

Re: function problem

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 7:35 PM, contro opinion wrote: > code1: > > def FirstDeco(func): >    print 'haha' >    y=func() >    return y >    print  y Since there's a `return` right before it, the latter `print` here will *never* be executed. Cheers, Chris -- http://mail.python.org/mailman/listinf

decorator problem1:

2012-01-09 Thread contro opinion
test1.py def deco(func): print 'i am in deco' return func @deco def test(): print 'i am in test' when you run it ,you get : test2.py def tsfunc(func): def wrappedFunc(): print '[%s] %s() called' % (ctime(), func.__name__) print 'i am in deco' return func(

decorator problem

2012-01-09 Thread contro opinion
test1.py def deco(func): print 'i am in deco' @deco def test(): print 'i am in test' when you run it ,you get : i am in deco test2.py def tsfunc(func): def wrappedFunc(): print 'i am in deco' return func() return wrappedFunc @tsfunc def test():

Re: replacing __dict__ with an OrderedDict

2012-01-09 Thread Terry Reedy
On 1/9/2012 8:05 PM, Roy Smith wrote: In article<11jrt8-l32@satorlaser.homedns.org>, Ulrich Eckhardt wrote: Some people advocate that the test framework should intentionally randomize the order, to flush out inter-test dependencies that the author didn't realize existed (or intend). If

UnicodeEncodeError in compile

2012-01-09 Thread pyscripter
Using python 3.2 in Windows 7 I am getting the following: >>compile('pass', r'c:\temp\工具\module1.py', 'exec') UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character Can anybody explain why the compile statement tries to convert the unicode filename using mb

decorator and wrap

2012-01-09 Thread contro opinion
def deco(func): def wrap(): print 'i am in deco' return func() return wrap @deco def test(): print "i am in test" when you run it ,there is no result , def deco(func): print 'i am in deco' return func() @deco def test(): print "i am in test" w

Shutting worker threads down gracefully after signal, portably

2012-01-09 Thread Duncan Findlay
Suppose I've got a Python daemon that spawns a bunch of worker threads, waits for a singal (e.g. SIGTERM) and then shuts down the worker threads gracefully. What's the simplest way to do the signal handling portably across as many operating systems as possible (at least Linux and FreeBSD). Speci

Re: decorator problem

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 8:14 PM, contro opinion wrote: > test1.py > > def deco(func): > print 'i am in deco' > > @deco > def test(): >      print 'i am in test' > > > when you run it ,you get : > i am in deco > > > > test2.py > > def tsfunc(func): > def wrappedFunc(): >   print 'i

Re: decorator problem1:

2012-01-09 Thread Chris Rebert
On Mon, Jan 9, 2012 at 7:59 PM, contro opinion wrote: > test1.py > > def deco(func): >    print 'i am in deco' >    return func > > @deco > > def test(): >   print 'i am in test' > > when you run it ,you get : > > > > test2.py > > def tsfunc(func): >     def wrappedFunc(): >     print '[%s] %s

Re: decorator and wrap

2012-01-09 Thread Chris Rebert
Cheers, Chris -- http://rebertia.com On Mon, Jan 9, 2012 at 8:34 PM, contro opinion wrote: > > def deco(func): > def wrap(): > print 'i am in deco' > return func() > return wrap > > @deco > def test(): > print  "i am in test" > when you run it ,there is no result , >

Re: decorator problem

2012-01-09 Thread 88888 Dihedral
Chris Rebert於 2012年1月10日星期二UTC+8下午1時15分53秒寫道: > On Mon, Jan 9, 2012 at 8:14 PM, contro opinion wrote: > > test1.py > > > > def deco(func): > > print 'i am in deco' > > > > @deco > > def test(): > >      print 'i am in test' > > > > > > when you run it ,you get : > > i am in deco > > > > > > >

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Thomas Rachel
Am 09.01.2012 23:35 schrieb Dominic Binks: On 1/9/2012 2:19 PM, Νικόλαος Κούρας wrote: Can you please explain me what the [0] in host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) instead? what is th

Re: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error

2012-01-09 Thread Chris Angelico
On Tue, Jan 10, 2012 at 5:42 PM, Thomas Rachel wrote: > BTW: This behaviour might be useful with gethostbyaddr() as well - if the > first one returned has gone away, you have the chance to reach the 2nd > one... In its directest sense, probably not. All you're getting is multiple names for the sa