Re: [OT] master/slave debate in Python

2018-09-26 Thread David Palao
Hello,
My opinion is that the terms "master/slave" describe well some situations.
They could be seen by some people as offensive (although unfortunately
sometimes true, even today) when applied to persons. But it is not
offensive when applied to processes in a computer. They are not living
entities.

I would say that when talking about programming, the terms have a
perfect meaning. Otherwise, what is the correct way to use the words
master and slave? Not using them?

Best


El dom., 23 sept. 2018 a las 17:00, Albert-Jan Roskam
() escribió:
>
> *sigh*. I'm with Hettinger on this.
>
> https://www.theregister.co.uk/2018/09/11/python_purges_master_and_slave_in_political_pogrom/
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python to C code generator

2018-01-17 Thread David Palao
Hi,
Have a look at Cython.

Best

2018-01-17 12:04 GMT+01:00 kushal bhattacharya :
> Hi,
> Is there any python framework or any tool as  which can generate C code from 
> python code as it is .
>
> Thanks,
> Kushal
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: WANT: bad code in python (for refactoring example)

2017-02-15 Thread David Palao
2017-02-15 10:36 GMT+01:00 Makoto Kuwata :
> Thanks Irmen and Steven,
>
> I'm sorry that my explanation is not enough.
> I'm looking for bad python code, not refactoring examples.
> I can do (and want to do) refactor bad code by myself.
>
> Is there any bad python code (or project) with proper size?
>
> # I found a lot of bad PHP code in github, but didn't find bad Python code.
>
> --
> regards,
> makoto kuwata
>
>
> On Wed, Feb 15, 2017 at 3:28 PM, Steven D'Aprano 
> wrote:
>
>> On Wed, 15 Feb 2017 07:44:03 +0900, Makoto Kuwata wrote:
>>
>> > Hi,
>> >
>> > Is there any *just right* python code to refactor?
>> > In other words, I'm finding bad code example in python.
>>
>>
>> Try looking at the ActiveState website for recipes in Python. Especially
>> look at the ones with negative ratings, but even positively rated recipes
>> are often nonsense.
>>
>> E.g. http://code.activestate.com/recipes/580750
>>
>> does nothing more that define
>>
>> echo = sys.stdout.write
>>
>> Why not use sys.stdout.write directly? Or print? If I saw somebody using
>> this recipe in production code, in the way shown, I'd refactor it to just
>> use print. There's no advantage to re-inventing the wheel this way.
>>
>>
>>
>> --
>> Steve
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
> --
> https://mail.python.org/mailman/listinfo/python-list

Hello,
IMHO most code can be refactored.
Forme the point is how you want to teach it and what you want to teach
exactly. For instance, if you are following a tdd approach, then the
project you choose, should better come with that in mind.
If you are not considering tests, for whatever reason, I guess any
simple enough project would be good. Of course, it depends on the
details of what you want to teach.

BTW, at work I have been told to organize a course about testing and
good programming practices with Python. I was thinking in developing
an example by myself...
Best

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


Re: How to store properties

2017-02-08 Thread David Palao
2017-02-08 13:34 GMT+01:00 Cholo Lennon :
> On 02/08/2017 08:26 AM, Cecil Westerhof wrote:
>>
>> In Java you (can) use a properties file store configuration. What is
>> the best way to do something like that in Python?
>> I saw ConfigParser, but have the feeling that it is not really used.
>
>
> I use it a lot ;-)
>
>
>> Would a JSON file be a good idea?
>>
>
>
> --
> Cholo Lennon
> Bs.As.
> ARG
> --
> https://mail.python.org/mailman/listinfo/python-list

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


Re: constructor classmethods

2016-11-07 Thread David Palao
>>
>> If the class in question has legitimate, non-testing, reasons to specify 
>> different Queues, then make it a default argument instead:
>>
>> def __init__(self, ..., queue=None):
>>  if queue is None:
>>  queue = Queue()
>>  self.queue = queue
>
> I already stated that this is is fine, as long as the number of arguments 
> stays in manageable levels. Although I do think testing is good enough reason 
> to have it injected anytime. For consistency, it makes sense to have same way 
> to create all objects. I wouldn't suggested of using that mechanism in public 
> API's, just in internal components.
>

But if the number of arguments is not manageable, you need to change
the design anyway, for the sake of cleanness. So YAGNI.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to implement semaphores in python?

2016-06-07 Thread David Palao
Hi,
Have you checked this
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Semaphore
?

Best

2016-06-07 11:43 GMT+02:00 karthik jagilinki :
> Hello All,
>
> I need some help with semaphore implementation between two programs in 
> python. I'd be glad if anyone can give me some help.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: String concatenation

2016-05-10 Thread David Palao
2016-05-10 9:54 GMT+02:00 Steven D'Aprano
:
> On Tuesday 10 May 2016 17:13, Paul Rubin wrote:
>
>> Steven D'Aprano  writes:
>>> Australia's naming laws almost certainly wouldn't allow such a name.
>>
>> https://en.wikipedia.org/wiki/Facebook_real-
> name_policy_controversy#Vietnamese
>
> "Phuc Dat Bich" was a hoax, but it probably would be allowed in Australia.
>
> I'm surprised that Spanish names are not affected. Consider a woman who goes 
> by
> the personal name of Maria Teresa, whose father's first surname was García and
> mother's first surname was Ramírez. Her name would therefore be Maria Teresa
> García Ramírez. If she marries Elí Arroyo López, then she might change her 
> name
> to Maria Teresa García Ramírez de Arroyo. With six words, that would fall foul
> of Facebook's foul naming policy.
>
>
> http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list

In Spain "de Arroyo" officially does not become part of the name. The
same applies to other countries as well. Not 100% sure that it is true
in every Spanish speaking country though.

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


Re: Guido sees the light: PEP 8 updated

2016-04-18 Thread David Palao
2016-04-18 5:19 GMT+02:00 Steven D'Aprano :
> On Mon, 18 Apr 2016 11:39 am, Rustom Mody wrote:
>
>> yes we can agree on this -- arbitrary line lengths are almost certainly
>> unreadable.
>> The problem then becomes so what is optimal?
>
> I really don't think it is a problem. We have about 400 years
> of experience with printed text, and that experience tells us
> that the optimal width for reading prose in Western languages
> is about 60 characters, give or take. This width is optimal
> for eye movement, and minimizes the number of errors and
> reduces eye-strain.
>
> There's only so far that our eyes can follow a line to the
> right without increasing stress or reading errors, and
> likewise when returning back to the left margin. The longer
> the line, the higher the chance of losing track, and the
> physical effort it takes to read. (You have to move the eyes
> further, and for extremely long lines, you may have to move
> your entire head.)
>
> Long lines are simply harder to read because you have to
> move your eyes more, and the longer the lines, the greater
> the tendency to wander across the lines. Especially if the
> lines are close together and the height of the lines is
> small. (It boggles my mind how many programmers I've met who
> routinely view their code in tiny physical heights, even
> when reading it in fine detail.)
>
> The optimal width for eye-tracking (that is, the maximum
> width for which the rate of such errors can be disregarded)
> is somewhere about sixty characters per line.
>
> The same eye-tracking considerations apply to code, but:
>
> when it comes to code, we don't always have to track all the
> way back to the left-hand margin. If we start (say) up to
> twenty columns in, then we can afford to write up to twenty
> columns further to the right too.
>
>
> (Also, code tends to have VERY ragged right-hand margins.
> Not all lines end up even close to sixty characters wide.)
>
> There are other considerations though. Unlike prose, with
> code, shorter lines *may* sometimes force an increase in
> complexity. For instance, temporary variables need to be
> created, or new functions created, just to avoid otherwise
> excessively long lines. So one might be willing to accept a
> little more eye-movement for a little less code complexity.
>
> So allowing a total width of 80 (give or take) is already a
> compromise from the optimal sixty characters. This compromise
> allows for indented code, and allows up to 20 characters
> extra to avoid creating more complexity elsewhere.
>
>
> But there's another factor: long lines of code are themselves
> a code-smell. Perhaps:
>
> - you have indented too deeply, suggesting that your function
>   is doing too much or has too much internal complexity:
>
>   def func():
>   if a:
>   for b in seq:
>   while c:
>   with d:
>   try:
>   try:
>   for e in it:
>   block  # only 48 columns available here
>
>   (But note also that even with this extreme example, eight
>   indentation levels deep, you can still fit almost
>   characters per line without breaking the 80-char limit.
>   You can do a lot in 50 characters.)
>
>
> - you have too many expressions on one line, suggesting that
>   the over-all complexity of the line is excessive;
>
> - your variable or function names are needlessly verbose or
>   are doing too much or are too specific
>   ("calculate_number_of_pages_and_number_of_semicolons_in_chapter_one");
>
> - or you are violating the rule of Demeter:
>   get(customer.trousers.pocket.wallet).open().money.pay(1)
>
>
> In other words, long lines of code are themselves an
> indication of poorly-designed code. Even though there are
> exceptions, we should resist strongly the urge to extend
> beyond the 60-80 (or perhaps 90 in extreme cases) limit.
> Whenever I hear people saying that they regularly need to
> use 100 or even 120 columns for their code, what I hear is
> "my code is badly written".
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Excellent! Thank you for this contribution.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to parameterize unittests

2016-04-14 Thread David Palao
2016-04-14 16:08 GMT+02:00 Antoon Pardon :
>
> I have a unittest for my avltree module.
>
> Now I want this unittest to also run on a subclass of avltree.
> How can I organise this, so that I can largely reuse the
> original TestCase?
>
> --
> Antoon Pardon
> --
> https://mail.python.org/mailman/listinfo/python-list

First, is it necessary to test the functionality twice?

If so then, why don't you simply subclass the original TestCase?

Or am I missing the point of your question?

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


Re: newbie question

2016-03-24 Thread David Palao
Hi,
Use "eval":
s = "(1, 2, 3, 4)"
t = eval(s)

Best

2016-03-24 11:39 GMT+01:00 ast :
> Hi
>
> I have a string which contains a tupe, eg:
>
> s = "(1, 2, 3, 4)"
>
> and I want to recover the tuple in a variable t
>
> t = (1, 2, 3, 4)
>
> how would you do ?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: show instant data on webpage

2016-01-27 Thread David Palao
2016-01-26 18:26 GMT+01:00 mustang :
>
>> open("myData.dat", "w").close()
>>
>> while True:
>>  temp = sensor.readTempC()
>>  riga = "%f\n" % temp
>>  with open("myData.dat", "a") as f:
>>  f.write(riga)
>>  time.sleep(1)
>
> yes great it works!thanks a lot!
> Anyway to refresh temperature I've to recall anytime the php page.
> My idea is to read for example the first line every x seconds...it should
> work.
> Is it possible to use python and not php to plot data?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm not sure to understand how you are using php, but indeed you can
use python to plot data (have a look at matplotlib, for instance) and
also to make dynamic web pages (Flask, django).

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


Re: Python Unit test

2016-01-26 Thread David Palao
Well, there is a very specific example in there.
But you still don't give us much information about *concrete* troubles you have.
I *guess* that one of the following is true:
1) You have problems to understand some part of the example in the
unittest module documentation.
2) You don't know how to apply those ideas to some specific code you have.
3) something else.
Could you please be more specific?

Best

2016-01-26 13:26 GMT+01:00  :
> Yes I have studied the page but it's quite vague to me. So we have this 
> project - Development of a touch screen controllable IEC61850 standard 
> protocol analyzer. With this analyzer user can monitor and analyze network 
> traffic in substation network.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python-2.7.3 vs python-3.2.3

2016-01-26 Thread David Palao
Hello,
On my system I have 2.7.10 and 3.4.3 system wide, but it is not
debian. Of course, the "python" executable can be only one of them at
a given time.
Another option is tu use a virtual environment or something (pyvenv or
virtualenv).


Best

2016-01-26 13:26 GMT+01:00 Gene Heskett :
> Greetings;
>
> I have need of using a script written for python3, but the default python
> on wheezy is 2.7.3.
>
> I see in the wheezy repos that 3.2.3-6 is available.
>
> Can/will they co-exist peacefully?
>
> Thank you.
>
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page 
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread David Palao
2016-01-26 16:56 GMT+01:00 Joel Goldstick <joel.goldst...@gmail.com>:
> On Tue, Jan 26, 2016 at 10:48 AM, Tolu Agboola <toluagbo...@gmail.com>
> wrote:
>
>> I'll go with number 2. I don't know how to apply the ideas to the code I
>> have.
>>
>> Sent from my iPhone
>>
>> > On 26 Jan 2016, at 15:48, David Palao <dpalao.pyt...@gmail.com> wrote:
>> >
>> > Well, there is a very specific example in there.
>> > But you still don't give us much information about *concrete* troubles
>> you have.
>> > I *guess* that one of the following is true:
>> > 1) You have problems to understand some part of the example in the
>> > unittest module documentation.
>> > 2) You don't know how to apply those ideas to some specific code you
>> have.
>> > 3) something else.
>> > Could you please be more specific?
>> >
>> > Best
>> >
>> > 2016-01-26 13:26 GMT+01:00  <toluagbo...@gmail.com>:
>> >> Yes I have studied the page but it's quite vague to me. So we have this
>> project - Development of a touch screen controllable IEC61850 standard
>> protocol analyzer. With this analyzer user can monitor and analyze network
>> traffic in substation network.
>> >> --
>> >> https://mail.python.org/mailman/listinfo/python-list
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> Test driven development with python and django.  The complete text is
> online here:
> http://chimera.labs.oreilly.com/books/123400754/pr02.html#_python_3_and_programming
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
> --
> https://mail.python.org/mailman/listinfo/python-list

Good reference.
I like also this one:
http://code.tutsplus.com/tutorials/test-driven-development-in-python--net-30137
which is shorter.

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


Re: show instant data on webpage

2016-01-26 Thread David Palao
2016-01-26 17:10 GMT+01:00 mustang :
> I've built a sensor to measure some values.
> I would like to show it on a web page with python.
>
>
> This is an extract of the code:
>
> file  = open("myData.dat", "w")
>
> while True:
> temp = sensor.readTempC()
> riga = "%f\n" % temp
> file.write(riga)
> time.sleep(1.0)
>
> file.close()
>
> Until this all ok.
> Then in PHP I read the file and show it on internet. It works ok but...
> First problem. I've to stop the streaming with CTRl-C to load the PHP file
> because if I try to read during measurement I cannot show anything (I think
> because the file is in using).
> How can I show time by time in a webpage the output?
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Is this an option?

open("myData.dat", "w").close()

while True:
temp = sensor.readTempC()
riga = "%f\n" % temp
with open("myData.dat", "a") as f:
f.write(riga)
time.sleep(1)

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


Re: Python Unit test

2016-01-26 Thread David Palao
Hello,
It would be good to provide more details on what you need help for.
For instance, have you read the manual
https://docs.python.org/3/library/unittest.html
?
It even contains a couple of examples.

Best

2016-01-26 12:09 GMT+01:00  :
> I'm a University student of IT with majors in Embedded Systems. I have this 
> assignment where I have to write Unittest for a simple Python Code without 
> having prior knowledge of Python. I really need some help.
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to python

2015-07-20 Thread David Palao
2015-07-20 7:20 GMT+02:00 Arthi Vigneshwari arthi15sm...@gmail.com:
 Hi,
   Am interested to learn python!Can you please guide me how to start with
 python which will help in my selenium automation?

 Regards,
 Arthi

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


Hi,
If you enter learning python in a search engine, you'll probably get
several interesting resources to start with it.
For instance, have you had a look at
https://www.python.org/about/gettingstarted/
?

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


Re: PYTHON QUESTION

2015-06-11 Thread David Palao
2015-06-11 12:44 GMT+02:00  adebayo.abra...@gmail.com:
 Help with this problem!

 Temperature converter
 Description

 Write two functions that will convert temperatures back and forth from the 
 Celsius and Fahrenheit temperature scales. The formulas for making the 
 conversion are as follows:

   Tc=(5/9)*(Tf-32)
   Tf=(9/5)*Tc+32

 where Tc is the Celsius temperature and Tf is the Fahrenheit temperature. 
 More information and further descriptions of how to do the conversion can be 
 found at this NASA Webpage. If you finish this assignment quickly, add a 
 function to calculate the wind chill.
 Input

 Your program should ask the user to input a temperature and then which 
 conversion they would like to perform.
 --
 https://mail.python.org/mailman/listinfo/python-list

Hello,
While people here is kindly helping others, it doesn't work the way
you are posing it: we will not do your homeworks.
If you want some help, please, present some code that you wrote and
does not work, or a specific question about the problem. For instance,
how can I write a function in python?
BTW, probably your questions should go to the tutor mailing list...

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


Re: I just need this question explained.

2015-06-11 Thread David Palao
2015-06-11 14:03 GMT+02:00 Adebayo Abraham adebayo.abra...@gmail.com:
 I am not requesting for a solution. I just need the question explained. I am 
 a beginner python developer and i do not know where to start from to solve 
 this problem. So anybody, somebody: please explain this question. Am i to 
 create a testcase or create the code to display a value?

 Challenge: FitFam

 Problem

 The aerobics class begins. The trainer says, Please position yourselves on 
 the training mat so that each one of you has enough space to move your arms 
 around freely, and not hit anybody else. People start milling around on the 
 mat, trying to position themselves properly. Minutes pass, and finally the 
 trainer is so annoyed that he asks you to write a program that will position 
 all the people correctly, hoping it will be quicker than letting them figure 
 it out for themselves!

 You are given the dimensions (width and length) of the mat on which the class 
 takes place. For every student, there is a circular area she has to have for 
 herself, with radius equal to the reach of her arms. These circles can not 
 intersect, though they can touch; and the center of each circle (where the 
 student stands) has to be on the mat. Note that the arms can reach outside 
 the mat. You know that there's plenty of space on the mat — the area of the 
 mat is at least five times larger than the total area of the circles required 
 by all the people in the class. It will always be possible for all the people 
 to position themselves as required.

 Input

 The first line of the input gives the number of test cases, T. T test cases 
 follow. Each test case consists of two lines. The first line contains three 
 integers: N, W and L, denoting the number of students, the width of the mat, 
 and the length of the mat, respectively. The second line contains N integers 
 ri, denoting the reach of the arms of the ith student.

 Output

 For each test case, output one line containing Case #n: y, where n is the 
 case number (starting from 1) and y is a string containing 2N numbers, each 
 of which can be an integer or a real number: x1, y1, x2, y2, etc., where the 
 pair (xi, yi) is the position where the ith student should stand (with 0 ≤ xi 
 ≤ W and 0 ≤ yi ≤ L).

 As there will likely be multiple ways to position the students on the mat, 
 you may output any correct positioning; but remember that you may not submit 
 an output file more than 200kB in size.

 Limits

 1 ≤ T ≤ 50.
 1 ≤ W, L ≤ 109.
 1 ≤ ri ≤ 105.
 The area of the mat is at least 5 times larger than the total area of the 
 circles:
 5*π*(r12 + ... + rN2) ≤ W*L.
 Small dataset

 1 ≤ N ≤ 10.
 Large dataset

 1 ≤ N ≤ 103.
 The total number of circles in all test cases will be ≤ 6000.
 Sample


 Input

 Output

 2
 2 6 6
 1 1
 3 320 2
 4 3 2
 Case #1: 0.0 0.0 6.0 6.0
 Case #2: 0.0 0.0 7.0 0.0 12.0 0.0

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

Hello again,
It looks to me that you have to write the code that is able to read
the input described and produce the wished output.
You could organize the program like
1) read input
2) compute
3) print out result
Perhaps each part being a function.

Try something and tell us when you are blocked.

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


Re: What sort of data structure to use?

2015-06-03 Thread David Palao
2015-06-03 10:19 GMT+02:00 David Aldrich david.aldr...@emea.nec.com:
 Hi



 I have written a Python utility that performs a certain activity on some
 predefined sets of files.  Here is the outline of what I have written:



 # File Set A

 pathA = ‘pathA’

 fileListA = [‘fileA1.txt’, ‘fileA2.txt’]



 # File Set B

 pathB = ‘pathB’

 fileListB = [‘fileB1.txt’, ‘fileB2.txt’, ‘fileB3.txt’]



 myFunc1(pathA, fileListA)

 myFunc2(pathA, fileListA)



 myFunc1(pathB, fileListB)

 myFunc2(pathB, fileListB)



 I want to add more file sets, so I really want to add the sets to a list and
 iterate over the list, calling myFunc1  myFunc2 for each item.



 My question is: what sort of data structure could I use to organise this,
 given that I want to associate a set of files with each path and that, for
 each set, there is an arbitrary number of files?



 Best regards



 David




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


And if you really want to link the path to the list of files, you
could define an object FileList (trivially) implementing the iterator
protocol.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What sort of data structure to use?

2015-06-03 Thread David Palao
2015-06-03 10:19 GMT+02:00 David Aldrich david.aldr...@emea.nec.com:
 Hi



 I have written a Python utility that performs a certain activity on some
 predefined sets of files.  Here is the outline of what I have written:



 # File Set A

 pathA = ‘pathA’

 fileListA = [‘fileA1.txt’, ‘fileA2.txt’]



 # File Set B

 pathB = ‘pathB’

 fileListB = [‘fileB1.txt’, ‘fileB2.txt’, ‘fileB3.txt’]



 myFunc1(pathA, fileListA)

 myFunc2(pathA, fileListA)



 myFunc1(pathB, fileListB)

 myFunc2(pathB, fileListB)



 I want to add more file sets, so I really want to add the sets to a list and
 iterate over the list, calling myFunc1  myFunc2 for each item.



 My question is: what sort of data structure could I use to organise this,
 given that I want to associate a set of files with each path and that, for
 each set, there is an arbitrary number of files?



 Best regards



 David




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


Hi,
What about a for loop?
paths = [pathA, pathB, pathC]
functions = (myFunc1, myFunc2)
file_lists = [fileListA, fileListB,fileListC]
for path, file_list in zip(paths, file_lists):
for f in functions:
f(path, file_list)

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


Re: Where is 'palindrome' defined?

2015-06-01 Thread David Palao
Hi,
Because palindrome != parlindrome?
Have you read the error message? Did you try to understand it?

Best

2015-06-01 6:46 GMT+02:00 fl rxjw...@gmail.com:
 Hi,

 When I search solution of reverse a string/number, I came across a short
 function online:

 def palindrome(num):
 return str(num) == str(num)[::-1]

 I thought that it is a general function. And with the following variable:

 a
 '1234_'

 parlindrome(a)

 Traceback (most recent call last):
   File pyshell#126, line 1, in module
 parlindrome(a)
 NameError: name 'parlindrome' is not defined


 Then, I find that parlindrome is a special checking mirrored word.
 I use Python 2.7.9. Why does the error message show

 name 'parlindrome' is not defined



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


Re: Where is 'palindrome' defined?

2015-06-01 Thread David Palao
2015-06-01 11:21 GMT+02:00 Marko Rauhamaa ma...@pacujo.net:
 David Palao dpalao.pyt...@gmail.com:

 Because palindrome != parlindrome?
 Have you read the error message? Did you try to understand it?

 When you are starting with any new thing, even the simplest problems
 look baffling. Once you have achieved a few successes, such error
 messages start to make sense.


I didn't intend to be harsh. Sorry if I failed.
Anyway, for me the errors provided by python are mostly very useful.
When I forget to read them, or I'm simply too impatient to try to
understand them, I use to get very hard debugging sessions. The
contrary is often true.
What I tried to emphasize is the importance of paying careful
attention to the error messages. It is a good habit to start doing
this from the beginning.

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


Re: SyntaxError on progress module

2015-05-27 Thread David Palao
2015-05-27 9:30 GMT+02:00 alb al.bas...@gmail.com:
 Hi Mark,
 Mark Lawrence breamore...@yahoo.co.uk wrote:
 []
File 
 /home/debian/repos/2418_IASI-NG/Documents/Tools/tex_tool/venv/local/lib/python3.2/site-packages/progress/bar.py,
  line 48
  empty_fill = u'∙'
^
 SyntaxError: invalid syntax

 []

 Python 3.0 removed the 'u' for unicode in front of strings but due to
 popular demand to ease porting it was reinstated in 3.3.  Strip it away
 and you should be fine to go.

 I'm not particularly comfortable in fiddling with the library source,
 even if the change seems really minor, therefore I guess that I'll
 upgrade to a more recent version of Python/Debian.

 But here I have another question, as a python novice is there really any
 reason for me to use any particular version of Python?

 Should I start directly with the newest? What about 2.7?

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

Hi,
I would recommend to start with a 3.x Python. Perhaps 3.3 or 3.4? If
the version provided by your OS is older, you can always use a virtual
environment. Ask if you don't know about it.

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


Re: Encrypt python files

2015-05-06 Thread David Palao
Hello,
I'm afraid your question is either not well defined (or not well
enough) or wrong for this list, at least as I understand it.
Could you please explain it better?

Best

2015-05-06 8:37 GMT+02:00 Palpandi palpandi...@gmail.com:
 Hi,

 What are the ways to encrypt python files?
 --
 https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2015-04-22 Thread David Palao
Hello,
I can definitely recommend this:
http://norvig.com/21-days.html
Of course, more precise advice would be possible if you provide more
details of what is your background, what you know, and so on.

Best

2015-04-20 17:15 GMT+02:00 Chandra Prashad mishra prasadchandr...@gmail.com:
 sir how can i improve my basic knowledge about programming.can u give me
 some hint...just give me way

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

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


Re: A syntax question

2014-11-10 Thread David Palao
 My crystal ball is currently in for repair and is not expected back in
 the foreseeable future.

Without a crystal ball, this prediction might be not well founded.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ruby instance variable in python

2014-10-06 Thread David Palao
Hello,
If you explain what the ruby code does, I think much more people will
be able to help you. Don't forget, this is a Python list. Not
everybody knows Ruby here.

Best

2014-10-06 12:06 GMT+02:00 roro codeath rorocode...@gmail.com:
 in ruby:

 module M
 def ins_var
 @ins_var ||= nil
 end

 def m
 @ins_var = 'val'
 end

 def m2
 m
 ins_var # = 'val'
 end
 end

 in py:

 # m.py

 # how to def ins_var

 def m:
 # how to set ins_var

 def m2:
 m()
 # how to get ins var

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

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


Python vs C++

2014-08-21 Thread David Palao
Hello,
I consider myself a python programmer, although C++ was one of the
first languages I learned (not really deeply and long time ago).

Now I decided to retake C++, to broaden my view of the business.
However, as I progress in learning C++, I cannot take out of my head
one question

 Why to use C++ instead of python?

It is not ranting against C++. I was/am looking for small-medium
projects to exercise my C++ skills. But I'm interested in a genuine
C++ project: some task where C++ is really THE language (and where
python is actually a bad ab initio choice).
The usual argument in favour of C++ (when comparing to python) is
performance. But I'm convinced that, in general, the right approach is
python-profiling-(extension/numpy/Cython/...). At least for a python
programmer. I might be wrong, though.

This is, perhaps, a bit off-topic, but I really want to know the
thoughts of experienced python programmers on it.

Thanks in advance,

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


Re: Python vs C++

2014-08-21 Thread David Palao
Thank you for the interesting answers.

Just a clarification. Actually for the scope of this question, I
consider C and C++ quite different. At least when they are properly
used (eg, you could use C++ as a better C, but this is not C++ in its
full glory).
In my opinion, if all that you want is performance, coding critical
parts in C or Frotran should be enough. Or even Cython. As far as the
fraction of code that turns out to be critical is relatively small.
But C++ is a monster compared to C. And I realize it requires a huge
amount of time and practice to master it. The question is whether is
it worth as a generic approach or not (*). I tend to think that it
isn't that useful.

Best,

David


(*) as some of you already mentioned, you could need C++ for joining a
specific project, for instance. But that would not imply anything
about how well suited is C++ for that particular project.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Linux distros w/o Python in base installation

2014-08-12 Thread David Palao
2014-08-11 23:36 GMT+02:00 Ned Deily n...@acm.org:
 In article lsb84u$21c$1...@reader1.panix.com,
  Grant Edwards invalid@invalid.invalid wrote:
 Apparently.  Perhaps theres an enable LSB compliance option
 somewhere in the Arch install docs, but I didn't see it...

 Also beware that, unlike most other distributions and contrary to
 recommended practice, Arch has chosen to make Python 3 its default, that
 is, when everything is installed, `python` invokes `python3`, rather
 than `python2`.  So you may need to change shebang lines in scripts, etc.

 https://wiki.archlinux.org/index.php/python

 --
  Ned Deily,
  n...@acm.org

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

Also Gentoo uses Python3 by default for some months now. The positive
side effect for me has been that I started seriously to switch to
python3.

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


Re: how to write list in a file

2014-04-23 Thread David Palao
2014-04-23 9:53 GMT+02:00 Dhananjay dhananjay.c.jo...@gmail.com:
 Hello everyone,

 I am trying hard to write a list to a file as follows:


 def average_ELECT(pwd):
 os.chdir(pwd)
 files = filter(os.path.isfile, os.listdir('./'))
 folders = filter(os.path.isdir, os.listdir('./'))
 eelec = 0.0; evdw = 0.0; EELEC = []; elecutoff = [];
 g = Gnuplot.Gnuplot()
 for f1 in files:
 #   if f1[21:23]=='12':
 if f1[27:29]==sys.argv[1]: # vdw cutoff remains constant; see 2nd
 column of output
 fl1 = open(f1,'r').readlines()
 #   print len(fl1)

 for i in range(1, len(fl1)):
 fl1[i]=fl1[i].split()
 eelec = eelec + float(fl1[i][1])
 evdw = evdw + float(fl1[i][2])
 #print fl1[i][1], fl1[i][2]
 avg_eelec = eelec/40
 avg_evdw = evdw/40
 #   print eelec, evdw
 #   print f1[21:23], f1[27:29], avg_eelec, avg_evdw
 print f1[21:23], f1[27:29], avg_eelec
 #   EELEC.append(avg_eelec); elecutoff.append(float(f1[21:23]))
 eelec=0.0; evde=0.0;
 a = f1[21:23]+' '+f1[27:29]+' '+str(avg_eelec)
 EELEC.append(a)
 print sorted(EELEC)
 with open('EElect_elec12-40_vdwxxx.dat','w') as wr:
 for i in EELEC:
 print i
 wr.write(%s\n % i)
 wr.close()


 The script is printing print sorted(EELEC) as well as print f1[21:23],
 f1[27:29], avg_eelec very well.
 However, for some reason, I neither see any file (expected to see
 EElect_elec12-40_vdwxxx.dat as per the script) generated nor any error
 message.

 Could anyone suggest me correction here.

 Thanking you in advance.

 -- DJ



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


A couple of minor points:
* You don't need wr.close() after the with open(...) as wr: block.
* Are you sure that you are looking in the right directory?
* Why do you need the g = Gnuplot.Gnuplot() line? It looks to me
that you have skipped some things while doing copy and paste?

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


howto check programs and C libraries

2013-10-04 Thread David Palao
Hello,
I'm in charge of preparing a computer room for the practices of
introduction to programming.
One of the tasks is checking that from all the computers in the room
one can execute some programs and link (and compile) against some
libraries.
My first idea was using Autotools (or cmake), but as I'm a big fan of
python, I was thinking how to do that with python, and I don't have a
clear solution yet.
I know that distutils includes the distutils.command.config module,
and I think it could do the job (when properly subclassed).
Do you have a better idea?
Thanks in advance.
Regards,

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