Re: Python : writing to a file

2015-01-11 Thread Dave Angel
You accidentally did a Reply instead of a Reply-List.  So the email came 
to me and not to the list.  if your mail program doesn't support 
reply-list, do a reply-all and remove the personal addresses.  The list 
is what's important here.


On 01/11/2015 12:20 AM, Ganesh Pal wrote:

On Sat, Jan 10, 2015 at 9:07 PM, Dave Angel  wrote:





I did execute the program multiple times, It appeared that it was not
working because I was trying to view the contents of the file using
cat commad and cat didn't display the data.

case (a) output with cat:

node- 1# file test_2.txt
test_2.txt: ASCII text, with no line terminators

node-1# cat test_2.txt



You chopped off the output there.  It probably looked like this:


node-1# cat test_2.txt
Sundaynode-1#


Your output is there, right before the prompt.  Since you neglected the 
newline in your code, that's what you'd expect, wouldn't you?


Incidentally, in most systems that prompt would mean you're running as 
root.  Bad idea, especially when you're learning to program.


--
DaveA

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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Steven D'Aprano
Ethan Furman wrote:

> On 01/10/2015 06:32 PM, Steven D'Aprano wrote:
>> 
>> If you treat your readers as idiots, only idiots will read your writing.
> 
> Or the morbidly curious, which I presume covers your case (along with a
> handful of others ;) .


Reading Rick is like taking bad drugs. Every time I've had it in the past,
it was a bad trip. I know that this time it's going to be a bad trip. And
yet I just can't help myself.

If that isn't a form of stupidity, I don't know what is.



-- 
Steven

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


Re: Help running python tests on MIPS

2015-01-11 Thread Steven D'Aprano
Ramesh wrote:

> I am new to python.
> 
> I downloaded python 2.7.8 tarball, successfully cross compiled it, to make
> sure that the subsystems are correctly built, I tried running the python
> test scripts on the MIPS based target board. I hit the below error while I
> do so,
[...]
> I tried setting PATH & PYTHONPATH, but it doesn't seem to fix the issue.

Tried setting them to what?


> Can someone please advice on what possibly is causing this problem / how
> to fix this?

Try running these commands from the operating system's shell, and report on
the output:


ls -ld /opt/Python-2.7.8/lib/python2.7/lib-dynload/

ls -l /opt/Python-2.7.8/lib/python2.7/lib-dynload/*coll*

python -c "import collections; print collections.__file__"



That will help diagnose the problem.



-- 
Steven

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


Re: Help running python tests on MIPS

2015-01-11 Thread Steven D'Aprano
Ramesh wrote:

> I am new to python.
> 
> I downloaded python 2.7.8 tarball, successfully cross compiled it, to make
> sure that the subsystems are correctly built, I tried running the python
> test scripts on the MIPS based target board. I hit the below error while I
> do so,


On second thoughts, how are you doing this? If I'm reading the next line
correctly:

> # /opt/Python-2.7.8/bin/python2.7
> /opt/Python-2.7.8/lib/python2.7/test/test___all__.py

you haven't installed Python, you've just compiled it and are now trying to
run the test suite manually.

If you read the README file, you should see instructions that tell you to
run the following commands:

./configure
make
make test
sudo make install


I recommend following those instructions if you can.


-- 
Steven

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


Re: Python : writing to a file

2015-01-11 Thread Ganesh Pal
On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel  wrote:
>
>
> You chopped off the output there.  It probably looked like this:
>
>
> node-1# cat test_2.txt
> Sundaynode-1#
>
>
> Your output is there, right before the prompt.  Since you neglected the
> newline in your code, that's what you'd expect, wouldn't you?
>
> Incidentally, in most systems that prompt would mean you're running as root.
> Bad idea, especially when you're learning to program.
>

I didn't get the output before the prompt ,I actually didn't chop off
the output . below is the complete flow.

# cat get_day.py
#!/usr/bin/python

import time
f = open ('test_a.txt','wb+')
DAY = time.strftime("%A")
f.write(DAY)
f.close()
Throttling-1# python get_day.py


node-1# cat test_a.txt   // This didn't give any result

node-1# less test_a.txt //  I can see the text here
Sunday
test_a.txt (END)



Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python : writing to a file

2015-01-11 Thread Peter Otten
Ganesh Pal wrote:

> On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel  wrote:
>>
>>
>> You chopped off the output there.  It probably looked like this:
>>
>>
>> node-1# cat test_2.txt
>> Sundaynode-1#
>>
>>
>> Your output is there, right before the prompt.  Since you neglected the
>> newline in your code, that's what you'd expect, wouldn't you?
>>
>> Incidentally, in most systems that prompt would mean you're running as
>> root. Bad idea, especially when you're learning to program.
>>
> 
> I didn't get the output before the prompt ,I actually didn't chop off
> the output . below is the complete flow.
> 
> # cat get_day.py
> #!/usr/bin/python
> 
> import time
> f = open ('test_a.txt','wb+')
> DAY = time.strftime("%A")
> f.write(DAY)
> f.close()
> Throttling-1# python get_day.py
> 
> 
> node-1# cat test_a.txt   // This didn't give any result
> 
> node-1# less test_a.txt //  I can see the text here
> Sunday
> test_a.txt (END)

What does

$ echo $PS1

print? If there's a \r (carriage return) you should change it to avoid this 
confusion.

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


Few coding suggestions

2015-01-11 Thread Ganesh Pal
Hello Team,

Iam trying to generate a file which would will should the contents in
the below format

# cat  /root/schedule.conf

Sunday 10:20 10:30
Sunday 10:30 10:40
Sunday 10:50  10:60


I have to build the above format on the local linux machine using
python 2.7 version and then copy the file to the remote machine.

Here is the progress and few questions on the same ,

Program :

node-1# cat time_range.py
def yield_times():
from datetime import date, time, datetime, timedelta
start = datetime.combine(date.today(), time(23, 50))
yield start.strftime("%A %H:%M")
while True:
start += timedelta(minutes=10)
yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(05):
 print gen.next()

node-1# python time_range.py
Sunday 23:50
Monday 00:00
Monday 00:10
Monday 00:20
Monday 00:30

(a)  How do I modify the output to have an another column with a
difference of 5 mins

Example :

node-1# python time_range.py

Sunday 23:50 23:05
Monday 00:00 00:05
Monday 00:10 00:05
Monday 00:20 00:15
Monday 00:30 00: 20

(b)  how to copy the above output (i.e with the new column to a file.)


(c)  The  final output should be a file , having the entries  day ,
start , end time of the remote file. how do  i pass the  this to
yeild-times()

import time

/* Assuming I retrive the below values h,m,d from the remote machine*/

h = time.strftime("%H")
m = time.strftime("%M")
d = date.today()


def yield_times():
  global h,m,d
from datetime import date, time, datetime, timedelta
start = datetime.combine(date.today(), time(int(h),int(m))) /*
converting string to int)
yield start.strftime("%A %H:%M")
while True:
start += timedelta(minutes=10)
yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(15):
 print gen.next()


Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Few Coding suggestions - resending

2015-01-11 Thread Ganesh Pal
Hello Team,

Iam trying to generate a file which should have the  contents in the
below format

# cat  /root/schedule.conf

Sunday 10:20 10:30
Sunday 10:30 10:40
Sunday 10:50  10:60


I have to build the above format on the local linux machine using
python 2.7 version and then copy the file to the remote machine.

Here is the progress and few questions on the same ,

Program :

node-1# cat time_range.py
def yield_times():
from datetime import date, time, datetime, timedelta
start = datetime.combine(date.today(), time(23, 50))
yield start.strftime("%A %H:%M")
while True:
start += timedelta(minutes=10)
yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(05):
 print gen.next()

node-1# python time_range.py
Sunday 23:50
Monday 00:00
Monday 00:10
Monday 00:20
Monday 00:30

(a)  How do I modify the output to have an another column with a
difference of 5 mins

Example :

node-1# python time_range.py

Sunday 23:50 23:05
Monday 00:00 00:05
Monday 00:10 00:05
Monday 00:20 00:15
Monday 00:30 00: 20

(b)  how to copy the above output (i.e with the new column to a file.)


(c)  The  final output should be a file , having the entries  day ,
start , end time of the remote file. how do  i pass the  this to
yeild-times()

import time

/* Assuming I retrive the below values h,m,d from the remote machine*/

h = time.strftime("%H")
m = time.strftime("%M")
d = date.today()


def yield_times():
  global h,m,d
from datetime import date, time, datetime, timedelta
start = datetime.combine(date.today(), time(int(h),int(m))) /*
converting string to int)
yield start.strftime("%A %H:%M")
while True:
start += timedelta(minutes=10)
yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(15):
 print gen.next()


Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: python-ldap 2.4.19

2015-01-11 Thread Michael Ströder
Find a new release of python-ldap:

  http://pypi.python.org/pypi/python-ldap/2.4.19

python-ldap provides an object-oriented API to access LDAP directory
servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for
that purpose. Additionally it contains modules for other LDAP-related
stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema).

Project's web site:

  http://www.python-ldap.org/

Ciao, Michael.


Released 2.4.19 2015-01-10

Changes since 2.4.18:

Lib/
* Fixed missing ReconnectLDAPObject._reconnect_lock when pickling
  (see SF#64, thanks to Dan O'Reilly)
* Added ldap.controls.pagedresults which is pure Python implementation of
  Simple Paged Results Control (see RFC 2696) and delivers the correct
  result size

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


DICOM to jpg

2015-01-11 Thread Abdul Abdul
Hello,

Is there a way to convert a DICOM file to an image using Python?

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


VipIMAGE 2015 - ANNOUNCEMENT & CALL FOR CONTRIBUTIONS

2015-01-11 Thread tava...@fe.up.pt
Dear Colleague,

We are pleased to announce the International Conference VipIMAGE 2015 - V 
ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE 
PROCESSING (www.fe.up.pt/~vipimage) to be held October 19-21, 2015, in H10 
Costa Adeje Palace, Costa Adeje, Tenerife, Spain.

Possible Topics (not limited to)
- Signal and Image Processing
- Computational Vision
- Medical Imaging
- Physics of Medical Imaging
- Tracking and Analysis of Movement
- Simulation and Modeling
- Image Acquisition
- Industrial Applications
- Shape Reconstruction
- Segmentation, Matching, Simulation
- Data Interpolation, Registration, Acquisition and Compression
- 3D Vision
- Virtual Reality
- Visual Inspection
- Software Development for Image Processing and Analysis
- Computer Aided Diagnosis, Surgery, Therapy, and Treatment
- Computational Bioimaging and Visualization
- Telemedicine Systems and Applications

Invited Lecturers
- Alexandre Xavier Falcão, Universidade de Campinas, Brazil
- Cristian A. Linte, Mayo Clinic, USA
- Da-Chuan Cheng, China Medical University, Taiwan
- Fiorella Sgallari, University of Bologna, Italy
- Yongjie Zhang, Carnegie Mellon University, USA
- Xue-cheng Tai, University of Bergen, Norway

Thematic Sessions
Proposals to organize Thematic Sessions under the auspicious of VipIMAGE 2015 
are welcome.
Proposals for Thematic Sessions should be submitted by email to the conference 
co-chairs (tava...@fe.up.pt, rna...@fe.up.pt).

Publications
Proceedings: The proceedings book will be published by the Taylor & Francis 
Group and indexed by Thomson Reuters Conference Proceedings Citation Index, IET 
Inspect and Elsevier Scopus.
Springer Book: A book with 20 invited works from the ones presented in the 
conference will be published by Springer under the book series "Lecture Notes 
in Computational Vision and Biomechanics".
Journal Publication: A dedicated special issue of the Taylor & Francis 
International Journal "Computer Methods in Biomechanics and Biomedical 
Engineering: Imaging & Visualization" will be published with extended versions 
of the best works presented in the conference.

Important Dates
- Deadline for Thematic Session Proposals: February 28, 2015
- Deadline for Extended Abstracts: March 15, 2015
- Authors Notification: April 15, 2015
- Deadline for Papers: June 15, 2015
 

We are looking forward to see you in Tenerife next October,
João Manuel R. S. Tavares
Renato Natal Jorge
(VipIMAGE 2015 co-chairs)


For further details, please, have a look in the conference website at: 
www.fe.up.pt/~vipimage, the Facebook page at: 
www.facebook.com/pages/Vipimage/237980719665456, or join the LinkedIn group at: 
http://www.linkedin.com/groups?gid=4752820&trk=hb_side_g.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Rustom Mody
On Sunday, January 11, 2015 at 10:56:11 AM UTC+5:30, Devin Jeanpierre wrote:
> On Sat, Jan 10, 2015 at 6:32 PM, Steven D'Aprano wrote:
> > At the point you are demonstrating reduce(), if the reader doesn't
> > understand or can't guess the meaning of "n = 4", "n+1" or range(), they
> > won't understand anything you say.
> >
> > Teachers need to understand that education is a process of building upon
> > that which has come before. If the teacher talks down to the student by
> > assuming that the student knows nothing, and tries to go back to first
> > principles for every little thing, they will never get anywhere.
> 
> Agree wholeheartedly. That said, I do think reduce(operator.mul, [1,
> 2, 3, 4]) actually _is_ a better example, since it cuts right to the
> point.

In keeping with Rick's super-polite suggestion to remove
irreleventia like range and variables(!), if we are about to
improve that doc, I would remove the
1,2,3,4
pattern as well and replace with something more random.

The mathematically minded student may think that this has something
to do with arithmetic progressions,
that it does clever algebraic simplifications like
𝚺 i = n(n+1)/2

A favorite example of mine is automata-acceptance:
If 
δ : Q × Σ → Q is a transition function
F is the set of final states
q₀ is the start state
and s is a string

then
reduce(δ,q₀,s) ∈ F
expresses "automaton accepts string s"

Should that go into the doc??
I'll leave that to somebody else whose name starts with 'R' :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Few Coding suggestions - resending

2015-01-11 Thread Dave Angel

On 01/11/2015 06:47 AM, Ganesh Pal wrote:

Hello Team,

Iam trying to generate a file which should have the  contents in the
below format

# cat  /root/schedule.conf

Sunday 10:20 10:30
Sunday 10:30 10:40
Sunday 10:50  10:60


I have to build the above format on the local linux machine using
python 2.7 version and then copy the file to the remote machine.

Here is the progress and few questions on the same ,

Program :

node-1# cat time_range.py
def yield_times():
 from datetime import date, time, datetime, timedelta
 start = datetime.combine(date.today(), time(23, 50))
 yield start.strftime("%A %H:%M")
 while True:
 start += timedelta(minutes=10)
 yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(05):
  print gen.next()

node-1# python time_range.py
Sunday 23:50
Monday 00:00
Monday 00:10
Monday 00:20
Monday 00:30

(a)  How do I modify the output to have an another column with a
difference of 5 mins

Example :

node-1# python time_range.py

Sunday 23:50 23:05
Monday 00:00 00:05
Monday 00:10 00:05
Monday 00:20 00:15
Monday 00:30 00: 20


No idea how that represents "a difference of 5 minutes".  So I'll take a 
totally wild guess that you meant:


Sunday 23:50 23:55
Monday 00:00 00:05
Monday 00:10 00:15
Monday 00:20 00:25
Monday 00:30 00:35

which would have the 2nd column 5 minutes after the first.

You need another datetime object, let's call it 'end'

end = start + timedelta(minutes=5)

and now you want to yield three things, in a tuple:

yield (start.strftime("%A"), start.strftime("%H:%M"),
   end.strftime("%H:%M"))

Of course that's a pain to do twice, as you have two yields in that 
function.  I'll leave you to reorder the loop to make that unnecessary. 
 Hint, do the yield first, THEN increment the start variable.


and in the other loop, you want
res = "{} {} {}\n".format(gen.next)
print res,



(b)  how to copy the above output (i.e with the new column to a file.)



Instead of printing, just do f.write(res).  Or do both. Notice that to 
make this easy, i avoided doing any formatting in the print statement. 
I used a trailing comma on it to avoid print adding a newline, and 
instead put it explicitly in the format method call.




(c)  The  final output should be a file , having the entries  day ,
start , end time of the remote file. how do  i pass the  this to
yeild-times()

import time

/* Assuming I retrive the below values h,m,d from the remote machine*/

h = time.strftime("%H")
m = time.strftime("%M")
d = date.today()



Those first two are strings, but the third is a datetime object.  That 
last can be painful to pass between machines.




def yield_times():
   global h,m,d


No idea what that's all about.  If you want to pass arguments to 
yield_times(), put them inside the parens.



 from datetime import date, time, datetime, timedelta
 start = datetime.combine(date.today(), time(int(h),int(m))) /*
converting string to int)


Got some C code in there?  Use # for comments.

You don't seem to be honoring the 'd' value from the other machine.


 yield start.strftime("%A %H:%M")
 while True:
 start += timedelta(minutes=10)
 yield start.strftime("%A %H:%M")
gen = yield_times()
for ii in range(15):
  print gen.next()


Regards,
Ganesh




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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Dan Sommers
On Sun, 11 Jan 2015 06:20:34 -0800, Rustom Mody wrote:


> A favorite example of mine is automata-acceptance:
> If 
> δ : Q × Σ → Q is a transition function
> F is the set of final states
> q₀ is the start state
> and s is a string
> 
> then
> reduce(δ,q₀,s) ∈ F
> expresses "automaton accepts string s"
> 
> Should that go into the doc??

Absolutely.  :-)  If the docs had explained that reduce is
actually a finite state machine framework, then I wouldn't
have written my such framework.

> I'll leave that to somebody else whose name starts with 'R' :-)

Uh, oh.  Sorry.

-- 
Dan Sommers, neither of which begins with an 'R'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Grant Edwards
On 2015-01-10, Chris Angelico  wrote:
> On Sun, Jan 11, 2015 at 5:05 AM, Rick Johnson
> wrote:
>> 
>> EXAMPLE 1: "Reducing Comprehension" 
>> https://docs.python.org/2/howto/doanddont.html#using-the-batteries
>> 
>
> 1) Why are you focusing on the /2/ docs, rather than /3/?
> 2) Why are you ranting, rather than submitting docs patches?

3) There are still people who read RR posts?

-- 
Grant



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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Chris Angelico
On Mon, Jan 12, 2015 at 3:04 AM, Grant Edwards  wrote:
> On 2015-01-10, Chris Angelico  wrote:
>> 1) Why are you focusing on the /2/ docs, rather than /3/?
>> 2) Why are you ranting, rather than submitting docs patches?
>
> 3) There are still people who read RR posts?

Yeah, there are. Steven summarized it thus, although I can't
personally speak to the accuracy of the specifics:

On Sun, Jan 11, 2015 at 8:31 PM, Steven D'Aprano
 wrote:
> Reading Rick is like taking bad drugs. Every time I've had it in the past,
> it was a bad trip. I know that this time it's going to be a bad trip. And
> yet I just can't help myself.
>
> If that isn't a form of stupidity, I don't know what is.

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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Michael Torrie
On 01/11/2015 09:04 AM, Grant Edwards wrote:
> 3) There are still people who read RR posts?

The last post by RR helping someone with a tk problem was very helpful,
and rather elucidating, as are most of his post on tk.  It was rather
refreshing to see several posts like this.  I thought perhaps this would
signify a new era.  But alas, no, he's slipped back into his lazy ways.
 Too bad really. He seems to be a smart person.  He could contribute to
Python in positive ways if he chose (like patching the documentation, or
contributing code).  Unfortunately when he gets like this he can't even
get up the energy to open bug reports.  Easier to just rant on the list
apparently.  Now perhaps there are two RRs, in some sort of conflict in
the same person.  Sad to see this one winning out.

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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Chris Angelico
On Mon, Jan 12, 2015 at 4:11 AM, Michael Torrie  wrote:
> The last post by RR helping someone with a tk problem was very helpful,
> and rather elucidating, as are most of his post on tk.  ...
> Now perhaps there are two RRs, in some sort of conflict in
> the same person.  Sad to see this one winning out.

Doubtful. Even when he's answering tkinter questions (and is imparting
useful information), he still has the same abrasive style. It reflects
badly on Python that the help is provided in such a way, but unless
there's someone else with as much expertise as Rick has, that's not
going to change. (Either that, or we just all start recommending PyQT
or GTK or something.)

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


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Rustom Mody
On Sunday, January 11, 2015 at 10:49:11 PM UTC+5:30, Chris Angelico wrote:
> On Mon, Jan 12, 2015 at 4:11 AM, Michael Torrie  wrote:
> > The last post by RR helping someone with a tk problem was very helpful,
> > and rather elucidating, as are most of his post on tk.  ...
> > Now perhaps there are two RRs, in some sort of conflict in
> > the same person.  Sad to see this one winning out.
> 
> Doubtful. Even when he's answering tkinter questions (and is imparting
> useful information), he still has the same abrasive style. It reflects
> badly on Python that the help is provided in such a way, but unless
> there's someone else with as much expertise as Rick has, that's not
> going to change. (Either that, or we just all start recommending PyQT
> or GTK or something.)

You can always tell the unwitting new questioner that Rick's 
content is useful [when it is] whereas his style is ignorable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Few coding suggestions

2015-01-11 Thread Denis McMahon
On Sun, 11 Jan 2015 17:14:35 +0530, Ganesh Pal wrote:

> (a)  How do I modify the output to have an another column with a
> difference of 5 mins

I'm not sure I understand the problem you're trying to solve, and it 
seems to me that you are presenting your problem in terms of your partial 
solution.

Try stating the actual problem.

Some hints, based on my best guess of what you're actually trying to do.

If you want a program to execute every n minutes, the easiest way to do 
this is normally to use the cron scheduler to start your program every n 
minutes.

If you want to append the output of a program to an existing file, open 
the file in append mode.

You normally add lines to a file, not columns.

You my want to investigate various ways of serialising data inside a 
file, eg csv, json etc. Also things like date and time formats if this is 
some sort of log file.

It would however be much easier to help you with your problem if you 
stated the problem you're trying to solve, eg "I wish to create a 
snapshot of process memory and cpu use every 5 minutes and send it to 
another server."

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread Mark Lawrence

On 11/01/2015 16:04, Grant Edwards wrote:

On 2015-01-10, Chris Angelico  wrote:

On Sun, Jan 11, 2015 at 5:05 AM, Rick Johnson
 wrote:


EXAMPLE 1: "Reducing Comprehension" 
https://docs.python.org/2/howto/doanddont.html#using-the-batteries



1) Why are you focusing on the /2/ docs, rather than /3/?
2) Why are you ranting, rather than submitting docs patches?


3) There are still people who read RR posts?



Admittedly this was a bad one but his contributions to tkinter/IDLE are 
useful.  Contrast that to our former Resident Unicode Expert or our 
Greek Web Design Expert.  Then years ago there was Xah Lee telling us 
how to write docs, it was so funny the way he was torn to shreds.  As 
for Ilias Lazaridu what can I say, except that I beat all when having a 
day that starts with me getting out of bed on the wrong side, and worse 
later on when my hair do gets ruined!!! :)


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Using a ChangeLog as a canonical source of package metadata (was: Announce: PyPrimes 0.2.1a)

2015-01-11 Thread Steven D'Aprano
Ben Finney wrote:
[...]
> The perils of duplicate sources of information: a Changelog makes claims
> about which version is latest, but the packaging metadata comes from
> somewhere else.
> 
> This problem is addressed quite well, in my opinion, by the Debian
> packaging tools. The tools by default read the following information:
> 
> * release version string
> * maintainer name
> * maintainer email address
> * target suite (a conceptual “which Debian version should this go into”)
> 
> from the Changelog document, automatically. This means that the
> Changelog document, as well as being directly useful to the recipient as
> a text document, becomes the canonical place to record all those fields
> for the packaging tools to read. No need to maintain duplicate records.

A very interesting way to handle this, and one which deserves further
configuration.

I currently read this metadata from the Python code itself. The advantages
of putting the metadata into the source code include:

- the source code is the definitive source of information about itself;
- even if the user deletes the README and CHANGELOG files, they can 
  still find the metadata;
- if your application wants to report a version number (as many apps 
  do) then it is easy for them to do so.


But the disadvantages include:

- it's a bit sad to have to put such metadata into the source code;
- the risk of the changelog getting out of date.


> I would like Python's packaging tools to have the same capability.
> 
> This requires recording the Changelog document in a machine-parseable
> format, with specified locations for each of the fields to be read for
> each version.

I wonder whether it would be better to have setup.py check the CHANGELOG and
halt if it isn't up to date? 



> I have recently gone through a process of converting the Changelog for a
> package I maintain (‘python-daemon’) to reStructuredText [0]. This has
> all the above features: machine-parseable, a well-defined way to attach
> fields to a section, etc.
> 
> [0] reStructuredText: http://docutils.sourceforge.net/rst.html>
> 
> I've now produced a small Python library which knows how to transform a
> reST Changelog to package metadata; and how to get that package metadata
> into and out of a Python distribution with Distutils.

Sounds interesting. Where can we see this?

> The result is that I will never again upload the package with a mismatch
> between what the Changelog claims is the latest version, and what the
> package metadata says.
> 
> 
> This may be generally useful to others. I'm interested to know how
> people would expect to use this. As an extension to Distutils? As a
> third-party library? Something else?

Offering it as a third-party library is a good start, but perhaps you could
discuss this on the packaging mailing list and see whether they have any
interest in it?

https://mail.python.org/mailman/listinfo/distutils-sig/


-- 
Steven

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


Re: Help running python tests on MIPS

2015-01-11 Thread rramesh1
On Sunday, January 11, 2015 at 1:45:33 AM UTC-8, Steven D'Aprano wrote:
> Ramesh wrote:
> 
> > I am new to python.
> > 
> > I downloaded python 2.7.8 tarball, successfully cross compiled it, to make
> > sure that the subsystems are correctly built, I tried running the python
> > test scripts on the MIPS based target board. I hit the below error while I
> > do so,
> 
> 
> On second thoughts, how are you doing this? If I'm reading the next line
> correctly:
> 
> > # /opt/Python-2.7.8/bin/python2.7
> > /opt/Python-2.7.8/lib/python2.7/test/test___all__.py
> 
> you haven't installed Python, you've just compiled it and are now trying to
> run the test suite manually.
> 
> If you read the README file, you should see instructions that tell you to
> run the following commands:
> 
> ./configure
> make
> make test
> sudo make install
> 
> 
> I recommend following those instructions if you can.
> 
> 
> -- 
> Steven

Thank you for the response.

I did see the README, here is what I am doing

configure
#Make hostpython & hostpgen
make python
make test
mv python hostpython 
mv Parser/hostpgen hostpgen
# Do a distclean before cross compiling
make distclean

# Configure with cross toolchain options
# gcc, g++, ar & ranlib for MIPS
# prefix pointing to /usr/lib on the target file system (MIPS)
configure 
#Build python for MIPS
make
make install

Actually I hit a problem in install (I got it worked around by doing -i (ignore 
errors), but later found the issue & fixed by a patch, after which - there were 
no errors in make install as well).

After the install, I am removing (rm -rf) certain files that I think are of no 
use as the target has limited flash space. 

==
   /bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/lib2to3
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/email
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/bsddb
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/xml
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/pydoc_data
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/lib-tk
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/sqlite3
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/idlelib
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/share
/bin/rm -rf 
${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/config/libpython2.7.a
/bin/rm -rf ${PYTHON_ROOTFS_DEPLOY_DIR}/lib/python2.7/test/audiodata

==

I set the PYTHONPATH point to /opt/Python-2.7.8/lib/python2.7

Still hit the same error. Am I missing something else?

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


]beginer] what i need to code simple graphics?

2015-01-11 Thread fir
what i need to code simple graphic in python?
Im totally new in python, though im moderately experienced in c

2d perpixel graphic probably, or other kind of graphic too
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help running python tests on MIPS

2015-01-11 Thread rramesh1
On Sunday, January 11, 2015 at 1:39:20 AM UTC-8, Steven D'Aprano wrote:
> Ramesh wrote:
> 
> > I am new to python.
> > 
> > I downloaded python 2.7.8 tarball, successfully cross compiled it, to make
> > sure that the subsystems are correctly built, I tried running the python
> > test scripts on the MIPS based target board. I hit the below error while I
> > do so,
> [...]
> > I tried setting PATH & PYTHONPATH, but it doesn't seem to fix the issue.
> 
> Tried setting them to what?
> 
> 
> > Can someone please advice on what possibly is causing this problem / how
> > to fix this?
> 
> Try running these commands from the operating system's shell, and report on
> the output:
> 
> 
> ls -ld /opt/Python-2.7.8/lib/python2.7/lib-dynload/
> 
> ls -l /opt/Python-2.7.8/lib/python2.7/lib-dynload/*coll*
> 
> python -c "import collections; print collections.__file__"
> 
> 
> 
> That will help diagnose the problem.
> 
> 
> 
> -- 
> Steven

For the above commands, here is the output 

# ls -ld /opt/Python-2.7.8/lib/python2.7/lib-dynload/ 
drwxr-xr-x2 root root  681 Jan 10  2015 
/opt/Python-2.7.8/lib/python2.7/lib-dynload/
# ls -l /opt/Python-2.7.8/lib/python2.7/lib-dynload/*coll*
ls: /opt/Python-2.7.8/lib/python2.7/lib-dynload/*coll*: No such file or 
directory
# /opt/Python-2.7.8/bin/python2.7 -c "import collections; print collections.__fi
le__" 
Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/Python-2.7.8/lib/python2.7/collections.py", line 8, in 
from _collections import deque, defaultdict
ImportError: No module named _collections
# 

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


extracting numbers with decimal places from a string

2015-01-11 Thread Store Makhzan
I have this script which can calculate the total of numbers given in a string
 script -
total = 0
for c in '0123456789':
   total += int(c)
print total
 script -

How should I modify this script to find the total of if the numbers given in 
the string form have decimal places? That is, how do I need to modify this line:
- script -
for c in '1.32, 5.32, 4.4, 3.78':
- script -
to find the total of these given numbers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-11 Thread semeon . risom
On Saturday, 10 January 2015 21:31:25 UTC-6, Denis McMahon  wrote:
> On Fri, 09 Jan 2015 09:49:25 -0800, semeon.risom wrote:
> 
> > Thank you for the help btw. I think I'm close to a solution, but I'm
> > having issue feeding the coordinates from my csv file into the formula.
> > 
> > This is the error I get:
> > Traceback (most recent call last):
> >   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
> >   corr.py", line 68, in 
> > makeimg(length, orientation)
> >   File "C:\Users\Owner\Desktop\Stimuli Generation\Coordinates\Generate_w
> >   corr.py", line 40, in makeimg
> > orientation = orientation % 180
> > TypeError: unsupported operand type(s) for %: 'list' and 'int'
>  
>  
> > and here's the code:
> > 
> > from PIL import Image, ImageDraw from numpy import math
> > 
> > # import csv import csv f = open('C:\Users\Owner\DesktopStimuli
> > Generation\Coordinates\file.csv', 'rb')
> > rdr = csv.reader(f)
> > f.seek(0)
> > i = 0 a = []
> > b = []
> > for row in rdr:
> > a.append(row[0]) 
> > b.append(row[1])
> 
> This makes a and b both lists
> 
> Having read some other errors that you are having, you need to make sure 
> that these items are numeric and not string data
> 
> for row in rdr:
> a.append(int(row[0]))
> b.append(int(row[1]))
> 
> > # using lists of values for length in [a]:
> > for orientation in [b]:
> > makeimg(length, orientation)
> 
> This puts list a inside another list, and puts list b inside another 
> list, and then passes the whole of lists a and b in the first call to 
> makeimg.
> 
> makeimg expects 2 integer parameters on each call, not two lists!
> 
> As you have already created lists, you don't need to wrap them inside 
> another list.
> 
> # using lists of values 
> for length in a:
> for orientation in b:
> makeimg(length, orientation)
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

The code is working correctly. Thank you! The only change I had to make was 
referring to it as a float instead of an integer. 

The images are generating, however I'm noticing that it's making an image for 
every possible pair in each list (i.e. Image 1: a1 and b1; Image 2: a1 and b2; 
Image 3: a1 and b3) instead of an image for each row (e.g. Image 1: a1 and 
b1; Image 2: a2 and b2; Image 3: a3 and b3...).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-11 Thread Denis McMahon
On Sun, 11 Jan 2015 11:41:28 -0800, semeon.risom wrote:

> The code is working correctly. Thank you! The only change I had to make
> was referring to it as a float instead of an integer.
> 
> The images are generating, however I'm noticing that it's making an
> image for every possible pair in each list (i.e. Image 1: a1 and b1;
> Image 2: a1 and b2; Image 3: a1 and b3) instead of an image for each
> row (e.g. Image 1: a1 and b1; Image 2: a2 and b2; Image 3: a3 and
> b3...).

Try these changes:

# before the csv reader, declare a single list
params = []

# in the csv reader, append each pair of params to the list as
# a tuple

for row in rdr:
params.append( ( int(row[0]), int(row[1]) ) )


# use the lists of tuples to generate one image per tuple

for item in params:
makeimg(item[0], item[1])

#

You could also skip the list generation entirely.

After the main function definition:

f = open(filename, 'r')
rdr = csv.reader(f)
for row in rdr:
makeimg(int(row[0]), int(row[1]))

Also please note that you only need to quote the bits of the post that 
you are replying to to give context, not the whole post.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan  wrote:
> I have this script which can calculate the total of numbers given in a string
>  script -
> total = 0
> for c in '0123456789':
>total += int(c)
> print total
>  script -
>
> How should I modify this script to find the total of if the numbers given in 
> the string form have decimal places? That is, how do I need to modify this 
> line:
> - script -
> for c in '1.32, 5.32, 4.4, 3.78':
> - script -
> to find the total of these given numbers.
> --
> https://mail.python.org/mailman/listinfo/python-list

split the string on ',' to get a list of strings.  loop thru list
using float(s), add float values


-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generate jpg files using line length (pixels) and orientation (degrees)

2015-01-11 Thread Dave Angel

On 01/11/2015 02:41 PM, semeon.ri...@gmail.com wrote:

On Saturday, 10 January 2015 21:31:25 UTC-6, Denis McMahon  wrote:



# using lists of values
for length in a:
 for orientation in b:
 makeimg(length, orientation)

--
Denis McMahon, denismfmcma...@gmail.com


The code is working correctly. Thank you! The only change I had to make was 
referring to it as a float instead of an integer.

The images are generating, however I'm noticing that it's making an image for 
every possible pair in each list (i.e. Image 1: a1 and b1; Image 2: a1 and b2; 
Image 3: a1 and b3) instead of an image for each row (e.g. Image 1: a1 and 
b1; Image 2: a2 and b2; Image 3: a3 and b3...).



The minimum change for that would be to zip the lists together:

for length, orientation in zip(a,b):
makeimg(length, orientation)


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


Re: Using a ChangeLog as a canonical source of package metadata

2015-01-11 Thread Ben Finney
Steven D'Aprano  writes:

> I currently read this metadata from the Python code itself. The
> advantages of putting the metadata into the source code include:
>
> - the source code is the definitive source of information about itself;

The Changelog document should be in the same source tree and maintained
by the same people, so I don't count that as a difference between the
two approaches.

> - even if the user deletes the README and CHANGELOG files, they can 
>   still find the metadata;

Perhaps I didn't emphasise it, but: The approach I'm advocating (as
inspired by Debian packaging tools) has the version metadata
*canonically* recorded in the Changelog, but not *only* stored there.

The packaging tools parse the version metadata from the Changelog, then
duplicate whatever metadata is needed in various other places — such as
for programmatic access by the package's own code.

> - if your application wants to report a version number (as many apps 
>   do) then it is easy for them to do so.

The idea is to parse from the Changelog the version metadata, and record
it in Setuptools metadata. Then the ‘pkg_resources’ module of Setuptools
allows programmatic access to that metadata.

Thanks for enumerating those points, I think they are adequately
addressed by this approach.


> > I've now produced a small Python library which knows how to
> > transform a reST Changelog to package metadata; and how to get that
> > package metadata into and out of a Python distribution with
> > Distutils.
>
> Sounds interesting. Where can we see this?

It is the approach used in ‘python-daemon’ version 2. Find the source at
https://alioth.debian.org/projects/python-daemon/>. The
‘ChangeLog’, ‘setup.py’, ‘version.py’, ‘daemon/_metadata.py’ files are
the relevant ones to examine.

Since this is a new approach I'm trying, I flubbed a couple of versions:
you'll need version 2.0.1 or later (I omitted the ‘version’ module
entirely from the earlier distribution), and you'll need ‘docutils’
already installed (a future ‘python-daemon’ distribution will declare
this dependency).

I'll be interested to see how Python developers like this.

-- 
 \  “The process by which banks create money is so simple that the |
  `\ mind is repelled.” —John Kenneth Galbraith, _Money: Whence It |
_o__)   Came, Where It Went_, 1975 |
Ben Finney

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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Store Makhzan
On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote:
> On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote:
> > I have this script which can calculate the total of numbers given in a 
> > string
> >  script -
> > total = 0
> > for c in '0123456789':
> >total += int(c)
> > print total
> >  script -
> >
> > How should I modify this script to find the total of if the numbers given 
> > in the string form have decimal places? That is, how do I need to modify 
> > this line:
> > - script -
> > for c in '1.32, 5.32, 4.4, 3.78':
> > - script -
> > to find the total of these given numbers.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> split the string on ',' to get a list of strings.  loop thru list
> using float(s), add float values
> 
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com

Thank you
Here is what I did:

- script -
#Check if a perfect cube
total = 0
for c in ('1.23', '2.4', '3.123'):
   print float(c)
   total += float(c)
print total
- script -

Which gave me the result I wanted.
Since I am new to Python, I used () as a guess, and it worked.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: DICOM to jpg

2015-01-11 Thread Dan Stromberg
On Sun, Jan 11, 2015 at 5:01 AM, Abdul Abdul  wrote:
> Hello,
>
> Is there a way to convert a DICOM file to an image using Python?
>
> Thanks.

Does GDCM do what you need?

http://gdcm.sourceforge.net/wiki/index.php/Main_Page
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 3:26 PM, Store Makhzan  wrote:
> On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote:
>> On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote:
>> > I have this script which can calculate the total of numbers given in a 
>> > string
>> >  script -
>> > total = 0
>> > for c in '0123456789':
>> >total += int(c)
>> > print total
>> >  script -
>> >
>> > How should I modify this script to find the total of if the numbers given 
>> > in the string form have decimal places? That is, how do I need to modify 
>> > this line:
>> > - script -
>> > for c in '1.32, 5.32, 4.4, 3.78':
>> > - script -
>> > to find the total of these given numbers.
>> > --
>> > https://mail.python.org/mailman/listinfo/python-list
>>
>> split the string on ',' to get a list of strings.  loop thru list
>> using float(s), add float values
>>
>>
>> --
>> Joel Goldstick
>> http://joelgoldstick.com
>
> Thank you
> Here is what I did:
>
> - script -
> #Check if a perfect cube
> total = 0
> for c in ('1.23', '2.4', '3.123'):
>print float(c)
>total += float(c)
> print total
> - script -
>
> Which gave me the result I wanted.
> Since I am new to Python, I used () as a guess, and it worked.

That's fine, but its different than your original question.  In your
original question you had a string of floats separated by commas.  To
solve that problem you need to first split the string on the commas:

my_list = "1.23, 2.4, 3.123".split(",")

that will give you ['1.23', '2.4', '3.123']

>From there do what you did starting with your for loop



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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


MS-DOS Commands

2015-01-11 Thread Jenacee Owens
I'm new to python and every time i type a command into the MS-DOS Commands it 
looks like this.

>>>strings

Traceback";line 1 in 
name error:name strings'is not defined

how can i fix this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote:

> my_list = "1.23, 2.4, 3.123".split(",")
> 
> that will give you ['1.23', '2.4', '3.123']

No, it gives

| $ python
| Python 2.7.9 (default, Dec 11 2014, 08:58:12) 
| [GCC 4.9.2] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> my_list = "1.23, 2.4, 3.123".split(",")
| >>> my_list
| ['1.23', ' 2.4', ' 3.123']
| >>>

| $ python3
| Python 3.4.2 (default, Dec 27 2014, 13:16:08) 
| [GCC 4.9.2] on linux
| Type "help", "copyright", "credits" or "license" for more information.
| >>> my_list = "1.23, 2.4, 3.123".split(",")
| >>> my_list
| ['1.23', ' 2.4', ' 3.123']
| >>> 

In order to get the result you described, one needs at least

| >>> '1.23, 2.4, 3.123'.split(', ')
| ['1.23', '2.4', '3.123']

This is safer:

| >>> from re import split
| >>> split(r'\s*,\s*', '1.23, 2.4, 3.123')
| ['1.23', '2.4', '3.123']

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MS-DOS Commands

2015-01-11 Thread Ian Kelly
On Sun, Jan 11, 2015 at 3:13 PM, Jenacee Owens  wrote:
> I'm new to python and every time i type a command into the MS-DOS Commands it 
> looks like this.
>
strings
>
> Tracebackfile "";line 1 in 
> name error:name strings'is not defined

That error is from the Python interpreter, not MS-DOS (by which I
assume you mean the Windows command prompt; nobody seriously uses
MS-DOS any more).

> how can i fix this?

That depends on what it is you're trying to do. If you're actually
trying to run some program called 'strings' from the command prompt
then you'll need to exit the Python interpreter first (or open a
second command prompt window).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MS-DOS Commands

2015-01-11 Thread Gary Herron

On 01/11/2015 02:13 PM, Jenacee Owens wrote:

I'm new to python and every time i type a command into the MS-DOS Commands it 
looks like this.


strings

Traceback";line 1 in 
name error:name strings'is not defined

how can i fix this?


What where you trying to accomplish, and what did you expect that to 
do?  It's not a valid Python statement, so an error message that says as 
much is to be expected.


You really should start with a Python tutorial.

More comments:

 * You did not type that "into the MS-DOS Commands", but rather to
   Python (or more accurately, to the Python interpreter).
 * Python does not have "commands", but rather "statements".
 * There is a module named strings, and you could import it (to use
   Python's terminology) with the "import strings" statement, but
   there's probably not much need to do so.  But then the "strings"
   statement you typed would not produce an error message, but would
   just print out a line informing you that strings is a module -- not
   very useful.
 * Rather than using Python in an MS-DOS window, you should consider
   trying statements and programs in Idle -- A reasonable GUI
   environment to experiment with Python.  It came with your
   installation of Python.
 * In the future, questions should be accompanied with information
   about your version of Python (Python2 or Python3) and the platform
   you are running it on. (Apparently Windows in your case.)

Gary Herron





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


Re: MS-DOS Commands

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 5:13 PM, Jenacee Owens  wrote:
> I'm new to python and every time i type a command into the MS-DOS Commands it 
> looks like this.
>
strings
>
> Tracebackfile "";line 1 in 
> name error:name strings'is not defined
>
> how can i fix this?

Nothing to do with DOS, there is no strings

Try this:
>>>my_string = "hi there"
>>>print my_string
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 5:20 PM, Thomas 'PointedEars' Lahn
 wrote:
> Joel Goldstick wrote:
>
>> my_list = "1.23, 2.4, 3.123".split(",")
>>
>> that will give you ['1.23', '2.4', '3.123']
>
> No, it gives
>
> | $ python
> | Python 2.7.9 (default, Dec 11 2014, 08:58:12)
> | [GCC 4.9.2] on linux2
> | Type "help", "copyright", "credits" or "license" for more information.
> | >>> my_list = "1.23, 2.4, 3.123".split(",")
> | >>> my_list
> | ['1.23', ' 2.4', ' 3.123']
> | >>>
>
> | $ python3
> | Python 3.4.2 (default, Dec 27 2014, 13:16:08)
> | [GCC 4.9.2] on linux
> | Type "help", "copyright", "credits" or "license" for more information.
> | >>> my_list = "1.23, 2.4, 3.123".split(",")
> | >>> my_list
> | ['1.23', ' 2.4', ' 3.123']
> | >>>
>
> In order to get the result you described, one needs at least
>
> | >>> '1.23, 2.4, 3.123'.split(', ')
> | ['1.23', '2.4', '3.123']
>
> This is safer:
>
> | >>> from re import split
> | >>> split(r'\s*,\s*', '1.23, 2.4, 3.123')
> | ['1.23', '2.4', '3.123']
>

I'm not sure what you are trying to point out as your examples confirm
my code.  Am I missing something.

As for feeding a beginner regex solutions, I'm on the side that this
is a terrible idea.  Regex is not something a beginner should worry
about!
> --
> PointedEars
>
> Twitter: @PointedEars2
> Please do not cc me. / Bitte keine Kopien per E-Mail.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Store Makhzan wrote:

> I have this script which can calculate the total of numbers given in a
> string […]
> total = 0
> for c in '0123456789':
>total += int(c)
> print total
> 
> […]
> How should I modify this script to find the total of if the numbers given
> in the string form have decimal places? That is, how do I need to modify
> this line: […]
> 
> for c in '1.32, 5.32, 4.4, 3.78':
> 
> […] to find the total of these given numbers.

The original script already does not do what it advertises.  Instead, it 
iterates over the characters of the string, attempts to convert each to an 
integer and then computes the sum.  That is _not_ “calculate the total of 
numbers given in a string”.

A solution has been presented, but it is not very pythonic because the 
original code was not; that should have been

### Ahh, Gauß ;-)
print(sum(map(lambda x: int(x), list('0123456789'
### 

Also, it cannot handle non-numeric strings well.  Consider this instead:

### 
from re import findall

s = '1.32, 5.32, 4.4, 3.78'
print(sum(map(lambda x: float(x), findall(r'-?\d+\.\d+', s
### 

But if you are sure that except for the comma separator there are only 
numeric strings, it is more efficient to use re.split() instead of 
re.findall() here.


Aside:

I thought I had more than a fair grasp of regular expressions, but I am 
puzzled by

| $ python3
| Python 3.4.2 (default, Dec 27 2014, 13:16:08) 
| [GCC 4.9.2] on linux
| >>> from re import findall
| >>> s = '1.32, 5.32, 4.4, 3.78'
| >>> findall(r'-?\d+(\.\d+)?', s)
| ['.32', '.32', '.4', '.78']

Why does this more flexible pattern not work as I expected in Python 3.x, 
but virtually everywhere else?

And why this?

| >>> findall(r'-?\d+\.\d+', s)
| ['1.32', '5.32', '4.4', '3.78']
| >>> findall(r'-?\d+(\.\d+)', s)
| ['.32', '.32', '.4', '.78']

Feature?  Bug?

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Grant Edwards
On 2015-01-11, Joel Goldstick  wrote:

> That's fine, but its different than your original question.  In your
> original question you had a string of floats separated by commas.  To
> solve that problem you need to first split the string on the commas:
>
> my_list = "1.23, 2.4, 3.123".split(",")
>
> that will give you ['1.23', '2.4', '3.123']

Well, almost:

$ python
Python 2.7.9 (default, Jan 11 2015, 15:39:24) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "1.23, 2.4, 3.123".split(",")
['1.23', ' 2.4', ' 3.123']

Note the leating whitespace in two of the elements. In this case, the
leading whitespace is ignored if you pass the values to float():

>>>map(float,"1.23, 2.4, 3.123".split(","))
[1.23, 2.4, 3.123]

Or for you young folks who prefer the more long-winded version:

>>> [float(s) for s in "1.23, 2.4, 3.123".split(",")]
[1.23, 2.4, 3.123]

In other situations, the leading whitespace might matter.

-- 
Grant



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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Joel Goldstick wrote:
>>> my_list = "1.23, 2.4, 3.123".split(",")
>>>
>>> that will give you ['1.23', '2.4', '3.123']
>>
>> No, it gives
>>
>> […]
>> | >>> my_list = "1.23, 2.4, 3.123".split(",")
>> | >>> my_list
>> | ['1.23', ' 2.4', ' 3.123']
   ^   ^
>> | >>>
>>
>> In order to get the result you described, one needs at least
>>
>> | >>> '1.23, 2.4, 3.123'.split(', ')
>> | ['1.23', '2.4', '3.123']
>>
>> […]
> 
> I'm not sure what you are trying to point out as your examples confirm
> my code.

No, they don't.

> Am I missing something.
^
(Is that a question.)

You are missing a leading space character because in the string the comma 
was followed by one.

> As for feeding a beginner regex solutions, I'm on the side that this
> is a terrible idea.  Regex is not something a beginner should worry
> about!

NAK.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Joel Goldstick
On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
 wrote:
> Joel Goldstick wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Joel Goldstick wrote:
 my_list = "1.23, 2.4, 3.123".split(",")

 that will give you ['1.23', '2.4', '3.123']
>>>
>>> No, it gives
>>>
>>> […]
>>> | >>> my_list = "1.23, 2.4, 3.123".split(",")
>>> | >>> my_list
>>> | ['1.23', ' 2.4', ' 3.123']
>^   ^
>>> | >>>
>>>
>>> In order to get the result you described, one needs at least
>>>
>>> | >>> '1.23, 2.4, 3.123'.split(', ')
>>> | ['1.23', '2.4', '3.123']
>>>
>>> […]
>>
>> I'm not sure what you are trying to point out as your examples confirm
>> my code.
>
> No, they don't.
>
>> Am I missing something.
> ^
> (Is that a question.)
>
> You are missing a leading space character because in the string the comma
> was followed by one.

I see that now.  Performing float on each element of the list will
take care of that, or I guess .strip() on each first.
>
>> As for feeding a beginner regex solutions, I'm on the side that this
>> is a terrible idea.  Regex is not something a beginner should worry
>> about!
>
> NAK.
>
> --
> PointedEars
>
> Twitter: @PointedEars2
> Please do not cc me. / Bitte keine Kopien per E-Mail.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Joel Goldstick wrote:

> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
>  wrote:
>> Joel Goldstick wrote:
>>> Am I missing something.
>>^
>> […]
>> You are missing a leading space character because in the string the comma
>> was followed by one.
> 
> I see that now.  Performing float on each element of the list will
> take care of that, or I guess .strip() on each first.

As I showed, .strip() is unnecessary.  But float() is always necessary for 
computing the sum and suffices indeed together with s.split() if s is just a 
comma-separated list of numeric strings with optional whitespace leading and 
trailing the comma:

  print(sum(map(lambda x: float(x), s.split(',')))

Please trim your quotes to the relevant minimum.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MS-DOS Commands

2015-01-11 Thread Mark Lawrence

On 11/01/2015 22:13, Jenacee Owens wrote:

I'm new to python and every time i type a command into the MS-DOS Commands it 
looks like this.


strings


Traceback";line 1 in 
name error:name strings'is not defined

how can i fix this?



Others have already commented, so I'll just ask would you be more 
comfortable on the tutor mailing list 
https://mail.python.org/mailman/listinfo/tutor ?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Mark Lawrence

On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:

Store Makhzan wrote:


I have this script which can calculate the total of numbers given in a
string […]
total = 0
for c in '0123456789':
total += int(c)
print total

[…]
How should I modify this script to find the total of if the numbers given
in the string form have decimal places? That is, how do I need to modify
this line: […]

for c in '1.32, 5.32, 4.4, 3.78':

[…] to find the total of these given numbers.


The original script already does not do what it advertises.  Instead, it
iterates over the characters of the string, attempts to convert each to an
integer and then computes the sum.  That is _not_ “calculate the total of
numbers given in a string”.

A solution has been presented, but it is not very pythonic because the
original code was not; that should have been

### Ahh, Gauß ;-)
print(sum(map(lambda x: int(x), list('0123456789'
### 

Also, it cannot handle non-numeric strings well.  Consider this instead:

### 
from re import findall

s = '1.32, 5.32, 4.4, 3.78'
print(sum(map(lambda x: float(x), findall(r'-?\d+\.\d+', s
### 

But if you are sure that except for the comma separator there are only
numeric strings, it is more efficient to use re.split() instead of
re.findall() here.


Aside:

I thought I had more than a fair grasp of regular expressions, but I am
puzzled by

| $ python3
| Python 3.4.2 (default, Dec 27 2014, 13:16:08)
| [GCC 4.9.2] on linux
| >>> from re import findall
| >>> s = '1.32, 5.32, 4.4, 3.78'
| >>> findall(r'-?\d+(\.\d+)?', s)
| ['.32', '.32', '.4', '.78']

Why does this more flexible pattern not work as I expected in Python 3.x,
but virtually everywhere else?

And why this?

| >>> findall(r'-?\d+\.\d+', s)
| ['1.32', '5.32', '4.4', '3.78']
| >>> findall(r'-?\d+(\.\d+)', s)
| ['.32', '.32', '.4', '.78']

Feature?  Bug?



I can't tell you as I avoid regexes like I avoid the plague.  Having 
said that I do know that there loads of old bugs on the bug tracker, 
many of which are fixed in the "new" regex module that's available here 
https://pypi.python.org/pypi/regex/


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Peter Otten
Thomas 'PointedEars' Lahn wrote:

> Joel Goldstick wrote:
> 
>> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
>>  wrote:
>>> Joel Goldstick wrote:
 Am I missing something.
>>>^
>>> […]
>>> You are missing a leading space character because in the string the
>>> comma was followed by one.
>> 
>> I see that now.  Performing float on each element of the list will
>> take care of that, or I guess .strip() on each first.
> 
> As I showed, .strip() is unnecessary.  But float() is always necessary for
> computing the sum and suffices indeed together with s.split() if s is just
> a comma-separated list of numeric strings with optional whitespace leading
> and trailing the comma:
> 
>   print(sum(map(lambda x: float(x), s.split(',')))
> 
> Please trim your quotes to the relevant minimum.

Hm, can you explain what this

lambda x: float(x)

is supposed to achieve? I mean other than to confuse a newbie...


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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Chris Angelico
On Mon, Jan 12, 2015 at 11:09 AM, Peter Otten <__pete...@web.de> wrote:
>>
>>   print(sum(map(lambda x: float(x), s.split(',')))
>>
>> Please trim your quotes to the relevant minimum.
>
> Hm, can you explain what this
>
> lambda x: float(x)
>
> is supposed to achieve? I mean other than to confuse a newbie...

Maybe he gets paid by the character.

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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Peter Otten wrote:

> Thomas 'PointedEars' Lahn wrote:
>> […]  But float() is always necessary for computing the sum and suffices 
>> indeed together with s.split() if s is just a comma-separated list of 
>> numeric strings with optional whitespace leading and trailing the comma:
>> 
>>   print(sum(map(lambda x: float(x), s.split(',')))
>> 
>> Please trim your quotes to the relevant minimum.
   
> Hm, can you explain what this
> 
> lambda x: float(x)
> 
> is supposed to achieve? I mean other than to confuse a newbie...

  print(sum(map(float, s.split(','

suffices in this case, of course.

I could have done without the snide remarks.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Steven D'Aprano
Thomas 'PointedEars' Lahn wrote:

> This is safer:
> 
> | >>> from re import split
> | >>> split(r'\s*,\s*', '1.23, 2.4, 3.123')
> | ['1.23', '2.4', '3.123']

Safer, slower, and unnecessary.

There is no need for the nuclear-powered bulldozer of regular expressions
just to crack this tiny peanut. We can split on commas, and then strip
whitespace:

py> values = "1.234   ,4.5678,   9.0123  ,4.321,0.9876  "
py> [s.strip() for s in values.split(',')]
['1.234', '4.5678', '9.0123', '4.321', '0.9876']


but in fact, we don't even need that, since float is perfectly happy to
accept strings with leading and trailing spaces:

py> float('1.2345  ')
1.2345


-- 
Steven

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


Re: extracting numbers with decimal places from a string

2015-01-11 Thread MRAB

On 2015-01-12 00:04, Mark Lawrence wrote:

On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:

Store Makhzan wrote:


I have this script which can calculate the total of numbers given in a
string […]
total = 0
for c in '0123456789':
total += int(c)
print total

[…]
How should I modify this script to find the total of if the numbers given
in the string form have decimal places? That is, how do I need to modify
this line: […]

for c in '1.32, 5.32, 4.4, 3.78':

[…] to find the total of these given numbers.


The original script already does not do what it advertises.  Instead, it
iterates over the characters of the string, attempts to convert each to an
integer and then computes the sum.  That is _not_ “calculate the total of
numbers given in a string”.

A solution has been presented, but it is not very pythonic because the
original code was not; that should have been

### Ahh, Gauß ;-)
print(sum(map(lambda x: int(x), list('0123456789'
### 

Also, it cannot handle non-numeric strings well.  Consider this instead:

### 
from re import findall

s = '1.32, 5.32, 4.4, 3.78'
print(sum(map(lambda x: float(x), findall(r'-?\d+\.\d+', s
### 

But if you are sure that except for the comma separator there are only
numeric strings, it is more efficient to use re.split() instead of
re.findall() here.


Aside:

I thought I had more than a fair grasp of regular expressions, but I am
puzzled by

| $ python3
| Python 3.4.2 (default, Dec 27 2014, 13:16:08)
| [GCC 4.9.2] on linux
| >>> from re import findall
| >>> s = '1.32, 5.32, 4.4, 3.78'
| >>> findall(r'-?\d+(\.\d+)?', s)
| ['.32', '.32', '.4', '.78']

Why does this more flexible pattern not work as I expected in Python 3.x,
but virtually everywhere else?

And why this?

| >>> findall(r'-?\d+\.\d+', s)
| ['1.32', '5.32', '4.4', '3.78']
| >>> findall(r'-?\d+(\.\d+)', s)
| ['.32', '.32', '.4', '.78']

Feature?  Bug?



I can't tell you as I avoid regexes like I avoid the plague.  Having
said that I do know that there loads of old bugs on the bug tracker,
many of which are fixed in the "new" regex module that's available here
https://pypi.python.org/pypi/regex/


It's not a bug.

re.findall returns the capture groups, if present, or the entire match
if there are no capture groups.

In this instance, it's better to use a non-capture group:

findall(r'-?\d+(?:\.\d+)', s)

It's all in the docs! :-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Thomas 'PointedEars' Lahn
Mark Lawrence wrote:

> On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:
>> I thought I had more than a fair grasp of regular expressions, but I am
>> puzzled by
>>
>> | $ python3
>> | Python 3.4.2 (default, Dec 27 2014, 13:16:08)
>> | [GCC 4.9.2] on linux
>> | >>> from re import findall
>> | >>> s = '1.32, 5.32, 4.4, 3.78'
>> | >>> findall(r'-?\d+(\.\d+)?', s)
>> | ['.32', '.32', '.4', '.78']
>>
>> Why does this more flexible pattern not work as I expected in Python 3.x,
>> but virtually everywhere else?
>>
>> And why this?
>>
>> | >>> findall(r'-?\d+\.\d+', s)
>> | ['1.32', '5.32', '4.4', '3.78']
>> | >>> findall(r'-?\d+(\.\d+)', s)
>> | ['.32', '.32', '.4', '.78']
>>
>> Feature?  Bug?
> 
> I can't tell you

I know now why I get this result.  It is a feature, not a bug:


|
| re.findall(pattern, string, flags=0)
|   Return all non-overlapping matches of pattern in string, as a list of 
|   strings. The string is scanned left-to-right, and matches are returned 
|   in the order found. If one or more groups are present in the pattern,

|   return a list of groups; this will be a list of tuples if the pattern
^^^   
|   has more than one group. Empty matches are included in the result unless 
|   they touch the beginning of another match.

A solution is to use non-capturing parentheses:

| >>> findall(r'-?\d+(?:\.\d+)?', '1.32, 5.32, 4.4, 3.78')
| ['1.32', '5.32', '4.4', '3.78']

> as I avoid regexes like I avoid the plague.

You should reconsider.  Regular expressions are a powerful tool.

> Having said that I do know that there loads of old bugs on the bug 
> tracker, many of which are fixed in the "new" regex module that's 
> available here https://pypi.python.org/pypi/regex/

Interesting, thank you.

Please trim your quotes to the relevant minimum next time, though.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: extracting numbers with decimal places from a string

2015-01-11 Thread Steven D'Aprano
Thomas 'PointedEars' Lahn wrote:

> The original script already does not do what it advertises.  Instead, it
> iterates over the characters of the string, attempts to convert each to an
> integer and then computes the sum.  That is _not_ “calculate the total of
> numbers given in a string”.

Yes, and the second piece of code the Original Poster provided is even
worse:

#Check if a perfect cube
total = 0
for c in ('1.23', '2.4', '3.123'):
   print float(c)
   total += float(c)
print total


I don't see how adding up some numbers checks whether it is a perfect cube.
I guess this is a good example of this:

At Resolver we've found it useful to short-circuit any doubt 
and just refer to comments in code as 'lies'.

http://import-that.dreamwidth.org/956.html



> A solution has been presented, but it is not very pythonic because the
> original code was not; that should have been
> 
> ### Ahh, Gauß ;-)
> print(sum(map(lambda x: int(x), list('0123456789'

That can be simplified to:

sum(map(int, '0123456789'))

which can then be passed to print() if required.



> Also, it cannot handle non-numeric strings well.  Consider this instead:

The OP hasn't specified whether or not he has to deal with non-numeric
strings, or how he wants to deal with them. But my guess is that he
actually doesn't want strings at all, and needs to be taught how to work
with lists of floats and/or ints.


> ### 
> from re import findall
> 
> s = '1.32, 5.32, 4.4, 3.78'
> print(sum(map(lambda x: float(x), findall(r'-?\d+\.\d+', s
> ### 

Consider this:

py> s = '123^%#@1.2abc, %#$@2.1&*%^'
py> print(sum(map(lambda x: float(x), findall(r'-?\d+\.\d+', s
3.3

If your aim is just to hide the fact that you have bad data, then the regex
solution "works". Many beginners think that their job as a programmer is to
stop the program from raising an exception no matter what. But I suggest
that Postel's Law:

Be conservative in what you emit, and liberal in what you accept.

shouldn't apply here. I don't think any reasonable person would expect that
the string "123^%#@1.2abc" should be treated as 1.2.


> Aside:
> 
> I thought I had more than a fair grasp of regular expressions, but I am
> puzzled by
> 
> | $ python3
> | Python 3.4.2 (default, Dec 27 2014, 13:16:08)
> | [GCC 4.9.2] on linux
> | >>> from re import findall
> | >>> s = '1.32, 5.32, 4.4, 3.78'
> | >>> findall(r'-?\d+(\.\d+)?', s)
> | ['.32', '.32', '.4', '.78']
> 
> Why does this more flexible pattern not work as I expected in Python 3.x,
> but virtually everywhere else?

This is documented by findall:


py> help(findall)
Help on function findall in module re:

findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.

If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.

Empty matches are included in the result.



-- 
Steven

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


Re: Few Coding suggestions - resending

2015-01-11 Thread Ganesh Pal
On Sun, Jan 11, 2015 at 7:57 PM, Dave Angel  wrote:
>>
>>
> No idea how that represents "a difference of 5 minutes".  So I'll take a 
> totally wild guess that you meant:
>
> Sunday 23:50 23:55
> Monday 00:00 00:05
> Monday 00:10 00:15
> Monday 00:20 00:25
> Monday 00:30 00:35
>
> which would have the 2nd column 5 minutes after the first.
>
> You need another datetime object, let's call it 'end'
>
> end = start + timedelta(minutes=5)
>
> and now you want to yield three things, in a tuple:
>
> yield (start.strftime("%A"), start.strftime("%H:%M"),
>end.strftime("%H:%M"))
>
> Of course that's a pain to do twice, as you have two yields in that function. 
>  I'll leave you to reorder the loop to make that unnecessary.  Hint, do the 
> yield first, THEN increment the start variable.

Thanks for the inputs , I tried doing the increments and decrements
first and then Yield

 Program:

  Login-1@SNAP-BOX-1 new]$ cat time_range_01.py
#!/usr/bin/python
import time
from datetime import date, time, datetime, timedelta
#h = datetime.strftime("%H")
#m = datetime.strftime("%M")
h=23
m=50
d = date.today()
print d

def yield_times():
global  h,m,d
start = datetime.combine(d, time(int(h),int(m)))
end = datetime.combine(d, time(int(h),int(m)))
while True:
start += timedelta(minutes=10)
end = start + timedelta(minutes=5)

yield(start.strftime("%A"),start.strftime("%H:%M"),end.strftime("%H:%M"))
gen = yield_times()
for i in range(10):
print gen.next()

output :
[Login-1@SNAP-BOX-1 new]$ python time_range_01.py
2015-01-12
('Tuesday', '00:00', '00:05')
('Tuesday', '00:10', '00:15')
('Tuesday', '00:20', '00:25')
('Tuesday', '00:30', '00:35')
('Tuesday', '00:40', '00:45')
('Tuesday', '00:50', '00:55')
('Tuesday', '01:00', '01:05')
('Tuesday', '01:10', '01:15')
('Tuesday', '01:20', '01:25')
('Tuesday', '01:30', '01:35')

PS :   Except formatting the results looks pretty much what i was
expecting .I was pretty much happy to see this last night :) .


> and in the other loop, you want
> res = "{} {} {}\n".format(gen.next)
> print res,
>
>>

Thanks ,  I will have to modify for the new output

>> (b)  how to copy the above output (i.e with the new column to a file.)
>>
>
> Instead of printing, just do f.write(res).  Or do both. Notice that to make 
> this easy, i avoided doing any formatting in the print statement. I used a 
> trailing comma on it to avoid print adding a newline, and instead put it 
> explicitly in the format method call.
>
>>

Sure

>> (c)  The  final output should be a file , having the entries  day ,
>> start , end time of the remote file. how do  i pass the  this to
>> yeild-times()
>>
>> import time
>>
>> /* Assuming I retrive the below values h,m,d from the remote machine*/
>>
>> h = time.strftime("%H")
>> m = time.strftime("%M")
>> d = date.today()
>>
>
> Those first two are strings, but the third is a datetime object.  That last 
> can be painful to pass between machines.

Correct , also looks like I have another issue , if I happen to pass
the first two strings

#  instead hard coded value i.e h = 23 and y =50 , i try using the
string directly I end up getting the below error :

h = datetime.strftime("%H")
m = datetime.strftime("%M")

[Login-1@SNAP-BOX-1 new]$ python  time_range_01.py
Traceback (most recent call last):
  File "time_range_01.py", line 4, in 
h = datetime.strftime("%H")
TypeError: descriptor 'strftime' requires a 'datetime.date' object but
received a 'str'

The date time object is retrieved once once from the remote machine
and just for building the file in the required format.
Do you foresee any problems using this ?

>
>>
>> def yield_times():
>>global h,m,d
>
>
> No idea what that's all about.  If you want to pass arguments to 
> yield_times(), put them inside the parens.
>
sure .

Regards,
Gpal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Poor Documentation Examples

2015-01-11 Thread alex23

On 11/01/2015 7:31 PM, Steven D'Aprano wrote:

If that isn't a form of stupidity, I don't know what is.


Maybe you're just eternally optimistic that people can change for the 
better.


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


List of "python -m" tools

2015-01-11 Thread Miki Tebeka
Greetings,

I've compiled a list of "python -m" tools at 
pythonwise.blogspot.com/2015/01/python-m.html.

Did I miss something? What are your favorite "python -m" tools?

Thanks,
--
Miki
-- 
https://mail.python.org/mailman/listinfo/python-list


annoying doctest problem

2015-01-11 Thread gordianknot1981
#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
kivy_class_ptn  = re.compile(r"<\b[\w_.\@\+]+>:?")


def test_kivy_class(s):
"""
>>> s = ":"
>>> test_kivy_class(s)
":"
>>> s = ""
>>> test_kivy_class(s)
""
"""
ret =  re.search(kivy_class_ptn, s)
if ret: return ret.group()
else:   return ''




if __name__ == "__main__":

import doctest
doctest.testmod()



output:

**
File 
"F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
 line 19, in __main__.test_kivy_class
Failed example:
test_kivy_class(s)
Expected:
":"
Got:
':'
**
File 
"F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
 line 22, in __main__.test_kivy_class
Failed example:
test_kivy_class(s)
Expected:
""
Got:
''
**
1 items had failures:
   2 of   8 in __main__.test_kivy_class
***Test Failed*** 2 failures.




It failed with an unknown reason that evaluate two expected equal value but got 
an unexpected result! I'm struggling with this problem for a long time. Did I 
did something wrong? And how do I to fix it?

any help is appreciated. :)






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


Re: annoying doctest problem

2015-01-11 Thread gordianknot1981
gordian...@gmail.com於 2015年1月12日星期一 UTC+8下午12時20分46秒寫道:
> #!/usr/bin/python
> # -*- coding: utf-8 -*-
> 
> import re
> kivy_class_ptn  = re.compile(r"<\b[\w_.\@\+]+>:?")
> 
> 
> def test_kivy_class(s):
> """
> >>> s = ":"
> >>> test_kivy_class(s)
> ":"
> >>> s = ""
> >>> test_kivy_class(s)
> ""
> """
> ret =  re.search(kivy_class_ptn, s)
> if ret: return ret.group()
> else:   return ''
> 
> 
> 
> 
> if __name__ == "__main__":
> 
> import doctest
> doctest.testmod()
> 
> 
> 
> output:
> 
> **
> File 
> "F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
>  line 19, in __main__.test_kivy_class
> Failed example:
> test_kivy_class(s)
> Expected:
> ":"
> Got:
> ':'
> **
> File 
> "F:/MyDocument/[Programing]/Python/PhotoshopAsGui/python3_branch/regexSnippet.py",
>  line 22, in __main__.test_kivy_class
> Failed example:
> test_kivy_class(s)
> Expected:
> ""
> Got:
> ''
> **
> 1 items had failures:
>2 of   8 in __main__.test_kivy_class
> ***Test Failed*** 2 failures.
> 
> 
> 
> 
> It failed with an unknown reason that evaluate two expected equal value but 
> got an unexpected result! I'm struggling with this problem for a long time. 
> Did I did something wrong? And how do I to fix it?
> 
> any help is appreciated. :)


Sorry for asking a dummy problem. I just solve it by changing the string quote 
from double to single. The problem is that doctest treat double quote string 
and single quote string as different value!


>>> s = ":"
>>> test_kivy_class(s)
':'   < change from double quote to single
>>> s = "" 
>>> test_kivy_class(s)
''< change from double quote to single




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


Re: List of "python -m" tools

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 20:17:48 -0800, Miki Tebeka wrote:

> Greetings,
> 
> I've compiled a list of "python -m" tools at
> pythonwise.blogspot.com/2015/01/python-m.html.
> 
> Did I miss something? What are your favorite "python -m" tools?

The three I use all the time are:

- doctools
- unittest
- my own custom test suites



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


Re: annoying doctest problem

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 20:20:35 -0800, gordianknot1981 wrote:
[...]
> Expected:
> ":"
> Got:
> ':'

doctest is *very* fussy about the strings matching exactly. You have to 
use single quotes.

I've been burned by this once or twice...


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


importing os.path -- why does it work?

2015-01-11 Thread Steven D'Aprano
Using the `spam.eggs` syntax for modules only works if spam is a package 
and eggs is a sub-package or module. For example, this fails:


py> import glob.fnmatch
Traceback (most recent call last):
  File "", line 1516, in 
_find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'glob.fnmatch'; glob is not a package



even though fnmatch is a module in glob's namespace:

py> import glob
py> glob.fnmatch




On the other hand, if you have a proper package, it works:

py> import collections.abc
py> collections.__package__
'collections'



But bizarrely, you can import os.path this way!

py> import os.path
py> os.path

py> os.__package__
''



By what wizardry does this work?


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


Re: Using a ChangeLog as a canonical source of package metadata

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 12:37:03 -0800, wxjmfauth wrote:

> 1) I downloaded pyprimes-0.2.1a.tar.gz 
> 2) I extracted the relevant part,
> the py files, the pyprimes subdirectory,
> awful.py, compat23.py, factors.py, test.py, .. and put in
> d:\junk

That is not the way packages work.

pyprimes is a package, which means it has to stay together in a single 
directory called "pyprimes", with a file called "__init__.py" inside it. 
It is not a set of independent modules.

Please read the README file, it explains the correct way to install 
pyprimes. You should use the setup.py installer script.

If you insist on manually doing this, you can copy the *entire* pyprimes 
package directory. That is, unpack the tar.gz file to something like this:


pyprimes/
+-- CHANGES.txt  
+-- LICENCE.txt
+-- MANIFEST  
+-- README.txt
+-- setup.py
+-- src/
+-- pyprimes/
+-- __init__.py
+-- awful.py
+-- factors.py
+-- test.py
etc.


Copy the *entire* folder pyprimes/src/pyprimes/ and move that somewhere 
into your PYTHONPATH. 

Or instead you can:

cd pyprimes/src  # ***NOT*** pyprimes/src/pyprimes !!!


and run python from there.


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


Re: importing os.path -- why does it work?

2015-01-11 Thread Ian Kelly
On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano  wrote:
> But bizarrely, you can import os.path this way!
>
> py> import os.path
> py> os.path
> 
> py> os.__package__
> ''
>
>
>
> By what wizardry does this work?

By the wizardry of adding an entry to sys.modules.

https://hg.python.org/cpython/file/8b3c609f3f73/Lib/os.py#l112
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List of "python -m" tools

2015-01-11 Thread Christian Heimes
On 12.01.2015 05:17, Miki Tebeka wrote:
> Greetings,
> 
> I've compiled a list of "python -m" tools at 
> pythonwise.blogspot.com/2015/01/python-m.html.
> 
> Did I miss something? What are your favorite "python -m" tools?

My all time favorite is "python -me", https://pypi.python.org/pypi/e.
It's a small yet elegant tool for the command line.

Christian



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


Re: List of "python -m" tools

2015-01-11 Thread Chris Angelico
On Mon, Jan 12, 2015 at 5:08 PM, Christian Heimes  wrote:
> My all time favorite is "python -me", https://pypi.python.org/pypi/e.
> It's a small yet elegant tool for the command line.

That's cool!

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


Re: importing os.path -- why does it work?

2015-01-11 Thread Steven D'Aprano
On Sun, 11 Jan 2015 23:00:45 -0700, Ian Kelly wrote:

> On Sun, Jan 11, 2015 at 10:31 PM, Steven D'Aprano 
> wrote:
>> But bizarrely, you can import os.path this way!
>>
>> py> import os.path
>> py> os.path
>>  py>
>> os.__package__
>> ''
>>
>>
>>
>> By what wizardry does this work?
> 
> By the wizardry of adding an entry to sys.modules.
> 
> https://hg.python.org/cpython/file/8b3c609f3f73/Lib/os.py#l112


/head-desk

It's always the simplest thing... 

Thanks.

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