.Re: scanf string in python

2017-04-21 Thread Robert L.
> > I have a string which is returned by a C extension.
> >
> > mystring = '(1,2,3)'
> >
> > HOW can I read the numbers in python ?
> 
> re.findall seems the safest and easiest solution:
> 
> >>> re.findall(r'(\d+)', '(1, 2, 3)')
> ['1', '2', '3']
> >>> map(int, re.findall(r'(\d+)', '(1, 2, 3)'))
> [1, 2, 3]


'(1,2,3)'.scan(/\d+/).map &:to_i

 ===>
[1, 2, 3]

-- 
[T]he attackers tore off the woman's clothes and raped her until five others
arrived  The new arrivals took turns having sex with her and then sodomized
her  At gunpoint, the assailants forced the mother and son to have sex.
www.sun-sentinel.com/local/palm-beach/sfl-flpdunbar0822nbaug22-story.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bigotry (you win, I give up)

2017-04-21 Thread Antoon Pardon
Op 20-04-17 om 17:25 schreef Rustom Mody:
> But more importantly thank you for your polite and consistent pointing out to
> Ben Finney that his religion-bashing signature lines [many of them] and his 
> claims to wish this list be welcoming are way out of sync.

I don't know. I think a concept like welcoming is too complex, to draw such
simple conclusions. First of all we have to make a choice about the public we
want to be welcoming to. I'm rather confident we can agree we don't want to
be welcoming to bigots on this list.

Then feeling welcome is not a boolean, people can feel welcome to a different
degree and there are many factors at work. If people tend to react in a friendly
manner to there co-participants, people generally should feel welcome. A 
statment
in a signature that isn't addressing anyone personnaly may give rise to some
irritation but shouldn't make this list feel unwelcome to someone.

Do you think critising any idea in one's signature is enough to conclude that
this person doesn't wish this list to be welcoming?

-- 
Antoon.

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


Re: Rawest raw string literals

2017-04-21 Thread Tim Chase
On 2017-04-21 08:23, Jussi Piitulainen wrote:
> Tim Chase writes:
>> Bash:
>>   cat <>   "single and double" with \ and /
>>   EOT
>>
>> PS: yes, bash's does interpolate strings, so you still need to do
>> escaping within, but the arbitrary-user-specified-delimiter idea
>> still holds.
> 
> If you put any quote characters in the initial EOT, it doesn't.
> Quote removal on the EOT determines the actual EOT at the end.
> 
>   cat <<"EOT"
>   Not expanding any $amount here
>   EOT

Huh, I just tested it and you're 100% right on that.  But I just
re-read over that section of my `man bash` page and don't see
anything that stands out as detailing this.  Is there something I
missed in the docs?

Thanks for this little tip (filing away for future use)

-tkc


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


Re: Rawest raw string literals

2017-04-21 Thread Jussi Piitulainen
Tim Chase  writes:

> On 2017-04-21 08:23, Jussi Piitulainen wrote:
>> Tim Chase writes:
>>> Bash:
>>>   cat <>>   "single and double" with \ and /
>>>   EOT
>>>
>>> PS: yes, bash's does interpolate strings, so you still need to do
>>> escaping within, but the arbitrary-user-specified-delimiter idea
>>> still holds.
>> 
>> If you put any quote characters in the initial EOT, it doesn't.
>> Quote removal on the EOT determines the actual EOT at the end.
>> 
>>   cat <<"EOT"
>>   Not expanding any $amount here
>>   EOT
>
> Huh, I just tested it and you're 100% right on that.  But I just
> re-read over that section of my `man bash` page and don't see anything
> that stands out as detailing this.  Is there something I missed in the
> docs?

It's in this snippet, yanked straight from the man page:

   The format of here-documents is:

  <<[-]word
  here-document
  delimiter

   No  parameter expansion, command substitution, arithmetic expansion,
   or pathname expansion is performed on word.  If  any  characters  in
   word  are  quoted,  the  delimiter is the result of quote removal on
   word, and the lines in the here-document are not expanded.  If  word
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Skip Montanaro
On Thu, Apr 20, 2017 at 3:19 PM, Peter Otten <__pete...@web.de> wrote:

> If being helpful really is the only purpose of the metaclass you can
> implement a SomeClass.__dir__() method instead:
>
>  def __dir__(self):
>  names = dir(self._instance)
>  # 
>  return names
>

Thanks. That would probably get me halfway home in Python 3, but appears to
have no effect in Python 2. It wouldn't solve the missing attributes in
help()/pydoc either.

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


Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Skip Montanaro
2017-04-20 15:55 GMT-05:00 Lele Gaifax :

> Does
>
> underlying = getattr(SomeOtherClass, a)
> def _meth(self, *args, _underlying=underlying):
> return _underlying(self._instance, *args)
>
> help?
>

Hi, Lele. Long time no chat...

I thought of that, but with _underlying declared after *args I get a syntax
error in Python 2. If I move it in front of *args, the syntax error
disappears, but it gets interpreted as a the first argument of the method.
So if I call

obj.m1(4000)

it tries to call

4000(self._instance, *args)

Maybe functools.partial would be useful in this scenario, where I'm passing
the unbound method object to be called as a parameter. I'll have to play
around with that.

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


Re: Metaclass conundrum - binding value from an outer scope

2017-04-21 Thread Peter Otten
Skip Montanaro wrote:

> On Thu, Apr 20, 2017 at 3:19 PM, Peter Otten <__pete...@web.de> wrote:
> 
>> If being helpful really is the only purpose of the metaclass you can
>> implement a SomeClass.__dir__() method instead:
>>
>>  def __dir__(self):
>>  names = dir(self._instance)
>>  # 
>>  return names
>>
> 
> Thanks. That would probably get me halfway home in Python 3, but appears
> to have no effect in Python 2. It wouldn't solve the missing attributes in
> help()/pydoc either.

OK, looks like I messed up. 

Another round, this time with a metaclass. As you have found partial() does 
not work as a method because it's not a descriptor (i. e. no __get__() 
method). Instead you can try a closure:

def make_method(a):
underlying = getattr(SomeOtherClass, a)
@functools.wraps(underlying)
def _meth(self, *args, **kw):
return underlying(self._instance, *args, **kw)
return _meth

class SomeMeta(type):
def __new__(cls, name, parents, dct):
for a in dir(SomeOtherClass):
if a[0] == "_": continue
dct[a] = make_method(a)
return super(SomeMeta, cls).__new__(cls, name, parents, dct)


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


Re: Bigotry (you win, I give up)

2017-04-21 Thread breamoreboy
On Friday, April 21, 2017 at 10:08:08 AM UTC+1, Antoon Pardon wrote:
> Op 20-04-17 om 17:25 schreef Rustom Mody:
> > But more importantly thank you for your polite and consistent pointing out 
> > to
> > Ben Finney that his religion-bashing signature lines [many of them] and his 
> > claims to wish this list be welcoming are way out of sync.
> 
> I don't know. I think a concept like welcoming is too complex, to draw such
> simple conclusions. First of all we have to make a choice about the public we
> want to be welcoming to. I'm rather confident we can agree we don't want to
> be welcoming to bigots on this list.
> 
> Then feeling welcome is not a boolean, people can feel welcome to a different
> degree and there are many factors at work. If people tend to react in a 
> friendly
> manner to there co-participants, people generally should feel welcome. A 
> statment
> in a signature that isn't addressing anyone personnaly may give rise to some
> irritation but shouldn't make this list feel unwelcome to someone.
> 
> Do you think critising any idea in one's signature is enough to conclude that
> this person doesn't wish this list to be welcoming?
> 
> -- 
> Antoon.

Talking of signatures another of Robert L's beauties landed three or so hours 
ago.  He really is a right little charmer :-(

Kindest regards.

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


Re: Bigotry (you win, I give up)

2017-04-21 Thread Ethan Furman

On 04/21/2017 03:38 AM, breamore...@gmail.com wrote:


Talking of signatures another of Robert L's beauties landed three or so hours 
ago.  He really is a right little charmer :-(


Not on the Python Mailing List.

--
~Ethan~

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


Basics of pythons 🐍

2017-04-21 Thread harounelyaakoubi
Hey everyone, I'm willing to learn python , ant advices ? 
Thanks in advance 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bigotry (you win, I give up)

2017-04-21 Thread breamoreboy
On Friday, April 21, 2017 at 2:33:03 PM UTC+1, Ethan Furman wrote:
> On 04/21/2017 03:38 AM, breamoreboy wrote:
> 
> > Talking of signatures another of Robert L's beauties landed three or so 
> > hours ago.  He really is a right little charmer :-(
> 
> Not on the Python Mailing List.
> 
> --
> ~Ethan~

I'm seen one message this morning via gmane.comp.python.general but that and a 
few more can be seen on GG.  I'm pretty thick skinned but I find the signatures 
completely revolting.  Keep him out please!!!

Kindest regards.

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


Re: Bigotry (you win, I give up)

2017-04-21 Thread Ethan Furman

On 04/21/2017 06:33 AM, Ethan Furman wrote:

On 04/21/2017 03:38 AM, breamore...@gmail.com wrote:



Talking of signatures another of Robert L's beauties landed three or so hours 
ago.  He really is a right little
charmer :-(


Not on the Python Mailing List.


I see one of them made it through.  My apologies (human error).

--
Python List Moderator

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


Re: Basics of pythons 🐍

2017-04-21 Thread Thomas Nyberg
On 04/21/2017 08:06 AM, harounelyaako...@gmail.com wrote:
> Hey everyone, I'm willing to learn python , ant advices ? 
> Thanks in advance 
> 
Here is a tutorial:

https://docs.python.org/3/tutorial/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Direct Download Movies - No Download Limits - Download DivX DVD Movies

2017-04-21 Thread pradawalker
On Saturday, December 5, 2009 at 11:52:52 PM UTC-5, hussain dandan wrote:
> Movie Download Reviews offers Free Online Movie Download,Hollywood
> Movie Download,Free Full Movie Download,Download Latest Hollywood
> Movies,Free Movie
> 
> http://hollywood-moives.blogspot.com/
> http://hollywood-moives.tk

wont fast downloding movies
-- 
https://mail.python.org/mailman/listinfo/python-list


Write a function sorting(L).

2017-04-21 Thread Mohammed Ahmed
Write a function sorting(L) that takes a list of numbers and returns the list 
with all
elements sorted in ascending order.
Note: do not use the sort built in function

it is a python question
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function sorting(L).

2017-04-21 Thread Chris Angelico
On Sat, Apr 22, 2017 at 5:58 AM, Mohammed Ahmed  wrote:
> Write a function sorting(L) that takes a list of numbers and returns the list 
> with all
> elements sorted in ascending order.
> Note: do not use the sort built in function
>
> it is a python question

Yes, it is. It looks like the sort of question that you're supposed to
try to answer in order to learn how to write software. I suggest you
try to answer it.

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


Re: Write a function sorting(L).

2017-04-21 Thread alister
On Fri, 21 Apr 2017 12:58:52 -0700, Mohammed Ahmed wrote:

> Write a function sorting(L) that takes a list of numbers and returns the
> list with all elements sorted in ascending order.
> Note: do not use the sort built in function
> 
> it is a python question

& the reason for this question is what exactly?




-- 
Why isn't there a special name for the tops of your feet?
-- Lily Tomlin
-- 
https://mail.python.org/mailman/listinfo/python-list


Write a function group(L).

2017-04-21 Thread Mohammed Ahmed
Write a function group(L) that takes a list of integers. The function returns a 
list of
two lists one containing the even values and another containing the odd values.

it is a python question
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function sorting(L).

2017-04-21 Thread Mohammed Ahmed
On Friday, April 21, 2017 at 10:01:40 PM UTC+2, alister wrote:
> On Fri, 21 Apr 2017 12:58:52 -0700, Mohammed Ahmed wrote:
> 
> > Write a function sorting(L) that takes a list of numbers and returns the
> > list with all elements sorted in ascending order.
> > Note: do not use the sort built in function
> > 
> > it is a python question
> 
> & the reason for this question is what exactly?
> 
> 
> 
> 
> -- 
> Why isn't there a special name for the tops of your feet?
>   -- Lily Tomlin

i don't understand you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function sorting(L).

2017-04-21 Thread Mohammed Ahmed
On Friday, April 21, 2017 at 10:02:55 PM UTC+2, Chris Angelico wrote:
> On Sat, Apr 22, 2017 at 5:58 AM, Mohammed Ahmed  wrote:
> > Write a function sorting(L) that takes a list of numbers and returns the 
> > list with all
> > elements sorted in ascending order.
> > Note: do not use the sort built in function
> >
> > it is a python question
> 
> Yes, it is. It looks like the sort of question that you're supposed to
> try to answer in order to learn how to write software. I suggest you
> try to answer it.
> 
> ChrisA

i tried a lot but i can't answer it so i thought of getting some help here
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function sorting(L).

2017-04-21 Thread Chris Angelico
On Sat, Apr 22, 2017 at 6:04 AM, Mohammed Ahmed  wrote:
> On Friday, April 21, 2017 at 10:02:55 PM UTC+2, Chris Angelico wrote:
>> On Sat, Apr 22, 2017 at 5:58 AM, Mohammed Ahmed  
>> wrote:
>> > Write a function sorting(L) that takes a list of numbers and returns the 
>> > list with all
>> > elements sorted in ascending order.
>> > Note: do not use the sort built in function
>> >
>> > it is a python question
>>
>> Yes, it is. It looks like the sort of question that you're supposed to
>> try to answer in order to learn how to write software. I suggest you
>> try to answer it.
>>
>> ChrisA
>
> i tried a lot but i can't answer it so i thought of getting some help here

If you tried, you should have some partly-working code. Post your code
here - something like this:

"""
Hi! I have the following homework assignment, which I'm struggling
with. Here's what I've come up with so far, but instead of doing X, Y,
and Z, it does Q and then throws SpamError. Can you help me find
what's wrong in my code, please?
"""

Otherwise, you're just asking us to do your homework for you. We
won't. I teach programming for a living, so I'm very much happy to
help you to learn; but giving you the answer won't help you learn,
it'll only help you get past this exercise.

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


Re: Write a function sorting(L).

2017-04-21 Thread Rob Gaddi

On 04/21/2017 01:04 PM, Mohammed Ahmed wrote:

On Friday, April 21, 2017 at 10:02:55 PM UTC+2, Chris Angelico wrote:

On Sat, Apr 22, 2017 at 5:58 AM, Mohammed Ahmed  wrote:

Write a function sorting(L) that takes a list of numbers and returns the list 
with all
elements sorted in ascending order.
Note: do not use the sort built in function

it is a python question


Yes, it is. It looks like the sort of question that you're supposed to
try to answer in order to learn how to write software. I suggest you
try to answer it.

ChrisA


i tried a lot but i can't answer it so i thought of getting some help here



Have you tried a) Googling for information on sorting algorithms and 
then b) implementing one in Python?



--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function sorting(L).

2017-04-21 Thread Michael Torrie
On 04/21/2017 01:58 PM, Mohammed Ahmed wrote:
> Write a function sorting(L) that takes a list of numbers and returns the list 
> with all
> elements sorted in ascending order.
> Note: do not use the sort built in function
> 
> it is a python question

Sounds like a basic homework question.

Which part are you struggling with?  Do you know how to work with lists
and iterate through their values?  Do you know how to sort numbers?  Do
you know how to make a function?  What does your program look like so far?

I'm glad you're learning Python in a classroom setting.  Have you sat
down with your instructor to discuss the gaps in your knowledge as you
proceed?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function group(L).

2017-04-21 Thread Ian Kelly
On Fri, Apr 21, 2017 at 2:01 PM, Mohammed Ahmed  wrote:
> Write a function group(L) that takes a list of integers. The function returns 
> a list of
> two lists one containing the even values and another containing the odd 
> values.
>
> it is a python question

This group will be happy to help you with your homework but we're not
going to do it for you. What have you tried already and what parts are
you struggling with?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write a function group(L).

2017-04-21 Thread Gary Herron

On 04/21/2017 01:01 PM, Mohammed Ahmed wrote:

Write a function group(L) that takes a list of integers. The function returns a 
list of
two lists one containing the even values and another containing the odd values.

it is a python question


In fact, this is *not* a question, Python or otherwise.

Welcome to python-list.  If you ask a Python question, it will probably 
get answered.  If you want someone to do your homework, it will probably 
not happen.



--
Dr. Gary Herron
Professor of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Write a function sorting(L).

2017-04-21 Thread bartc

On 21/04/2017 21:04, Mohammed Ahmed wrote:

On Friday, April 21, 2017 at 10:02:55 PM UTC+2, Chris Angelico wrote:

On Sat, Apr 22, 2017 at 5:58 AM, Mohammed Ahmed  wrote:

Write a function sorting(L) that takes a list of numbers and returns the list 
with all
elements sorted in ascending order.
Note: do not use the sort built in function

it is a python question


Yes, it is. It looks like the sort of question that you're supposed to
try to answer in order to learn how to write software. I suggest you
try to answer it.

ChrisA


i tried a lot but i can't answer it so i thought of getting some help here


You need an algorithm.

How would you sort a set of numbered cards? I might start with looking 
for the smallest, and either moving that to the front, or using it to 
build a new set.


(It's not clear from the question whether the list needs to be sorted 
in-place, or a new list is returned with the elements sorted.)


--
bartc

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


Re: Write a function sorting(L).

2017-04-21 Thread Tim Chase
On 2017-04-21 12:58, Mohammed Ahmed wrote:
> Write a function sorting(L) that takes a list of numbers and
> returns the list with all elements sorted in ascending order.
> Note: do not use the sort built in function
> 
> it is a python question

No "sort" functions here...

  >>> lst=[3,1,4,1,5,9,2,6,5]
  >>> getattr(__builtins__, dir(__builtins__)[-9])(lst)
  [1, 1, 2, 3, 4, 5, 5, 6, 9]

Might have to tweak it based on your version of Python.

For a more robust version:

  >>> import heapq
  >>> heapq.heapify(lst)
  >>> heapq.nsmallest(len(lst), lst)
  [1, 1, 2, 3, 4, 5, 5, 6, 9]

No built-in sort there either. ;-)

Or, you could show your code instead of trying to get the mailing
list to do your homework for you.

-tkc



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


textwrap.fill algorithm? (Difference with vim)

2017-04-21 Thread Matěj Cepl
Hi,

I have a gedit Python plugin which should do line wrap using 
textwrap.fill() function.  However, even when I have set the 
length of line to the same number as in vim (65), the result is 
substantially different (textwrap.fill paragraphs are 
significantly narrower). See for example this diff (removed 
lines are wrapped by vim, added by textwrap.fill-based plugin).

Why cannot textwrap.fill get those words “grown so” to the first 
line of the wrapped text? Any ideas about the difference in the 
algorithms for line-wrapping in vim and in textwrapper.fill?

Thank you for any suggestions,

Matěj Cepl

~$ git diff -- mind.rst
diff --git a/mind.rst b/mind.rst
index a9523c2..e55c56b 100644
--- a/mind.rst
+++ b/mind.rst
@@ -63,16 +63,18 @@ personal religious belief. It is a commentary, in the light 
of
 specialised knowledge, on a particular set of statements made in the
 Christian creeds and their claim to be statements of fact.
 
-It is necessary to issue this caution, for the popular mind has grown so
-confused that it is no longer able to receive any statement of fact
-except as an expression of personal feeling. Some time ago, the present
-writer, pardonably irritated by a very prevalent ignorance concerning
-the essentials of Christian doctrine, published a brief article in which
-those essentials were plainly set down in words that a child could
-understand. Every clause was preceded by some such phrase as: “the
-Church maintains”, “the Church teaches”, “if the Church is right”, and
-so forth. The only personal opinion expressed was that, though the
-doctrine might be false, it could not very well be called dull.
+It is necessary to issue this caution, for the popular mind has
+grown so confused that it is no longer able to receive any
+statement of fact except as an expression of personal feeling.
+Some time ago, the present writer, pardonably irritated by a very
+prevalent ignorance concerning the essentials of Christian
+doctrine, published a brief article in which those essentials
+were plainly set down in words that a child could understand.
+Every clause was preceded by some such phrase as: “the Church
+maintains”, “the Church teaches”, “if the Church is
+right”, and so forth. The only personal opinion expressed was
+that, though the doctrine might be false, it could not very well
+be called dull.
 
 Every newspaper that reviewed this article accepted it without question
 as a profession of faith-some (Heaven knows why) called it “a courageous
~$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: textwrap.fill algorithm? (Difference with vim)

2017-04-21 Thread Peter Otten
Matěj Cepl wrote:

> I have a gedit Python plugin which should do line wrap using
> textwrap.fill() function.  However, even when I have set the
> length of line to the same number as in vim (65), the result is
> substantially different (textwrap.fill paragraphs are
> significantly narrower). See for example this diff (removed
> lines are wrapped by vim, added by textwrap.fill-based plugin).
> 
> Why cannot textwrap.fill get those words “grown so” to the first
> line of the wrapped text? Any ideas about the difference in the
> algorithms for line-wrapping in vim and in textwrapper.fill?

It's not the algorithm, it's the width. Try textwrap.fill(text, 72).


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


Re: textwrap.fill algorithm? (Difference with vim)

2017-04-21 Thread Matěj Cepl
On 2017-04-21, 21:54 GMT, Peter Otten wrote:
> It's not the algorithm, it's the width. Try 
> textwrap.fill(text, 72).

I don’t understand. Why 72? I have set tw=65 in vim.

Matěj

-- 
https://matej.ceplovi.cz/blog/, Jabber: mc...@ceplovi.cz
GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
 
Of course I'm respectable. I'm old. Politicians, ugly buildings,
and whores all get respectable if they last long enough.
  --John Huston in "Chinatown."
-- 
https://mail.python.org/mailman/listinfo/python-list


combine if filter terms from list

2017-04-21 Thread Rory Schramm
Hi,

I'm trying to use python list comprehensions to combine multiple terms for
use by a for loop if condition.


filters = [ 'one', 'two', 'three']
for line in other_list:
if ' and '.join([item for item in filters]) not in line[2]:
print line

The list comp returns  one and two and three and ..

The problem I'm having is the for loop isn't filtering out the terms from
the filter list. I suspect the problem is the if condition is treating the
results for the list comprehension as a literal string and not part of the
if condition itself. I'm not sure how to fix this though.

Any ideas on How to make this work?

Thanks!,

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


Re: textwrap.fill algorithm? (Difference with vim)

2017-04-21 Thread MRAB

On 2017-04-21 23:17, Matěj Cepl wrote:

On 2017-04-21, 21:54 GMT, Peter Otten wrote:
It's not the algorithm, it's the width. Try 
textwrap.fill(text, 72).


I don’t understand. Why 72? I have set tw=65 in vim.

textwrap.fill counts characters. It won't put "grown so" on the first 
line because that would make it longer than 65 characters (72, to be exact).


Why is Vim trying to put 72 characters onto the first line?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Basics of pythons 🐍

2017-04-21 Thread tommy yama
Hi there,

For what, you want to learn?





On Sat, Apr 22, 2017 at 1:10 AM, Thomas Nyberg  wrote:

> On 04/21/2017 08:06 AM, harounelyaako...@gmail.com wrote:
> > Hey everyone, I'm willing to learn python , ant advices ?
> > Thanks in advance
> >
> Here is a tutorial:
>
> https://docs.python.org/3/tutorial/
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: combine if filter terms from list

2017-04-21 Thread MRAB

On 2017-04-22 01:17, Rory Schramm wrote:

Hi,

I'm trying to use python list comprehensions to combine multiple terms for
use by a for loop if condition.


filters = [ 'one', 'two', 'three']
for line in other_list:
 if ' and '.join([item for item in filters]) not in line[2]:
 print line

The list comp returns  one and two and three and ..

The problem I'm having is the for loop isn't filtering out the terms from
the filter list. I suspect the problem is the if condition is treating the
results for the list comprehension as a literal string and not part of the
if condition itself. I'm not sure how to fix this though.

Correct. The join is returning 'one and two and three'. The condition is 
true if that string isn't in line[2]. (What is line? Is it a string? If 
so, then line[2] is one character of that string.)



Any ideas on How to make this work?


If you want it to do this:

if 'one' not in line[2] and 'two' not in line[2] and 'three' not in 
line[2]:


you can write:

if all(word not in line[2] for word in filters):

or:

if not any(word in line[2] for word in filters):
--
https://mail.python.org/mailman/listinfo/python-list


Re: textwrap.fill algorithm? (Difference with vim)

2017-04-21 Thread Gregory Ewing

Matěj Cepl wrote:

On 2017-04-21, 21:54 GMT, Peter Otten wrote:

It's not the algorithm, it's the width. Try 
textwrap.fill(text, 72).


I don’t understand. Why 72?


Because the first line including those words is 72 characters
long.

I don't know what vim is doing, but if you tell Python you
want lines no longer than 65 characters, it takes you at
your word.

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


Re: combine if filter terms from list

2017-04-21 Thread Ben Finney
Rory Schramm  writes:

> I'm trying to use python list comprehensions to combine multiple terms
> for use by a for loop if condition.

Thank you for a small code example. It doesn't have enough to illustrate
the problem you're describing; we can't run it and see what you're seeing.

> filters = [ 'one', 'two', 'three']
> for line in other_list:
> if ' and '.join([item for item in filters]) not in line[2]:
> print line

What is ‘line’?

What is the example input, and what output are you expecting to see, and
what output do you see instead?

Please construct and present a small and also *complete* example, that
we can also run to have a chance of seeing the same behaviour.

> The problem I'm having is the for loop isn't filtering out the terms from
> the filter list. I suspect the problem is the if condition is treating the
> results for the list comprehension as a literal string and not part of the
> if condition itself. I'm not sure how to fix this though.

Without a complete exampel, and a comparison between what the actual
output is versus what you expect to see, I am not able to understand
the problem description, especially “not part of the if condition itself”.

> Any ideas on How to make this work?

Once we can see a complete small example that demonstrates the
behaviour, we may have a better chance.

-- 
 \  “If you don't fail at least 90 percent of the time, you're not |
  `\aiming high enough.” —Alan Kay |
_o__)  |
Ben Finney

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


Turtle window not closing

2017-04-21 Thread Harshika Varadhan via Python-list
Hi everyone,
I am creating a game where the user inputs a coordinate to place their piece on 
a chess board. My code then draws the chess board with a turtle and fills in 
the squares in with green where the user can place their next piece. After the 
user inputs their first coordinate, the turtle draws the board, but then the 
window doesn't close and the program ends up crashing. Is there any way to 
solve this problem?I appreciate your help.
My function for drawing the chess board:
def draw_board():    t = turtle.Turtle()    t.speed(0)    t.ht()    t.up()    
t.goto(-100, -100)    t.down()
    for i in range(0, 8):        for j in range(0, 8):            if 
free_squares[i][j] == ".":                if j != 7:                    
t.fillcolor("green")                    t.pencolor("black")                    
t.begin_fill()                    for k in range(4):                        
t.forward(50)                        t.left(90)                    t.end_fill() 
                   t.forward(50)                if j == 7:                    
t.fillcolor("green")                    t.pencolor("black")                    
t.begin_fill()                    for k in range(4):                        
t.forward(50)                        t.left(90)                    t.end_fill() 
                   t.right(270)                    t.forward(50)                
    t.left(90)                    t.forward(350)                    t.right(180)
    turtle.bye()
Thank you, Harshi
-- 
https://mail.python.org/mailman/listinfo/python-list