comp.lang.python - 25 new messages in 15 topics - digest
comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en
comp.lang.python@googlegroups.com
Today's topics:
* When 'super' is not a good idea - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/e976c6338ab6f79f?hl=en
* cpython compilation parameter - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/a155f002d2785880?hl=en
* Cashing in PythonWin name space?... seems unexpected to me - 2 messages, 2
authors
http://groups.google.com/group/comp.lang.python/t/b7739667c59d7ec4?hl=en
* Python + webservice - 2 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b12fe629de674144?hl=en
* Is pythonic version of scanf() or sscanf() planned? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f63da3ff1a308e5b?hl=en
* No threading.start_new_thread(), useful addition? - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/f7e946f84e30b7c3?hl=en
* save windows clipboard content temporarily and restore later - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/736adad7c55b4bb9?hl=en
* best vi / emacs python features - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/43ba2321010580ba?hl=en
* ANN: Testoob 1.15 released - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/ee62e861412847f4?hl=en
* transparent splash screen - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/7c2ba4e04555b4e3?hl=en
* del an imported Class at EOF... why? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/3c0bd6eef521c5d8?hl=en
* threading module, call thread.interrupt_main() - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/b410a194441ee753?hl=en
* Is there a better way to code variable number of return arguments? - 3
messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/41d3464020866bda?hl=en
* trouble with regex? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/66f0849bb02480ae?hl=en
* Problem Displaying Pics - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/500c186c7f22f6ca?hl=en
==============================================================================
TOPIC: When 'super' is not a good idea
http://groups.google.com/group/comp.lang.python/t/e976c6338ab6f79f?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 6:28 am
From: Jean-Michel Pichavant
alex23 wrote:
> Jean-Michel Pichavant <jeanmic...@sequans.com> wrote:
>
>> alex23 wrote:
>>
>>> To me, the explicit reference to the base class violates DRY. It also
>>> means you need to manually change all such references should the base
>>> class ever change, something that using super() avoids.
>>>
>> I found the correct answer
>> (http://www.artima.com/weblogs/viewpost.jsp?thread=236275)
>>
>
> I'm not entirely sure how an opinion + explanation of the underlying
> mechanics is more or less "correct" than a development principle...
>
The correctness applies to my answer, not the super mechanism. The super
mechanism is correct and properly documented since python 2.6, so anyone
is free to use it.
I'm just trying to give arguments in favor of using the explicit base
class name instead of super.
And in my opinion, explicit names are (slightly) better because there's
no underlying explanation required when using the base class name
instead of super.
JM
==============================================================================
TOPIC: cpython compilation parameter
http://groups.google.com/group/comp.lang.python/t/a155f002d2785880?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Oct 8 2009 6:34 am
From: cEd
Hello,
I'm wondering how to compile python to get good performance.
Because when I compare this ugly code which find prime number:
# prime_number.py
start=30000
for is_first in range(start):
found = 0
is_first+=1
for i in range (2, is_first):
if not (is_first%(i)):
found = 1
break
if not found:
print is_first
between :
- the python distributed with my ubuntu
#time python prime_number.py > /dev/null
real 0m12.237s
user 0m12.129s
sys 0m0.024s
- and the one compiled by my self
time my_python_compiled prime_number.py > /dev/null
real 0m42.193s
user 0m41.891s
sys 0m0.044s
so which option should I give or which flag ???
regards
cEd
== 2 of 2 ==
Date: Thurs, Oct 8 2009 6:39 am
From: "Diez B. Roggisch"
cEd wrote:
> Hello,
>
> I'm wondering how to compile python to get good performance.
> Because when I compare this ugly code which find prime number:
>
> # prime_number.py
> start=30000
> for is_first in range(start):
> found = 0
> is_first+=1
> for i in range (2, is_first):
> if not (is_first%(i)):
> found = 1
> break
> if not found:
> print is_first
>
>
> between :
> - the python distributed with my ubuntu
> #time python prime_number.py > /dev/null
> real 0m12.237s
> user 0m12.129s
> sys 0m0.024s
>
> - and the one compiled by my self
> time my_python_compiled prime_number.py > /dev/null
> real 0m42.193s
> user 0m41.891s
> sys 0m0.044s
>
> so which option should I give or which flag ???
I doubt that there is such a flag. There must be a different reason for
this. Can you give us the python versions for each, and architecture (32/64
bit)?
Diez
==============================================================================
TOPIC: Cashing in PythonWin name space?... seems unexpected to me
http://groups.google.com/group/comp.lang.python/t/b7739667c59d7ec4?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Oct 8 2009 6:47 am
From: bsneddon
I saw an issue on winXP box not connected to internet yesterday,
where i was running
a script in the interactive window on PythonWin . I would modify the
script save and
import and was still running the old version. I did that several
times with same result.
I even renamed the function and it showed up but ran the old script.
Very strange.
I tried reproducing this morning on a machine that is connected to
internet was unable to
but did get the behavior below that I do not understand.
created module named spam with this code.
def ello():
print "Your father smells of elderberrys"
Here is expert for interactive window to explain the issue: question
is below.
PythonWin 2.6 (r26:66721, Oct 2 2008, 11:35:03)
I
renamed ello to insult and re-imported.
>>> dir(spam)
[clip.. 'ello', 'insult']
ello still exist in namespace an runs ... not so strange
>>> spam.ello()
Your father smells of elderberrys
>>> del(spam)
delete spam and it no longer runs as expected.
modify insult to this:
def insult():
print "Your father smells of elderberrys/n and your mother was a
kiniggit"
Q.
on re-importing spam ello is back and continues to run. I did note
expect this to be the
case. Can someone explain what is happening?
>>> dir(spam)
[clip..., 'ello', 'insult']
>>> spam.ello()
Your father smells of elderberrys
>>> spam.insult()
Your father smells of elderberrys/n and your mother was a kiniggit
>>>
Thanks for your help.
Bill Sneddon
== 2 of 2 ==
Date: Thurs, Oct 8 2009 9:45 am
From: Simon Forman
On Thu, Oct 8, 2009 at 9:47 AM, bsneddon <bsneddon@yahoo.com> wrote:
> I saw an issue on winXP box not connected to internet yesterday,
> where i was running
> a script in the interactive window on PythonWin . I would modify the
> script save and
> import and was still running the old version. I did that several
> times with same result.
> I even renamed the function and it showed up but ran the old script.
> Very strange.
>
> I tried reproducing this morning on a machine that is connected to
> internet was unable to
> but did get the behavior below that I do not understand.
>
> created module named spam with this code.
> def ello():
> print "Your father smells of elderberrys"
>
> Here is expert for interactive window to explain the issue: question
> is below.
>
> PythonWin 2.6 (r26:66721, Oct 2 2008, 11:35:03)
> I
>
>
> renamed ello to insult and re-imported.
>
>>>> dir(spam)
> [clip.. 'ello', 'insult']
>
> ello still exist in namespace an runs ... not so strange
>>>> spam.ello()
> Your father smells of elderberrys
>
>>>> del(spam)
> delete spam and it no longer runs as expected.
>
> modify insult to this:
> def insult():
> print "Your father smells of elderberrys/n and your mother was a
> kiniggit"
>
> Q.
> on re-importing spam ello is back and continues to run. I did note
> expect this to be the
> case. Can someone explain what is happening?
>
>>>> dir(spam)
> [clip..., 'ello', 'insult']
>>>> spam.ello()
> Your father smells of elderberrys
>>>> spam.insult()
> Your father smells of elderberrys/n and your mother was a kiniggit
>>>>
>
>
> Thanks for your help.
>
> Bill Sneddon
The reload() function might be what you need:
http://docs.python.org/library/functions.html#reload
HTH,
~Simon
==============================================================================
TOPIC: Python + webservice
http://groups.google.com/group/comp.lang.python/t/b12fe629de674144?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Oct 8 2009 6:50 am
From: Fred Chevitarese
First of all, thanks for these replies...
Someone has an example of python + suds generating a XML and consuming
a webservice or, in suds documentation has one?
Thanks again ;)
On Oct 8, 8:32 am, Jakob Kristensen <j4k...@gmail.com> wrote:
> Ralf Schoenian wrote:
> > > Has anyone made something like this and can share with me a bit of
> > > experience?
>
> > Did you try sudshttps://fedorahosted.org/suds?I've got good results
> > with this library.
>
> > Ralf
>
> After working with both ZSI and Suds, i must say i've had by far the
> best experiences with Suds. It's very light-weight compared to ZSI
> (which by no means is light-weighted).
== 2 of 2 ==
Date: Thurs, Oct 8 2009 7:21 am
From: Fred Chevitarese
Hello again!!
Now i'm reading the documentation... If i got doubts, i ask here!
Thanks ;)
On Oct 8, 10:50 am, Fred Chevitarese <fchevitar...@gmail.com> wrote:
> First of all, thanks for these replies...
> Someone has an example of python + suds generating a XML and consuming
> a webservice or, in suds documentation has one?
>
> Thanks again ;)
>
> On Oct 8, 8:32 am, Jakob Kristensen <j4k...@gmail.com> wrote:
>
>
>
> > Ralf Schoenian wrote:
> > > > Has anyone made something like this and can share with me a bit of
> > > > experience?
>
> > > Did you try sudshttps://fedorahosted.org/suds?I'vegot good results
> > > with this library.
>
> > > Ralf
>
> > After working with both ZSI and Suds, i must say i've had by far the
> > best experiences with Suds. It's very light-weight compared to ZSI
> > (which by no means is light-weighted).
==============================================================================
TOPIC: Is pythonic version of scanf() or sscanf() planned?
http://groups.google.com/group/comp.lang.python/t/f63da3ff1a308e5b?hl=en
==============================================================================
== 1 of 2 ==
Date: Thurs, Oct 8 2009 7:26 am
From: ryniek90
On 6 Paź, 06:37, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
> On Sun, 4 Oct 2009 15:48:16 -0700 (PDT), TerryP <bigboss1...@gmail.com>
> declaimed the following in gmane.comp.python.general:
>
> > In the last 4 years, I have never missed functions like .*scanf() or
> > atoi().
>
> > It's probably a greeaaat thing that Python provides nether as built
> > ins (per se).
>
> Uhm... Isn't the second one spelled "int()" <G>
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Ok thanks all for answers. Not counting .split() methods and regexps,
there's nothing interesting.
But I remember that lambda function also was unwelcome in Python, but
finally it is and is doing well. So maybe someone, someday decide to
put in Python an alternative, really great implementation of scanf() ?
== 2 of 2 ==
Date: Thurs, Oct 8 2009 9:33 am
From: Ben Sizer
On Oct 3, 11:06 pm, ryniek90 <rynie...@gmail.com> wrote:
> Hi
>
> I know that in python, we can do the same with regexps or *.split()*,
> but thats longer and less practical method than *scanf()*. I also found
> that (http://code.activestate.com/recipes/502213/), but the code
> doesn't looks so simple for beginners. So, whether it is or has been
> planned the core Python implementation of *scanf()* ? (prefered as a
> batteries included method)
Perhaps struct.unpack is close to what you need? Admittedly that
doesn't read from a file, but that might not be a problem in most
cases.
--
Ben Sizer
==============================================================================
TOPIC: No threading.start_new_thread(), useful addition?
http://groups.google.com/group/comp.lang.python/t/f7e946f84e30b7c3?hl=en
==============================================================================
== 1 of 3 ==
Date: Thurs, Oct 8 2009 8:16 am
From: Hendrik van Rooyen
On Thursday, 8 October 2009 13:24:14 Christian Heimes wrote:
> Laszlo Nagy wrote:
> > But really thread.start_new_thread is better:
> >
> > import thread.start_new_thread as thr
> >
> > thr(my_function,arg1,arg2)
>
> Please don't use the thread module directly, especially the
> start_new_thread function. It a low level function that bypasses the
> threading framework. The is no good reason to use this function in favor
> of threading.Thread().
I have seen this advice a couple of times now, and I do not understand it.
From my perspective (which is admittedly jaundiced) Threading just adds a
bunch of superfluous stuff like a run method and other weird things that I
cannot see a need for.
The simplicity of this kind of code:
def this_is_a_thread(arg1,arg2):
do_some_initialisation(arg1,arg2)
while some_condition:
do_some_stuff()
which then gets started with thread.start_new_thread, does it for me.
What does the Threading module buy me, other than a formal OO approach?
- Hendrik
== 2 of 3 ==
Date: Thurs, Oct 8 2009 8:33 am
From: Christian Heimes
Hendrik van Rooyen wrote:
> What does the Threading module buy me, other than a formal OO approach?
* the interpreter won't know about your thread when you bypass the
threading module and use the thread module directly. The thread isn't in
the list of active threads and the interpreter is unable to wait for the
thread to exit when Python shuts down. All threads created by the thread
module behave like daemonic threads.
* exception reporting doesn't work with thread.start_new_thread
* profiling and tracing doesn't work with thread.start_new_thread
* introspection of active thread doesn't work because threads started by
thread.start_new_thread are invisible for the rest of the interpreter
* you have to roll your own system to join a thread
* probably more stuff
In Python 3.0 the thread module has been renamed to _thread in order to
reflect the nature of the C extension.
Christian
== 3 of 3 ==
Date: Thurs, Oct 8 2009 8:35 am
From: Christian Heimes
Ulrich Eckhardt wrote:
> No, as this one doesn't give me a handle to the thread. I also find this
> barely readable, for sure it doesn't beat the readability of the proposed
> function.
Roll your own convenient function, though. :) At work we have this short
function in our tool box:
def daemonthread(target, name=None, autostart=True, args=(), kwargs=None):
"""Start a thread as daemonic thread
"""
thread = Thread(target=target, name=name, args=args, kwargs=kwargs)
thread.setDaemon(True)
if autostart:
thread.start()
return thread
Christian
==============================================================================
TOPIC: save windows clipboard content temporarily and restore later
http://groups.google.com/group/comp.lang.python/t/736adad7c55b4bb9?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 8:27 am
From: kakarukeys
Is there a way to:
1. save windows clipboard content temporarily in a variable
2. (the clipboard content is then overwritten by some other
applications)
3. restore the saved data back into the clipboard.
?
I've tried win32clipboard's GetClipboardData, SetClipboardData.
The GetClipboardData method is able to retrieve clipboard content only
after a format is specified.
Restoring the data with that format could result in information loss,
for example when HTML text is saved in ordinary text format. There is
no format that could preserve 100% of any kind of clipboard content.
Does anyone has a brilliant solution?
==============================================================================
TOPIC: best vi / emacs python features
http://groups.google.com/group/comp.lang.python/t/43ba2321010580ba?hl=en
==============================================================================
== 1 of 3 ==
Date: Thurs, Oct 8 2009 8:31 am
From: edexter
On Oct 7, 10:07 am, OdarR <olivier.da...@gmail.com> wrote:
> hello,
>
> * this is not a troll *
>
> which kind of help you have with your favorite editor ?
>
> personnally, I find emacs very nice, in the current state of my
> knowledge, when I need to reindent the code.
> you know how this is critical in python...:-)
>
> I don't use other python-mode features for the moment, maybe you have
> some advices.
> I used with success an Xemacs on Solaris, as well as a Aquamacs on
> Mac.
>
> For the vi/vim guys, explain us the best features this editor give you
> in your py files !
>
> thanks,
>
> Olivier
I like alot of the features of both on gvim they show white space
symbols but I find both emacs and gvim a pain to extend
and I need to find a key word and then hilight columns so because of
the complexity it has become rich edit vs scintilla..
I wrote my own syntax highlighter for rich edit 2 for csound but not
with all the complexity I am planning later.. jedit looked
very intresting but I haven't figured out the output window yet they
do have python embeded well jython anyway (like gvim does)
== 2 of 3 ==
Date: Thurs, Oct 8 2009 8:40 am
From: Falcolas
On Oct 8, 7:23 am, Jean-Michel Pichavant <jeanmic...@sequans.com>
wrote:
> Chris Jones wrote:
> > On Wed, Oct 07, 2009 at 07:06:08PM EDT, TerryP wrote:
>
> > [..]
>
> >> I am a freak: I do not use nor want syntax highlighting. I don't want
> >> my editor to understand mail, irc, or the www either, I want it to
> >> edit text efficiently so I can go on with the rest of my life as soon
> >> as possible. Given the choice of using a space cadets editor like
> >> emacs or something primitive one like ed, I would choose *ed* just to
> >> speed things up and save on wrist strain. Before I read a tutorial
> >> about vi, I used XEmacs very happily---vi just lines up better with
> >> how my brain works.
>
> >> --
>
> >> It is also general consensus that I am nuts ;)
>
> > I don't think so.
>
> > Always felt that syntax highlighting for instance is way overrated. Haven't
> > tried "ed" yet, but since I have already stripped down my everything to what
> > I thought was minimal, now that you mention it, this may be where I'm bound.
>
> > I do have a question:
>
> > You mentioned Vim's clientserver mode.
>
> > What's it good for?
>
> > Thanks,
>
> > CJ
>
> Strange how things can differ from one person to another. Syntax
> highlighting is the feature I'm missing the most when I'm using pure vi.
> Looks like some are getting annoyed by it, I think it provides useful
> and meaningful informations through colors.
>
> JM
I have found that syntax hilighting is useful, as long as it isn't
overwhelming. Zenburn is a great highlighting scheme which is fairly
easy on the eyes to use (no startling colors anywhere), yet the
differences are enough for me to quickly pick out syntax elements.
Garrick
== 3 of 3 ==
Date: Thurs, Oct 8 2009 9:47 am
From: Ross Ridge
TerryP <bigboss1964@gmail.com> wrote:
>ed -- I can quickly edit files without having to wait on an ncurses
>app to start up. Although I rarely have access to GNU versions of ed,
>they use readline which is a big perk when you make a typo.
I used to fallback on ed when network connections got really slow and
I could log in using Telnet line-mode, but it's been a long time since
the I could tell the difference between the start up time of any editor.
They all, ed, nvi or GNU emacs, start up instantaneously for me.
>nvi -- smaller and faster then vim, works great over slow ssh links or
>when editing huge files. I like nvi over the original vi, because most
>of the limitations of the old-school vi are removed; unlimited undo is
>the best feature added.
I like nvi because by default it's quirk for quirk compatible with the
original vi, including single-level undo. (Well at least until they
screwed things up with the new file/input encoding scheme.)
>EDIT.COM -- much faster then notepad over remote connections, and it
>understands both DOS and UNIX end of lines; meaning I can skip
>converting formats, the only downside is it's still a 16-bit program.
I use MS-DOS Editor from time to time, but mainly because it means I
don't have to change window focus.
>I am a freak: I do not use nor want syntax highlighting. I don't want
>my editor to understand mail, irc, or the www either, I want it to
>edit text efficiently so I can go on with the rest of my life as soon
>as possible. Given the choice of using a space cadets editor like
>emacs or something primitive one like ed, I would choose *ed* just to
>speed things up and save on wrist strain.
But in actual practice you use a space cadets editor like Vim.
Ross Ridge
--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rridge@csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
==============================================================================
TOPIC: ANN: Testoob 1.15 released
http://groups.google.com/group/comp.lang.python/t/ee62e861412847f4?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 8:55 am
From: oripel
Testoob is the advanced Python test runner and testing framework that
spices up any existing unittest test suite.
Home: http://code.google.com/p/testoob
Version 1.15 (Oct. 2009) adds better Python 2.6, IronPython, and
Jython support, as well as test coverage improvements, better color
support, and some new options and bugfixes. *nix and Windows are fully
supported.
Installation options:
* 'easy_install -U testoob'
* One of the packages at http://code.google.com/p/testoob/downloads/list
This version wouldn't have been possible without the help of Ronnie
van 't Westeinde.
==============================================================================
TOPIC: transparent splash screen
http://groups.google.com/group/comp.lang.python/t/7c2ba4e04555b4e3?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 8:59 am
From: NighterNet
I been looking for simple way to create a transparent splash screen.
Using gif,png,jpg just by loading the file into it. Using version
3.1.1 Any help would be nice.
==============================================================================
TOPIC: del an imported Class at EOF... why?
http://groups.google.com/group/comp.lang.python/t/3c0bd6eef521c5d8?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 9:37 am
From: Simon Forman
On Thu, Oct 8, 2009 at 1:42 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> Hans Mulder wrote:
>
>> Errrhm, no. He is not deleting the PyQt4 module from sys.modules;
>> he's only deleting the name QtGui from his own namespace. Next
>> time Python comes across
>>
>> from PyQt4 import QtGui
>>
>> , it finds that the module PyQt4 already exists in sys.modules, so
>> Python does not have to load the module again. All it has to do is
>> bind name QtGui in the importing module to the class with the same
>> name in the PyQt4 module. That does not take many cycles.
>
> I recently discovered that when IDLE restarts (as when one runs a file from
> an edit window), it clears the global namespace but does not clear
> sys.modules. Hence re-running a script that does time-consuming imports is
> much faster, as only the global name binding is done after the first run.
Is that with or without '-n'?
==============================================================================
TOPIC: threading module, call thread.interrupt_main()
http://groups.google.com/group/comp.lang.python/t/b410a194441ee753?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 9:40 am
From: Simon Forman
2009/10/7 找尋自己的一片天 <command.bbs@alexbbs.twbbs.org>:
> Sorry to ask, but i don't know how to solve it.
>
> I try to call thread.interrupt_main() function in my child thread's run method
> which is inherit threading.Thread class.
>
> But it didn't work, does anyone know why?
>
> Thanks a lot!!
>
"it didn't work" is not enough information.
What is your code (smallest version that shows the problem)?
And what is the traceback?
==============================================================================
TOPIC: Is there a better way to code variable number of return arguments?
http://groups.google.com/group/comp.lang.python/t/41d3464020866bda?hl=en
==============================================================================
== 1 of 3 ==
Date: Thurs, Oct 8 2009 9:41 am
From: "Dr. Phillip M. Feldman"
I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:
if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]
(and so on). Is there a cleaner way to accomplish the same thing?
--
View this message in context: http://www.nabble.com/Is-there-a-better-way-to-code-variable-number-of-return-arguments--tp25803294p25803294.html
Sent from the Python - python-list mailing list archive at Nabble.com.
== 2 of 3 ==
Date: Thurs, Oct 8 2009 9:43 am
From: Paul Rubin
"Dr. Phillip M. Feldman" <pfeldman@verizon.net> writes:
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on). Is there a cleaner way to accomplish the same thing?
That is poor style. Just return the result as a list.
== 3 of 3 ==
Date: Thurs, Oct 8 2009 9:52 am
From: Christian Heimes
Dr. Phillip M. Feldman schrieb:
> I currently have a function that uses a list internally but then returns the
> list items as separate return
> values as follows:
>
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on). Is there a cleaner way to accomplish the same thing?
You can simply "return result". If you want to make sure that you return
a copy of the internal list, do "return list(result)" or "return
tuple(result)".
Christian
==============================================================================
TOPIC: trouble with regex?
http://groups.google.com/group/comp.lang.python/t/66f0849bb02480ae?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 9:42 am
From: MRAB
inhahe wrote:
> Can someone tell me why this doesn't work?
>
> colorre = re.compile ('('
> '^'
> '|'
> '(?:'
> '\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
> '(?:'
> ',(?:10|11|12|13|14|15|0\\d|\\d)'
> ')?'
> ')'
> ')(.*?)')
>
> I'm trying to extract mirc color codes.
>
> this works:
>
> colorre = re.compile ('\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
> '(?:'
> ',(?:10|11|12|13|14|15|0\\d|\\d)'
> ')?'
> )
>
> but I wanted to modify it so that it returns me groups of (color code,
> text after the code), except for the first text at the beginning of the
> string before any color code, for which it should return ('', text).
> that's what the first paste above is trying to do, but it doesn't work.
> here are some results:
>
> >>> colorre.findall('a\x0b1,1')
> [('', ''), ('\x0b1,1', '')]
> >>> colorre.findall('a\x0b1,1b')
> [('', ''), ('\x0b1,1', '')]
> >>> colorre.findall('ab')
> [('', '')]
> >>> colorre.findall('\x0b1,1')
> [('', '')]
> >>> colorre.findall('\x0b1,1a')
> [('', '')]
> >>>
>
> i can easily work with the string that does work and just use group
> starting and ending positions, but i'm curious as to why i can't get it
> working teh way i want :/
>
The problem with the regex is that .*? is a lazy repeat: it'll try to
match as few characters as possible, which is why the second group is
always ''. Try a greedy repeat instead, but matching only
non-backspaces:
colorre = re.compile('('
'^'
'|'
'(?:'
'\x0b(?:10|11|12|13|14|15|0\\d|\\d)'
'(?:'
',(?:10|11|12|13|14|15|0\\d|\\d)'
')?'
')'
')([^\x0b]*)')
==============================================================================
TOPIC: Problem Displaying Pics
http://groups.google.com/group/comp.lang.python/t/500c186c7f22f6ca?hl=en
==============================================================================
== 1 of 1 ==
Date: Thurs, Oct 8 2009 9:43 am
From: "Gabriel Genellina"
En Thu, 08 Oct 2009 12:30:16 -0300, Victor Subervi
<victorsubervi@gmail.com> escribió:
> http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1
>
> On Wed, Oct 7, 2009 at 4:11 PM, Rami Chowdhury
> <rami.chowdhury@gmail.com>wrote:
>
>> On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi <
>> victorsubervi@gmail.com> wrote:
>>
>> print 'Content-Type: image/jpeg'
>>> print 'Content-Encoding: base64'
>>> print
>>> print content.encode('base64')
Are you sure this is your actual code?
py> import urllib
py> data =
urllib.urlopen("http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1").read()
py> data[:30]
'Content-Encoding: base64\n\n\n/9j'
py> data[-30:]
'XdjTJvaaF5fvfMVgbUM+gatZXFzb\n\n'
1) The Content-Encoding line is taken as part of the response entity (the
picture data), but should be part of the header. I bet you have a blank
line after Content-Type.
2) Note the \n\n at the end
py> data = data[27:-2]
py> decoded = data.decode("base64")
py> open("test.jpg","wb").write(decoded)
I tried to open test.jpg, but it's corrupt.
py> len(decoded)
65535
py> decoded[:30]
'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x01\x00H\x00H\x00\x00\xff\xe1
\xadExif\x00\x00'
Very suspicious file size... Looks like a jpeg image that was truncated at
that size. See whether it is already corrupt in the database and repair it
(you're using a data type large enough to hold the image, aren't you?)
After fixing the database, you can omit the unnecesary base64 encoding;
anyway I'd add a Content-Length header to avoid that spurious \n at the
end.
--
Gabriel Genellina
==============================================================================
You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.
To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en
To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com
To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en
To report abuse, send email explaining the problem to abuse@googlegroups.com
==============================================================================
Google Groups: http://groups.google.com/?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home