On 2020-09-25 7:46 AM, Chris Angelico wrote:
On Fri, Sep 25, 2020 at 3:43 PM Frank Millman wrote:
Hi all
I have a problem related (I think) to list comprehension namespaces. I
don't understand it enough to figure out a solution.
In the debugger, I want to examine the contents of the current
On Fri, Sep 25, 2020 at 3:43 PM Frank Millman wrote:
>
> Hi all
>
> I have a problem related (I think) to list comprehension namespaces. I
> don't understand it enough to figure out a solution.
>
> In the debugger, I want to examine the contents of the current instance,
> so I can type
>
> (P
Nicholas Cole wrote:
[x.id for x in some_function()]
According to the profiler, some_function was being called 52,000 times
Is some_function recursive, by any chance?
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
The length of the list produced by the comprehension also give you good
information.
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, Jul 22, 2019 at 11:33 PM Nicholas Cole wrote:
>
> I was profiling a slow function in an application last week, and came
> across something that I still can’t explain. Inside a loop that was being
> called 4 times, inside a for loop that ran for a few dozen times there was
> a list compress
The function IMHO must be returning a generator. I would look for a problem
in the generator code.
--
https://mail.python.org/mailman/listinfo/python-list
It is impossible to diagnose without seeing more context. Specifically,
you'll need to share the code around this line. The whole function,
preferably.
On Mon, Jul 22, 2019 at 9:31 AM Nicholas Cole
wrote:
> I was profiling a slow function in an application last week, and came
> across something
On 12/30/2016 2:37 PM, Jason Friedman wrote:
Now, this puzzles me:
[x,y for a in data]
File "", line 1
[x,y for a in data]
^
SyntaxError: invalid syntax
I believe that python begins to parse this as
[x, (y for a in data)], a list of 2 items,
except that the required () are
> data = (
>> ... (1,2),
>> ... (3,4),
>> ... )
>>
> [x,y for a in data]
>> File "", line 1
>> [x,y for a in data]
>>^
>> SyntaxError: invalid syntax
>>
>> I expected:
>> [(1, 2), (3, 4)]
>
>
> Why would you expect that? I would expect the global variables x and y, or
> if
On Sat, 31 Dec 2016 06:37 am, Jason Friedman wrote:
> $ python
> Python 3.6.0 (default, Dec 26 2016, 18:23:08)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
data = (
> ... (1,2),
> ... (3,4),
> ... )
[a for a in data]
> [(1, 2), (3, 4)]
>
On Fri, Dec 30, 2016 at 2:58 PM, Joaquin Alzola
wrote:
>
>
>>Now, this puzzles me:
>
> [x,y for a in data]
>> File "", line 1
>>[x,y for a in data]
> > ^
>>SyntaxError: invalid syntax
>
>>I expected:
>>[(1, 2), (3, 4)]
>
> You can try [(x,z) for x,z in data].
> In your situation
>Now, this puzzles me:
[x,y for a in data]
> File "", line 1
>[x,y for a in data]
> ^
>SyntaxError: invalid syntax
>I expected:
>[(1, 2), (3, 4)]
You can try [(x,z) for x,z in data].
In your situation a takes the values (1,2) or (3,4) in the one that I put x and
z take the
On Fri, Dec 30, 2016 at 2:37 PM, Jason Friedman wrote:
> $ python
> Python 3.6.0 (default, Dec 26 2016, 18:23:08)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
data = (
> ... (1,2),
> ... (3,4),
> ... )
[a for a in data]
> [(1, 2), (3, 4)
On Wed, Oct 28, 2015 at 12:36 PM, Zachary Ware
wrote:
> On Wed, Oct 28, 2015 at 11:25 AM, Larry Martell
> wrote:
>> I'm trying to do a list comprehension with an if and that requires an
>> else, but in the else case I do not want anything added to the list.
>>
>> For example, if I do this:
>>
>>
Hi Larry,
On 10/28/2015 10:25 AM, Larry Martell wrote:
> I'm trying to do a list comprehension with an if and that requires an
> else, but in the else case I do not want anything added to the list.
>
> For example, if I do this:
>
> white_list = [l.control_hub.serial_number if l.wblist ==
> wbli
On Wed, Oct 28, 2015 at 11:25 AM, Larry Martell wrote:
> I'm trying to do a list comprehension with an if and that requires an
> else, but in the else case I do not want anything added to the list.
>
> For example, if I do this:
>
> white_list = [l.control_hub.serial_number if l.wblist == wblist_e
KK Sasa writes:
> Hi there,
>
> The list comprehension is results = [d2(t[k]) for k in
> xrange(1000)], where d2 is a function returning a list, say
> [x1,x2,x3,x4] for one example. So "results" is a list consisting of
> 1000 lists, each of length four. Here, what I want to get is the sum
> of 10
On 13/12/2014 03:04, KK Sasa wrote:
Sorry, i should say I'm using pythonxy, maybe it imports other things.
That is good to know but without any context it's rather difficult to
relate it to anything. Some people may have photographic memories and
so remember everything that's been said in a
Sorry, i should say I'm using pythonxy, maybe it imports other things.
--
https://mail.python.org/mailman/listinfo/python-list
On 12 December 2014 at 06:22, KK Sasa wrote:
> Hi there,
>
> The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where
> d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So
> "results" is a list consisting of 1000 lists, each of length four. Here, what
> I
KK Sasa wrote:
> Peter Otten於 2014年12月12日星期五UTC+8下午8時32分55秒寫道:
>> Jussi Piitulainen wrote:
>>
>> > KK Sasa writes:
>> >
>> >> def p(x,t,point,z,obs):
>> >> d = x[0]
>> >> tau = [0]+[x[1:point]]
>> >> a = x[point:len(x)]
>> >> at = sum(i*j for i, j in zip(a, t))
>> >> nu = [ex
Peter Otten於 2014年12月12日星期五UTC+8下午8時32分55秒寫道:
> Jussi Piitulainen wrote:
>
> > KK Sasa writes:
> >
> >> def p(x,t,point,z,obs):
> >> d = x[0]
> >> tau = [0]+[x[1:point]]
> >> a = x[point:len(x)]
> >> at = sum(i*j for i, j in zip(a, t))
> >> nu = [exp(z[k]*(at-d)-sum(tau[k])) f
Jussi Piitulainen於 2014年12月12日星期五UTC+8下午7時12分39秒寫道:
> KK Sasa writes:
>
> > def p(x,t,point,z,obs):
> > d = x[0]
> > tau = [0]+[x[1:point]]
> > a = x[point:len(x)]
> > at = sum(i*j for i, j in zip(a, t))
> > nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)]
> >
Jussi Piitulainen wrote:
> KK Sasa writes:
>
>> def p(x,t,point,z,obs):
>> d = x[0]
>> tau = [0]+[x[1:point]]
>> a = x[point:len(x)]
>> at = sum(i*j for i, j in zip(a, t))
>> nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)]
>> de = sum(nu, axis=0)
>> probabil
KK Sasa writes:
> def p(x,t,point,z,obs):
> d = x[0]
> tau = [0]+[x[1:point]]
> a = x[point:len(x)]
> at = sum(i*j for i, j in zip(a, t))
> nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)]
> de = sum(nu, axis=0)
> probability = [nu[k]/de for k in xrange(p
KK Sasa wrote:
> Hi there,
>
> The list comprehension is results = [d2(t[k]) for k in xrange(1000)],
> where d2 is a function returning a list, say [x1,x2,x3,x4] for one
> example. So "results" is a list consisting of 1000 lists, each of length
> four. Here, what I want to get is the sum of 1000
Peter Otten於 2014年12月12日星期五UTC+8下午5時13分58秒寫道:
> KK Sasa wrote:
>
> > Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道:
> >> On 12/12/2014 06:22, KK Sasa wrote:
> >> > Hi there,
> >> >
> >> > The list comprehension is results = [d2(t[k]) for k in xrange(1000)],
> >> > where d2 is a function returning
KK Sasa wrote:
> Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道:
>> On 12/12/2014 06:22, KK Sasa wrote:
>> > Hi there,
>> >
>> > The list comprehension is results = [d2(t[k]) for k in xrange(1000)],
>> > where d2 is a function returning a list, say [x1,x2,x3,x4] for one
>> > example. So "results"
Am 12.12.14 09:30, schrieb KK Sasa:
Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道:
Hi Mark and Yotam, Thanks for kind reply. I think I didn't make my
problem clear enough. The slow part is "[d2(t[k]) for k in
xrange(1000)]". In addition, I don't need to construct a list of 1000
lists inside, but
Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道:
> On 12/12/2014 06:22, KK Sasa wrote:
> > Hi there,
> >
> > The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where
> > d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So
> > "results" is a list consisting o
On 12/12/2014 06:22, KK Sasa wrote:
Hi there,
The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a
function returning a list, say [x1,x2,x3,x4] for one example. So "results" is a
list consisting of 1000 lists, each of length four. Here, what I want to get is the
On 28/03/13 15:25, Wolfgang Maier wrote:
Dear all, with
a=list(range(1,11))
why (in Python 2.7 and 3.3) is this explicit for loop working:
for i in a[:-1]:
a.pop() and a
giving:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[1
Tim Chase tim.thechases.com> writes:
> it's because you're taking a snapshot copy of "a" in the middle of
> the loop. In your first example, if you change it to
>
> results = []
> for i in a[:-1]:
> results.append(a.pop() and a)
> print results
>
> you get the same thing as your list
Wolfgang Maier wrote:
> Dear all, with
> a=list(range(1,11))
>
> why (in Python 2.7 and 3.3) is this explicit for loop working:
> for i in a[:-1]:
> a.pop() and a
>
> giving:
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
> [1, 2, 3, 4, 5, 6, 7, 8]
> [1, 2, 3, 4, 5, 6, 7]
> [1, 2, 3, 4, 5, 6]
> [1, 2, 3, 4,
On 2013-03-28 15:25, Wolfgang Maier wrote:
> Dear all, with
> a=list(range(1,11))
>
> why (in Python 2.7 and 3.3) is this explicit for loop working:
> for i in a[:-1]:
> a.pop() and a
As you discover:
> Especially, since these two things *do* work as expected:
> [a.pop() and a[:] for i in a[
Wow, lots of things I had never heard of in your posts.
I guess I need to do some homework...
Cantabile
--
http://mail.python.org/mailman/listinfo/python-list
On 12 November 2012 13:23, Joshua Landau wrote:
> Just a few tricks you may have missed:
>
> On 12 November 2012 10:48, Ulrich Eckhardt <
> ulrich.eckha...@dominolaser.com> wrote:
>
>> Am 11.11.2012 23:24, schrieb Cantabile:
>
> if required.intersection(params.**keys()) != required:
>>
>
> i
Just a few tricks you may have missed:
On 12 November 2012 10:48, Ulrich Eckhardt
wrote:
> Am 11.11.2012 23:24, schrieb Cantabile:
if required.intersection(params.**keys()) != required:
>
if required.issubset(params):
>missing = required - set(params.keys())
>
missing = required.
Am 11.11.2012 23:24, schrieb Cantabile:
I'm writing a small mail library for my own use, and at the time I'm
testing parameters like this:
Let's ignore the facts that there is an existing mail library, that you
should use real parameters if they are required and that exit() is
completely inap
On Sun, 11 Nov 2012 18:21:32 -0600, Tim Chase wrote:
> On 11/11/12 17:18, Steven D'Aprano wrote:
>> but that leaves you with the next two problems:
>>
>> 2) Fixing the assert still leaves you with the wrong exception. You
>> wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an
>> IO
On 11/11/12 17:18, Steven D'Aprano wrote:
> but that leaves you with the next two problems:
>
> 2) Fixing the assert still leaves you with the wrong exception. You
> wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an IOError
> would you? No of course not. So why are you suggestin
Thanks everyone for your answers. That's much clearer now.
I see that I was somehow fighting python instead of using it. Lesson
learned (for the time being at least) :)
I'll probably get back with more questions...
Cheers,
Cantabile
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 11 Nov 2012 18:37:05 -0500, Terry Reedy wrote:
> or if you want them to be identified by keyword only (since 7 positional
> args is a bit much)
>
> def __init__(self, smtp, login, *, subject, from, to, msg):
>
> (I forget when this feature was added)
It's a Python 3 feature.
--
Stev
On 11/11/2012 5:56 PM, Ian Kelly wrote:
On Sun, Nov 11, 2012 at 3:24 PM, Cantabile wrote:
I'd like to do something like that instead of the 'for' loop in __init__:
assert[key for key in required if key in params.keys()]
A list evaluates as true if it is not empty. As long as at least one
of
On Sun, 11 Nov 2012 23:24:14 +0100, Cantabile wrote:
> Hi,
> I'm writing a small mail library for my own use, and at the time I'm
> testing parameters like this:
>
> class Mail(object):
> def __init__(self, smtp, login, **params)
> blah
> blah
> required = ['Subjec
> assert[key for key in required if key in params.keys()]
...
> Could you explain why it doesn't work and do you have any idea of how it
> could work ?
Well, here, if any of the items are found, you get a list that is
non-False'ish, so the assert passes.
It sounds like you want all() (available
On Sun, Nov 11, 2012 at 3:24 PM, Cantabile wrote:
> I'd like to do something like that instead of the 'for' loop in __init__:
>
> assert[key for key in required if key in params.keys()]
A list evaluates as true if it is not empty. As long as at least one
of the required parameters is present, th
On 17 October 2012 06:09, Dwight Hutto wrote:
> On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony
> wrote:
>> Is it not true that list comprehension is much faster the the for loops?
>>
>> If it is not the correct way of doing this, i appoligize.
>> Like i said, I'm learing list comprehension.
>>
>
On 10/17/2012 3:13 AM, rusi wrote:
On Oct 17, 10:22 am, Terry Reedy wrote:
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
My response is to the part Kevin could *not* convert, not the parts he
rusi於 2012年10月17日星期三UTC+8下午10時50分11秒寫道:
> On Oct 17, 7:37 pm, Dave Angel wrote:
>
>
>
> > And I'd wager all the improvement is in the inner loop, the dot() function.
>
>
>
> Sorry -- red herring!
>
>
>
> Changing
>
>
>
> def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in
>
On Oct 17, 7:37 pm, Dave Angel wrote:
> And I'd wager all the improvement is in the inner loop, the dot() function.
Sorry -- red herring!
Changing
def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in
zip(*b)] for ra in a]
to
def mm1(a,b): return [[sum([x*y for x,y in zip(ra,rb)])
Dave Angel於 2012年10月17日星期三UTC+8下午10時37分01秒寫道:
> On 10/17/2012 10:06 AM, rusi wrote:
>
> > On Oct 17, 5:33 pm, Dave Angel wrote:
>
> >> On 10/17/2012 12:43 AM, Kevin Anthony wrote:> Is it not true that list
> >> comprehension is much faster the the for loops?
>
> >>
>
> >>> If it is not the co
On 10/17/2012 10:06 AM, rusi wrote:
> On Oct 17, 5:33 pm, Dave Angel wrote:
>> On 10/17/2012 12:43 AM, Kevin Anthony wrote:> Is it not true that list
>> comprehension is much faster the the for loops?
>>
>>> If it is not the correct way of doing this, i appoligize.
>>> Like i said, I'm learing li
On Oct 17, 7:06 pm, rusi wrote:
> On Oct 17, 5:33 pm, Dave Angel wrote:
>
> > On 10/17/2012 12:43 AM, Kevin Anthony wrote:> Is it not true that list
> > comprehension is much faster the the for loops?
>
> > > If it is not the correct way of doing this, i appoligize.
> > > Like i said, I'm learin
On Oct 17, 5:33 pm, Dave Angel wrote:
> On 10/17/2012 12:43 AM, Kevin Anthony wrote:> Is it not true that list
> comprehension is much faster the the for loops?
>
> > If it is not the correct way of doing this, i appoligize.
> > Like i said, I'm learing list comprehension.
> list comprehensions
On 10/17/2012 12:43 AM, Kevin Anthony wrote:
> Is it not true that list comprehension is much faster the the for loops?
>
> If it is not the correct way of doing this, i appoligize.
> Like i said, I'm learing list comprehension.
>
(Please don't top-post; it ruins the ordering. In these forums,
On 17/10/12 09:13:57, rusi wrote:
> On Oct 17, 10:22 am, Terry Reedy wrote:
>> On 10/16/2012 9:54 PM, Kevin Anthony wrote:
>>
>>> I've been teaching myself list comprehension, and i've run across
>>> something i'm not able to convert.
>>
>> list comprehensions specifically abbreviate the code that
On Oct 17, 10:22 am, Terry Reedy wrote:
> On 10/16/2012 9:54 PM, Kevin Anthony wrote:
>
> > I've been teaching myself list comprehension, and i've run across
> > something i'm not able to convert.
>
> list comprehensions specifically abbreviate the code that they are
> (essentially) equivalent to.
On 10/16/2012 9:54 PM, Kevin Anthony wrote:
I've been teaching myself list comprehension, and i've run across
something i'm not able to convert.
list comprehensions specifically abbreviate the code that they are
(essentially) equivalent to.
res = []
for item in source:
res.append(f(item))
On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony
wrote:
> Is it not true that list comprehension is much faster the the for loops?
>
> If it is not the correct way of doing this, i appoligize.
> Like i said, I'm learing list comprehension.
>
I thought it was matrix multiplication mixed with list co
Is it not true that list comprehension is much faster the the for loops?
If it is not the correct way of doing this, i appoligize.
Like i said, I'm learing list comprehension.
Thanks
Kevin
On Oct 16, 2012 10:14 PM, "Dave Angel" wrote:
> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
> > I've been
On Oct 17, 7:14 am, Dave Angel wrote:
> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
>
>
>
>
>
>
>
>
>
> > I've been teaching myself list comprehension, and i've run across something
> > i'm not able to convert.
>
> > here's the original code for matrix multiplcation
>
> > retmatrix = Matrix(self.
On Tue, Oct 16, 2012 at 10:13 PM, Dave Angel wrote:
> On 10/16/2012 09:54 PM, Kevin Anthony wrote:
>> I've been teaching myself list comprehension, and i've run across something
>> i'm not able to convert.
>>
>> here's the original code for matrix multiplcation
>>
>> retmatrix = Matrix(self.__row,
On Tue, Oct 16, 2012 at 10:13 PM, Dwight Hutto wrote:
> On Tue, Oct 16, 2012 at 9:54 PM, Kevin Anthony
> wrote:
>> I've been teaching myself list comprehension, and i've run across something
>> i'm not able to convert.
>>
>> here's the original code for matrix multiplcation
>>
>> retmatrix = Matr
On 10/16/2012 09:54 PM, Kevin Anthony wrote:
> I've been teaching myself list comprehension, and i've run across something
> i'm not able to convert.
>
> here's the original code for matrix multiplcation
>
> retmatrix = Matrix(self.__row,other.__col)
> for m in range(0,retmatrix.__row):
> for n
Thanks, Ian.
That does seem to explain it. The inner loop doesn't have access to the
class's name space, and of course you can't fix it by referencing Foo.y
explicitly, because the class isn't fully defined yet.
Ultimately, we realized that the dict should be created in the __init__
method, so t
On Mar 20, 3:50 pm, Ian Kelly wrote:
> On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber
>
> wrote:
> > On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer"
> > declaimed the following in
> > gmane.comp.python.general:
>
> >> When trying to create a class with a dual-loop generator expression in
On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber
wrote:
> On Tue, 20 Mar 2012 16:23:22 -0400, "J. Cliff Dyer"
> declaimed the following in
> gmane.comp.python.general:
>
>>
>> When trying to create a class with a dual-loop generator expression in a
>> class definition, there is a strange scopin
On 2/29/2012 8:52 AM, Johann Spies wrote:
Please post plain text, the standard for all python.org mailing lists
and corresponding newsgroups, and not html. Some readers print the html
as plain text, which is confusing and obnoxious. Other like mine, do
skip the plain text version and print the
On Wed, Feb 29, 2012 at 5:52 AM, Johann Spies wrote:
> I understand the following:
>
> In [79]: instansie
> instansie
> Out[79]: 'Mangosuthu Technikon'
>
> In [80]: t = [x.alt_name for x in lys]
> t = [x.alt_name for x in lys]
>
> In [81]: t
> t
> Out[81]: []
>
> In [82]: t.append(instansie)
> t.a
In James Broadhead
writes:
> On 29 February 2012 13:52, Johann Spies wrote:
> > In [82]: t.append(instansie)
> > t.append(instansie)
> >
> > In [83]: t
> > t
> > Out[83]: ['Mangosuthu Technikon']
> > In [84]: t = [x.alt_name for x in lys].append(instansie)
> > t = [x.alt_name for x in lys].ap
On 29 February 2012 13:52, Johann Spies wrote:
> In [82]: t.append(instansie)
> t.append(instansie)
>
> In [83]: t
> t
> Out[83]: ['Mangosuthu Technikon']
> In [84]: t = [x.alt_name for x in lys].append(instansie)
> t = [x.alt_name for x in lys].append(instansie)
>
> In [85]: t
> t
>
> In [86]: t
t...@thsu.org writes:
> On Sep 2, 9:54 am, Bart Kastermans wrote:
>> if d(a,b) == 1 and a < b:
>
> It will probably be faster if you reverse the evaluation order of that
> expression.
>
> if a
> That way the d() function is called less than half the time. Of course
> this assumes that a that's tr
On Sep 2, 9:54 am, Bart Kastermans wrote:
> if d(a,b) == 1 and a < b:
It will probably be faster if you reverse the evaluation order of that
expression.
if ahttp://mail.python.org/mailman/listinfo/python-list
MRAB writes:
> On 02/09/2011 01:35, Bart Kastermans wrote:
>> graph = [[a,b] for a in data for b in data if d(a,b) ==1 and a< b]
>> graph2 = []
>> for i in range (0, len(data)):
>> for j in range(0,len(data)):
>> if d(data[i],data[j]) == 1 and i< j:
>> graph2.append
On 02/09/2011 01:35, Bart Kastermans wrote:
In the following code I create the graph with vertices
sgb-words.txt (the file of 5 letter words from the
stanford graphbase), and an edge if two words differ
by one letter. The two methods I wrote seem to me to
likely perform the same computations, t
Neil Cerutti writes:
> On 2011-07-29, Dennis Lee Bieber wrote:
>> Fine... So normpath it first...
>>
> os.path.normpath(r'C:/windows').split(os.sep)
>> ['C:', 'windows']
That apparently doesn't distinguish between r'C:\windows' and
r'C:windows'. On Windows the first is an absolute pat
* Michael Torrie [2011-07-31 03:44]:
> On Jul 29, 2011 6:33 PM, "Michael Poeltl"
> wrote:
> >
> > what about this?
> > >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split()
> > ['home', 'h1122', 'bin', 'ghi']
> > >>>
>
> Doesn't work on filenames with spaces in them.
you are right; me, I ne
On Jul 29, 2011 6:33 PM, "Michael Poeltl"
wrote:
>
> what about this?
> >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split()
> ['home', 'h1122', 'bin', 'ghi']
> >>>
Doesn't work on filenames with spaces in them.
--
http://mail.python.org/mailman/listinfo/python-list
Carl Banks wrote:
> It's not even fullproof on Unix.
>
> '/home//h1122/bin///ghi/'.split('/')
>
> ['','home','','bin','','','ghi','']
What? No. Absolutely not -- that would be a major bug. Did you actually try
it?
>>> '/home//h1122/bin///ghi/'.split('/')
['', 'home', '', 'h1122', 'bin', '', '
* Alexander Kapps [2011-07-29 22:30]:
> On 29.07.2011 21:30, Carl Banks wrote:
>
>> It's not even fullproof on Unix.
>>
>> '/home//h1122/bin///ghi/'.split('/')
>>
>> ['','home','','bin','','','ghi','']
what about this?
>>> ' '.join('/
On 29.07.2011 21:30, Carl Banks wrote:
It's not even fullproof on Unix.
'/home//h1122/bin///ghi/'.split('/')
['','home','','bin','','','ghi','']
The whole point of the os.path functions are to take care of whatever oddities
there are in the path system. When you use string manipulation to m
On Thursday, July 28, 2011 2:31:43 PM UTC-7, Ian wrote:
> On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille wrote:
> > On 7/28/2011 1:18 PM gry said...
> >>
> >> [python 2.7] I have a (linux) pathname that I'd like to split
> >> completely into a list of components, e.g.:
> >> '/home/gyoung/ha
Alan Meyer wrote:
> This is not properly portable to all OS, but you could simply split on
> the slash character, e.g.,
>
> pathname.split('/')
more portable pathname.split(os.sep)
--
http://mail.python.org/mailman/listinfo/python-list
On 2011-07-29, Dennis Lee Bieber wrote:
> On Thu, 28 Jul 2011 15:31:43 -0600, Ian Kelly
> declaimed the following in
> gmane.comp.python.general:
>
>> Using os.sep doesn't make it cross-platform. On Windows:
>>
>> >>> os.path.split(r'C:\windows')
>> ('C:\\', 'windows')
>> >>> os.path.split(r'C:/
On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille wrote:
> On 7/28/2011 1:18 PM gry said...
>>
>> [python 2.7] I have a (linux) pathname that I'd like to split
>> completely into a list of components, e.g.:
>> '/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
>> 'hacks', 'pathhack
On 7/28/2011 1:18 PM gry said...
[python 2.7] I have a (linux) pathname that I'd like to split
completely into a list of components, e.g.:
'/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
'hacks', 'pathhack', 'foo.py']
os.path.split gives me a tuple of dirname,basename, but the
On 28.07.2011 22:44, Ian Kelly wrote:
On Thu, Jul 28, 2011 at 2:18 PM, gry wrote:
[python 2.7] I have a (linux) pathname that I'd like to split
completely into a list of components, e.g.:
'/home/gyoung/hacks/pathhack/foo.py' -->['home', 'gyoung',
'hacks', 'pathhack', 'foo.py']
os.path.
On Thu, Jul 28, 2011 at 2:47 PM, Ian Kelly wrote:
> On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly wrote:
>> path = '/home/gyoung/hacks/pathhack/foo.py'
>> parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))]
>> parts.reverse()
>> print parts
>>
>> But that's horrendously ugl
Neil Cerutti wrote:
If an elegant solution doesn't occur to me right away, then I
first compose the most obvious solution I can think of. Finally,
I refactor it until elegance is either achieved or imagined.
+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly wrote:
> path = '/home/gyoung/hacks/pathhack/foo.py'
> parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))]
> parts.reverse()
> print parts
>
> But that's horrendously ugly. Just write a generator with a while
> loop or something
On 7/28/2011 4:18 PM, gry wrote:
[python 2.7] I have a (linux) pathname that I'd like to split
completely into a list of components, e.g.:
'/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
'hacks', 'pathhack', 'foo.py']
os.path.split gives me a tuple of dirname,basename, but the
On Thu, Jul 28, 2011 at 2:18 PM, gry wrote:
> [python 2.7] I have a (linux) pathname that I'd like to split
> completely into a list of components, e.g.:
> '/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
> 'hacks', 'pathhack', 'foo.py']
>
> os.path.split gives me a tuple of dirname
On 2011-07-28, gry wrote:
> [python 2.7] I have a (linux) pathname that I'd like to split
> completely into a list of components, e.g.:
>'/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
> 'hacks', 'pathhack', 'foo.py']
>
> os.path.split gives me a tuple of dirname,basename, but th
Hi,
[python 2.7] I have a (linux) pathname that I'd like to split
completely into a list of components, e.g.:
'/home/gyoung/hacks/pathhack/foo.py' --> ['home', 'gyoung',
'hacks', 'pathhack', 'foo.py']
Not sure what your exact requirements are, but the following seems to work:
pathname
On Wed, Apr 20, 2011 at 12:03 PM, Chris Angelico wrote:
> On Thu, Apr 21, 2011 at 12:44 AM, Ian Kelly wrote:
>> So, the question for the OP: Is this file being run with execfile?
>>
>
> Not execfile per se; the code is fetched from the database and then
> executed with:
>
> PyObject *v=PyRun_Str
On Thu, Apr 21, 2011 at 12:44 AM, Ian Kelly wrote:
> So, the question for the OP: Is this file being run with execfile?
>
Not execfile per se; the code is fetched from the database and then
executed with:
PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0);
Is Py_file_input t
On Wed, Apr 20, 2011 at 4:41 AM, Peter Otten <__pete...@web.de> wrote:
> The assignment writes to the local namespace, the lambda function reads from
> the global namespace; this will only work as expected if the two namespaces
> are the same:
>
exec """type = 42; print filter(lambda x: x == t
Chris Angelico wrote:
> On Wed, Apr 20, 2011 at 5:16 PM, Tim Roberts wrote:
>> You can solve this through the common lamba idiom of a closure:
>>
>> lst=filter(lambda x,posttype=posttype: x["type"].lower()==posttype,lst)
>
> Seems a little odd, but sure. I guess this means that a function's
> def
On Wed, Apr 20, 2011 at 8:16 PM, Steven D'Aprano
wrote:
> There's your problem. IDEs often play silly buggers with the environment
> in order to be "clever". You've probably found a bug in whatever IDE
> you're using.
>
> And this is why I won't touch the buggers with a 30 ft pole, at least not
>
1 - 100 of 297 matches
Mail list logo