I've just spent two hours banging my head against what I *thought*
(wrongly!) was a spooky action-at-a-distance bug in unittest, so I
thought I'd share it with anyone reading.
I have a unit test which I inherit from a mixin class that looks
something like this:
def testBadArgType(self):
On Mon, 25 Apr 2011 23:18:05 +0200, Thomas Rachel
wrote:
: That is right, but I cannot see where he mentions the "direction" of the
: socket. My fist thought was that he tries to have a server socket...
Quite right. I thought it was implied by the need to bind :-)
Sorry for the lack of deta
On Apr 26, 9:59 am, Steven D'Aprano wrote:
> On Mon, 25 Apr 2011 20:28:22 -0700, Gnarlodious wrote:
> > I have an SQLite query that returns a list of tuples:
>
> > [('0A',), ('1B',), ('2C',), ('3D',),...
>
> > What is the most Pythonic way to loop through the list returning a list
> > like this?:
On Mon, 25 Apr 2011 20:28:22 -0700, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a list
> like this?:
>
> ['0A', '1B', '2C', '3D',...
Others have point
itertools can help you do this too:
import itertools
tl = [('0A',), ('1B',), ('2C',), ('3D',)]
itertools.chain.from_iterable(tl)
list(itertools.chain.from_iterable(tl))
['0A', '1B', '2C', '3D']
Checkout http://docs.python.org/library/itertools.html#itertools.chain
for more info.
On Mon, Apr
Gnarlodious writes:
> I have an SQLite query that returns a list of tuples:
> [('0A',), ('1B',), ('2C',), ('3D',),...
> What is the most Pythonic way to loop through the list returning a
> list like this?:
> ['0A', '1B', '2C', '3D',...
Try:
tlist = [('0A',), ('1B',), ('2C',), ('3D',)]
al
On Apr 25, 2011, at 11:28 PM, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
This works for me -
On Apr 25, 9:42 pm, CM wrote:
> flat_list = [item[0] for item in returned_list]
HA! So easy. Thanks.
-- Gnarlie
--
http://mail.python.org/mailman/listinfo/python-list
>What is the most Pythonic way to loop through the list returning a
>list like this?:
here's how I'd do it:
>>> i
[(1, 'a'), (2, 'b'), (3, 'c')]
>>> for item in i:
... a+=list(item)
...
...
>>> a
[1, 'a', 2, 'b', 3, 'c']
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 25, 11:28 pm, Gnarlodious wrote:
> I have an SQLite query that returns a list of tuples:
>
> [('0A',), ('1B',), ('2C',), ('3D',),...
>
> What is the most Pythonic way to loop through the list returning a
> list like this?:
>
> ['0A', '1B', '2C', '3D',...
>
> -- Gnarlie
For just this case,
I have an SQLite query that returns a list of tuples:
[('0A',), ('1B',), ('2C',), ('3D',),...
What is the most Pythonic way to loop through the list returning a
list like this?:
['0A', '1B', '2C', '3D',...
-- Gnarlie
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 25 Apr 2011 16:48:42 -0700, Raymond Hettinger wrote:
> Here's a handy utility function for you guys to play with:
>
> http://code.activestate.com/recipes/577676/
Nice.
That's similar to itertools.groupby except that it consolidates all the
equal key results into one list, instead
Raymond Hettinger writes:
> Here's a handy utility function for you guys to play with:
> http://code.activestate.com/recipes/577676/
Cute, but why not use collections.defaultdict for the return dict?
Untested:
d = defaultdict(list)
for key,value in ifilter(bool,imap(mapper, data)):
On Mon, 25 Apr 2011 16:26:37 -0700, Paul Rubin wrote:
> Chris Angelico writes:
>> results = [function() for function in actions]
>
> results = map(apply, actions)
Sadly not in Python 3, where map is lazy and you need to add a call to
list to make it equivalent to the list comp.
--
Steven
-
harrismh777 wrote:
maybe the way
to be really consistent (especially with the Zen of Python, explicit is
better than implicit) that int --> float --> complex (imaginary) should
not occur either !
Applying parts of the Zen selectively can be dangerous.
Practicality also beats purity. I've used
On Mon, 25 Apr 2011 14:17:50 +0100, Passiday wrote:
Hello,
I'd like to experiment with Python, connecting my Linux PC with MIDI
device (standard synthesiser keyboard).
I am pretty new to the Python world, so the questions that crop up, I
assume, could be pretty basic to someone who had spent
Here's a handy utility function for you guys to play with:
http://code.activestate.com/recipes/577676/
Raymond
twitter: @raymondh
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, Apr 25, 2011 at 3:28 PM, Thomas Rachel
wrote:
> Am 25.04.2011 16:29, schrieb Thomas Rachel:
>
>> or maybe even better (taking care for closures):
>>
>> function = bool
>> value = 'the well at the end of the world'
>> ## ...
>> actions.append(lambda val=value: function(val))
>> ## ...
>> fo
Chris Angelico writes:
> results = [function() for function in actions]
results = map(apply, actions)
--
http://mail.python.org/mailman/listinfo/python-list
On 25-4-2011 23:15, rjmccorkle wrote:
> does anyone know a solution to shutting down windows 7 x64 via python
> script? the win32 obviously doesn't work... something similar?
http://goo.gl/5tVPj
(a recipe on activestate, First hit on Google for 'python ctypes shutdown')
Works fine on my win7 x64
On Tue, Apr 26, 2011 at 8:01 AM, John Nagle wrote:
> Don't worry about having MySQL do the CONCAT. That happens
> once during query parsing here, because all the arguments to
> CONCAT are defined in the statement.
>
Good point. Although the abstraction is still a little leaky in that
you can't u
Hey!
Try to use like this: http://sprunge.us/RcYb
change values for understanding code.
Good ideas guys!
---
Jayme Proni Filho
Skype: jaymeproni
Twitter: @jaymeproni
Phone: +55 - 17 - 3631 - 6576
Mobile: +55 - 1
On 4/18/2011 1:44 AM, Tim Golden wrote:
On 18/04/2011 09:29, Tracubik wrote:
Hi all,
i'm reading a python tutorial in Ubuntu's Full Circle Magazine and i've
found this strange use of %s:
sql = "SELECT pkid,name,source,servings FROM Recipes WHERE name like
'%%%s%
%'" %response
response is a str
Look this code! Perhaps, It can help you with login.
http://segfault.in/2010/12/sending-gmail-from-python/
2011/4/25 Chris Angelico
> On Tue, Apr 26, 2011 at 7:38 AM, Jayme Proni Filho
> wrote:
> > I can be wrong but I think you can not login in gmail with urllib because
> I
> > think gmail use
On Tue, Apr 26, 2011 at 7:18 AM, Thomas Rachel
wrote:
> Am 25.04.2011 22:30, schrieb Chris Angelico:
>
>> If you don't care what port you use, you don't need to bind at all.
>> That may be why it's not mentioned - the classic TCP socket server
>> involves bind/listen/accept, and the classic TCP cl
Am 25.04.2011 16:29, schrieb Thomas Rachel:
or maybe even better (taking care for closures):
function = bool
value = 'the well at the end of the world'
## ...
actions.append(lambda val=value: function(val))
## ...
for function in actions:
results.append(function())
Or yet even better:
class
Am 25.04.2011 22:30, schrieb Chris Angelico:
If you don't care what port you use, you don't need to bind at all.
That may be why it's not mentioned - the classic TCP socket server
involves bind/listen/accept, and the classic TCP client has just
connect; bind/connect is a lot less common.
That
Am 25.04.2011 22:14 schrieb Hans Georg Schaathun:
On Tue, 26 Apr 2011 05:49:07 +1000, Chris Angelico
wrote:
: The way you talk of "the" external interface, I'm assuming this
: computer has only one. Is there a reason for not simply binding to
: INADDR_ANY aka 0.0.0.0?
Ah. That's wha
On Tue, Apr 26, 2011 at 7:15 AM, nusrath ahmed wrote:
> I have written a python script that should log me in to a website. For the
> time being I want to login to gmail.com. My script pulls up the gmail
> webpage but does not input the login id and the password in the fields and
> does not log me
On Tue, Apr 26, 2011 at 6:24 AM, Hans Georg Schaathun
wrote:
> Hmmm. socket.INADDR_ANY is an integer and bind insists on a string
> for the hostname (Python 2.6). Is there any use for the integer
> constant? "0.0.0.0" does exactly what I wanted though. Thanks again.
Apologies - I've done mos
does anyone know a solution to shutting down windows 7 x64 via python
script? the win32 obviously doesn't work... something similar?
--
http://mail.python.org/mailman/listinfo/python-list
I have written a python script that should log me in to a website. For the time
being I want to login to gmail.com. My script pulls up the gmail webpage but
does not input the login id and the password in the fields and does not log me
in. I assume I am missing on something in my script. Can so
On Apr 25, 10:09 am, Thomas Rachel wrote:
> Am 25.04.2011 16:41, schrieb rjmccorkle:
>
> > The code is fine but it seems it won't switch baud rates using
> > pyserial. I have to initiate the first msg in 9600 to change the
> > setting of the gps
> > And then send the second command in 115200 beca
On Tue, Apr 26, 2011 at 6:14 AM, Hans Georg Schaathun
wrote:
> : The way you talk of "the" external interface, I'm assuming this
> : computer has only one. Is there a reason for not simply binding to
> : INADDR_ANY aka 0.0.0.0?
>
> Ah. That's what I really wanted. Thanks a lot. I wonder why
On Mon, 25 Apr 2011 21:14:51 +0100, Hans Georg Schaathun
wrote:
: : The way you talk of "the" external interface, I'm assuming this
: : computer has only one. Is there a reason for not simply binding to
: : INADDR_ANY aka 0.0.0.0?
:
: Ah. That's what I really wanted. Thanks a lot. I wond
On Tue, 26 Apr 2011 05:49:07 +1000, Chris Angelico
wrote:
: You can run 'ifconfig' without being root, so there must be a way. At
: very worst, parse ifconfig's output.
Of course, but I am not sure that's simpler than the manual solution.
Especially since there is more than one version of ifc
On Apr 25, 3:49 pm, Chris Angelico wrote:
> On Tue, Apr 26, 2011 at 5:37 AM, Hans Georg Schaathun
> wrote:
>
> > Has anyone found a simple solution that can be administered without
> > root privileges? I mean simpler than passing the ip address
> > manually :-)
>
> You can run 'ifconfig' withou
On Tue, Apr 26, 2011 at 5:37 AM, Hans Georg Schaathun
wrote:
> Has anyone found a simple solution that can be administered without
> root privileges? I mean simpler than passing the ip address
> manually :-)
You can run 'ifconfig' without being root, so there must be a way. At
very worst, parse
Is there a simple way to find the external interface and bind a
socket to it, when the hostname returned by socket.gethostname()
maps to localhost?
What seems to be the standard ubuntu configuration lists the local
hostname with 127.0.0.1 in /etc/hosts. (I checked this on two ubuntu
boxen, on onl
On Fri, 22 Apr 2011 12:19:56 -0700 (PDT), sturlamolden
wrote:
: To optimise computational code, notice that Python itself
: gives you a 200x performance penalty. That is much more
: important than not using all 4 cores on a quadcore processor.
: In this case, start by identifying bottlenecks
On Tue, Apr 26, 2011 at 12:29 AM, Thomas Rachel
wrote:
> for function in actions:
> results.append(function())
Can this become:
results = [function() for function in actions]
Chris Angelico
--
http://mail.python.org/mailman/listinfo/python-list
Westley Martínez wrote:
> On Fri, Apr 22, 2011 at 10:08:20AM -0400, Mel wrote:
[ ... ]
>> But sys.exit() doesn't return a string. My fave is
>>
>> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
>> [GCC 4.4.3] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>
Am 25.04.2011 16:41, schrieb rjmccorkle:
The code is fine but it seems it won't switch baud rates using
pyserial. I have to initiate the first msg in 9600 to change the
setting of the gps
And then send the second command in 115200 because it's in
configuration mode on the unit.
Ok.
> I can s
On 4/25/2011 2:20 AM, harrismh777 wrote:
Steven D'Aprano wrote:
It seems to me that weak typing is a Do What I Mean function, and DWIM is
a notoriously bad anti-pattern that causes far more trouble than it is
worth. I'm even a little suspicious of numeric coercions between integer
and float. (Bu
On Apr 25, 7:06 am, Thomas Rachel wrote:
> Am 25.04.2011 14:46, schrieb rjmccorkle:
>
> > hi - I need to open a serial port in 9600 and send a command followed
> > by closing it, open serial port again and send a second command at
> > 115200. I have both commands working separately from the pytho
Am 12.04.2011 04:58, schrieb rantingrick:
That's sounds good MRAB! After you mentioned this i had an epiphany...
why not just add an extra argument to dict.update?
dict.update(D, clobberexistingkeys=False)
This is AFAICS inconsistent to the possibility to do dict.update(a,
k1=v1, k2=v2).
Am 10.04.2011 18:21, schrieb Mel:
Chris Angelico wrote:
Who would use keyword arguments with a function that takes only one arg
anyway?
It's hard to imagine. Maybe somebody trying to generalize function calls
(trying to interpret some other language using a python program?)
# e.g. input win
On 25-Apr-11 08:30 AM, Ken Seehart wrote:
On 4/25/2011 4:59 AM, Colin J. Williams wrote:
On 24-Apr-11 13:07 PM, Ken Seehart wrote:
On 4/24/2011 2:58 AM, Steven D'Aprano wrote:
Consider this in Python 3.1:
def f(a=42):
... return a
...
f()
42
f.__defaults__ = (23,)
f()
23
Is this an a
Hello,
I'd like to experiment with Python, connecting my Linux PC with MIDI
device (standard synthesiser keyboard).
I am pretty new to the Python world, so the questions that crop up, I
assume, could be pretty basic to someone who had spent some time with
it.
So, here comes:
1) Is everything wha
Am 25.04.2011 14:46, schrieb rjmccorkle:
hi - I need to open a serial port in 9600 and send a command followed
by closing it, open serial port again and send a second command at
115200. I have both commands working separately from the python
command line but it won't work in the script. Any ide
In article
<224f6621-2fc4-4827-8a19-3a12371f3...@l14g2000pre.googlegroups.com>,
rjmccorkle wrote:
> hi - I need to open a serial port in 9600 and send a command followed
> by closing it, open serial port again and send a second command at
> 115200. I have both commands working separately from
hi - I need to open a serial port in 9600 and send a command followed
by closing it, open serial port again and send a second command at
115200. I have both commands working separately from the python
command line but it won't work in the script. Any idea why?
import serial
from time import slee
On 4/25/2011 4:59 AM, Colin J. Williams wrote:
On 24-Apr-11 13:07 PM, Ken Seehart wrote:
On 4/24/2011 2:58 AM, Steven D'Aprano wrote:
Consider this in Python 3.1:
def f(a=42):
... return a
...
f()
42
f.__defaults__ = (23,)
f()
23
Is this an accident of implementation, or can I trust t
On 24-Apr-11 13:07 PM, Ken Seehart wrote:
On 4/24/2011 2:58 AM, Steven D'Aprano wrote:
Consider this in Python 3.1:
def f(a=42):
... return a
...
f()
42
f.__defaults__ = (23,)
f()
23
Is this an accident of implementation, or can I trust that changing
function defaults in this fashion i
On Apr 20, 2:43 pm, Andreas Tawn wrote:
> > Algis Kabaila writes:
>
> > > Are there any modules for vector algebra (three dimensional
> > > vectors, vector addition, subtraction, multiplication [scalar
> > > and vector]. Could you give me a reference to such module?
>
> > NumPy has array (and mat
On Monday 25 April 2011 12:59:38 rusi wrote:
> On Apr 25, 4:49 am, Robert Kern wrote:
> > On 4/22/11 7:32 PM, Algis Kabaila wrote:
> > > On Saturday 23 April 2011 06:57:23 sturlamolden wrote:
> > >> On Apr 20, 9:47 am, Algis Kabaila
> > >
> > > wrote:
> > >>> Are there any modules for vector alge
56 matches
Mail list logo