Re: Good books in computer science?
I just came across this, a rather advanced algorithms book but my favorite kind: the text (in draft form, anyway) is free online. http://www.cs.princeton.edu/theory/complexity/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Error in Pango while using cairo/librsvg
I use pyWxSVG to convert a svg file to a png image. pyWxSVG is svg canvas for wxPython. View and print svg file or svg content, convert svg to raster graphics. Open svg, svgz file as wx.Image, use wx.BITMAP_TYPE_SVG, wx.BITMAP_TYPE_SVGZ type. Partial support svg format. Tested with Python 2.5 and wxPython 2.8.9.2. Path parser and elliptical arc approximation from Enable. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does Guido want in a GUI toolkit for Python?
On Mon, 29 Jun 2009 16:47:58 -0400, Terry Reedy wrote: > The replacement would need to work with Py 3. TK does. I have not > noticed that anything else does, though that should change eventually. > (And I am sure someone will point of something I have not noticed.) PyQt does. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Spam? Re: whizBase vs. Python
On Jun 29, 11:04 am, Tim Harig wrote: > On 2009-06-29, NurAzije wrote: > > > Hi, > > I am working on a study and I need expert opinion, I did not work with > > Python before, can anyone help me with a comparison betweenWhizBase > > (www.whizbase.com) and Python please. > > Given posts > like:http://groups.google.com/group/Server-side-programing/browse_thread/t... > is this just thinly veiled spam? The domain and the posting IP address are > both out of Sarajevo, Bosnia. > > Obviously you alreadly know your product is nothing but a database > macro processor. Python is a dynamic programming language and therefore > far more capable. > > Your product is proprietary with less capability while Python is free and > powerful. Hi Tim, I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, for that it is interesting for me. regards, Ashraf Gheith -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for developer to help me
Dear Lawrence, On Tue, 30 Jun 2009 15:48:52 +1200, Lawrence D'Oliveiro wrote: > In message , Daniel > Gerzo wrote: > >> http://bitbucket.org/danger/pysublib/src/ > > Can't seem to get through to your site. BitBucket isn't actually my site, it's a Mercurial hosting provider. I wonder why it doesn't work for you...maybe some routing problem, I advice you to try a bit later. -- S pozdravom / Best regards Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with mysql db
En Tue, 30 Jun 2009 03:33:52 -0300, Dennis Lee Bieber escribió: On Mon, 29 Jun 2009 11:59:59 -0300, "Gabriel Genellina" declaimed the following in gmane.comp.python.general: The fact that it's the same character used for formatting strings with the % operator is an unfortunate coincidence (or a very bad choice, I don't know). At the core -- if one looks at the Python source of the module and takes into account that, prior to MySQL 5.x, MySQL did not support "prepared statements", everything being sent as a full string query -- MySQLdb actually uses string interpolation to fill in the fields... AFTER, of course, passing all the arguments through a function that "safes" them (escaping sensitive characters, converting numerics to string equivalent, etc., wrapping quotes about them). Thanks for the historical reference. Even then, the code *could* have used other markers, like ?, doing the appropiate substitutions before the final string interpolation... (but critisizing the original design after many years isn't fair!) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Imaging Library download link broken?
In message , Tim Harig wrote: > On 2009-06-29, Lawrence D'Oliveiro > wrote: >> Sounds more like broken OS with no integrated package management. > > Package managers with dependency tracking were all the rage when I first > started using Linux. So I tried Red Hat and everything worked great until > the depency database corrupted itself. I have been using and administering various flavours of Linux--Red Hat, SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about the last decade, and I have NEVER seen this mythical dependency database corruption of which you speak. If you thought they were "all the rage" before, they're pretty much mandatory now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Imaging Library download link broken?
On 2009-06-30, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> Package managers with dependency tracking were all the rage when I first >> started using Linux. So I tried Red Hat and everything worked great until >> the depency database corrupted itself. > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over about > the last decade, and I have NEVER seen this mythical dependency database > corruption of which you speak. Its usually referred to as RPM hell (like DLL hell) although it can happen to DEB packages as well. You end up in a situation with cyclic dependencies where you cannot delete one application because it depends on a second but you cannot remove the second because it depends on the first. What can I say. It happens. It happened to me. > If you thought they were "all the rage" before, they're pretty much > mandatory now. I have been happy for years using my own heavily modified version of Slackware for installing the base system. After that, I install everything from source. Incidently, a similar discussion has started in a subthread of comp.unix.shell. -- http://mail.python.org/mailman/listinfo/python-list
Re: Spam? Re: whizBase vs. Python
On 2009-06-30, NurAzije wrote: > On Jun 29, 11:04 am, Tim Harig wrote: >> On 2009-06-29, NurAzije wrote: >> > I am working on a study and I need expert opinion, I did not work with >> > Python before, can anyone help me with a comparison betweenWhizBase >> > (www.whizbase.com) and Python please. >> Given posts >> like:http://groups.google.com/group/Server-side-programing/browse_thread/t... >> is this just thinly veiled spam? The domain and the posting IP address are >> both out of Sarajevo, Bosnia. > I am not a spammer, WhizBase is from Sarajevo and I am from Sarajevo, > for that it is interesting for me. >From your post in Server-side-programming you *do* heavily endorse the product and must therefore know about the product itself. I don't know what I can tell you about Python any more then to mention that it is a genteral purpose programming language. It can be used very effectively for creating websites. It could easily be used to create a program that does what the WhizBase product does; and, it can be used for tasks far outside of creating websites. Perhaps, if you give us a little more specific idea of what you want to know about it, we could be more helpful to you. -- http://mail.python.org/mailman/listinfo/python-list
Specific iterator in one line
This is purely sport question. I don't really intend to use the answer
in my code, but I am wondering, if such a feat could be done.
I have a following problem: I have a list based upon which I would
like to construct a different one. I could simply use list
comprehensions, but there is an additional trick: for some elements on
this list, I would like to return two objects. For example I have a
list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
would like to add 2 'b', like this:
[1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
The easy way is to return a tuple ('b', 'b') for 1s and then flatten
them. But this doesn't seem very right - I'd prefer to create a nice
iterable right away. Is it possible to achieve this? Curiosly, the
other way round is pretty simple to achieve, because you can filter
objects using if in list comprehension.
--
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
Oh, and there is additional requirement: it must be a one liner with
at most 80 characters ;-)
W dniu 30 czerwca 2009 10:44 użytkownik Filip Gruszczyński
napisał:
> This is purely sport question. I don't really intend to use the answer
> in my code, but I am wondering, if such a feat could be done.
>
> I have a following problem: I have a list based upon which I would
> like to construct a different one. I could simply use list
> comprehensions, but there is an additional trick: for some elements on
> this list, I would like to return two objects. For example I have a
> list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
> would like to add 2 'b', like this:
>
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
>
> The easy way is to return a tuple ('b', 'b') for 1s and then flatten
> them. But this doesn't seem very right - I'd prefer to create a nice
> iterable right away. Is it possible to achieve this? Curiosly, the
> other way round is pretty simple to achieve, because you can filter
> objects using if in list comprehension.
>
>
> --
> Filip Gruszczyński
>
--
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Imaging Library download link broken?
On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: > In message , Tim Harig wrote: > >> On 2009-06-29, Lawrence D'Oliveiro >> wrote: >>> Sounds more like broken OS with no integrated package management. >> >> Package managers with dependency tracking were all the rage when I >> first started using Linux. So I tried Red Hat and everything worked >> great until the depency database corrupted itself. > > I have been using and administering various flavours of Linux--Red Hat, > SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over > about the last decade, and I have NEVER seen this mythical dependency > database corruption of which you speak. Really? I've seen it, or at least something that looks like it if you squint. In my experience, it can usually be fixed by: yum clean all on recent Redhat based systems. Worst case, there may be a lockfile that needs deleting as well. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson wrote: Steven D'Aprano wrote: Why do you think a smart editing environment is in opposition to coding conventions? Surely an editor smart enough to know a variable name spoken as "pear tree" is an instance and therefore spelled as pear_tree (to use your own example) would be smart enough to know a variable name spoken as "red" is a constant and therefore spelled "RED"? no. I think a smart editing environment should support a coding convention. If an editor is smart enough to track type and instance information, yes. It should be able to generate the right strings for symbols. The question is, how do we get such a smart editor. as far as I know, none exist and the smart ones so far seem to be oriented towards hand use and are almost inaccessible to speech. But is it really possible for an editor to be smart enough -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Imaging Library download link broken?
On 2009-06-30, Steven D'Aprano wrote: > On Tue, 30 Jun 2009 20:16:02 +1200, Lawrence D'Oliveiro wrote: >> In message , Tim Harig wrote: >>> Package managers with dependency tracking were all the rage when I >>> first started using Linux. So I tried Red Hat and everything worked >>> great until the depency database corrupted itself. >> I have been using and administering various flavours of Linux--Red Hat, >> SuSE, Mandrake (before it was Mandriva), Gentoo, Debian, Ubuntu--over >> about the last decade, and I have NEVER seen this mythical dependency >> database corruption of which you speak. > Really? I've seen it, or at least something that looks like it if you > squint. In my experience, it can usually be fixed by: > yum clean all Yum wasn't available then and I have never used it. Maybe it does a better job these days. I don't know. I get along fine without it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Measuring Fractal Dimension ?
On Jun 29, 3:17 am, greg wrote: > Paul Rubin wrote: > > Steven D'Aprano writes: > > >>But that depends on what you call "things"... if electron shells are real > >>(and they seem to be) and discontinuous, and the shells are predicted/ > >>specified by eigenvalues of some continuous function, is the continuous > >>function part of nature or just a theoretical abstraction? > > Another thing to think about: If you put the atom in a > magnetic field, the energy levels of the electrons get > shifted slightly. To the extent that you can vary the > magnetic field continuously, you can continuously > adjust the energy levels. > > This of course raises the question of whether it's > really possible to continuously adjust a magnetic field. > But it's at least possible to do so with much finer > granularity than the differences between energy levels > in an atom. > > So if there is a fundamentally discrete model > underlying everything, it must be at a much finer > granularity than anything we've so far observed, and > the discrete things that we have observed probably > aren't direct reflections of it. > > -- > Greg Electron shells and isolated electrons stuck in a magnetic field are different phenomena that can't be directly compared. Or, at least, such a comparison requires you to explain why it's proper. -- http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
On Tue, 30 Jun 2009 09:57:27 +0100, Rhodri James wrote: On Tue, 30 Jun 2009 03:37:15 +0100, Eric S. Johansson wrote: Steven D'Aprano wrote: Why do you think a smart editing environment is in opposition to coding conventions? Surely an editor smart enough to know a variable name spoken as "pear tree" is an instance and therefore spelled as pear_tree (to use your own example) would be smart enough to know a variable name spoken as "red" is a constant and therefore spelled "RED"? no. I think a smart editing environment should support a coding convention. If an editor is smart enough to track type and instance information, yes. It should be able to generate the right strings for symbols. The question is, how do we get such a smart editor. as far as I know, none exist and the smart ones so far seem to be oriented towards hand use and are almost inaccessible to speech. But is it really possible for an editor to be smart enough Gah. Ignore me. I hit 'send' instead of 'cancel', after my musings concluded that yes, an editor could be smart enough, but it would have to embed a hell of a lot of semantic knowledge of Python and it still wouldn't eliminate the need to speak the keyboard at times. -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
2009/6/30 Filip Gruszczyński :
> This is purely sport question. I don't really intend to use the answer
> in my code, but I am wondering, if such a feat could be done.
>
> I have a following problem: I have a list based upon which I would
> like to construct a different one. I could simply use list
> comprehensions, but there is an additional trick: for some elements on
> this list, I would like to return two objects. For example I have a
> list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
> would like to add 2 'b', like this:
>
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
>
> The easy way is to return a tuple ('b', 'b') for 1s and then flatten
> them. But this doesn't seem very right - I'd prefer to create a nice
> iterable right away. Is it possible to achieve this? Curiosly, the
> other way round is pretty simple to achieve, because you can filter
> objects using if in list comprehension.
>>> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1]))
['b', 'b', 'a', 'a', 'b', 'b']
69 chars long (plus or minus how the input list is written).
Where's my golf trophy? ;)
Cheers,
Chris
--
Goes to burn this shameful code...
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list
Access NtQueryInformationProces() from Python
Hi, I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. Can anyone direct me to some examples where they have been successfully called through Python? Thanks and regards, Rajat Notice: This e-mail is intended solely for use of the individual or entity to which it is addressed and may contain information that is proprietary, privileged, company confidential and/or exempt from disclosure under applicable law. If the reader is not the intended recipient or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If this communication has been transmitted from a U.S. location it may also contain data subject to the International Traffic in Arms Regulations or U.S. Export Administration Regulations and cannot be disseminated, distributed or copied to foreign nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department of State or appropriate export licensing authority. If you have received this communication in error, please notify the sender by reply e-mail or collect telephone call and delete or destroy all copies of this e-mail message, any physical copies made of this e-mail message and/or any file attachment(s). -- http://mail.python.org/mailman/listinfo/python-list
Re: Access NtQueryInformationProces() from Python
Dudeja, Rajat wrote: Hi, I'm looking for a way to call the NtQueryInformationProces() and ReadProcessMemory() of WindowsXP from Python. Can anyone direct me to some examples where they have been successfully called through Python? You want to look at ctypes: http://docs.python.org/library/ctypes.html?highlight=ctypes#module-ctypes TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
Filip Gruszczyäski writes: > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b'] Using itertools: >>> list(chain(*imap([['a'],['b','b']].__getitem__, [1,0,0,1]))) ['b', 'b', 'a', 'a', 'b', 'b'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
Chris Rebert a écrit :
(snip)
reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1]))
['b', 'b', 'a', 'a', 'b', 'b']
69 chars long (plus or minus how the input list is written).
You can save 4 more characters using tumple dispatch instead of dict
dispatch:
reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1]))
Where's my golf trophy? ;)
golf ? Why golf ?-)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
On Tue, 30 Jun 2009 09:44:39 +0100, Filip Gruszczyński
wrote:
This is purely sport question. I don't really intend to use the answer
in my code, but I am wondering, if such a feat could be done.
I have a following problem: I have a list based upon which I would
like to construct a different one. I could simply use list
comprehensions, but there is an additional trick: for some elements on
this list, I would like to return two objects. For example I have a
list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
would like to add 2 'b', like this:
[1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
The easy way is to return a tuple ('b', 'b') for 1s and then flatten
them. But this doesn't seem very right - I'd prefer to create a nice
iterable right away. Is it possible to achieve this? Curiosly, the
other way round is pretty simple to achieve, because you can filter
objects using if in list comprehension.
If you'll allow me a prior "import itertools",
[i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)]
does the job in 62 characters.
--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
On Tue, Jun 30, 2009 at 2:19 AM, Bruno
Desthuilliers wrote:
> Chris Rebert a écrit :
> (snip)
>
> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1]))
>>
>> ['b', 'b', 'a', 'a', 'b', 'b']
>>
>> 69 chars long (plus or minus how the input list is written).
>
> You can save 4 more characters using tumple dispatch instead of dict
> dispatch:
>
> reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1]))
>
>> Where's my golf trophy? ;)
>
> golf ? Why golf ?-)
http://en.wikipedia.org/wiki/Code_golf
It's the sport the OP is playing.
Cheers,
Chris
--
http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
Eric S. Johansson wrote: Tim Chase wrote: It sounds like the issue should be one of making your screen-reader smarter, not dumbing down Python conventions. I don't know what SR you're using (Jaws? Window Eyes? yasr? screeder? speakup? Naturally speaking is speech recognition (speech in text out) it is not text to speech although it does have a pluging for that Sorry...I didn't catch that you were using speech-recognition (SR) instead of text-to-speech (TTS). I didn't see it mentioned in another thread-branch after I had posted. While I have used SR in some testing, I've found that while it's passable for prose (and even that, proclamations of "95% accuracy" sound good until you realize how many words comprise 5% of your daily typing :), it's not so good for code unless you have a very specific programming-language+SR designed editing environment...as you've been griping. However, the problem seems not to be PEP-8, but rather the inabilities of your SR combined with the failings of your editor. For coding, you might want to investigate a tool like Dasher[1] which offers an alternate form of input. It allows for custom vocabularies/keymaps if you need, as well as more precise specification of a full keyboard (caps vs. mixed-case, specific punctuation characters, etc). The predictive entry should be smart enough to pick up previously entered constants/terms saving you entry speed. It can also be driven by a wide variety of pointing devices (mouse, trackball, touchpad, head-tracker, gyro-input, etc). You might also experiment with other editors that allow for more efficient editing. Hope these give you another option to consider, if SR plus your current editor aren't cutting it for you, -tkc [1] http://www.inference.phy.cam.ac.uk/dasher/ http://en.wikipedia.org/wiki/Dasher http://www.youtube.com/results?search_query=dasher http://video.google.com/videosearch?q=dasher -- http://mail.python.org/mailman/listinfo/python-list
RE: Specific iterator in one line
> > This is purely sport question. I don't really intend to use the answer
> > in my code, but I am wondering, if such a feat could be done.
> >
> > I have a following problem: I have a list based upon which I would
> > like to construct a different one. I could simply use list
> > comprehensions, but there is an additional trick: for some elements on
> > this list, I would like to return two objects. For example I have a
> > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
> > would like to add 2 'b', like this:
> >
> > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
> >
> > The easy way is to return a tuple ('b', 'b') for 1s and then flatten
> > them. But this doesn't seem very right - I'd prefer to create a nice
> > iterable right away. Is it possible to achieve this? Curiosly, the
> > other way round is pretty simple to achieve, because you can filter
> > objects using if in list comprehension.
> >
> If you'll allow me a prior "import itertools",
>
> >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)]
>
> does the job in 62 characters.
list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
50 characters. Do I win £5?
--
http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
[Trimming for length, sorry if that impacts too much on intelligibility] On Tue, 30 Jun 2009 02:52:37 +0100, Eric S. Johansson wrote: let's use an example. Admittedly, this is a very simple example but hopefully it illustrates my point What I dictate is: from pots is class telephone What should generate is: class Telephone (pots): as you can see, taken from the simplistic expression, we generate the right pep-8 convention. (I think). This is not the only grammar one can use but, it's one that comes to mind that doesn't have a lot of dead ends. [snip fuller example] at each stage of the way, names get transformed into the pep-8 form without me having to say anything special. The environment knows what form it wants and does the transformation automatically. I'm surprised people aren't doing this already for their handcrafted code. It's one less bit of detail you need to pay attention to. This goes a long way, but it doesn't eliminate the need for some forms of escape coming up on a moderately frequent basis. Consider "Coffee strength equals five" for example: this could mean either coffee_strength = 5 or COFFEE_STRENGTH = 5 depending on whether we will later be using it as a constant or not. Python doesn't have syntactic constants, which is precisely why PEP-8 is useful. You might have enough smarts in your system for it to remember after the first time you use "coffee strength", and it might be unambiguous, but at the very least you need to be able to say "Constant coffee strength equals five" first time round. This isn't the only occasion when you simply don't have the context to avoid verbal disambiguation. Are you accessing attributes of the class MyClass or its instance my_class, for instance? In your initial post you seemed to be claiming that having to do this disambiguation textually was bad, and PEP-8 should therefore be rejected. Given that I'm not prepared to lose the productivity increase that comes with being able to disambiguate visually at a glance, I don't see that it's avoidable. Incidentally, since what you're proposing is essentially templating, wouldn't it be better to do it as post-processing on the speech recognition rather than building it directly into an editor? to resolve -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
RE: Specific iterator in one line
> > > This is purely sport question. I don't really intend to use the answer
> > > in my code, but I am wondering, if such a feat could be done.
> > >
> > > I have a following problem: I have a list based upon which I would
> > > like to construct a different one. I could simply use list
> > > comprehensions, but there is an additional trick: for some elements on
> > > this list, I would like to return two objects. For example I have a
> > > list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
> > > would like to add 2 'b', like this:
> > >
> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
> > >
> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten
> > > them. But this doesn't seem very right - I'd prefer to create a nice
> > > iterable right away. Is it possible to achieve this? Curiosly, the
> > > other way round is pretty simple to achieve, because you can filter
> > > objects using if in list comprehension.
> > >
> > If you'll allow me a prior "import itertools",
> >
> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)]
> >
> > does the job in 62 characters.
>
> list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
>
> 50 characters. Do I win £5?
list("".join([("a","bb")[x] for x in [1,0,0,1]])
Or 49 :o)
--
http://mail.python.org/mailman/listinfo/python-list
Re: The Python Way for module configuration?
On Sun, Jun 28, 2009 at 10:22 AM, kj wrote: > In <[email protected]> Ben Finney > > > writes: > > >(Even if you don't want to receive email, could you please give your > >actual name in the ‘From’ field instead of just initials? It makes > >conversation less confusing.) > > I don't know why, but for as long as I can remember everyone calls > me kj, even my mom. My name is Keaweikekahialiʻiokamoku > Jallalahwallalruwalpindi > > kj > > -- > http://mail.python.org/mailman/listinfo/python-list > > Is that Mongolian? :) (poor joke) Anyway, I tend to just use the name of a character from the most recent book I've read. People often can't tell the difference (though this one is something of a stretch) and I get to maintain my illusion of anonymous. -- http://mail.python.org/mailman/listinfo/python-list
RE: Specific iterator in one line
Andreas Tawn wrote:
>> > > This is purely sport question. I don't really intend to use the
>> > > answer in my code, but I am wondering, if such a feat could be done.
>> > >
>> > > I have a following problem: I have a list based upon which I would
>> > > like to construct a different one. I could simply use list
>> > > comprehensions, but there is an additional trick: for some elements
>> > > on this list, I would like to return two objects. For example I have
>> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
>> > > would like to add 2 'b', like this:
>> > >
>> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
>> > >
>> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten
>> > > them. But this doesn't seem very right - I'd prefer to create a nice
>> > > iterable right away. Is it possible to achieve this? Curiosly, the
>> > > other way round is pretty simple to achieve, because you can filter
>> > > objects using if in list comprehension.
>> > >
>> > If you'll allow me a prior "import itertools",
>> >
>> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)]
>> >
>> > does the job in 62 characters.
>>
>> list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
>>
>> 50 characters. Do I win £5?
>
> list("".join([("a","bb")[x] for x in [1,0,0,1]])
>
> Or 49 :o)
>>> len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""")
48
>>> sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])
['b', 'b', 'a', 'a', 'b', 'b']
--
http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
"Andreas Tawn" writes:
> list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
> 50 characters. Do I win £5?
Er, missing right paren. Try:
list("".join(("a","bb")[x] for x in [1,0,0,1]))
--
http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
50 characters. Do I win £5?
list("".join([("a","bb")[x] for x in [1,0,0,1]])
Or 49 :o)
Well, you have a missing ")" character, but that would be the
49th. You can[*] abuse python's parsing by removing certain
spaces with
list(''.join([('a','bb')[x]for x in[1,0,0,1]]))
bringing you down to 47. In more recent versions of Python, you
can then pass a generator instead of a list-comprehension:
list(''.join(('a','bb')[x]for x in[1,0,0,1]))
bringing you to 45.
-tkc
[*] not *should*, but *can*
--
http://mail.python.org/mailman/listinfo/python-list
RE: Specific iterator in one line
Peter Otten wrote:
> Andreas Tawn wrote:
>
>>> > > This is purely sport question. I don't really intend to use the
>>> > > answer in my code, but I am wondering, if such a feat could be done.
>>> > >
>>> > > I have a following problem: I have a list based upon which I would
>>> > > like to construct a different one. I could simply use list
>>> > > comprehensions, but there is an additional trick: for some elements
>>> > > on this list, I would like to return two objects. For example I have
>>> > > a list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
>>> > > would like to add 2 'b', like this:
>>> > >
>>> > > [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
>>> > >
>>> > > The easy way is to return a tuple ('b', 'b') for 1s and then flatten
>>> > > them. But this doesn't seem very right - I'd prefer to create a nice
>>> > > iterable right away. Is it possible to achieve this? Curiosly, the
>>> > > other way round is pretty simple to achieve, because you can filter
>>> > > objects using if in list comprehension.
>>> > >
>>> > If you'll allow me a prior "import itertools",
>>> >
>>> > >>> [i for e in [1,0,0,1] for i in itertools.repeat('ab'[e], e+1)]
>>> >
>>> > does the job in 62 characters.
>>>
>>> list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
>>>
>>> 50 characters. Do I win £5?
>>
>> list("".join([("a","bb")[x] for x in [1,0,0,1]])
>>
>> Or 49 :o)
>
len("""sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])""")
> 48
sum(([["a"],["b","b"]][i]for i in [1,0,0,1]),[])
> ['b', 'b', 'a', 'a', 'b', 'b']
forgot one extra space:
>>> sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[])
['b', 'b', 'a', 'a', 'b', 'b']
>>> len("""sum(([["a"],["b","b"]][i]for i in[1,0,0,1]),[])""")
47
--
http://mail.python.org/mailman/listinfo/python-list
Learning to use decorators with classes
Hi, I'm writing an LDAP plugin for my TG2 application. In this I wrote a small class based decorator with args to set up a connection and call the necessary functionality but I'm having problems with it. Here's my code: class getConnection(object): def __init__(self, settings, credentials): self.settings = settings self.credentials = credentials def __call__(self, f): def wrapped_f(*args, **kw): ...code snipped... try: if tls: connection.start_tls_s() if anon: con.simple_bind_s() else: con.simple_bind_s( dn, pw ) except ldap.LDAPError, e: print e.message['info'] else: kw['conn'] = connection try: f(*args, **kw) except Exception, e: print 'Exception in Plugin execution: %s' % e finally: connection.unbind() return wrapped_f class LdapPlugin(Plugin): ... def __init__(self, **kw): Plugin.__init__(self) @getConnection(self._settings, self.__cred__) def search(self, **kw): print 'Searching' ... Here the base class constructor(Plugin) fetches plugin specific settings from the web framework and stores it in self._settings and user info in self.__cred__ . Now when the method is invoked, this is the error I get: File '.../plugins/ldap/ldap/__init__.py', line 69 in LdapPlugin @getConnection(self._settings, self.__cred__) NameError: name 'self' is not defined I can simply write a method that gets a connection and deal with it but I wanted to know and learn why decorators is not working in this case. Regards, SZ " life isn't heavy enough,it flies away and floats far above action" Access Yahoo!7 Mail on your mobile. Anytime. Anywhere. Show me how: http://au.mobile.yahoo.com/mail -- http://mail.python.org/mailman/listinfo/python-list
Passing parameters for a C program in Linux.
Hi all, I have to write an automted script which will test my c program. That program when run will ask for the commands. For example: local-host# ./cli Enter 1 for add Enter 2 for sub Enter 3 for mul 1---Our option Enter two numbers 44 33 Our option Result is 77 As shown in the above example it lists all the options and waits for user input and once given, it does some operations and waits for some more. This has to be automated. Can someone give suggestions how to do this in Python (Linux Platform in particular). Thank you, Venu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing in PDF
Em Seg 29 Jun 2009, às 20:39:22, Lawrence D'Oliveiro escreveu: > In message > [email protected]>, Jun wrote: > > ... is there open source solution ? > > Poppler? pypdf -- http://pybrary.net/pyPdf/ A Pure-Python library built as a PDF toolkit. It is capable of: * extracting document information (title, author, ...), * splitting documents page by page, * merging documents page by page, * cropping pages, * merging multiple pages into a single page, * encrypting and decrypting PDF files. By being Pure-Python, it should run on any Python platform without any dependencies on external libraries. It can also work entirely on StringIO objects rather than file streams, allowing for PDF manipulation in memory. It is therefore a useful tool for websites that manage or manipulate PDFs. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: [email protected] - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
RE: Specific iterator in one line
> -Original Message- > From: [email protected] [mailto:python- > [email protected]] On Behalf Of Paul Rubin > Sent: Tuesday, June 30, 2009 11:27 AM > To: [email protected] > Subject: Re: Specific iterator in one line > > "Andreas Tawn" writes: > > list("".join([("a","b"*2)[x] for x in [1,0,0,1]]) > > 50 characters. Do I win £5? > > Er, missing right paren. Try: > > list("".join(("a","bb")[x] for x in [1,0,0,1])) > -- Indeed. Stupid paste ;o) -- http://mail.python.org/mailman/listinfo/python-list
python extend c++ module
I have written a c++ extend module and I use distutils to build.
setup.py
from distutils.core import setup, Extension
setup(name="noddy", version="1.0",
ext_modules=[
Extension("noddy3", ["noddy3.cpp", "a.cpp"])
])
I found it's quite strange when compiling. I didn't use extern "C" at
all
, how can python get the right c++ funciton name without any compile
error??
I found that it first use gcc to compile noddy3.cpp and then link by g+
+.
Could anyone explain what it's all about?
Thanks a lot!!
here is the compiling message.
---
running install
running build
running build_ext
building 'noddy3' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp
-o
build/temp.linux-i686-2.6/noddy3.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid
for
Ada/C/ObjC but not for C++
g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o
build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so
build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so
running install_lib
copying build/lib.linux-i686-2.6/noddy3.so ->
/usr/local/lib/python2.6/site-packages
running install_egg_info
Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-
info
Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info
--
http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
Eric S. Johansson wrote: Ethan Furman wrote: Eric S. Johansson wrote: yup how long will i[t] be before you become disablesd? maybe not as badly as I am but you should start feeling some hand problems in your later 40's to early 50's and it goes down hill from there. self preservation/interest comes to mind as a possible motive for action. I thought 15 years would be enough for somebody else to push the isssue but no. if it is going to be, it has to be me. For anyone who is still able to use their hands for typing, especially if you're beginning to encounter the painful wrists, consider switching to a Dvorak layout. It was a system I was curious about even before I needed it, and when I did need it I was able to create the layout in assembler (now, of course, it's widely available as a standard keyboard layout). I started noticing the pain in my late twenties (aggravated, I'm sure, by arthritis), but with switching to Dvorak the pain left and has only very rarely been noticable again. It will mostly likely be a challenge to switch, but well worth it. a good suggestion but not really addressing the point I'm trying to make of building a system that would help people more profoundly injured. for example, I've tried Dvorak and the act of typing was so painful that I couldn't learn it You must previously define what you are calling "more profoundly injured". Which disabled abilities are you talking about ? What about people that have difficulties to speak because of partial jaw paralysis. They would need systems that recognize eye blinks to write down code. What about blind people, color blind ... ? Would a new disabled friendly PEP 8 version fits all their needs ? To come back to a more python related subject, I don't think it falls into PEP responsibility to take into account all the disabled abilities you can find in the dev community. This falls into the tools they used to workaround their issues and there's surely much work to be done here. In the end, as someone mentioned before, PEPs are only guidelines, and you are entitled to break them if the rule hurts you. This is one of the many beauties of python, it's flexible. Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing in PDF
On 2009-06-30, Eduardo Lenz wrote: > Em Seg 29 Jun 2009, às 20:39:22, Lawrence D'Oliveiro escreveu: >> In message > >> [email protected]>, Jun wrote: >> > ... is there open source solution ? >> >> Poppler? > > pypdf -- http://pybrary.net/pyPdf/ > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > * extracting document information (title, author, ...), > * splitting documents page by page, > * merging documents page by page, > * cropping pages, > * merging multiple pages into a single page, > * encrypting and decrypting PDF files. While it may be a pure-python library, the problem is that AFAICT it doesn't actually solve the problem at hand. The requirement is to "draw" on the pages of an existing PDF document (add annotations). > By being Pure-Python, it should run on any Python platform > without any dependencies on external libraries. It can also > work entirely on StringIO objects rather than file streams, > allowing for PDF manipulation in memory. It is therefore a > useful tool for websites that manage or manipulate PDFs. True, but does it allow you to add text/lines/etc. to a page? -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Specific iterator in one line
Filip Gruszczyński:
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
I like this version (43 golf holes), it's readable enough:
[c for d in[1,0,0,1]for c in("a","bb")[d]]
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using Python for file packing
On Mon, 29 Jun 2009 14:16:34 -0700, Scott David Daniels wrote: >>> Do you mean like a zip or tar file? >>> >>> http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html >>> >> >> I had no idea you could access a single file from a ZIP or TAR without >> explicitly extracting it somewhere. Thanks. > > You will find the zip format works better if you are compressing. The > zipfile compression is per file in the archive, rather than applied to > the entire archive (as in tarfile). The results of the tar format > decision is that extracting the last file in a .tgz (.tar.gz) or > .tar.bz2 (sometimes called .tbz) requires the expansion of the entire > archive, while extraction on a .zip is reposition, read, and possibly > expand. Even without compression, the tar format is ill-suited to random access. If you can choose the format, use a zip file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing in PDF
Em Ter 30 Jun 2009, às 04:19:13, Grant Edwards escreveu: > On 2009-06-30, Eduardo Lenz wrote: > > Em Seg 29 Jun 2009, às 20:39:22, Lawrence D'Oliveiro escreveu: > >> In message >> > >> [email protected]>, Jun wrote: > >> > ... is there open source solution ? > >> > >> Poppler? > > > > pypdf -- http://pybrary.net/pyPdf/ > > > > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > > > * extracting document information (title, author, ...), > > * splitting documents page by page, > > * merging documents page by page, > > * cropping pages, > > * merging multiple pages into a single page, > > * encrypting and decrypting PDF files. > > While it may be a pure-python library, the problem is that > AFAICT it doesn't actually solve the problem at hand. The > requirement is to "draw" on the pages of an existing PDF > document (add annotations). > > > By being Pure-Python, it should run on any Python platform > > without any dependencies on external libraries. It can also > > work entirely on StringIO objects rather than file streams, > > allowing for PDF manipulation in memory. It is therefore a > > useful tool for websites that manage or manipulate PDFs. > > True, but does it allow you to add text/lines/etc. to a page? being a pure python library makes "easy" to add those features. And also, one can ask for those features for the developers. I think that this list is a good place to point the existing solutions (not always the exact solution) and also to collect valuable information about python libraries. Please, lets keep in mind that this is not the debian list :). []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: [email protected] - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Help me plsss...
Hi All, Environment :- Solaris Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 Oracle version :- 10.2.0.3 Below is the library path echo $LD_LIBRARY_PATH /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib: /data/oracle/product/10.2.0.3/lib Issue :- We have been recently migrated from 9i to 10g database and also from AIX to Solaris. When we were using 9i i can able to import cx_oracle library... But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... newprd$ python ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. >>> import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. PLs help meee ... Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 P.S.: Please ensure all your FXPCA queries are CC'd to [email protected] & GCMS related queries are CC'd to "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence -- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" --- --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.-- http://mail.python.org/mailman/listinfo/python-list
Re: Help me plsss...
Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software > Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to > Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that > below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 > (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" > or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such > file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's > trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > > P.S.: Please ensure all your FXPCA queries are CC'd to > [email protected] & GCMS related queries are CC'd to > "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to > get a quicker response in case of my absence > > > -- > “This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" > --- > > --- > > This e-mail may contain confidential and/or privileged information. If you > are not the intended recipient (or have received this e-mail in error) please > notify the sender immediately and delete this e-mail. Any unauthorized > copying, disclosure or distribution of the material in this e-mail is > strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for > additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me plsss...
Hi Marc, Thanks for the repl... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 P.S.: Please ensure all your FXPCA queries are CC'd to [email protected] & GCMS related queries are CC'd to "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence -- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" --- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/db...@dbemea cc [email protected] Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > > P.S.: Please ensure all your FXPCA queries are CC'd to [email protected] & GCMS related queries are CC'd to "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > > > -- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" > --- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution o
Re: Help me plsss...
Hi Marc, Thanks for the repl... Ican see below in /data/oracle/product/10.2.0.3/lib newprd$ ls -ltr libclntsh* -rwxrwxr-x 1 oracle dba 24048416 Apr 29 10:49 libclntsh.so.10.1 lrwxrwxrwx 1 oracle dba 51 Apr 29 10:49 libclntsh.so -> /data/oracle/product/10.2.0.3/lib/libclntsh.so.10.1 Cheers, Harsha. FXPCA & GCMS & CLS SUPPORT Phone : +91-80-4187 3075 FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 P.S.: Please ensure all your FXPCA queries are CC'd to [email protected] & GCMS related queries are CC'd to "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence -- ?This mail is transmitted to you on behalf of HCL Technologies" "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" --- Marco Bizzarri 30/06/2009 17:40 To Harsha Reddy/ext/db...@dbemea cc [email protected] Subject Re: Help me plsss... Of course, you're sure that under /data/oracle/product/10.2.0.3/lib you can find libclntsh.so.9.0 Regards Marco On Tue, Jun 30, 2009 at 1:45 PM, Harsha Reddy wrote: > > Hi All, > > Environment :- Solaris > Python Version :- ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based on > Python 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5 > Oracle version :- 10.2.0.3 > > Below is the library path > > echo $LD_LIBRARY_PATH > /data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib::/data/lgcmsp1/apps/dbus_3_0_8_14/SPARC_5.8/6.0/lib:/data/lgcmsp1/apps/dbus_3_0_8_14/vitria.3.1/SPARC_5.8/6.0/lib:/data/oracle/product/10.2.0.3/lib > > > Issue :- > > We have been recently migrated from 9i to 10g database and also from AIX to Solaris. > > When we were using 9i i can able to import cx_oracle library... > > But now iam in Solaris and 10g database and same when iam trying to do that below is the error iam getting... > > newprd$ python > ActivePython 2.4.3 Build 11 (ActiveState Software Inc.) based onPython 2.4.3 (#1, Apr 3 2006, 18:34:02) [C] on sunos5Type "help", "copyright", "credits" or "license" for more information. > > >>> import cx_Oracle > Traceback (most recent call last): > File "", line 1, in ? > ImportError: ld.so.1: python: fatal: libclntsh.so.9.0: open failed: No such file or directory > > Does it mean that cx_oracle library not there (or) if you see the error it's trying to get 9i libraries fatal: libclntsh.so.9.0. > > > > PLs help meee ... > Cheers, > Harsha. > > FXPCA & GCMS & CLS SUPPORT > Phone : +91-80-4187 3075 > FXPCA HOTLINE : +91-80-64522431 GCMS & CLS HOTLINE : +91-80-6450 8482 > > P.S.: Please ensure all your FXPCA queries are CC'd to [email protected] & GCMS related queries are CC'd to "gcms_it_supp...@dmg UK" & CLS related queries are CC'd to CLS_IT_SUPPORT to get a quicker response in case of my absence > > > -- > ?This mail is transmitted to you on behalf of HCL Technologies" > "Diese Post wird Ihnen im Namen der HCL Technologies übermittelt" > --- > > --- > > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. > > Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Marco Bizzarri http://code.google.com/p/qt-asterisk/ http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/ --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution o
Re: timer
Paul Moore wrote: 2009/6/29 MRAB : superpollo wrote: hi folks. the follwing shoud print 'stuff' for 3 seconds and then stop. why it does not work? (prints stuff forever) 1 #!/usr/bin/python 2 3 import threading 4 import sys 5 6 t = threading.Timer(3.0, sys.exit) 7 t.start() 8 while True: 9 print "stuff ", The Timer runs the function in another thread. Perhaps sys.exit is just exiting that thread and not the main thread. sys.exit raises a SystemExit exception, which will get handled in the new thread (where it won't do anything). Conceded, this isn't particularly intuitive. For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. thank u paul. if u dont mind, would you give me a more detailed piece of code that does what i mean? tia -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
Hi, this can be done using module "subprocess"; there is also function popen() in module "os" and module popen2, but they are deprecated since Python 2.6. PM 2009/6/30 [email protected] : > Hi all, > I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1---Our option > Enter two numbers > 44 33 Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
ANN: Package Manager GUI for Python (Windows)
Hi All, I'm pleased to announce a GUI package manager (v 0.12) for Python versions 2.x under Windows. http://sourceforge.net/projects/pythonpkgmgr/ It's tightly linked to the pypi repository and offers the following functions: - search packages on pypi by name - install (via easyinstall or pip) - deinstall/remove packages - see package documentation - see package examples - install .EGG packages - Generate package manifest If you find any issues, please don't hesitate to report them via our tracker on the project page. Regards David -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning to use decorators with classes
Mr SZ a écrit :
Hi,
I'm writing an LDAP plugin for my TG2 application. In this I wrote a small
class based decorator with args to set up a connection and call the necessary
functionality but I'm having problems with it. Here's my code:
(snip code)
class LdapPlugin(Plugin):
...
def __init__(self, **kw):
Plugin.__init__(self)
@getConnection(self._settings, self.__cred__)
Don't use '__name__', they are reserved for the implementation. And
FWIW, don't use '__name' unless you have a really compelling reason to
do so.
def search(self, **kw):
print 'Searching'
...
This can't work, and it's a FAQ FWIW - but since there's no official
c.l.py FAQ, we won't hold it against you !-)
def and class are both *executable* statements (yes, classes and
functions creation - like almost anything in Python - are run-time
operations).
The first one creates a function object - *wherever* it happens - and
bind the function object to the function's name in the current
namespace. Think of it as an equivalent of the following javascript snippet:
var func_name = function(arg) { /* function's body */ };
The second statement - class - builds a class object from the names
defined in the class statement's body (that is, names defined in the
class statement's body will become attributes of the class object).
Now about the 'methods' and 'self' stuff...
First understand that there's *nothing* magical with 'self'. It's *not*
a keyword. It's only a naming convention, and you could use any legal
Python identified instead.
The reason we have to explicitly mention it as first argument of the
function is that it's the only way the function's body can get access to
the current instance. What happens is (overly simplified) that during
attribute resolution, when the found attribute happens to be a function,
this function is wrapped - together with the instance on which the
attribute was looked up and it's class - into a callable method object.
Then when you call this method object, it inserts the instance as first
argument to the function call, and returns the result of the function
call (if you want to read more about this and how computed attributes
are implemented in Python, google for 'descriptor protocol').
IOW, and to make a long story short, calling instance.method is the same
as calling Class.method(instance).
Ok, now to the point: when you call getConnection within the class
statement's body, there's no magical "self" keyword poiting to an
instance, and since the class itself doesn't yet exists, so there's *no*
way you could get at an instance of it anyway !-)
There are many ways to solve your problem, the simplest bing probably to
write another decorator calling on the first one, ie:
def connected_method(func):
def connected(self, *args, **kw):
wrapped = getConnection(self.__this, self.__that)(func)
return wrapped(*args, **kw)
return connected
Note that this may not be that efficient - you'll have quite a few
function calls involved here.
While we're at it, a couple comments on your code... First, please read
pep08 (naming and coding conventions) on python.org. Conventions are
very important in Python.
wrt/ error handling:
try:
if tls:
connection.start_tls_s()
if anon:
con.simple_bind_s()
else:
con.simple_bind_s(dn, pw)
except ldap.LDAPError, e:
print e.message['info']
This kind of "error handling" is more than useless - it's worse than no
error handling at all. If you cannot handle the problem (I really mean
*handle*, you know, like do something to fix it), just let the exception
propagate - you'll get a nice traceback with all the necessary debugging
informations. Users of your package can always add a top-level
"catch-all" exception handler that will log tracebacks, send alert mails
to the team, and present the end-user with a nicely formatted error
message (and even possibly a way to handle the problem - like providing
appropriate connection data (credentials, url, whatever) !-)
Also note that sys.stdout is for *normal* program outputs. Error
messages belongs to sys.stderr.
else:
kw['conn'] = connection
try:
f(*args, **kw)
except Exception, e:
print 'Exception in Plugin execution: %s' % e
Same as above : if you can't handle the exception, leave it alone.
HTH
--
http://mail.python.org/mailman/listinfo/python-list
Re: timer
2009/6/30 superpollo : > Paul Moore wrote: >> For a non-toy example, you'd probably create an Event object, use your >> timer to set the event, and your while loop would do while >> event.is_set(), so the problem wouldn't arise. > > thank u paul. if u dont mind, would you give me a more detailed piece of > code that does what i mean? No problem: import threading e = threading.Event() t = threading.Timer(3.0, e.set) t.start() while not e.is_set(): print "Hello, threading world" Hope this helps, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
Paul Moore wrote: 2009/6/29 MRAB : superpollo wrote: hi folks. the follwing shoud print 'stuff' for 3 seconds and then stop. why it does not work? (prints stuff forever) 1 #!/usr/bin/python 2 3 import threading 4 import sys 5 6 t = threading.Timer(3.0, sys.exit) 7 t.start() 8 while True: 9 print "stuff ", The Timer runs the function in another thread. Perhaps sys.exit is just exiting that thread and not the main thread. sys.exit raises a SystemExit exception, which will get handled in the new thread (where it won't do anything). Conceded, this isn't particularly intuitive. For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. Paul. so why this does not work? 1 #!/usr/bin/python 2 3 import threading 4 5 e = threading.Event() 6 t = threading.Timer(3.0, e.set()) 7 t.start() 8 while not e.isSet(): 9 print "stuff ", it does *NOT* print (but it should, shouldn't it?), then exits after 3 sec but with error: Exception in thread Thread-1:Traceback (most recent call last): File "/usr/lib/python2.3/threading.py", line 442, in __bootstrap self.run() File "/usr/lib/python2.3/threading.py", line 575, in run self.function(*self.args, **self.kwargs) TypeError: 'NoneType' object is not callable what gives? -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
superpollo wrote: so why this does not work? 1 #!/usr/bin/python 2 3 import threading 4 5 e = threading.Event() 6 t = threading.Timer(3.0, e.set()) 7 t.start() 8 while not e.isSet(): 9 print "stuff ", it does *NOT* print (but it should, shouldn't it?), then exits after 3 sec but with error: Nice try, but you're passing *the result of calling e.set* as the function parameter to Timer. And the result of calling e.set () is None. So you're passing None as the function-to-call. Which it does. And then... TypeError: 'NoneType' object is not callable Try passing the function instead: threading.Timer (3.0, e.set).start () TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
On Jun 30, 5:42 pm, Petr Messner wrote: > Hi, > > this can be done using module "subprocess"; there is also function > popen() in module "os" and module popen2, but they are deprecated > since Python 2.6. > > PM > > 2009/6/30 [email protected] : > > > Hi all, > > I have to write an automted script which will test my c > > program. That program when run will ask for the commands. For example: > > > local-host# ./cli > > Enter 1 for add > > Enter 2 for sub > > Enter 3 for mul > > 1 ---Our option > > Enter two numbers > > 44 33 Our option > > Result is 77 > > > As shown in the above example it lists all the options and waits for > > user input and once given, it does some operations and waits for some > > more. This has to be automated. > > > Can someone give suggestions how to do this in Python (Linux Platform > > in particular). > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Can you give some more explanation about how exactly this can be done.. Thanks for reply, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
Paul Moore wrote: 2009/6/30 superpollo : Paul Moore wrote: For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. thank u paul. if u dont mind, would you give me a more detailed piece of code that does what i mean? No problem: import threading e = threading.Event() t = threading.Timer(3.0, e.set) t.start() while not e.is_set(): print "Hello, threading world" Hope this helps, Paul hi while i was waiting 4 ur reply, i posted an almost equal example, but it does not work... -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
superpollo writes: > so why this does not work? > > 1 #!/usr/bin/python > 2 > 3 import threading > 4 > 5 e = threading.Event() > 6 t = threading.Timer(3.0, e.set()) The second arg needs to be a callable - maybe you meant e.set without the brackets? -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
Paul Moore wrote: 2009/6/30 superpollo : Paul Moore wrote: For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. thank u paul. if u dont mind, would you give me a more detailed piece of code that does what i mean? No problem: import threading e = threading.Event() t = threading.Timer(3.0, e.set) t.start() while not e.is_set(): print "Hello, threading world" Hope this helps, Paul do not bother answering... my fault. i wrote e.set() and not e.set thanks again -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
i would like to thank each and everyone for help given, and aplologise for my inaccuracy. thanks 10**3! superchicken -- http://mail.python.org/mailman/listinfo/python-list
Re: timer
2009/6/30 superpollo : > Paul Moore wrote: >> >> 2009/6/30 superpollo : >> >>> Paul Moore wrote: >>> For a non-toy example, you'd probably create an Event object, use your timer to set the event, and your while loop would do while event.is_set(), so the problem wouldn't arise. >>> >>> thank u paul. if u dont mind, would you give me a more detailed piece of >>> code that does what i mean? >> >> >> No problem: >> >> import threading >> >> e = threading.Event() >> t = threading.Timer(3.0, e.set) >> t.start() >> >> while not e.is_set(): >> print "Hello, threading world" >> >> Hope this helps, >> Paul > > do not bother answering... my fault. > > i wrote e.set() and not e.set > > > > thanks again No problem - I made the same mistake while I was writing the sample :-) (I also forgot t.start() the first time. So I'm winning 2-1 on trivial mistakes :-)) Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: ImageEnhance.Contrast - is this fishy or what?
On Jun 17, 12:38 am, Scott David Daniels wrote: > > Over on image-sig, Fredrik Lundh responded: > > And the award for finding the oldest bug in PIL goes to... (that code > > was last touched in 1996). > > > > Congrats, roop, on getting this discovered just in the nick of time. > /me takes a bow :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
2009/6/30 [email protected] : ... > Can you give some more explanation about how exactly this can be > done.. Popen object enables you to run any program in a newly-created child process, write to its standard input and read from its standard and error outputs. There is an example how your test program could look like: import subprocess p = subprocess.Popen("./cli", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) result, errs = p.communicate("1\n44 33\n") assert not errs assert result.splitlines()[-1] == "Result is 77" Popen objects have also attributes stdin, stdout and stderr, you can use them if you do not want to use communicate(). Be aware that you if you call stdout.read(), it reads everything and blocks until EOF occurrs (usually until the popen-ed program quits). You can also use readline(), but this can also block until the subprocess writes any line. In cases where this could be a problem (i think this automated test programs are not that cases) polling, nonblocking I/O or threads can be used. I have pasted complete example (with a script simulating your "cli" program) here: http://paste.pocoo.org/show/125944/ PM -- http://mail.python.org/mailman/listinfo/python-list
python3 fail to start
i just install the python 3.1 dmg onto my mac. when i run python3, it fail with : Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: Abort trap couldnt understand the problem. anyone can help? -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
On Jun 30, 11:46 am, "[email protected]" wrote: > Hi all, > I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1 ---Our option > Enter two numbers > 44 33 Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. The easiest (and ugliest) way to do this would probably be to write a file input.txt and a file output.txt with each input/output value, and then to do this on the command prompt: ./a.out < input.txt | diff output.txt - this will run a.out (assuming that's your program's name), feed in input.txt as input, and pipe that into diff to compute the differences between its output and output.txt -- http://mail.python.org/mailman/listinfo/python-list
Re: identify checksum type?
Christian Heimes wrote:
PK schrieb:
Given a checksum value, whats the best way to find out what type it is?
meaning. I can use hashlib module and compute a md5 or sha1 for a given data
etc..but given a checksum value say "d2bda52ee39249acc55a75a0f3566105" whats
the best way for me to identify if its a sha1 or md5 or anyother sum type
for that matter?
is there a nice way to do this in python?
As far as I know there is no way to identify a checksum by its value. A
checksum is just a number. You can try an educated guess based on the
length of the checksum. Or you can try all hash algorithms until you get
a hit but that may lead to security issues.
Some applications prefix the hash value with an identifier like "{MD5}"
or "{SHA1}".
Christian
fortunately, the hashlib checksums can be distinguished by their length
On the newly minted 3.1:
import hashlib
text = b'BDFL forever; FLUFL for frequently'
for name in 'md5 sha1 sha224 sha256 sha384 sha512'.split():
result = getattr(hashlib, name)(text).hexdigest()
print('%6s:%3d %s' % (name, len(result), result))
md5: 32 457484d2817fbe475ab582bff2014e82
sha1: 40 242076dffbd432062b439335438f08ba53387897
sha224: 56 89c0439b1cf3ec7489364a4b8e50b3ba196706eecdb5e5aec6d6290f
sha256: 64 e10938435e4b5b54c9276c05d5f5d7c4401997fbd7f27f4d4...807d
sha384: 96 3fe7c7bf3e83d70dba7d59c3b79f619cf821a798040be2177...edb7
sha512:128 fe50d9f0c5780edb8a8a41e317a6936ec6305d856c78ccb8e...1fa0
You'll have to guess for adler32 vs. crc32 vs. seeded crc32, ...
--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list
Re: Learning to use decorators with classes
--- On Tue, 30/6/09, Bruno Desthuilliers
wrote:
>
> Don't use '__name__', they are reserved for the
> implementation. And FWIW, don't use '__name' unless you have
> a really compelling reason to do so.
>
That was an honest mistake!. Noted :)
>
> > def search(self, **kw):
> > print
> 'Searching'
> > ...
>
>
> This can't work, and it's a FAQ FWIW - but since there's no
> official c.l.py FAQ, we won't hold it against you !-)
>
Can you please point me to the FAQ related to this snippet. I would be grateful.
> def and class are both *executable* statements (yes,
> classes and functions creation - like almost anything in
> Python - are run-time operations).
>
> The first one creates a function object - *wherever* it
> happens - and bind the function object to the function's
> name in the current namespace. Think of it as an equivalent
> of the following javascript snippet:
>
> var func_name = function(arg) { /*
> function's body */ };
>
> The second statement - class - builds a class object from
> the names defined in the class statement's body (that is,
> names defined in the class statement's body will become
> attributes of the class object).
>
> Now about the 'methods' and 'self' stuff...
>
> First understand that there's *nothing* magical with
> 'self'. It's *not* a keyword. It's only a naming convention,
> and you could use any legal Python identified instead.
>
> The reason we have to explicitly mention it as first
> argument of the function is that it's the only way the
> function's body can get access to the current instance. What
> happens is (overly simplified) that during attribute
> resolution, when the found attribute happens to be a
> function, this function is wrapped - together with the
> instance on which the attribute was looked up and it's class
> - into a callable method object. Then when you call
> this method object, it inserts the instance as first
> argument to the function call, and returns the result of the
> function call (if you want to read more about this and how
> computed attributes are implemented in Python, google for
> 'descriptor protocol').
>
> IOW, and to make a long story short, calling
> instance.method is the same as calling
> Class.method(instance).
>
>
Thank you very much for your explanation. I will remember these points by heart.
> Ok, now to the point: when you call getConnection within
> the class statement's body, there's no magical "self"
> keyword poiting to an instance, and since the class itself
> doesn't yet exists, so there's *no* way you could get at an
> instance of it anyway !-)
>
> There are many ways to solve your problem, the simplest
> bing probably to write another decorator calling on the
> first one, ie:
>
>
> def connected_method(func):
> def connected(self, *args, **kw):
> wrapped =
> getConnection(self.__this, self.__that)(func)
> return wrapped(*args, **kw)
>
> return connected
>
>
> Note that this may not be that efficient - you'll have
> quite a few function calls involved here.
>
I was trying follow the concept of decorators with arguments and I can now
understand why it failed, thanks.
Thanks and regards,
SZ
Access Yahoo!7 Mail on your mobile. Anytime. Anywhere.
Show me how: http://au.mobile.yahoo.com/mail
--
http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
Rhodri James wrote: > [Trimming for length, sorry if that impacts too much on intelligibility] no problem, one of the hazards of speech recognition uses you become very verbose. > This goes a long way, but it doesn't eliminate the need for some forms > of escape coming up on a moderately frequent basis. Consider "Coffee > strength equals five" for example: this could mean either > > coffee_strength = 5 > > or > > COFFEE_STRENGTH = 5 > > depending on whether we will later be using it as a constant or not. > Python doesn't have syntactic constants, which is precisely why PEP-8 > is useful. You might have enough smarts in your system for it to > remember after the first time you use "coffee strength", and it might > be unambiguous, but at the very least you need to be able to say > "Constant coffee strength equals five" first time round. right. The initial state of a symbol is always a chatty moment. It sets the context and background information for subsequent use. My initial reaction is that when you do coffee strength equals five, it would pop up a simple dialog asking variable or constant? You would say "variable" and it would format everything the right way. This is a form of interactive dialogue that would be used consistently throughout the rest of the environment. > > This isn't the only occasion when you simply don't have the context > to avoid verbal disambiguation. Are you accessing attributes of the > class MyClass or its instance my_class, for instance? In your initial > post you seemed to be claiming that having to do this disambiguation > textually was bad, and PEP-8 should therefore be rejected. Given > that I'm not prepared to lose the productivity increase that comes > with being able to disambiguate visually at a glance, I don't see > that it's avoidable. I don't mind verbal disambiguation if it's infrequent. What I object to is being forced to disambiguate every time I use a symbol. The reason being is one is a minor increase in vocal load and can be made a dumb template (maybe) where is the other is just doing a bunch of makework over and over again. As for your my class example, you never ever use my_class unless it's prefaced by an instance of the class MyClass. And if you say something like My class yields fall class or fall class is my class or fall class = my class You have sufficient information to know that my class is a class name.and that you have some number of arguments and the system can run you through a dialogue to fill in the arguments. I wish I had the tools to create a simulation of what the editing sequence with the dialog box pop-ups in nice little animated movie. Heck, if I could just capture time lapse I could do it with paper and pencil and a voiceover. It would remind you of Gumby meets South Park but... I digress > > Incidentally, since what you're proposing is essentially templating, > wouldn't it be better to do it as post-processing on the speech > recognition rather than building it directly into an editor? > to resolve if my template in, you mean a system that can receive type information from somewhere about every single symbol in the system and then load up a grammar, handle the dialogs for disambiguation at the same time as providing an editing environment that lets you refer to symbols by their verbose name instead of their codename and still operate on. For example, replace an argument should pop up a dialog box with the second argument of the first method on the line. You then can change things by their names like second string or array index. Then sure, maybe a templating system would work. But I don't think it will thank you for continuing in this dialogue. -- http://mail.python.org/mailman/listinfo/python-list
packaging apps
I have a simple application that has a glade file and a .py file. How would I package that into an installer for Windows, Mac, and a deb file? Can anyone point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
Tim Chase wrote: > Eric S. Johansson wrote: > np. I get this confusion often. > > While I have used SR in some testing, I've found that while it's > passable for prose (and even that, proclamations of "95% accuracy" sound > good until you realize how many words comprise 5% of your daily typing > :), it's not so good for code unless you have a very specific > programming-language+SR designed editing environment...as you've been > griping. However, the problem seems not to be PEP-8, but rather the > inabilities of your SR combined with the failings of your editor. I've been working with speech recognition for 15 years. I've written something on the order of 10,000 lines of Python code both as open source and private projects. I've tried it least two dozen editors and they all fail miserably because they're focused on keyboard use (but understandable) I get good recognition accuracy because I train the system and then I let it train me. > > For coding, you might want to investigate a tool like Dasher[1] which > offers an alternate form of input. It allows for custom > vocabularies/keymaps if you need, as well as more precise specification > of a full keyboard (caps vs. mixed-case, specific punctuation > characters, etc). The predictive entry should be smart enough to pick > up previously entered constants/terms saving you entry speed. It can > also be driven by a wide variety of pointing devices (mouse, trackball, > touchpad, head-tracker, gyro-input, etc). I've tried it, it's quite promising but my hands term are sufficiently that I can't target accurately. This is a problem for me with mice as well. Maybe these tiny little spit dot icons and webpages drive me insane because it takes me two or three tries to put the right spot. but still, you would have the basic problem of getting the information about the code into language model of dasher so it could predict what might be chosen based on the previous context. It' 80% the same work and, doesn't help those of us with really bad hands. > > You might also experiment with other editors that allow for more > efficient editing. I've tried a whole bunch, like I said at least a dozen. They all fail for first reasons such as inability to access all functionality through keystrokes (easiest interface method from speech recognition) to virtually no autoformatting or worse yet, inconsistent autoformatting. The classic example is auto indentation based on previous lines. Emacs does a relatively right. I know this is also counter to the Python way but having something marking and outdent would be really useful so that a vocal driven command to indent or outdent a block would be practical. Oh, another failure point. Have you ever tried to selected beach and by voice. I mean I should say have you ever tried to select a region by voice. Doesn't work very well. Nuance has something called selective and say but it only works in very special Windows edit controls. Or, if you're doing toolkit supports the right signals/events. Nobody does in the the linux world and it doesn't look like they support them in the Windows world either. > > Hope these give you another option to consider, if SR plus your current > editor aren't cutting it for you, maybe we should have a conversation off list about different editors if you don't mind. I'm certainly open to alternatives but, I do have fairly high standards and one of them is that ^X^S doesn't crash the editor. :-) I have been using Emacs for too many years and it is such a reflex. Another alternative would be to help fix the NaturallySpeaking Emacs gateway vr-mode. While it doesn't truly improve the problem, it makes it a little more manageable. thank you for your time -- http://mail.python.org/mailman/listinfo/python-list
Re: identify checksum type?
Scott David Daniels wrote: > fortunately, the hashlib checksums can be distinguished by their length Unfortunately the world knows more hash algorithms than the Python standard library. :) Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
On Jun 30, 2009, at 6:46 AM, [email protected] wrote: I have to write an automted script which will test my c program. That program when run will ask for the commands. Keep in mind that, if your test script checks the program's output before giving it input, you can run into problems with buffering. The standard C library uses line-based buffering when a program is using a terminal for output, but when it's outputting to a pipe it uses block buffering. This can be a problem when running a process using subprocess--your program will buffer the prompt, and your test script won't see it, so the test will deadlock. The problem can also exist in the opposite direction. Possible solutions: - Explicitly set both your test script and your program to have line- buffered output. - Add a flush statement whenever you finish writing output and expect input. - Use pexpect, which uses a pseudo-tty and will make C stdio default to line buffering. - Use pdpi's solution, which, since it doesn't wait for a prompt before supplying input, doesn't have this issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: packaging apps
Hello, Regarding packaging for debian (.deb), the best reference I've found is: https://wiki.ubuntu.com/PackagingGuide/Python However, all that mess probably won't be needed anymore once this is finished: https://blueprints.edge.launchpad.net/ubuntu/+spec/desktop-karmic-automagic-python-build-system Best regards, Javier 2009/6/30 Ronn Ross : > I have a simple application that has a glade file and a .py file. How would > I package that into an installer for Windows, Mac, and a deb file? Can > anyone point me in the right direction? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: using input(), raw_input() to allow user to run different functions
On Jun 29, 5:22 pm, MRAB wrote: > [email protected] wrote: > > Something's been giving me difficulty.. > > > We have a USB-attached device that we frequently debug with simple > > python scripts. The model has always been that each script logs on to > > the device, does something, then logs off. As it turns out, we have > > mostly written scripts as unit tests for each API command. So, we'll > > call one script that will configure a process on the device, and a > > separate script that will retrieve the results of that process. > > > The model is changing inside the device such that all settings will be > > lost when we log off. This means we'll have to merge a bunch of > > scripts in various ways. > > > I thought it would be neat if I could have one master python script do > > the logon, then allow the user to input the name of a previously- > > written script he wanted to execute while logged on. Finally, when > > exiting the master script, the user would logout from the device. > > > I'm trying to test this by using input() or raw_input() to get the > > function the user wants to execute. I'm not having much luck. Here's > > an example: > > > Shell.py: > > #! /usr/bin/env python > > from CollectNDResults import * > > ... > > request = input('Script shell >>> ') > > print request > > exec (request) ## I realize the parentheses are not needed > > ... > > > When I run Shell.py I get this: > > > Script shell >>> CollectNDResults > > > > Traceback (most recent call last): > > File "./Shell.py", line 35, in ? > > Shell(sys.argv[1:]) > > File "./Shell.py", line 24, in Shell > > exec (request) > > TypeError: exec: arg 1 must be a string, file, or code object > > > Is there a good reference for me to figure out how to turn my function > > name into the code object that I want to execute? Is there a better > > way to do what I'm trying to do? > > >>> def foo(): > print "running foo" > > >>> import sys > >>> func_name = "foo" > >>> getattr(sys.modules[__name__], func_name)() > running foo Excellent replies, both. I'll get a lot of mileage out of this, thanks! -- http://mail.python.org/mailman/listinfo/python-list
Problem with uuid package when embedding a python interpreter
Hello,
I've tried to import a script in an embedded python intrepreter but
this script fails when it imports the uuid module. I have a
segmentation fault in Py_Finalize().
Here is a simple program which imitate my problem.
main.c :
#include "Python.h"
void test() {
Py_Initialize();
PyImport_Import(PyString_FromString("uuid"));
Py_Finalize();
}
main(int argc, char **argv)
{
for (i=0 ; i < 10; i++)
test();
}
For my application, I have to call Py_initialize and Py_Finalize
several times so factorizing them in the main function is not an easy
solution for me.
The core which is produced gives me this error :
Program terminated with signal 11, Segmentation fault.
#0 0x00190ef6 in type_dealloc (type=0x291320) at Objects/typeobject.c:
2609
2609_PyObject_GC_UNTRACK(type);
Thanks for your help
Jerome
--
http://mail.python.org/mailman/listinfo/python-list
Re: python3 fail to start
On Jun 30, 3:43 pm, ts wrote: > i just install the python 3.1 dmg onto my mac. when i run python3, it > fail with : > > Fatal Python error: Py_Initialize: can't initialize sys standard > streams > LookupError: unknown encoding: > Abort trap > > couldnt understand the problem. anyone can help? Hmm. It's working fine for me (OS X 10.5.7/Macbook Pro). What version of OS X are you using? How are you running python3---by typing 'python3' at a Terminal prompt, I assume? What's the output of the 'locale' command on your system? Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: pep 8 constants
I've tried it least two dozen editors and they all fail miserably because they're focused on keyboard use (but understandable) [...snip...] I've tried a whole bunch, like I said at least a dozen. They all fail for first reasons such as inability to access all functionality through keystrokes (easiest interface method from speech recognition) I'm not sure I follow which you want...you kvetch that they're too focused on keyboard use, but then that you can't access all functionality through the keyboard. [warning, blatant vim fanaticism follows] I use vim and can't remember the last time I used the mouse with it (save for occasionally lazily scrolling with the mouse-wheel, but you can scroll with the keyboard too), so it meets your "must be fully accessible through the keyboard" constraint. It also has single keystroke commands for indenting/exdenting the current line as you mention: > I know this is also counter to the Python way but having > something marking and outdent would be really useful so > that a vocal driven command to indent or outdent a block > would be practical. which can be done in insert-mode with control+D, control+T, and if you want to clear all indentation (all the way back to the first column), you can use "0" followed by control+D. Vim also allows for fairly detailed control over auto-indentation settings so you can match them to your preferences. I suspect Emacs may be configurable to offer similar functionality but I'd have to defer to the emacsen on the list. That said, I'll be the first to admit that the vi/vim learning curve is more like a brick wall than a curve. However, I find the efficiency gains abundantly than repaid the time I invested to learn it well. Dasher[1] I've tried it, it's quite promising but my hands term are sufficiently that I can't target accurately. Last I tried it, it scaled the target sizes based on probability. You might also try unconventional pointing devices for better precision. I've seen web-cam eye-tracking tools which might make it a bit easier. Or try a tablet input (where the motion corresponds linearly, as opposed to accelerated mouse motion). Such input options are listed on the Dasher website, at least for those they tested. Oh, another failure point. Have you ever tried to selected beach and by voice. I mean I should say have you ever tried to select a region by voice. yes, not a pleasant experience. Again, vim's modal interface allows for using text-objects so you can issue short-hand commands like ci" to "[c]hange the contents [i]nside the double-quotes I'm currently on/withing". The operator+motion and operator+textobject command syntax obviates a lot selection. While vim does offer a "visual" mode (akin to selection in other editors), I use it much less because of the power provided by the operator+[motion/textobject]. maybe we should have a conversation off list about different editors if you don't mind. I'm certainly open to alternatives but, I do have fairly high standards and one of them is that ^X^S doesn't crash the editor. :-) I have been using Emacs for too many years and it is such a reflex. as you're an emacs user, my vim suggestions may sound like heresy. ;-) But I suspect a skilled emacs user (or perhaps asking on an emacs-users list) could mimic much of the vim functionality. I just can't be of much assistance there. You're welcome to move it off-list...it's kinda drifted from python to general accessibility issues. CC'ing c.p.l for this one in case any emacsen care to chime in on their suggested tweaks. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Timeout when connecting to sybase DBS
Gil> I have looked for a timeout parameter to limit the 4 minutes to Gil> something more reasonable but couldn't find one. Can anyone please Gil> help? Gil> BTW, I'm using Sybase.connect(, , , Gil> datetime='auto') We use the Sybase module where I work, but I've never encountered this problem (or a timeout parameter of any kind). At any rate, you'll probably have more luck asking on the python-sybase mailing list: [email protected] -- Skip Montanaro - [email protected] - http://www.smontanaro.net/ when i wake up with a heart rate below 40, i head right for the espresso machine. -- chaos @ forums.usms.org -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Package Manager GUI for Python (Windows)
> Hi All, > > I'm pleased to announce a GUI package manager (v 0.12) for > Python versions 2.x under Windows. > > http://sourceforge.net/projects/pythonpkgmgr/ > > It's tightly linked to the pypi repository and offers > the following functions: > > - search packages on pypi by name > > - install (via easyinstall or pip) > > - deinstall/remove packages > > - see package documentation > > - see package examples > > - install .EGG packages > > - Generate package manifest > > If you find any issues, please don't hesitate to report > them via our tracker on the project page. Another time machine! The Release Notes for version 0.11 on http://www.preisshare.net/pythonpkgmgr/ says it was released on 10/09/09 :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
string character count
If I have a string for a file name such that I want to find the number
of characters to the left of the dot, how can that be done?
I did it this way:
x = "text12345.txt"
dot = x.find('.')
print dot
Was curious to see what method others would use - helps me learn. I
guess I was most curious to see if it could be done in one line.
And, how would a char count be done with no dot -- like if the string
were "textstringwithoutdot" or "no dot in text string"?
--
http://mail.python.org/mailman/listinfo/python-list
Unexpected behaviour of inner functions/ decorators
Hi all, I found a strange (for me) behaviour of inner function. If I execute the following code: # file in_f.py --- def dec_f(f): def inner_f(): if f.enabled: f() return inner_f @dec_f def funct(): print "Ciao" funct.enabled = True funct() # end of file - I get the following exception: File "/Users/fb/Documents/Prove python/in_f.py", line 15, in funct() File "/Users/fb/Documents/Prove python/in_f.py", line 5, in inner_f if f.enabled: AttributeError: 'function' object has no attribute 'enabled' The same happens when I rebind explicitely the function name instead of using the decorator: def funct(): print "Ciao" funct = dec_f(funct) It looks like the decorator uses an older instance of 'funct', which does not yet have the attribute dinamically attached to it. This seem to be confirmed by the fact that adding the attribute before rebinding the function name, the problem disappear: def funct(): print "Ciao" funct.enabled = False # this fixes the problem funct = dec_f(funct) So I have a workaround, but still don't understant why the original code does not work. Anyone can point me to an explanation? Thanks in advance Ciao --- FB -- http://mail.python.org/mailman/listinfo/python-list
Re: string character count
noydb wrote:
If I have a string for a file name such that I want to find the number
of characters to the left of the dot, how can that be done?
I did it this way:
x = "text12345.txt"
dot = x.find('.')
print dot
Was curious to see what method others would use - helps me learn. I
guess I was most curious to see if it could be done in one line.
>>> print "text12345.txt".find('.')
9
And, how would a char count be done with no dot -- like if the string
were "textstringwithoutdot" or "no dot in text string"?
If there's no dot then find() returns -1.
If you wanted to know the number of characters before the dot, if
present, or in total otherwise, then you could use split():
>>> len("text12345.txt".split(".", 1)[0])
9
>>> len("textstringwithoutdot".split(".", 1)[0])
20
--
http://mail.python.org/mailman/listinfo/python-list
Noob
Hello all, just joined this list and am just beginning to learn Python. Thanks to everyone for making this a great place to learn and their contributions. As mentioned, I'm new to Python (but have experience with other programming languages/scripting). I have a couple of questions... 1) Where might I find a comprehensive list of changes between Python 2.x and 3.x? 2) What are the differences between IPython and IDLE, is one better than the other, why? 3) Is there an IDE for Python development, which is the best? 4) I can't seem to install IPython for my 3.x branch (and I did install readline), I get the following error via Windows executable installation, *** run_installscript: internal error 0x ***.it installs fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If not compatible, is there a timeline for compatibility? Regards, ~kaffeen -- If you understand, things are just as they are. If you do not understand, things are just as they are. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with uuid package when embedding a python interpreter
En Tue, 30 Jun 2009 13:05:42 -0300, Jérôme Fuselier
escribió:
I've tried to import a script in an embedded python intrepreter but
this script fails when it imports the uuid module. I have a
segmentation fault in Py_Finalize().
#include "Python.h"
void test() {
Py_Initialize();
PyImport_Import(PyString_FromString("uuid"));
Py_Finalize();
}
main(int argc, char **argv)
{
for (i=0 ; i < 10; i++)
test();
}
For my application, I have to call Py_initialize and Py_Finalize
several times so factorizing them in the main function is not an easy
solution for me.
Are you sure you can't do that? Not even using Py_IsInitialized? Try to
avoid repeatedly calling Py_Initialize - won't work.
Python 2.x does not have a way to "un-initialize" an extension module
(that's a big flaw in Python design). Modules that contain global state
are likely to crash the interpreter when used by the second time. (Python
3 attempts to fix that)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
python+encryption
I have the key pair generated by the GPG. Now I want to use the public key for encrypting the password. I need to make a function in Python. Can somebody guide me on how to do this … to encrypt password by the public key ..how can i do this ,which library is best and easy to prefer.i have to work on ssh secure shell client. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of inner functions/ decorators
On Tue, Jun 30, 2009 at 1:44 PM, Francesco Bochicchio wrote: > [snip] > It looks like the decorator uses an older instance of 'funct', which > does not yet > have the attribute dinamically attached to it. This seem to be > confirmed by the fact that adding the attribute before > rebinding the function name, the problem disappear: The decorator is using the original function that you defined. By decorating 'funct' you are actually rebinding that name to the 'inner_f' function. So the statement 'funct.enabled = True' is actually creating an enabled property on the 'inner_f' function. Take a look at this code: >>> def def_f(f): ... def inner_f(): ... if iam.enabled: ... f() ... iam = inner_f ... return inner_f ... >>> @def_f ... def funct(): ... print 'Ciao' ... >>> funct.enabled = True >>> funct() Ciao -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Python/Pygame question
I have been experimenting with pygame. I would like to know how to go about placing an image of my creation as the background of the generated window. To where should I save the image, and what should it be saved as? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of inner functions/ decorators
Francesco Bochicchio wrote: def dec_f(f): def inner_f(): if f.enabled: f() return inner_f @dec_f def funct(): print "Ciao" The three lines above should behave a lot like: def funct_original(): print "Ciao" funct = dec_f(funct_original) > funct.enabled = True > funct() This is decorating "funct", but inner_f is testing the argument it was passed (funct_original), not inner_f (which is now called funct). No wonder it finds no "enabled" attribute. > So I have a workaround, but still don't understant why the original > code does not work. > Anyone can point me to an explanation? So, you can fix this like so: def dec_f(f): def inner_f(): if inner_f.enabled: f() return inner_f Or even: def dec_f(f): def inner_f(): if inner_f.enabled: f() inner_f.enabled = False return inner_f Thus testing the thing that you were marking with funct.enabled = True. Does this help explain? --Scott David Daniels [email protected] -- http://mail.python.org/mailman/listinfo/python-list
Re: python+encryption
jayshree gmail.com> writes: > > I have the key pair generated by the GPG. Now I want to use the public > key for encrypting the password. I need to make a function in Python. > Can somebody guide me on how to do this … PyCrypto -- http://mail.python.org/mailman/listinfo/python-list
Re: Direct interaction with subprocess - the curse of blocking I/O
> So well, I'd like to know, do you people know any solution to this > simple problem - making a user interact directly with a subprocess? you might want something like Expect. check out the pexpect module: http://pexpect.sourceforge.net/pexpect.html -Corey -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Imaging Library download link broken?
peter wrote: > >Just got a new computer and I'm trying to download my favourite >applications. All's well until I get to PIL, and here pythonware and >effbot both return a 502 Proxy error. > >Is this just a temporary glitch, or something more serious? And if >it's the latter, is there any alternative source? Surprisingly, this appears to have been caused by the death of Michael Jackson. The burden of people sending messages, downloading videos, buying albums, etc., has crippled the Internet worldwide. AT&T reported at its peak that there were more than 60,000 text messages PER SECOND being sent regarding Jackson. -- Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: tokenize module
bootkey wrote: > >Thanks for the reply. I wonder why the tokenizer classifies all >operators simply as OP, instead of the various operators listed in the >tok_name dictionary. I imagine it's just an exercise left to the reader. It's not that hard of an extension. -- Tim Roberts, [email protected] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Noob
En Tue, 30 Jun 2009 15:02:21 -0300, kaffeen escribió: Hello all, just joined this list and am just beginning to learn Python. Thanks to everyone for making this a great place to learn and their contributions. Welcome! As mentioned, I'm new to Python (but have experience with other programming languages/scripting). I have a couple of questions... 1) Where might I find a comprehensive list of changes between Python 2.x and 3.x? You may read the "What's new?" documents for 3.0 and 3.1: http://docs.python.org/3.1/whatsnew/index.html If you're learning Python the differences aren't so important now (the most obvious being that the print statement becomes a function). If you're using a book covering Python 2.x, install the latest on that series (2.6.2). Support for Python 3 is increasing but many 3rd party libraries have not been ported yet. 3) Is there an IDE for Python development, which is the best? Look in the wiki: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments or search past messages in this list. The topic arises every two months or so. There is no definitive answer. 4) I can't seem to install IPython for my 3.x branch (and I did install readline), I get the following error via Windows executable installation, *** run_installscript: internal error 0x ***.it installs fine with my 2.5.1 branch. Is IPython not compatible with Python 3.x? If not compatible, is there a timeline for compatibility? Ask the IPython team; but unless a project explicitely states that it's compatible with Python 3, you should assume it isn't. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
ANN: ActivePython 3.1.0.1 is now available
I'm happy to announce that ActivePython 3.1.0.1 is now available for download from: http://www.activestate.com/activepython/python3/ This is a major release that updates ActivePython3 to core Python 3.1. What is ActivePython? - ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux, HP-UX and AIX are made freely available. ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. See this page for full details: http://docs.activestate.com/activepython/3.1/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/3.1/ We would welcome any and all feedback to: [email protected] Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_product=ActivePython On what platforms does ActivePython run? ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") Extra Bits -- ActivePython releases also include the following: - ActivePython31.chm: An MS compiled help collection of the full ActivePython documentation set. Linux users of applications such as xCHM might find this useful. This package is installed by default on Windows. Extra bits are available from: http://downloads.activestate.com/ActivePython/etc/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining if a function is a method of a class within a decorator
I do not like top posting. Some thoughts in randon order: Introspection is version-specific. Call-time introspection is different from definition-time introspection. Do what is easy and works. Do not use recipes that depend on version-specific stuff you do not understand. Code objects, I believe, know the names of parameters. That question and responses were only about methods, not non-class functions. You get to match these responses to your post ;-). Terry David Hirschfield wrote: Yeah, it definitely seems like having two separate decorators is the solution. But the strange thing is that I found this snippet after some deep googling, that seems to do something *like* what I want, though I don't understand the descriptor stuff nearly well enough to get what's happening: http://stackoverflow.com/questions/306130/python-decorator-makes-function-forget-that-it-belongs-to-a-class answer number 3, by ianb. It seems to indicate there's a way to introspect and determine the class that the function is going to be bound to...but I don't get it, and I'm not sure it's applicable to my case. I'd love an explanation of what is going on in that setup, and if it isn't usable for my situation, why not? Thanks again, -David Terry Reedy wrote: David Hirschfield wrote: I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able to do some things a little differently depending on whether I'm swapping two functions, or two methods of a class. Unbounds methods are simply functions which have become attributes of a class. Especially in Py3, there is *no* difference. Bound methods are a special type of partial function. In Python, both are something else, though still callables. Conceptually, a partial function *is* a function, just with fewer parameters. Trouble is, it appears that when the decorator is called the function is not yet bound to an instance, so no matter whether it's a method or function, it looks the same to the decorator. Right. Whether it is an A or an A, it looks like an A. Worse: when the decorator is called, there is no class for there to be instances of. This simple example illustrates the problem: Add a second parameter to tell the decorator which variant of behavior you want. Or write two variations of the decorator and use the one you want. tjr -- http://mail.python.org/mailman/listinfo/python-list
PEP 376
Hello, I would like to propose this PEP for inclusion into Python 2.7 / 3.2 http://www.python.org/dev/peps/pep-0376/ It has been discussed a lot already in the distutils-SIG, but new feedbacks are welcome there's an implementation prototype here : http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py Regards Tarek -- Tarek Ziadé | http://ziade.org -- http://mail.python.org/mailman/listinfo/python-list
Re: It's ...
On Jun 24, 11:40 pm, "J. Cliff Dyer" wrote:
> Also note that you can iterate over a file several times:
>
> f = open('foo.txt')
> for line in f:
> print line[0] # prints the first character of every line
> for line in f:
> print line[1] #prints the second character of every line
>
No, you can't. The second loop prints nothing!
A file by default advances forward. Once you reach the end, you stay
there.
You could explicitly call f.seek(0, 0) to rewind it. Note that not
all file objects are seekable (e.g. pipes and sockets aren't).
The cleaner way to read a regular file twice is to *open* it time:
for line in open('foo.txt'):
print line[0] # prints the first character of every line
for line in open('foo.txt'):
print line[1] # prints the second character of every line
Quick recap for Angus:
for loops work on "iterables" - objects that can be asked for an
"iterator".
Python iterators are unseekable - once exhausted they stay empty.
Most iterables (e.g. lists) return a new iterator every time you ask,
so you can iterate over the same data many times.
But if you already have an iterator, you can use it in a for loop -
when asked for an iterator, it will offer itself (in other words an
iterator is a degenerate kind of iterable).
This is what happened with the file object - it's an iterator and
can't be reused.
Reusing the same iterator between for loops is sometimes useful if you
exit the first loop mid-way:
f = open('foo.mail')
# skip headers until you see an empty line
for line in f:
if not line.strip():
break
# print remainer or file
for line in f:
sys.stdout.write(line)
P.S. Warning: after you use ``for line in f``, it's dangerous to use
``f.read()`` and ``f.readline()`` (buffering mess - just don't.)
> Glad you're enjoying Beazley. I would look for something more
> up-to-date. Python's come a long way since 2.1. I'd hate for you to
> miss out on all the iterators, booleans, codecs, subprocess, yield,
> unified int/longs, decorators, decimals, sets, context managers and
> new-style classes that have come since then.
>
Seconded - 2.1 is ancient.
If you continue with the book, here is a quick list of the most
fundamental improvements to keep in mind:
1. Iterators, generators, generator expressions.
2. Working nested scopes.
3. Decorators.
4. with statement.
5. set & bool types.
6. Descriptors (if confusing, just understand properties).
7. from __future__ import division, // operator.
and the most refreshing modules added:
- subprocess
- ctypes
- itertools
- ElementTree
- optparse
and not new but I just love introducing it people:
- doctest
--
http://mail.python.org/mailman/listinfo/python-list
Re: string character count
On Jun 30, 1:56 pm, MRAB wrote:
> noydb wrote:
> > If I have a string for a file name such that I want to find the number
> > of characters to the left of the dot, how can that be done?
>
> > I did it this way:
> > x = "text12345.txt"
> > dot = x.find('.')
> > print dot
>
> > Was curious to see what method others would use - helps me learn. I
> > guess I was most curious to see if it could be done in one line.
>
> >>> print "text12345.txt".find('.')
> 9
>
> > And, how would a char count be done with no dot -- like if the string
> > were "textstringwithoutdot" or "no dot in text string"?
>
> If there's no dot then find() returns -1.
>
> If you wanted to know the number of characters before the dot, if
> present, or in total otherwise, then you could use split():
>
> >>> len("text12345.txt".split(".", 1)[0])
> 9
> >>> len("textstringwithoutdot".split(".", 1)[0])
> 20
Also:
len("text12345.txt".partition('.')[0])
9
--
http://mail.python.org/mailman/listinfo/python-list
invoking a method from two superclasses
In Python 3, how should super() be used to invoke a method defined in C that
overrides its two superclasses A and B, in particular __init__?
class A:
def __init__(self):
print('A')
class B:
def __init__(self):
print('B')
class C(A, B):
def __init__(self):
super().__init__()
print('C')
C()
Output is:
A
C
I've discovered the surprising fact described in the documentation of super
that specifying a class as the first argument of super means to skip that class
when
scanning the mro so that if C.__init__ includes the line
super(A, self).__init__()
what gets called is B.__init__, so that if I want to call __init__ of both
classes the
definition of C should have both of the following lines:
super().__init__()
super(A, self).__init__()
and that
super(B, self).__init__()
does nothing because B is the last class in the mro.
This seems weird. Would someone please give a clear example and explanation of
the recommended way of initializing both superclasses in a simple multiple
inheritance
situation?
Note: I am EXTREMELY knowledgeable about OO, Python, and many OOLs.
I don't mean to be arrogant, I just want to focus the discussion not open it to
a broad
interchange about multiple inheritance, the ways it can be used or avoided,
etc. I just
want to know how to use super. The documentation states the following:
"There are two typical use cases for super. In a class hierarchy with single
inheritance,
super can be used to refer to parent classes without naming them explicitly,
thus
making the code more maintainable."
"The second use case is to support cooperative multiple inheritance in a
dynamic
execution environment. This use case is unique to Python and is not found in
statically compiled languages or languages that only support single
inheritance.
This makes it possible to implement "diamond diagrams" where multiple base
classes implement the same method."
"For both use cases, a typical superclass call looks like this:
class C(B):
def method(self, arg):
super().method(arg)# This does the same thing as:
# super(C, self).method(arg)
"
Though it claims to be demonstrating both cases, it is only demonstrating single
inheritance and a particular kind of multiple inheritance where the method is
found
in only one class in the mro. This avoids situations where you want to call the
method anywhere it is found in the mro, or at least in the direct superclasses.
Perhaps __init__ is a special case, but I don't see how to figure out how to
__init__
two superclasses of a class from the documentation. I often file "bug reports"
about
documentation ambiguities, vagueness, incompletenesses, etc., but I don't want
to
do so for this case until I've heard something definitive about how it should
be
handled.
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list
Ubigraph vs Matplotlib (dynamic plotting, event handling)
Hello everyone, I intend to use python for some network graph plotting, with event handling (clicking on network nodes, zooming in/out etc..) and so far I have come across two good candidates which are Matplotlib and Ubigraph. Did anyone have any experience with either of them for dynamic plotting (a slider bar on a Qt interface causing the graph to be replotted for each value for example), as well as event handling? (it seems on first notice that Ubigraph will have an upperhand on that), as well as event handling such as mouse clicks? (on this one Matplotlib has good documentation showing it does achieve that while I find ubigraph's documentation lacking, but I'd preffere to have the opinion of those who have used them before). Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: handling https sites
On 26Jun2009 09:34, cgoldberg wrote: | > Is there any module in python to open https | > sites through a proxy. | | yes, you can use "urllib2". | | from the urllib2 docs: | "The default is to read the list of proxies from the environment | variables" | | So if you have a proxy setup, it should detect it from your | environment vars. If you want to specify something different, you | want to build an opener with a ProxyHandler: | | http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler Except that HTTPS through a proxy doesn't work: http://bugs.python.org/issue1424152 There's a patch under review. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 376
On Jun 30, 12:41 pm, Tarek Ziadé wrote: > Hello, > > I would like to propose this PEP for inclusion into Python 2.7 / 3.2 > > http://www.python.org/dev/peps/pep-0376/ > > It has been discussed a lot already in the distutils-SIG, but new > feedbacks are welcome > > there's an implementation prototype here > :http://bitbucket.org/tarek/pep376/src/tip/pkgutil.py +1 This seems to be a well-designed solution that corrects the ad-hoc- ness of installation while keeping its effects on existing tools small. I hate those egg-info files but I would be very happy if they'd at least always be in an accounted-for place. Maybe I'd even consider making use of them some day. As for setuptools, I'm sure it will accommodate the change and probably improve itself in the process. (And if the setuptools doesn't change then some other tool will grow into its niche; either way it'd be an improvement.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
