easy way to return a list of absolute file or directory path within a directory

2016-09-07 Thread iMath
Any easier solutions on returning a list of absolute file or directory path 
within a directory? Mine is  

list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: easy way to return a list of absolute file or directory path within a directory

2016-09-07 Thread Steven D'Aprano
On Wednesday 07 September 2016 17:08, iMath wrote:

> Any easier solutions on returning a list of absolute file or directory path
> within a directory? Mine is
> 
> list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory)))


Use a list comprehension:


[os.path.join(directory,entry) for entry in os.listdir(directory)]



-- 
Steven

git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

-- 
https://mail.python.org/mailman/listinfo/python-list


logging files

2016-09-07 Thread Davala santhosh kumar
how to run psutil.cputimes() program in remote machines using logfiles.
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread Alexander N. Moibenko

Hello,
when I build a binary with python 2.6 it builds without any problem.
When I build with python 2.7 the build fails after warnings like:
/opt/python/Python-2.7.12/Modules/posixmodule.o: In function 
`posix_tempnam':
/opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the use 
of `tempnam' is dangerous, better use `mkstemp'

collect2: ld returned 1 exit status

How this can be fixed?
Thanks,
Alexander
--
https://mail.python.org/mailman/listinfo/python-list


How to split value where is comma ?

2016-09-07 Thread Asad ur Rehman
Here is my view.py

import os.path
import commands

def call_report(request):
 
a = commands.getstatusoutput('/usr/local/freeswitch/bin/fs_cli -x "show 
calls"')
return HttpResponse(a)


When i run this command it gives output which you can see...


0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch
 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 
11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound 
Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,
 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 
11:40:53,1473262853,sofia/external/12036325259,CS_EXECUTE,Outbound 
Call,12036325259,,12036325259,,,ACTIVE,9047125683,9047125683,RECV,75a9d3ee-7511-11e6-a115-89a1f4981d2c,vb-pmedia,
 7841c6c0-7511-11e6-a139-89a1f4981
 d2c,outbound,2016-09-07 
11:40:57,1473262857,sofia/external/16189973135,CS_EXECUTE,Outbound 
Call,16189973135,,16189973135,,,ACTIVE,3473788006,3473788006,RECV,7841c6c0-7511-11e6-a139-89a1f4981d2c,vb-pmedia,
 78582a82-7511-11e6-a141-89a1f4981d2c,outbound,2016-09-07 
11:40:57,1473262857,sofia/external/16185392123,CS_EXECUTE,Outbound 
Call,16185392123,,16185392123,,,ACTIVE,3473788006,3473788006,RECV,78582a82-7511-11e6-a141-89a1f4981d2c,vb-pmedia,
 79eda1ec-7511-11e6-a161-89a1f4981d2c,outbound,2016-09-07 
11:41:00,1473262860,sofia/external/12037584114,CS_EXECUTE,Outbound 
Call,12037584114,,12037584114,,,ACTIVE,3473788006,3473788006,RECV,79eda1ec-7511-11e6-a161-89a1f4981d2c,vb-pmedia,
 7a02bb90-7511-11e6-a169-89a1f4981d2c,outbound,2016-09-07 
11:41:00,1473262860,sofia/external/13346775290,CS_EXECUTE,Outbound 
Call,13346775290,,13346775290,,,ACTIVE,3473788006,3473788006,RECV,7a02bb90-7511-11e6-a169-89a1f4981d2c,vb-pmedia
 , 7a1fa002-7511-11e6-a179-89a1f4981d2c,outbound,2016-09-07 
11:41:00,1473262860,sofia/external/15154483189,CS_EXECUTE,Outbound 
Call,15154483189,,15154483189,,,ACTIVE,3473788006,3473788006,RECV,7a1fa002-7511-11e6-a179-89a1f4981d2c,vb-pmedia,
 7a20d864-7511-11e6-a181-89a1f4981d2c,outbound,2016-09-07 
11:41:00,1473262860,sofia/external/12036325257,CS_EXECUTE,Outbound 
Call,12036325257,,12036325257,,,ACTIVE,9047125683,9047125683,RECV,7a20d864-7511-11e6-a181-89a1f4981d2c,vb-pmedia,
 7a354cf4-7511-11e6-a191-89a1f4981d2c,outbound,2016-09-07 
11:41:00,1473262860,sofia/external/13348725798,CS_EXECUTE,Outbound 
Call,13348725798,,13348725798,,,ACTIVE,9047125683,9047125683,RECV,7a354cf4-7511-11e6-a191-89a1f4981d2c,vb-pmedia,
 7e90e128-7511-11e6-a1d4-89a1f4981d2c,outbound,2016-09-07 
11:41:07,1473262867,sofia/external/13345880337,CS_EXECUTE,Outbound 
Call,13345880337,,13345880337,,,ACTIVE,9047125683,9047125683,RECV,7e90e128-7511-11e6-a1d4-89a1f49
 81d2c,vb-pmedia, 
7e9c3514-7511-11e6-a1e8-89a1f4981d2c,outbound,2016-09-07 
11:41:08,1473262868,sofia/external/12036325256,CS_EXECUTE,Outbound 
Call,12036325256,,12036325256,,,ACTIVE,9047125683,9047125683,RECV,7e9c3514-7511-11e6-a1e8-89a1f4981d2c,vb-pmedia,
 7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,outbound,2016-09-07 
11:41:09,1473262869,sofia/external/13344992844,CS_EXECUTE,Outbound 
Call,13344992844,,13344992844,,,ACTIVE,9047125683,9047125683,RECV,7f3cdc62-7511-11e6-a1ff-89a1f4981d2c,vb-pmedia,
 82179454-7511-11e6-a228-89a1f4981d2c,outbound,2016-09-07 
11:41:13,1473262873,sofia/external/16185392157,CS_EXECUTE,Outbound 


But i want to get output like this


0uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,hostname,sent_callee_name,sent_callee_num,b_uuid,b_direction,b_created,b_created_epoch,b_name,b_state,b_cid_name,b_cid_num,b_ip_addr,b_dest,b_presence_id,b_presence_data,b_callstate,b_callee_name,b_callee_num,b_callee_direction,b_sent_callee_name,b_sent_callee_num,call_created_epoch
 7135c05c-7511-11e6-a09e-89a1f4981d2c,outbound,2016-09-07 
11:40:45,1473262845,sofia/external/12036325207,CS_EXECUTE,Outbound 
Call,12036325207,,12036325207,,,ACTIVE,9047125683,9047125683,RECV,7135c05c-7511-11e6-a09e-89a1f4981d2c,vb-pmedia,
 75a9d3ee-7511-11e6-a115-89a1f4981d2c,outbound,2016-09-07 11:40:53,
1473262853,
sofia/external/1203632525,CS_EXECUTE,
Outbound Call,
12036325259,
,12036325259,
,
,ACTIVE,
9047125683,
9047125683,
RECV,
75a9d3ee-7511-11e6-a115-89a1f4981d2c,
vb-pmedia,7841c6c0-7

RE: [Non-DoD Source] Re: Python 3.5.0 python --version command reports 2.5.4

2016-09-07 Thread Yang, Gang CTR (US)
Thanks to all that replied. Indeed I had CollabNet SVN server installed a while 
back and it came with an older version of Python.



Gang Yang

Shonborn-Becker Systems Inc. (SBSI)
Contractor Engineering Supporting SEC
Office: 732-982-8561, x427

Cell: 732-788-7501
Email: gang.yang@mail.mil


From: Python-list [python-list-bounces+gang.yang.ctr=mail@python.org] on 
behalf of Terry Reedy [tjre...@udel.edu]
Sent: Wednesday, September 07, 2016 12:42 AM
To: python-list@python.org
Subject: [Non-DoD Source] Re: Python 3.5.0 python --version command reports 
2.5.4

All active links contained in this email were disabled.  Please verify the 
identity of the sender, and confirm the authenticity of all links contained 
within the message prior to copying and pasting the address to a Web browser.






On 9/6/2016 4:59 PM, US@f38.n261.z1 wrote:

> I just installed Python 3.5.0 (since 3.5.2 would not installed on Windows 2008
> R2) and tried the python --version command. Surprisingly, the command reported
> 2.5.4. What's going on?

Most likely you have 2.5.4 installed and are running it.

--
Terry Jan Reedy

--
Caution-https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to split value where is comma ?

2016-09-07 Thread Peter Pearson
On Wed, 7 Sep 2016 08:51:36 -0700 (PDT), Asad ur Rehman wrote:
[snip]
> sofia/external/1203632525,CS_EXECUTE,
> Outbound Call,
> 12036325259,
> ,12036325259,
> ,
> ,ACTIVE,
> 9047125683,
> 9047125683,
> RECV,
> 75a9d3ee-7511-11e6-a115-89a1f4981d2c,
> vb-pmedia,7841c6c0-7511-11e6-a139-89a1f4981d2c,
>  outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135,
>
> where is a comma there should start new line ... How can i do it ?

Is your question "Given a string that may contain some commas, how
do I insert a newline after each comma"?   (Note that that is *not*
what you show, but from what you show I can't tell what you want.)

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread Ben Finney
"Alexander N. Moibenko"  writes:

> /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the
> use of `tempnam' is dangerous, better use `mkstemp'
> collect2: ld returned 1 exit status
>
> How this can be fixed?

The clearest answer is already there in the warning message. Replace
your use of ‘tempnam’ with ‘mkstemp’.

If you don't know what that means because you didn't write the code,
then this is for whoever is maintaining that code. Read it, learn what
it does, find (or write) its unit tests to make sue you don't break
anything; then, change that usage as suggested.

-- 
 \“Consider the daffodil. And while you're doing that, I'll be |
  `\  over here, looking through your stuff.” —Jack Handey |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


dictionary total sum

2016-09-07 Thread py

Hello,

any ideas why this does not work?


def add(key, num):

... a[key] += num
...

a={}
a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
a

{'007-12': 22} # OK here, this is what I want

a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
a

{'007-12': None} # why does this became None?

Thanks

--
https://mail.python.org/mailman/listinfo/python-list


Re: dictionary total sum

2016-09-07 Thread Ned Batchelder
On Wednesday, September 7, 2016 at 8:25:42 PM UTC-4, p...@blacktoli.com wrote:
> Hello,
> 
> any ideas why this does not work?
> 
> >>> def add(key, num):
> ... a[key] += num
> ...
> >>> a={}
> >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
> >>> a
> {'007-12': 22} # OK here, this is what I want
> >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
> >>> a
> {'007-12': None} # why does this became None?
> 
> Thanks

Your add() function returns None (because it has no return statements).
Your failing statement is assigning that None to a["007-12"].

There are a number of helpful structures in Python to do this work for
you.  collections.Counter will probably be helpful:

>>> from collections import Counter
>>> a = Counter()
>>> a["007-12"] += 22
>>> a
Counter({'007-12': 22})
>>> a["007-12"] += 22
>>> a
Counter({'007-12': 44})

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does This Scare You?

2016-09-07 Thread Lawrence D’Oliveiro
On Monday, August 22, 2016 at 4:18:39 PM UTC+12, eryk sun wrote:
> It would help to consult a reverse-engineered implementation of
> RtlGetFullPathName_Ustr  and RtlIsDosDeviceName_Ustr. I'll check the
> ReactOS source code.

This 

 might also be useful (found from 
).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Joys Of Data-Driven Programming

2016-09-07 Thread Lawrence D’Oliveiro
On Thursday, August 18, 2016 at 2:36:31 PM UTC+12, I wrote:
> Solution: set up a table of rules ...

Here  is another 
example. The problem is to list all external file dependencies of a Blender 
document, to ensure that they exist etc. Currently, as far as I know, these 
external files might be fonts, images, libraries (additional Blender documents 
containing linked assets) and sounds. The processing for all of these is very 
similar. But within some categories, there are special cases for items which 
need to be ignored. So my loop starts like this:

for \
category, match, mismatch, extra \
in \
(
("fonts", {}, (("filepath" , ""),), ()),
("images", {"type" : "IMAGE"}, (), ("filepath_raw",)),
("libraries", {}, (), ()),
("sounds", {}, (), ()),
) \
:
...

where “match” is a dictionary where each key is an attribute name, and the 
value is the corresponding value that the attribute must have, while “mismatch” 
is a tuple of (key, value) 2-tuples, where each “key” is an attribute name, and 
“value” is a value that attribute must *not* have. The table is designed so 
that I can easily add new categories, and new criteria for each category, as I 
discover them in future.

So, within the above category loop, I loop over all items in the Blender 
document within that category that match the specified criteria:

for item in getattr(bpy.data, category) :
if (
item.packed_file == None
and
not any(getattr(item, k) == v for k, v in mismatch)
and
all(getattr(item, k) == match[k] for k in match)
) :

That additional “item.packed_file == None” check indicates that the object is 
not stored in the .blend file, but resides in an external file. That, at least, 
is a common characteristic of all object categories (so far...).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to run a .py file in IPython?

2016-09-07 Thread Lawrence D’Oliveiro
On Wednesday, August 31, 2016 at 3:22:40 AM UTC+12, umair durrani wrote:
> It seems that the script can't 'see' any files in the Data directory.

Have you tried adding debug statements to the script to
1) print out its default directory, and
2) what items it can see in that directory?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Helloworld with Python C extension

2016-09-07 Thread Lawrence D’Oliveiro
On Tuesday, August 30, 2016 at 6:07:15 PM UTC+12, Ganesh Pal wrote:
> I  was just wondering  how could the C extension   be debugged ?

My usual way of debugging C code is to stick printf statements close to where I 
think the problem areas might be. Write to stderr, not stdout, so you can 
redirect that to a logfile etc without interfering with normal output (if any).
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: dictionary total sum

2016-09-07 Thread Joaquin Alzola
On Wednesday, September 7, 2016 at 8:25:42 PM UTC-4, p...@blacktoli.com wrote:
> Hello,
>
> any ideas why this does not work?
>
> >>> def add(key, num):
> ... a[key] += num
> ...
> >>> a={}
> >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
> >>> a
> {'007-12': 22} # OK here, this is what I want
> >>> a["007-12"] = 22 if not a.has_key("007-12") else add("007-12",22)
> >>> a
> {'007-12': None} # why does this became None?
>
> Thanks

>Your add() function returns None (because it has no return statements).
>Your failing statement is assigning that None to a["007-12"].

>There are a number of helpful structures in Python to do this work for you.  
>collections.Counter will probably be helpful:

>>>> from collections import Counter
>>>> a = Counter()
>>>> a["007-12"] += 22
>>>> a
>Counter({'007-12': 22})
>>>> a["007-12"] += 22
>>>> a
>Counter({'007-12': 44})

Hi Ned

Also:
>>> a={}
>>> a["007-12"]=22
>>> a
{'007-12': 22}
>>> a["007-12"]+=22
>>> a
{'007-12': 44}
>>>

Will this fit his request?
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How to split value where is comma ?

2016-09-07 Thread Joaquin Alzola
> where is a comma there should start new line ... How can i do it ?

Use the split

a.split(",")
for x in a:
print(x)

This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to split value where is comma ?

2016-09-07 Thread D'Arcy J.M. Cain
On Wed, 7 Sep 2016 16:04:40 +
Joaquin Alzola  wrote:
> > where is a comma there should start new line ... How can i do it ?  
> 
> Use the split
> 
> a.split(",")
> for x in a:
> print(x)

Seems overly complex.

print(a.replace(',', '\n'))

> This email is confidential and may be subject to privilege. If you
> are not the intended recipient, please do not copy or disclose its
> content but contact the sender immediately upon receipt.

Do you realize how stupid it is to put this on a message sent all around
the world?

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread dieter
"Alexander N. Moibenko"  writes:
> when I build a binary with python 2.6 it builds without any problem.
> When I build with python 2.7 the build fails after warnings like:
> /opt/python/Python-2.7.12/Modules/posixmodule.o: In function
> `posix_tempnam':
> /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the
> use of `tempnam' is dangerous, better use `mkstemp'
> collect2: ld returned 1 exit status
>
> How this can be fixed?

I doubt that the (compiler) warning is responsible for the (linker) failure.

When I am faced with problems like this (usually during extension building;
I have never encountered a problem during a Python built), I try
to find out what (OS level) commands are executed by the build machinery
and then issue them manually on the command line: the build machinery
often hides error details revealed by executing the commands
directly on the command line.


What I can imagine is that your (OS level installed) C libraries (i.e. "libc"
and friends) no longer contain a "tempnam", letting the linker fail.
Thus, maybe, the compiler still warns about "tempnam" but the linker
already considers it as an error.

-- 
https://mail.python.org/mailman/listinfo/python-list