Hi,
is it possible to append data to or remove data from numpy arrays like
Python lists? I have some code where I currently use lists and often
do things like
a.append(elem)
a += b
del a[:-n]
I am thinking of changing to numpy arrays but it seems I cannot modify
numpy arrays like th
> The file name for the client script is passed by a parameter to a command
> which is repeated by this server in a loop.
Additional explanations can be helpful for the shown software situation.
> It is evaluated then how often a known record set count was sent.
It was actually determined for a
On 15.10.2016 18:16, Steve D'Aprano wrote:
# Python 3 only: use a dict comprehension
py> d = {x:[] for x in (1, 2, 3)}
py> d
{1: [], 2: [], 3: []}
dict (and set) comprehensions got backported so this works just as well
in Python 2.7
Wolfgang
--
https://mail.python.org/mailman/listinfo/pytho
On Sat, 15 Oct 2016 11:35 pm, Uday J wrote:
> Hi,
>
> Here is the code, which I would like to understand.
>
l=['a','b','c']
bm=dict.fromkeys(l,['-1','-1'])
fromkeys() doesn't make a copy of the list each time it is used. It uses the
exact same list each time. Watch:
py> L = []
py> d
On Sun, Oct 16, 2016 at 3:12 AM, Jussi Piitulainen
wrote:
> Chris Angelico writes:
>
>> On Sat, Oct 15, 2016 at 11:35 PM, Uday J wrote:
>> bm=dict.fromkeys(l,['-1','-1'])
>>
>> When you call dict.fromkeys, it uses the same object as the key every
>> time. If you don't want that, try a dict com
Chris Angelico writes:
> On Sat, Oct 15, 2016 at 11:35 PM, Uday J wrote:
> bm=dict.fromkeys(l,['-1','-1'])
>
> When you call dict.fromkeys, it uses the same object as the key every
> time. If you don't want that, try a dict comprehension instead:
s/key/value/
--
https://mail.python.org/mailm
Uday J writes:
> Hi,
>
> Here is the code, which I would like to understand.
>
l=['a','b','c']
bm=dict.fromkeys(l,['-1','-1'])
u={'a':['Q','P']}
bm.update(u)
bm
> {'a': ['Q', 'P'], 'c': ['-1', '-1'], 'b': ['-1', '-1']}
for k in bm.keys():
> bm[k].append('DDD')
>
On Sat, Oct 15, 2016 at 11:35 PM, Uday J wrote:
bm=dict.fromkeys(l,['-1','-1'])
When you call dict.fromkeys, it uses the same object as the key every
time. If you don't want that, try a dict comprehension instead:
bm = {x: ['-1', '-1'] for x in l}
This will construct a new list for every k
Hi,
Here is the code, which I would like to understand.
>>> l=['a','b','c']
>>> bm=dict.fromkeys(l,['-1','-1'])
>>> u={'a':['Q','P']}
>>> bm.update(u)
>>> bm
{'a': ['Q', 'P'], 'c': ['-1', '-1'], 'b': ['-1', '-1']}
>>> for k in bm.keys():
bm[k].append('DDD')
>>> bm
{'a': ['Q', 'P', 'DDD'], 'c': [
> >> Then nested calls like
> >>
> >> a = [].append('x').append('y').append('z')
>
> Sequential appends are nearly always done within a loop.
If not in a loop and you have multiple things already in an
iterable (or create the iterable inline) you can use extend
a= []
a.extend( [ 'x, 'y, 'z' ] )
On 4/22/2012 10:29, Bernd Nawothnig wrote:
[...]
In general I always prefer the pure functional approach. But you are
right, if it is too costly, one has to weigh the pros and contras.
Here's some stupid trick I came up with after reading this thread. It's
of very limited use, of course and I
On Sun, Apr 22, 2012 at 2:29 AM, Bernd Nawothnig
wrote:
>> But what about 2), the mixed (impure) functional design? Unfortunately,
>> it too has a failure mode: by returning a list, it encourages the error
>> of assuming the list is a copy rather than the original:
>>
>> mylist = [1, 2, 3, 4]
>> a
On 2012-04-22, Steven D'Aprano wrote:
> On Sat, 21 Apr 2012 14:48:44 +0200, Bernd Nawothnig wrote:
>
>> On 2012-04-20, Rotwang wrote:
>>> since a method doesn't assign the value it returns to the instance on
>>> which it is called; what it does to the instance and what it returns
>>> are two comple
On Sat, 21 Apr 2012 14:48:44 +0200, Bernd Nawothnig wrote:
> On 2012-04-20, Rotwang wrote:
>> since a method doesn't assign the value it returns to the instance on
>> which it is called; what it does to the instance and what it returns
>> are two completely different things.
>
> Returning a None-
On 2012-04-21, Kiuhnm wrote:
> Sorry if I wasn't clear. I meant that one should either relies on
> side-effects and write something like
>a.append('x').append('t').append('z')
> or use a more functional style and write
>a = a + [x] + [z]
> Mixing the two doesn't seem very elegant to me.
>
On 4/21/2012 18:14, Kiuhnm wrote:
On 4/21/2012 17:41, Bernd Nawothnig wrote:
On 2012-04-21, Kiuhnm wrote:
Returning a None-value is pretty useless. Why not returning self,
which would be
the resulting list in this case? Returning self would make the
language a little bit more functional, withou
On 4/21/2012 17:41, Bernd Nawothnig wrote:
On 2012-04-21, Kiuhnm wrote:
Returning a None-value is pretty useless. Why not returning self, which would be
the resulting list in this case? Returning self would make the
language a little bit more functional, without any drawback.
^
On 4/21/2012 9:08 AM, Dave Angel wrote:
On 04/21/2012 08:48 AM, Bernd Nawothnig wrote:
On 2012-04-20, Rotwang wrote:
since a method doesn't assign the value it returns to the instance on
which it is called; what it does to the instance and what it returns are
two completely different things.
R
On 2012-04-21, Kiuhnm wrote:
>> Returning a None-value is pretty useless. Why not returning self, which
>> would be
>> the resulting list in this case? Returning self would make the
>> language a little bit more functional, without any drawback.
>>
>> Then
On 4/21/2012 14:48, Bernd Nawothnig wrote:
On 2012-04-20, Rotwang wrote:
since a method doesn't assign the value it returns to the instance on
which it is called; what it does to the instance and what it returns are
two completely different things.
Returning a None-value is pretty useless. Why
On 04/21/2012 08:48 AM, Bernd Nawothnig wrote:
> On 2012-04-20, Rotwang wrote:
>> since a method doesn't assign the value it returns to the instance on
>> which it is called; what it does to the instance and what it returns are
>> two completely different things.
> Returning a None-value is prett
On 2012-04-20, Rotwang wrote:
> since a method doesn't assign the value it returns to the instance on
> which it is called; what it does to the instance and what it returns are
> two completely different things.
Returning a None-value is pretty useless. Why not returning self, which would be
the
On Sat, Apr 21, 2012 at 6:17 AM, Rotwang wrote:
> In general there's no reason why
>
a.method(arguments)
print a
>
> will print the same thing as
>
print a.method(arguments)
>
> since a method doesn't assign the value it returns to the instance on which
> it is called; what it does
On 4/20/2012 22:03, Jan Sipke wrote:
Can you explain why there is a difference between the following two
statements?
a = []
a.append(1)
print a
[1]
print [].append(1)
None
Try this one:
a = []
print a.append(1)
Does that answer your question?
Kiuhnm
--
http://mail.python.org/mai
On 20/04/2012 21:03, Jan Sipke wrote:
Can you explain why there is a difference between the following two
statements?
a = []
a.append(1)
print a
[1]
print [].append(1)
None
append is a method of the list object []. Methods, in general, both do
something to the objects of which they are a
On Sat, Apr 21, 2012 at 6:03 AM, Jan Sipke wrote:
> Can you explain why there is a difference between the following two
> statements?
>
a = []
a.append(1)
print a
> [1]
This looks at the list after appending.
print [].append(1)
> None
This looks at the return value of the ap
Can you explain why there is a difference between the following two
statements?
>>> a = []
>>> a.append(1)
>>> print a
[1]
>>> print [].append(1)
None
Best regards,
Jan Sipke
--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to use distutils to install a collection of modules in
/usr/local/lib/python2.7/site-packages. My distribution (Fedora 15)
doesn't include any /usr/local paths in sys.path, so the import fails
when running the program. The distutils documentation suggests adding
a $NAME.pth file to an ex
Thank you! Would never have found that by myself.
"Paul Rubin" wrote in message
news:7x7ha75zib@ruckus.brouhaha.com...
"Alex van der Spek" writes:
refd=dict.fromkeys(csvr.fieldnames,[]) ...
I do not understand why this appends v to every key k each time.
You have initialized every el
On Tue, May 3, 2011 at 12:56 PM, Paul Rubin wrote:
> "Alex van der Spek" writes:
> > refd=dict.fromkeys(csvr.fieldnames,[]) ...
> > I do not understand why this appends v to every key k each time.
>
> You have initialized every element of refd to the same list. Try
>
>refd = dict((k,[]) fo
"Alex van der Spek" writes:
> refd=dict.fromkeys(csvr.fieldnames,[]) ...
> I do not understand why this appends v to every key k each time.
You have initialized every element of refd to the same list. Try
refd = dict((k,[]) for k in csvr.fieldnames)
instead.
--
http://mail.python.org/mai
I open a csv file and create a DictReader object. Subsequently, reading
lines from this file I try to update a dictionary of lists:
csvf=open(os.path.join(root,fcsv),'rb')
csvr=csv.DictReader(csvf)
refd=dict.fromkeys(csvr.fieldnames,[])
for row in csvr:
for (k,v) in row.items():
re
On Wed, 07 Jul 2010 23:55:46 -0700, lavanya wrote:
> Hello all,
>
> How do you append to a file using Python os::file APIs. So that it
> appends to the content of the file. Not adding the content to the new
> line. But just appends next to the exiting content of the file.
>
> Example : current c
Hello all,
How do you append to a file using Python os::file APIs. So that it
appends to the content of the file. Not adding the content to the new
line. But just appends next to the exiting content of the file.
Example : current content of file
A B C
if we append D to it, it should be
A B C D
N
On Tue, Aug 11, 2009 at 8:17 PM, Krishna
Pacifici wrote:
> Nevermind,
> got it.
>
> Sorry.
>
Krishna Pacifici 08/11/09 2:12 PM >>>
> Hi,
> I want to append the values of a dictionary to a list. I have a dictionary
> sec_dict_clean and I want to append the values to a list, but am having a
> h
Nevermind,
got it.
Sorry.
>>> Krishna Pacifici 08/11/09 2:12 PM >>>
Hi,
I want to append the values of a dictionary to a list. I have a dictionary
sec_dict_clean and I want to append the values to a list, but am having a hard
time looping through the values in the dictionary.
I have tried som
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote:
> I have an application where I would like to append to the python path
> dynamically. Below is a test script I wrote. Here's what I thought
> would happen:
>
> 1) I run this script in a folder that is NOT already in PYTHONPATH
> 2
I have an application where I would like to append to the python path
dynamically. Below is a test script I wrote. Here's what I thought
would happen:
1) I run this script in a folder that is NOT already in PYTHONPATH
2) The script creates a subfolder called foo.
3) The script creates a file cal
IM, Y!M erikmaxfrancis
> Many would be cowards if they had courage enough.
> -- Thomas Fuller
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
--
View this message in context:
http://www.nabble.com/appending-*-to-glob-returns-files-with-%27*%27-%21%21-tp19579121p19638699.html
Sent from the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list
John [H2O] wrote:
I have a glob.glob search:
searchstring = os.path.join('path'+'EN*')
files = glob.glob(searchstring)
for f in files:
print f
___
This returns some files:
EN082333
EN092334
EN*
My routine cannot handle the '*' and it should'nt be returned anyway? :-/
A bug?
No, it me
On Sep 20, 6:37 am, "John [H2O]" <[EMAIL PROTECTED]> wrote:
> My routine cannot handle the '*' and it should'nt be returned anyway? :-/
>
> A bug?
Not at all. That's the same behaviour you'll get if you do 'ls EN*'.
In your case, you're asking to match on anything that begins with EN,
a subset of
On Sep 19, 1:37 pm, "John [H2O]" <[EMAIL PROTECTED]> wrote:
> I have a glob.glob search:
>
> searchstring = os.path.join('path'+'EN*')
shouldn't that be os.path.join(path, 'EN*') ?
> ___
> This returns some files:
> EN082333
> EN092334
> EN*
Mine doesn't return that last string.
>
> My routin
A bug?
--
View this message in context:
http://www.nabble.com/appending-*-to-glob-returns-files-with-%27*%27-%21%21-tp19579121p19579121.html
Sent from the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 15, 8:08 am, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 15, 3:30 am, [EMAIL PROTECTED] wrote:
>
> > Hey,
>
> > I started with this:
>
> > factByClass = {}
>
> ...
> > def update(key, *args):
> > x = factByClass.setdefault(key, [[], [], [], [] ])
> > for i, v in enumerate(args):
> >
On Aug 15, 3:30 am, [EMAIL PROTECTED] wrote:
> Hey,
>
> I started with this:
>
> factByClass = {}
>
...
> def update(key, *args):
> x = factByClass.setdefault(key, [[], [], [], [] ])
> for i, v in enumerate(args):
> x[i].append(v)
>
> Is there a better way?
Well, the following is p
Hey,
I started with this:
factByClass = {}
def update(key, x0, x1, x2, x3):
x = factByClass.setdefault(key, [ [], [], [], [] ])
x[0].append(x0)
x[1].append(x1)
x[2].append(x2)
x[3].append(x3)
update('one', 1, 2, 3, 4)
update('one', 5, 6, 7, 8)
update('two', 9, 10, 11, 12)
p
John Purser wrote:
> On Thu, 31 Aug 2006 18:39:45 GMT
> John Salerno <[EMAIL PROTECTED]> wrote:
>
>> John Salerno wrote:
>>> John Purser wrote:
>>>
I'd say you had a record with a null value for the namefirst field.
The join method don't like that.
>>> Wow, you're right! I tried this:
On Thu, 31 Aug 2006 18:39:45 GMT
John Salerno <[EMAIL PROTECTED]> wrote:
> John Salerno wrote:
> > John Purser wrote:
> >
> >> I'd say you had a record with a null value for the namefirst field.
> >> The join method don't like that.
> >
> > Wow, you're right! I tried this:
> >
> > if x[0] and
John Salerno wrote:
> John Purser wrote:
>
>> I'd say you had a record with a null value for the namefirst field.
>> The join method don't like that.
>
> Wow, you're right! I tried this:
>
> if x[0] and not x[0] == 'NULL':
>
> and sure enough it works after that. (Not sure if that's the best
John Purser wrote:
> I'd say you had a record with a null value for the namefirst field.
> The join method don't like that.
Wow, you're right! I tried this:
if x[0] and not x[0] == 'NULL':
and sure enough it works after that. (Not sure if that's the best way to
test, though. Just testing for
On Thu, 31 Aug 2006 18:11:15 GMT
John Salerno <[EMAIL PROTECTED]> wrote:
> Here's the code:
>
> class MyFrame(wx.Frame):
>
> def __init__(self):
> wx.Frame.__init__(self, None, wx.ID_ANY)
> panel = wx.Panel(self)
> dbconn = self.connect_db()
> dbconn.exec
p(*args, **kwargs)
File "C:\Python24\myscripts\bbdata_access\bbdata.py", line 64, in OnInit
frame = MyFrame()
File "C:\Python24\myscripts\bbdata_access\bbdata.py", line 15, in
__init__
name = ' '.join(x)
TypeError: sequence item 0: expected string, Non
Thanks for explaining and all the additional ideas!
R.D.
--
http://mail.python.org/mailman/listinfo/python-list
"DataSmash" wrote:
> I'm confused. Why is it that when I say "while len(list) < 5:", I get
> 5 items in my list.
> If I say "while len(list) < 6:", I get 6 items in the list and so on.
> I would think if I said "less than 5", I would get 4 items.
except that you're saying "as long as there are l
You're wanting it to stop when the len(list) == 4, right? The easiest
way to change the logic would be to say
while len(list) != 4:
but that could get you into trouble later on. The problem with the
len(list) < 5 expression is that the loop will run "one more time" as
long as len(list)
R.D.> I'm confused. Why is it that when I say "while len(list) < 5:", I
R.D.> get 5 items in my list. If I say "while len(list) < 6:", I get 6
R.D.> items in the list and so on. I would think if I said "less than
R.D.> 5", I would get 4 items. Can anyone explain this? Thanks.
DataSmash:
>I'm confused. Why is it that when I say "while len(list) < 5:", I get
>5 items in my list.
Because the last time when len(list) was < 5, the block of code following
the while executed and did something to the list to give it a length >= 5
(otherwise the block of code would be executed
DataSmash wrote:
> I'm confused. Why is it that when I say "while len(list) < 5:", I get
> 5 items in my list.
> If I say "while len(list) < 6:", I get 6 items in the list and so on.
> I would think if I said "less than 5", I would get 4 items.
> Can anyone explain this?
Yes - you loop until the
Em Qui, 2006-03-23 às 08:31 -0800, DataSmash escreveu:
> I'm confused. Why is it that when I say "while len(list) < 5:", I get
> 5 items in my list.
"while len(list) < 5:" implies that the loop will stop only when
len(list) >= 5.
HTH,
--
Felipe.
--
http://mail.python.org/mailman/listinfo/pyt
I'm confused. Why is it that when I say "while len(list) < 5:", I get
5 items in my list.
If I say "while len(list) < 6:", I get 6 items in the list and so on.
I would think if I said "less than 5", I would get 4 items.
Can anyone explain this?
Thanks.
R.D.
# Start an empty list
list = []
while
[Alex Martelli]
> If you want to hoist for performance, you can hoist more:
>
> appenders = foo.append, qux.append
> while some_condition:
> for appender, anitem in zip(appenders, calculate_something()):
> appender(anitem)
You are of course claiming a performance improvement over Car
Xavier Morel <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > Carl Banks <[EMAIL PROTECTED]> wrote:
> >...
> >>> class better_list (list):
> >>> tail = property(None, list.append)
> >> This is an impressive, spiffy little class.
> >
> > Yes, nice use of property.
> >
> > Ale
Alex Martelli wrote:
> Carl Banks <[EMAIL PROTECTED]> wrote:
>...
>>> class better_list (list):
>>> tail = property(None, list.append)
>> This is an impressive, spiffy little class.
>
> Yes, nice use of property.
>
> Alex
I don't know, I usually see people considering that proper
Alex Martelli wrote:
> Carl Banks <[EMAIL PROTECTED]> wrote:
>...
> > > class better_list (list):
> > > tail = property(None, list.append)
> >
> > This is an impressive, spiffy little class.
>
> Yes, nice use of property.
>
> > growing_lists = foo,qux
> > while some_condition:
> >
Carl Banks <[EMAIL PROTECTED]> wrote:
...
> > class better_list (list):
> > tail = property(None, list.append)
>
> This is an impressive, spiffy little class.
Yes, nice use of property.
> growing_lists = foo,qux
> while some_condition:
> for (s,x) in zip(growing_list,calculate
Lonnie Princehouse wrote:
> Here's a curious hack I want to put up for discussion. I'm thinking of
> writing a PEP for it.
A minor library change wouldn' t need a PEP.
> Observation
> -
> I found myself using this construct for assembling multiple lists:
>
> foo = []
> qu
Lonnie Princehouse wrote:
> Here's a curious hack I want to put up for discussion. I'm thinking of
> writing a PEP for it.
>
> Observation
> -
> I found myself using this construct for assembling multiple lists:
>
> foo = []
> qux = []
>
> while some_condition:
>
Here's a curious hack I want to put up for discussion. I'm thinking of
writing a PEP for it.
Observation
-
I found myself using this construct for assembling multiple lists:
foo = []
qux = []
while some_condition:
a, b = calculate_something()
foo.append
68 matches
Mail list logo