[ANN] Simlified Chinese version of Python 3 Cheat Sheet

2019-10-07 Thread laurent . pointal
Hello,

Thanks to Vivodo Lio (from Beijing, China), the Python 3 cheat Sheet (Mémento 
Python 3) is now available in Simplified Chinese (also already in french, 
english,  deutsche, and hungarian).

See at https://perso.limsi.fr/pointal/python:memento

It is still free to download, transform, adapt… and translate into other 
languages.

L.Pointal.
--
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/

Support the Python Software Foundation:
http://www.python.org/psf/donations/


forcallpy: embed Python, call Python scripts within Fortran programs

2018-09-05 Thread Laurent Pointal
Hello,

Here is an announce for people with main Fortran programs who need to 
call Python scripts and do not want to start another process each time. 
Forcallpy embeds the Python interpreter in your Fortran program and makes 
scalars or one dimensional arrays of numbers easy to transmit between the 
two languages. It automatically install numpy in the Python side (used by 
this library), and support Python multithreading.

Project git repository and bug tracking:

https://sourcesup.renater.fr/projects/forcallpy/

Documentation:

https://forcallpy.readthedocs.io/en/latest/

For an example, here is the Fortran demo program, without comments (more 
details in documentation about values transmission between Python and 
Fortran):

PROGRAM forcallpy_demo
  USE forcallpy
  USE, INTRINSIC :: iso_c_binding, ONLY: c_ptr, c_null_ptr, c_loc
 
  IMPLICIT NONE
  INTEGER :: coderr
  INTEGER :: intres
  INTEGER,DIMENSION(10),TARGET :: tabint;
  DOUBLE PRECISION,DIMENSION(5),TARGET :: tabdbl;
  TYPE(c_ptr),DIMENSION(3) :: tabptr;
  DOUBLE PRECISION,DIMENSION(4),TARGET :: tabres;
 
  tabint(1:10) = (/ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12  /)
  tabdbl(1:5) = (/ 10.1, 10.3, 10.5, 10.7, 10.9 /)
  tabptr(1:3) = (/ c_null_ptr, c_null_ptr , c_null_ptr  /)
  tabres(1:4) = (/ 0.0, 0.0, 0.0, 0.0 /)
  tabptr(2) = c_loc(tabdbl)
 
  CALL pyinit(register_sighandlers=1, print_errors=1, verbosity=0, &
 coderr=coderr)

  CALL pyrun_i4r8('print("result =",3 + 4 *  x)', x=3.6D0)
  CALL pyrun_i4r8('for i in range(3): print("This is a Python loop", i, 
"directly in fortran source.")')
  CALL pyrun_i4r8('import math')
  CALL pyrun_i4r8('print("Pi value is", math.pi)')
  CALL pyrun_i4r8('import sys'//NEW_LINE('a')//'sys.path.insert(0, ".")')
  CALL pyrun_i4r8('import forcallpy_demomodule')
  CALL pyrun_i4r8('print("Doc forcallpy:", forcallpy.__doc__)')
  CALL pyrun_i4r8('print("Namespace forcallpy:", dir(forcallpy)')
  intres = pyfct_i4r8_i4(&
"int(forcallpy_demomodule.a_function(a,b,c,x,av,zv,yw))", &
a=2,b=-4,c=7,x=3.5D+0,av=tabint,zv=tabdbl,yw=tabres)
  WRITE(*,*) "Result =", intres
  WRITE(*,*) "Inout array after:", tabres
  CALL pysub_i4r8("forcallpy_demomodule.a_subroutine(av,zv,p)", &
av=tabint,zv=tabdbl,p=tabptr) 
  WRITE(*,*) "Computing a zero division in Python"
  CALL pysub_i4r8("print(1/0)")
  CALL pyrun_i4r8('forcallpy_demomodule.test_threading()')
  call sleep(10)
  CALL pyterm() 
END PROGRAM forcallpy_demo

--

L.Pointal 
CNRS / LIMSI
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Update to Python 3 Cheat Sheet

2017-01-30 Thread Laurent Pointal via Python-announce-list
Hi,

I updated the cheat sheet on the aesthetic side. Parts bloc and their title 
are now more easily identified with colors (but its nice with B printing 
too).
French and german versions have also been updated.

See https://perso.limsi.fr/pointal/python:memento

A+
L.Pointal.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Update to Python 3 Cheat Sheet

2017-01-28 Thread Laurent Pointal
Hi,

I updated the cheat sheet on the aesthetic side. Parts bloc and their 
title are now more easily identified with colors (but its nice with B 
printing too).
French and german versions have also been updated.

See https://perso.limsi.fr/pointal/python:memento

A+
L.Pointal.
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] German translation of Python 3 Cheat Sheet

2016-09-14 Thread Laurent Pointal
Hello,

The Python 3 Sheet Cheat (Mémento Bases Python 3) has been 
translated into german by StR Martin Putzlocher. Thanks to him.

It can be downloaded on the same page as english and french
versions: https://perso.limsi.fr/pointal/python:memento

A+
L.Pointal.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: logging: getLogger() or getLogger(__name__)?

2016-07-27 Thread Laurent Pointal
Malcolm Greene wrote:

> I've read that best practice for logging is to place the following line
> at the top of all modules:
>  
> logger = getLogger(__name__)
>  
> I'm curious why the following technique wouldn't be a better choice:
>  
> logger = getLogger()
>  
> Are there scenarios that favor one style over another?

With __name__ you will have one logger per source file (module), with 
corresponding filtering possibilities, and organized hierarchically as are 
packages (logging use . to built its loggers hierarchy). 

Without __name__, you have one global default logger.

>  
> Thank you,
> Malcolm

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


Re: an error

2016-07-19 Thread Laurent Pointal
WePlayGames WeEnjoyIt wrote:


>  elif p2==8:
>pygame1.blit(image3,(143,146) <= missing )
>  total+=1
>  fps=40
>  clockfps.tick(fps)
>  pygame.display.update()
> 
> the problem with this is that i get an syntax error at the very end at the
> TOTAL+=1 when i delete this it tells me that there is an error at the
> clockfps.tick(fps) thing what the heck is going on :p

Someone else shows you the error.

When you have a syntax error in a specific line (see printed traceback), it 
is common to have to look at previous lines to identify some open 
parenthesis, brackets, square brackets with missing close one.

A+
Laurent.

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


Re: Touch screen development in Python

2016-07-13 Thread Laurent Pointal
Jahn wrote:

> I was thinking about Python touch screen applications for industrial
> boards( computers).
> If I have a touch screen  with that industrial board, what I must have
> installed to be able to
> write  touch screen applications in Python?

If you go with Kivy (its built for multitouch graphical interactive 
applications, can work on Windows, Linux, MacOSX, Android), see the 
following page for requirements:

https://kivy.org/docs/installation/installation.html

And learning how to use it (see examples).

https://kivy.org/docs/examples/gallery.html

Really, give it a try, even on your mouse controlled interface.

A+
Laurent.

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


Re: Touch screen development in Python

2016-07-11 Thread Laurent Pointal
Jahn wrote:

> Hi ,
> Does anyone use Python for  developping  applications that  work with a
> touch screen?

You should take a look at Kivy: https://kivy.org/

A+
L.Pointal.

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


Re: What the deal with python3.5m.so and python3.5.so ??

2016-07-03 Thread Laurent Pointal
Steven Truppe wrote:

> Hi all,
> 
> can someone tell me the difference between python3.5m.so and python3.5.so
> ??

The 'm' tagged version is for a Python compiled with PyMalloc:

https://www.python.org/dev/peps/pep-3149/

(found it with Blender's bundled Python)

> 
> Tanks in advance,
> Steven Truppe

A+
L.P.

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


Re: I need a pure python module from PyPI without additional packages on my OS.

2016-07-03 Thread Laurent Pointal
Seti Volkylany wrote:

> I heard about cairo, but it required installed on my computer before.

Some precision would be wellcome.

Do you need any pure Python module from PyPI ?

Do you need a "cairo compatible" pure Python module from PyPI ?

A+
L.P.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for opinions: A cross language development tool

2016-06-23 Thread Laurent Pointal
Tal Zion wrote:

> Bridge compiles Python modules into native code, 

What is "native", really microprocessor executable binary ? How do you adapt 
to diversity?

> which requires us to
> support Python *language* features (for, while, class, generators, etc)
> but it reuses CPython's libraries (list, dict, str, etc) 

Hum, "etc" is important here, CPython libraries makes Python power 
("batteries included"). And running such code on client side have 
*important* security concerns… I won't see people allowing automatically 
loaded Python scripts (or their binaries) execution on their system as is 
without a security layer.

> so we don't
> implement those, and it also uses CPython's ast module in order to parse
> Python code. So once we are done supporting all of the language
> features, any Python code should work. 

Supporting features is not only parsing code, it's providing same execution 
semantic. And its a reason it would be more complicated to use exactly same 
execution kernel to run other languages.

> Currently we have quite a few
> language features to implement, but we're working on it =) We're
> targeting Python 3.5.

You seem to start a new, potentially complex project (devil is in details), 
ignoring other works which already did same job:

Apart from ironpython, parrot, jython, already listed, you can look at:
 
Brython to run Python with a JavaScript/ECMAScript engine
http://brython.info/

MicroPython to run Python on small embedded systems
https://micropython.org/

Also look at https://wiki.python.org/moin/WebBrowserProgramming where there 
are many other projects of that kind.

You want Python on the web browser, try to produce asm.js code, you will 
benefit of all work done on JavaScript engines, and of security layers. 
But… you will have to rewrite the batteries into pure Python mixed with 
asm.js code, this is huge work.

Bon courage.

A+
L.Pointal.

> 
> Tal
> 
> On 06/21/2016 08:36 PM, Chris Angelico wrote:
>> On Wed, Jun 22, 2016 at 12:06 AM, Tal Zion  wrote:
>>> * Bridge makes Python faster: Python code compiled through Bridge is
>>> compiled to native code. Because we are leveraging LLVM's many
>>> optimizations, Python code will run faster than ever.
>> Can you run *any* Python program through Bridge? Absolutely anything?
>> Can you guarantee language compatibility?
>>
>> And if you can - what version of Python are you compatible with?
>>
>> ChrisA

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


Re: A tough one: split on word length?

2016-05-16 Thread Laurent Pointal
DFS wrote:

> Have:
> '584323 Fri 13 May 2016 17:37:01 - (UTC) 584324 Fri 13 May 2016
> 13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016
> 13:47:28 -0400'
> 
> Want:
> [('584323', 'Fri 13 May 2016 17:37:01 - (UTC)'),
>('584324', 'Fri 13 May 2016 13:44:40 -0400'),
>('584325', '13 May 2016 17:45:25 GMT'),
>('584326', 'Fri 13 May 2016 13:47:28 -0400')]
> 
> 
> Or maybe split() on space, then run through and add words of 6+ numbers
> to the list, then recombine everything until you hit the next group of
> 6+ numbers, and so on?
> 
> The data is guaranteed to contain those 6+ groups of numbers.

Test with regexp under Python3

>>> import re
>>> s = '584323 Fri 13 May 2016 17:37:01 - (UTC) 584324 Fri 13 May 2016 
13:44:40 -0400 584325 13 May 2016 17:45:25 GMT 584326 Fri 13 May 2016 
13:47:28 -0400'
>>> re.split("(\d{6})(.*?)", s)
['', '584323', '', ' Fri 13 May 2016 17:37:01 - (UTC) ', '584324', '', ' 
Fri 13 May 2016 13:44:40 -0400 ', '584325', '', ' 13 May 2016 17:45:25 GMT 
', '584326', '', ' Fri 13 May 2016 13:47:28 -0400']


Dismiss empty items and strip whitespaces at begin or end of string, and 
that's done.

A+
Laurent.
Note: re experts will provide a cleaner solution.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Performance with and without the garbage collector

2016-05-14 Thread Laurent Pointal
Steven D'Aprano wrote:

> Just for kicks, I've been playing around with running code snippets with
> and without the garbage collector enabled, looking to see if it will make
> any obvious difference to performance.
> 
> So far, I haven't found any.
> 
> For instance, I tried:
> 
> a = [i**3 for i in range(200)]
> del a[:]
> 
> thinking that garbage collecting almost two million ints would surely show
> some performance difference, but it doesn't.
> 
> Is anyone able to demonstrate a replicable performance impact due to
> garbage collection?

As CPython objects are reference-counted, you may see the GC in action if 
you setup some cycles in your script (here, your two million ints are 
removed — except for some small ints which remain alive for internal 
optimization).

>>> a = [i**3 for i in range(200)]
>>> b = [a]
>>> a.append(b)

>>> del a# a remain referenced in b list
>>> del b# b remain referenced in a list

Now, how to test for performance impact…

A+
Laurent.

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


Re: After a year using Node.js, the prodigal son returns

2016-05-07 Thread Laurent Pointal
Chris Angelico wrote:

> On Fri, May 6, 2016 at 11:45 PM, Grant Edwards
>  wrote:
>>> JavaScript is terrible. Really, really bad. And because of that, it
>>> has the potential to sweep the world.
>>
>> If your reasoning is correct, it'll never be able to overtake PHP.
>>
>> I've never written anything over a hundred or two lines in JavaScript,
>> but for small stuff it seems OK -- though as others have noted there
>> are some oddly missing batteries that result in use of a lot of small
>> external libraries for things that any C, PHP, or Python user would
>> have expected to be in the standard library.
> 
> Except that it's pretty easy to switch out PHP for Python, or anything
> else. JavaScript is what it is because it's hard to just use a
> different language.

Maybe Pyhton, using Brython (http://www.brython.info/)

(ok, its translated into JavaScript for execution in the web browser… maybe 
somedays it will be asmsjs)

A+
Laurent.

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


Re: from a module return a class

2016-03-19 Thread Laurent Pointal
John Gordon wrote:

> In 
> kevind0...@gmail.com writes:
> 
>> ##  prompt the user for a User name a& pWord
>> user_pword = promptUser_PWord()
> 
>> I get the error
>>   File "H:\dev\eclipse\workspace\genXls\src\genXls\promptUser_PWord.py",
>>   line 58
>> return user_pword
>> SyntaxError: 'return' outside function
> 
> Show us the complete definition of promptUser_PWord().

AFAIU It looks to be the module…

> 

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


Re: from a module return a class

2016-03-19 Thread Laurent Pointal
kevind0...@gmail.com wrote:

> Hello:
> 
> Working with python 2.7.
> 
> I have a module promptUser_PWord  that will prompt a user for their user
> name and pword.  Works fine stand alone.
> I also have a module, genXLS that does a bunch of processing it has worked
> fine for months.  And a class Unamepword define as follows: class
> Unamepword:
> ## 
> ## class to hold user name and pWord for Database
> uName = None
> pWord = None
> def __init__(self, uStr, pStr):
> self.uName = uStr
> self.pWord = pStr
> 
> There are scenarios where running genXLS requires the user to be prompted
> for their user name and password.
> 
> The final line of promptUser_PWord are:
> user_pword =  Unamepword(dbUser, pWord)
> return user_pword
> 
> 
> And in genXLS I have
> ##  prompt the user for a User name a& pWord
> user_pword = promptUser_PWord()
> 
> I get the error
>   File "H:\dev\eclipse\workspace\genXls\src\genXls\promptUser_PWord.py",
>   line 58
> return user_pword
> SyntaxError: 'return' outside function
> 
> 
> Here is my complete newbee question:
>How do I stich these pieces together so the user will be prompted and
>the values (contained in the class Unamepword) will be passed back to
>genXLS ?

Just… define a function (SyntaxError: 'return' outside function).


> The final line of promptUser_PWord become:

user_pword =  Unamepword(dbUser, pWord)
def get_user_pword():
 return user_pword

and call get_user_pword() from within genXLS:

user_pword = promptUser_PWord.get_user_pword()

A+
Laurent
> 
> Many thanks for your attention to this matter.
> 
> KD

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


Re: from a module return a class

2016-03-18 Thread Laurent Pointal
John Gordon wrote:

> In <56eaecc8$0$3658$426a7...@news.free.fr> Laurent Pointal
> <laurent.poin...@free.fr> writes:
> 
>> >> user_pword = promptUser_PWord()
>> > 
>> > Show us the complete definition of promptUser_PWord().
> 
>> AFAIU It looks to be the module…
> 
> If it were a module, it wouldn't be callable.  It has to be a function
> or a class.

So the error: SyntaxError: 'return' outside function





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


Re: ouvrir python

2016-01-06 Thread Laurent Pointal
Vincent Vande Vyvre wrote:

> Le 04/01/2016 10:10, Jacques Rosier a écrit :
>> J’ai téléchargé Python 351. Il est dans la liste des applications de mon
>> ordi (Lenovo; Windows 10). Mais impossible de l’ouvrir. Que faire?
> Cette liste de diffusion est anglophone, je te recommande de poster sur
> ce forum:
> 
> http://www.developpez.net/forums/f96/autres-langages/python-zope/
> 
> Vincent

Il y a un groupe francophone sur Usenet: fr.comp.lang.python
There is a french Usenet group: fr.comp.lang.python


A+
Laurent.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bug in Python 3.5.1

2015-12-24 Thread Laurent Pointal
Hello,

nisthesec...@verizon.net wrote:

> Dear Sir,
>I downloaded and installed Python 3.5.1 in Windows 10.
>The pip command was not part of it.
>In the future, can you kindly include numpy, scipy, and pygame as part
>of the Python release?
>I am a teacher trying to teach Python to my students.
>To get a working version of Python going is extremely tedious.
>Kind Regards,
>Nick Srinivasan

IMHO There is no chance that all these packages be distributed with Python 
in the standard libs.

Near the third party distributions already signaled (Anaconda, but there is 
also Pythonxy and others), for students you can take a look a Pyzo, which 
integrate an IDE with some common scientific packages.

http://www.pyzo.org/

It include following packages:

http://www.pyzo.org/packages.html#packages

But, no pygame… (maybe it can be installed via conda as indicated on this 
page - you may test under common student OS).

A+
Laurent.

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


[ANN] Python 3 Cheat Sheet v2.0

2015-11-02 Thread Laurent Pointal via Python-announce-list
Hello,

I just updated my one recto-verso sheet Python 3 Cheat Sheet

https://perso.limsi.fr/pointal/python:memento

Many modifications and enhancements (bytes, literal ints, assignment 
complement, conversion tricks, cleaning sequences indexing, complement on 
boolean logic, modules import, exceptions, small organization charts for flow 
control, complement on list dict set methods, string methods, complment on 
files).

Still available in english and in french.

As the document become more dense, old version is kept online if prefered.

A+
L.Pointal.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: [ANN] Python 3 Cheat Sheet v2.0

2015-10-31 Thread Laurent Pointal
Le Sat, 31 Oct 2015 12:16:08 +1100, Steven D'Aprano a écrit :

> On Sat, 31 Oct 2015 06:56 am, Laurent Pointal wrote:
>> https://perso.limsi.fr/pointal/python:memento
> 
> 
> Very nice! Thank you!
> 
> 
> Some small typos in the English version:


Thanks for your comments.

Q? Did you read version 1.2.2 or version 2.0 ?

Some typos propagate between versions (I fixed the "litteral"s), but I 
modified some parts (ex. for while loops the warning become "beware of 
infinite loops !" [I still have a space to remove before ! french/english 
typo differences]


> Some errors of fact:
> 
> Page 2, Generator of int sequences:
> 
> "range returns a «generator»"
> 
> This is not correct, `range` returns a lazy immutable sequence where the
> values are constructed as needed, not in advance.
> 
> https://docs.python.org/3/library/functions.html#func-range

Now (v2.0) range is presented as an integer sequence - without detail, 
dont know if beginners understand 'lasy' in our meaning.
 
> Page 2, Files:
> 
> "text file → read/write only strings, convert from/to required type"
> 
> While that is true for text files, it implies that open() always uses
> text files. This is not correct. You can open binary files too, and
> read/write raw bytes:
> 
> https://docs.python.org/3/library/functions.html#open
> https://docs.python.org/3/glossary.html#term-binary-file

Our students mainly work with text files, they have to convert all other 
values to str before writing. Its hard to be more complete within the 
remaining space. I'll see if I can add a small sentence about "text by 
default but can be binary with bytes content"

Thanks.
A+
Laurent.

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


Re: Idiosyncratic python

2015-09-24 Thread Laurent Pointal
wxjmfa...@gmail.com wrote:

> Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a écrit :
>> 
>> 
>> What are your favorite not-wrong-just-weird Python moments?
>> 
>> 
> Showing how to make Python 3.5.0 crash by
> just using an "é", U+00E9.

Like this ?


Python 3.5.0 (default, Sep 24 2015, 19:47:57) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "\u00E9"
>>> print(s)
é



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


[ANN] treetaggerwrapper V2 - Wrapper for TreeTagger

2015-09-22 Thread Laurent Pointal
Hello,

I'm please to annouce the update of Python treetaggerwrapper module.
It wraps the language independent part-of-speech tagger TreeTagger of Helmut 
Schmid in an easy to use tool, efficient to process large data corpus.

It is now Python2 and Python3 compatible, has defaults to utf-8 encoding, 
tries to autodetect treetagger installation directory, provides 
multiprocessing support, is pip installable…

Note: this V2 need adaptation in code based on previous version, see docs.

PyPI: https://pypi.python.org/pypi/treetaggerwrapper/2.0.6
(bug with https://pypi.python.org/pypi/treetaggerwrapper/ … ?)
Doc: http://treetaggerwrapper.readthedocs.org/
Project: https://perso.limsi.fr/pointal/dev:treetaggerwrapper

About TreeTagger: http://www.cis.uni-muenchen.de/~schmid/tools/TreeTagger/

A+
Laurent Pointal

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] treetaggerwrapper V2 - Wrapper for TreeTagger

2015-09-22 Thread Laurent Pointal
Hello,

I'm please to annouce the update of Python treetaggerwrapper module.
It wraps the language independent part-of-speech tagger TreeTagger of Helmut 
Schmid in an easy to use tool, efficient to process large data corpus.

It is now Python2 and Python3 compatible, has defaults to utf-8 encoding, 
tries to autodetect treetagger installation directory, provides 
multiprocessing support, is pip installable…

Note: this V2 need adaptation in code based on previous version, see docs.

PyPI: https://pypi.python.org/pypi/treetaggerwrapper/2.0.6
(bug with https://pypi.python.org/pypi/treetaggerwrapper/ … ?)
Doc: http://treetaggerwrapper.readthedocs.org/
Project: https://perso.limsi.fr/pointal/dev:treetaggerwrapper

About TreeTagger: http://www.cis.uni-muenchen.de/~schmid/tools/TreeTagger/

A+
Laurent Pointal
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] bbrecorder - a black box handler for logs

2015-09-21 Thread Laurent Pointal
Hello,

I'm please to annouce the availability of bbrecorder module and its 
BlackBoxHandler logging handler for Python 3 (tested on 3.4).

This logging handler manage caching of last N log records in memory until they 
are needed — and then generate them using standard common Python logging 
handlers.

It allows to enable a log level generating many log records, and only get last 
records when a crisis situation occur (typically in an exception handler).

Note: in case of hard Python crash (core dump), cached logs are lost ! — see 
important note in doc.

PyPI: https://pypi.python.org/pypi/bbrecorder/
Docs: http://bbrecorder.readthedocs.org/
Project: https://perso.limsi.fr/pointal/dev:bbrecorder

A+
L.Pointal.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] floatrange - a range() for floats

2015-09-21 Thread Laurent Pointal
Hello,

I'm please to publish a small utility module allowing to produce float based 
range sequences, with I hope a complete range-like interface. Because of 
floating point arithmetic, floatrange allows to specify a precision for 
"equality" when working with operators like 'in'.

It is Python2 and Python3 compatible.

PyPI: https://pypi.python.org/pypi/floatrange/
Doc: http://floatrange.readthedocs.org/
Project: https://perso.limsi.fr/pointal/python:floatrange

Float arithmetic: https://docs.python.org/3/tutorial/floatingpoint.html

A+
Laurent Pointal.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] osc4py3 - Open Sound Control package for Python 3

2015-09-21 Thread Laurent Pointal
Hello,

I'm please to annouce the availability of osc4py3 package, yet another 
implementation of the OSC protocol (packets manipulations, transport, messages 
routing).

* encoding/decoding of OSC message packets (including bundles)
* routing of incoming messages based on selector regexps or globbing
* timed messages with possible delay period
* named client/server for sending/subscribing
* different scheduling models (single process, totally multithread, only
   multithread for communications)
* extra processing of packets (hack points to encrypt/decrypt, sign/verify…)


PyPI: https://pypi.python.org/pypi/osc4py3
Doc: http://osc4py3.readthedocs.org/
Project: https://perso.limsi.fr/pointal/dev:osc4py3

About OSC: opensoundcontrol.org

A+
Laurent Pointal
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] Python TreeTagger wrapper updated to 2.2.1

2015-08-25 Thread Laurent Pointal
Hello,

for natural language processing, treetaggerwrapper, the Python wrapper for 
language independant part-of-speech statistical tagger TreeTagger from
H.Schmid is now available in version 2.2.1.

It is available on PyPI: 

https://pypi.python.org/pypi

And the doc is on Read the Docs:

http://treetaggerwrapper.readthedocs.org/

The source has been globally reworked, some modifications make it partially 
incompatible with 1.0 module. It should be more easy to use (tries to 
autodetect TreeTagger installation directory). It now works with Python2 
and Python3 with same source. 
I also added a treetaggerpoll module for use in a multiprocessing
context.

For important (and incompatible) modifications, see
http://treetaggerwrapper.readthedocs.org/en/latest/#important-modifications-notes
 

A+
Laurent Pointal laurent.poin...@limsi.fr

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


Re: [ANN] Python TreeTagger wrapper updated to 2.2.1

2015-08-25 Thread Laurent Pointal
Laurent Pointal wrote:

 It is available on PyPI:

… incomplete URL…

Here: https://pypi.python.org/pypi/treetaggerwrapper/


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


Re: Check if dictionary empty with == {}

2015-08-20 Thread Laurent Pointal
Anton wrote:

 Probably a silly question.
 Let's say I have a dictionary mydict and I need to test if a dictionary is
 empty.
 
 I would use
 
 if not mydict:
 do something
 
 But I just came across a line of code like:
 
 if mydict == {}:
 do something
 
 which seems odd to me, but maybe there is a valid use case, thus I decided
 to ask the community.
 
 Thanks.

You can also use:

if len(mydict) == 0:
do something

The form 'if not mydict:' is AMA the more pythonic, but it may be a source 
of question for beginners (what is the boolean meaning of a dictionnary…).

A+
Laurent.

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


Re: Regular expression and substitution, unexpected duplication

2015-08-19 Thread Laurent Pointal
MRAB wrote:

 On 2015-08-18 22:42, Laurent Pointal wrote:
 Hello,
zip
 ellipfind_re = re.compile(r((?=\.\.\.)|…), re.IGNORECASE|re.VERBOSE)
 ellipfind_re.sub(' ... ',
 C'est un essai... avec différents caractères… pour voir.)

 (?=...) is a lookahead; a non-capture group is (?:...).
 
 The regex should be r((?:\.\.\.)|…), which can be simplified to just
 r\.\.\.|… for your use-case. (You don't need the
 re.IGNORECASE|re.VERBOSE either!)

Thanks,

I made same mistake in another place, but dont see it here.

A+
Laurent.


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


Regular expression and substitution, unexpected duplication

2015-08-18 Thread Laurent Pointal
Hello,

I want to make a replacement in a string, to ensure that ellipsis are 
surrounded by spaces (this is not a typographycal problem, but a preparation 
for late text chunking).

I tried with regular expressions and the SRE_Pattern.sub() method, but I 
have an unexpected duplication of the replacement pattern:


The code:

ellipfind_re = re.compile(r((?=\.\.\.)|…), re.IGNORECASE|re.VERBOSE)
ellipfind_re.sub(' ... ', 
   C'est un essai... avec différents caractères… pour voir.)

And I retrieve:

C'est un essai ... ... avec différents caractères ...  pour voir.
^^^

I tested with/without group capture, same result.

My Python version:
Python 3.4.3 (default, Mar 26 2015, 22:03:40) 
[GCC 4.9.2] on linux

Any idea ?

Thanks.
Laurent.

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


Re: Who uses IDLE -- please answer if you ever do, know, or teach

2015-08-09 Thread Laurent Pointal
random...@fastmail.us wrote:

 On Sat, Aug 8, 2015, at 13:59, Laurent Pointal wrote:
  Level?
 
 Graduate (post-Bac in france)
 
 Yours or your students?

My students.

 
  1. Are you
  grade school (1=12)?
 
 (sorry, I dont know correspondance in france)
 
 Grade 12 refers to 17-18 year old students, each grade is one year.

Ok, students are at grade 12 (some at 13 after a failure in another cursus).

  undergraduate (Freshman-Senior)?
  post-graduate (from whatever)?
 
 I'm senior developer.
 
 Freshman, Sophomore, Junior, and Senior conventionally refer to each of
 the years of a conventional four-year bachelor's degree at a university
 (Also to grades 9-12 in high school, but in context that seems not to be
 what's meant here).

Oups, students are mainly beginners (but some algorithmic is being 
introduced in their previous pre-bachelor schools years, so we may see more 
experienced students).

The choice of IDLE is related to its standard installation with Python (at 
least on Windows, and easily available on Linux / MacOSX).
But, would appreciate some enhancements as seen in discussions (ex. typical 
example is line numbering).

A+
Laurent.


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


Re: Who uses IDLE -- please answer if you ever do, know, or teach

2015-08-08 Thread Laurent Pointal
Terry Reedy wrote:

 There have been discussions, such as today on Idle-sig , about who uses
 Idle and who we should design it for.  If you use Idle in any way, or
 know of or teach classes using Idle, please answer as many of the
 questions below as you are willing, and as are appropriate

I think they take a look at idlex
http://idlex.sourceforge.net/

 Private answers are welcome. They will be deleted as soon as they are
 tallied (without names).
 
 I realized that this list is a biased sample of the universe of people
 who have studied Python at least, say, a month.  But biased data should
 be better than my current vague impressions.
 
 0. Classes where Idle is used:
 Where?

IUT Orsay, Mesures Physiques, for teaching Python as programming language.

 Level?

Graduate (post-Bac in france)

 Idle users:
 
 1. Are you
 grade school (1=12)?

(sorry, I dont know correspondance in france)

 undergraduate (Freshman-Senior)?
 post-graduate (from whatever)?

I'm senior developer.

 2. Are you
 beginner (1st class, maybe 2nd depending on intensity of first)?
 post-beginner?

Post-beginner.

 3. With respect to programming, are you
 amateur (unpaid)
 professional (paid for programming)

Pro.


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


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Laurent Pointal
Simon Evans wrote:

zip
 -
 with open(C:\Beautiful Soup\ecologicalpyramid.html,r) as

You seem to run Python under Windows.

You have to take care of escape mechanism beyond \ char in string literals 
(see Python docs). 

By chance, \B and \e are not recognized as escape sequences, so they are 
left as is. But \a \b \f \n \r \t \v \x  will be processed differently

Double \ in your string:
C:\\Beautiful Soup\\ecologicalpyramid.html

Or use a raw string by prepending a r to disable escape sequences:
rC:\Beautiful Soup\ecologicalpyramid.html


zip

A+
Laurent.

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


Re: Trying to import numpy

2015-07-07 Thread Laurent Pointal
ryguy7272 wrote:

 I'm trying to use numpy.  I get this error:
 import numpy as np
 
 Traceback (most recent call last):
   File pyshell#1, line 1, in module
 import numpy as np
 ImportError: No module named numpy
 
 
 
 I followed the instructions here.
 https://pip.pypa.io/en/latest/installing.html

…download numpy installer from official site

http://www.scipy.org/scipylib/download.html

== http://sourceforge.net/projects/numpy/files/NumPy/1.9.2/

Choose the installer version for your Python2.7:

== 
http://sourceforge.net/projects/numpy/files/NumPy/1.9.2/numpy-1.9.2-win32-superpack-python2.7.exe/download

And install it with the installer.

zip remaining speech

A+
Laurent.

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


Re: Bug in floating point multiplication

2015-07-02 Thread Laurent Pointal
Steven D'Aprano wrote:

 Despite the title, this is not one of the usual Why can't Python do
 maths? bug reports.
 
 Can anyone reproduce this behaviour? If so, please reply with the version
 of Python and your operating system. Printing sys.version will probably
 do.
zip

On Kubuntu 15.04, it works.

Python 3.4.3 (default, Mar 26 2015, 22:03:40) 
[GCC 4.9.2] on linux
Type help, copyright, credits or license for more information.
 x = 1 - 1/2**53
 assert x == 0.
 for i in range(1, 100):
... if int(i*x) == i:
... print(i); break
... 
 

A+
Laurent.

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


Re: HOPE: A Python just-in-time compiler for astrophysical computations

2015-06-23 Thread Laurent Pointal
Mark Lawrence wrote:

 Another beasty I've just stumbled across which you may find interesting
 http://www.sciencedirect.com/science/article/pii/S2213133714000687
 
Why use a JIT complation when you could use some C++ generation then 
compilation as Python module, like with Pythran ?

https://github.com/serge-sans-paille/pythran

For heavy computing, you may loose some time before running computation, to 
have (generate) the right tool, then do the job with real bonus.

…
A+
Laurent.

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


Re: PYTHON QUESTION

2015-06-14 Thread Laurent Pointal
adebayo.abra...@gmail.com wrote his student exercise as raw text:

 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.

One link to help you: http://www.catb.org/esr/faqs/smart-questions.html

You have just to add the Python syntax for functions declaration and return 
value around your expressions (writing let as an exercise)… just care of a 
small difference between Python2 et Python3 with the division operator, 
which may makes you discover a tricky issue with integers manipulation 
(common to many programming languages).

A+

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


Re: should self be changed?

2015-05-26 Thread Laurent Pointal
zipher wrote:

 Would it be prudent to rid the long-standing argument (pun unintended)
 about self and the ulterior spellings of it, by changing it into a symbol
 rather than a name?
 
 Something like:
 
 class MyClass(object):
 
 def __init__(@):
 @.dummy = None

Just seeing the Python3.5 announce with @ used as matrix multiplication 
operator ;-)

 OR, even better, getting *rid of it* in the parameter list, so it stops
 confusing people about how many parameters a method needs, and transform
 it into a true *operator*.

Self is not an operator, its the target object as first parameter. And with 
Python you can call some methods directly using theclass.themethod(objet, 
param1, param2).

 class MyClass(object):
 
 def __init__(): #takes no arguments!
 @.dummy = None  #the @ invokes the class object's dictionary
 
 That would seem to be a nice solution to the problem, really.  It doesn't
 become PERLish because you've made it into a genuine operator -- self
 was always a non-variable that looked like a variable and hence created an
 itch that couldn't be scratched.

«Explicit is better than implicit»

I think that googling for that idea you will find other people already 
proposing it (I've seen propositions to directly remove part before the dot 
like this: .dummy = None). Just read it.

 Anyone else have any thoughts?

IMHO Zero chance that it be adopted.

A+
Laurent.

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


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-18 Thread Laurent Pointal
Aditya Raj Bhatt wrote:

 I always do single line comments with # but just for the sake of it I
 tried it with ''' ''' and it gives me a syntax error.
 
 In both the interpreter, and the source code text file, doing -
 
 a = 5 '''a comment'''
 
 results in a syntax error, with the very last quote at the end of the
 line highlighted in red. Of course, if I do -
 
 a = 5 #'''a comment'''
zip
 Can someone also provide a sort of a 'guide' to triple-quoted comments
 in general?

A triple ' or  string is a Python string, allowing line-return in string.

If it is in an expression (like a = 5 '''a comment'''), then it must be a 
valid expression (and here it is not).

You can have an expression alone, with no stored result (ie. no assignment 
to a name), and this is how are used triple quoted strings as comments.

a = 5
a comment

Take care of indent:

def f(x):
a = 5
an correctly indented expression to be
inside the function
return a * x

A+
Laurent.

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


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-18 Thread Laurent Pointal
Aditya Raj Bhatt wrote:

 On Wednesday, March 18, 2015 at 1:04:39 PM UTC-5, Laurent Pointal wrote:
  Can someone also provide a sort of a 'guide' to triple-quoted
 comments
  in general?
 
 A triple ' or  string is a Python string, allowing line-return in
 string.
 
 What do you mean by line-return in string? Is it newline? Does it mean I
 can write -
 
 '''first part
 second part'''
 
 ?

Yes.

 If it is in an expression (like a = 5 '''a comment'''), then it must
 be a
 valid expression (and here it is not).
 
 What is not a valid expression here?

What do you expect as result of this combination of an integer with a 
string?

 a = 5 '''a comment'''
  File stdin, line 1
a = 5 '''a comment'''
^
SyntaxError: invalid syntax

You may use an *, and you buid a valid expression with a result

 a = 5 * '''a comment'''

But… this may not be the value you wanted for a variable.

 a
'a commenta commenta commenta commenta comment'

So, a string is really not a comment, even if triple quote strings can be 
used alone to store multi-line comments.

A+
Laurent.

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


Re: A simple single line, triple-quoted comment is giving syntax error. Why?

2015-03-18 Thread Laurent Pointal
Laurent Pointal wrote:

(oups)
 Take care of indent:
 
 def f(x):
 a = 5
 an correctly indented expression to be
 inside the function
 return a * x

Here only the first indent of  at beginning of the string to be aligned 
to function bloc is important, remaining content of the string can be 
indented or not.



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


[Annonce] Une introduction à Python 3 - nouvelle version

2015-01-18 Thread Laurent Pointal
[updated book in french]

Bonjour,

L'ouvrage d'introduction à la programmation avec Python3 de B.Cordeau et 
L.Pointal a été mis à jour en version 1.618. Outre des améliorations dans la 
mise en page, les modifications suivantes ont été réalisées:

* Tous les dessins ont été refaits en utilisant le module LaTeX TikZ
* Changement de la présentation des scripts et codes interprétés Python
* Paragraphe 5.2.1 : corrections paramètres/arguments
* Ajout, paragraphe 6, d'une partie “Python scientifique”
* Ajout, paragraphe 8.3.4, d'un exemple d'interface graphique
* Ajout, paragraphe 9.1.4, de “La récursivité terminale”
* Quelques mots, paragraphe 9.2.3, sur le “duck tiping” et les annotations
* Réécriture de l'annexe C : “Jeux de caractères et encodage”
* La table des matières détaillée est déplacée en fin de document
* Un “Sommaire” est ajouté en début de document
* Déplacement du glossaire en fin de document et ajout de liens aux entrées
* Ajout de l'Abrégé Dense
* Et aussi tout plein d'améliorations et de corrections typos

L'ouvrage est distribué suivant la licence Creative Commons BY-NC-SA-3.0. 
Il est disponible en version PDF, avec ses sources, sur la page: 
http://perso.limsi.fr/pointal/python:courspython3

Bonne lecture.

B.Cordeau  L.Pointal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help understanding list operatoins inside functions in python 3

2015-01-13 Thread Laurent Pointal
Hello,

stephen.bou...@gmail.com wrote:

 I'm a bit confused why in the second case x is not [1,2,3]:
 
 x = []
 
 def y():
 x.append(1)
 
 def z():
 x = [1,2,3]

Here x is a local, so global x is not modified.
If you want to modify gobal x, write:
def z():
global x
x = [1,2,3]

You can read the Python FAQ about global/local rules:

https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python

Or Dive Into Python

http://www.diveintopython.net/html_processing/locals_and_globals.html

(and for your problem, its the same with Python2 and Python3)

Or…

A+
Laurent.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: dynamic values in yaml

2014-08-20 Thread Laurent Pointal
raphi...@gmail.com wrote:

 Note that in my example the content to be inserted is not the result 
of a
 variable substitution, but the result of a call to a function. format
 doesn't seem to work in this case. And jinja2 doesn't seem to provide 
a
 straight forward solution either
 
 Thx

Yoy may try it, setup an environment (dictionnary) with 'time' mapped 
to the time module, and render the template using this environment. 
Normally Jinja2 manage namespaces and function call.

Your template would be:

filename: /tmp/backup_{{ time.strftime('%Y-%m-%d') }}.tgz

And the environment for rendering simply:

import time
env = { time: time }

http://jinja.pocoo.org/docs/templates/#other-operators




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


Re: Python in financial services

2014-08-19 Thread Laurent Pointal
wxjmfa...@gmail.com wrote:

 I recommend to toy intensively with the 'EURO SIGN' in
 strings manipulations.
 
 Py3: It may luckily work, Python may crash or fails (it raises
 unicode errors on valid string!).
 
 Py2: It is safer and solid. There is however a subtility. 3rd
 party tools may consider the Euro as byte or as unicode and/or
 are missinterpreting it, leading to a huge missmatch.
 
 Example: IDLE
 
 print 'EURO' * 10
 EURO  EURO  EURO  EURO  EURO  EURO  EURO  EURO  EURO  EURO
 print u'EURO' * 10
   
 # result: nothing!
 

What version of Python do you use ?

With IDLE:

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type copyright, credits or license() for more information.
 print(€*10)
€€
 

With IDLE and Python 2.7, there seem to be an encoding problem:

 s = u€*10
  import sys
 sys.stdout.encoding
'utf-8'
 print s.encode(utf-8)
€€€€€€€€€€
 print s.encode(latin1)
€€

But with python2 on console, it works nicely:

laurent@litchi:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type help, copyright, credits or license for more 
information.
 s = u'€'
 s*10
u'\u20ac\u20ac\u20ac\u20ac\u20ac\u20ac\u20ac\u20ac\u20ac\u20ac'
 print s*10
€€

 This is not specific to the Euro. I let as an
 exercise to *understand* which chars are suffering
 from this issue. (Py2 and Py3)
 
 jmf
 
 PS Go, Ruby, C#, TeX (unicode engines): never meet a problem.

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


Re: Begginer in python trying to load a .dll

2014-08-19 Thread Laurent Pointal
c1234 py wrote:

 This appear in the terminal:
 
 
 runfile('C://Python Scripts')
   File C:\\sitecustomize.py, line 585, in runfile
 execfile(filename, namespace)
   File C://Sin título 38.py, line 19, in module
 hllApi = hllApiProto ((HLLAPI, hllDll), hllApiParams)
 AttributeError: function 'HLLAPI' not found
 Traceback (most recent call last):
   File stdin, line 1, in module

So you must find the (exact) name(s) exported by the DLL.

On Linux ther is objdump.

On Windows there is dumpbin
http://msdn.microsoft.com/en-us/library/c1h23y6c%28v=vs.100%29.aspx

On Windows, google also found this graphical tool:
http://www.dependencywalker.com/

A+

PS. If you have a C header file, it may be more easy to correctly build 
the ctype mapping (and if its not too big and filled of private 
property code, show it).

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


Re: dynamic values in yaml

2014-08-19 Thread Laurent Pointal
raphi...@gmail.com wrote:

 Hi,
 
 I'm using pyyaml, and need some values in a yaml files to be dynamic, 
for
 example somethin like:
 
   filename: /tmp/backup_{% time.strftime('%Y-%m-%d') }.tgz
 
 Is there a simple way to achieve this? (Eg with a templating system 
that
 would first handle the template parts from the yaml file)
 
 Thanks

I used jinja2 templating system to build (render) the yaml string 
representation before processing it with yaml.

But for a simple use, maybe a direct keyword replacement is easier (but 
gives less control in the template, more in the code).

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


RE: Controlling buffer alignment in file.read()

2014-03-22 Thread Laurent Pointal
Haralanov, Mitko wrote:

 For control at that level you'd be better off using
 direct system calls, i.e. os.open() and os.read(),
 then you can read exacty the number of bytes you want.
 
 
 The problem is not controlling the number of bytes read. That part seems
 to be working. The issue is that the buffer into which the data is placed
 needs to be of certain alignment (8byte-aligned). Python does not seem to
 have a way that allows me to control that.
 
 Thanks,
 - Mitko

Did you try to set buffering parameter to 0 (unbuffered) ?

Eventually going to os.open() which map tp low level (eventually followed by 
an os.fdopen())

http://docs.python.org/2/library/os.html#os.open

A+
Laurent.

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


Re: What are the kinds of software that are not advisable to be developed using Python?

2014-02-22 Thread Laurent Pointal
Chris Angelico wrote:


 Heavy computation might be unideal in Python, but if you can grunge it
 into NumPy operations, that won't be a problem.

May take a look to Pythran too, which generate C++ code from (limited subset 
of) Python code, usable as a Python compiled module or as standalone C++.

https://github.com/serge-sans-paille/pythran

A+
Laurent.

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


Re: decimal numbers

2014-02-15 Thread Laurent Pointal
luke.gee...@gmail.com wrote:

 hello,
 i have been working on a python resistor calculator to let my class show
 what you can do with python. now i have a script that makes the more
 speekable value of the resistance (res)
 
 #if len(str(res))  9:
 #  res2 = res / 10
 #  print de weerstand is %s,%s giga ohms % (res2)
 #elif len(str(res))  6:
 #  res2 = res / 100
 #  print de weerstand is %s,%s Mega ohm % (res2)
 #elif len(str(res))  3:
 #  res2 = res / 1000
 #  print de weerstand is, res2,kilo ohm
 #elif len(str(res))  4:
 #  res2 = res
 #  print de weerstand is, res2,ohm
 
 i commented it because it doesn't work (yet), when i have a resistance of
 9.9 Giga ohms it says it is 9 giga ohms. it seems to work with natural
 number, anyway of using decimals insted so that it says : the resistance
 is 9.9 Giga Ohms instead of 9 ?

Seem you are using Python2, if res is an integer the division by an integer 
values produce an integer result (changed in Python3), so you loose the 
decimal part.

Try dividing by floating point numbers, like res2 = res / 1000.


Note: should take a lok at the log10() function from math module.

(with Python3)

In [1]: from math import log10

In [2]: r = 132828378723

In [3]: int(log10(r))
Out[3]: 11

In [4]: r / 10**int(log10(r))
Out[4]: 1.32828378723

A+
Laurent.

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


Re: run command line on Windows without showing DOS console window

2013-11-20 Thread Laurent Pointal
Tim Golden wrote:

 On 20/11/2013 14:44, iMath wrote:
 
 
 is there anyway to run command line on Windows without showing DOS
 console window ?
 
 can you use the following command line to give a little example ?
 
 wget -r -np -nd http://example.com/packages/
 
 the path to wget is C:\Program Files\GnuWin32\bin\wget.exe
 
 
 subprocess.call([wget, -r, -np, -nd, http://example.com;])

Complement: use .pyw extension for your main Python module (avoid Python 
opening a console).

A+

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: understanding someone else's program

2013-11-18 Thread Laurent Pointal
C. Ng wrote:

 Hi all,
 
 Please suggest how I can understand someone else's program where
 - documentation is sparse
 - in function A, there will be calls to function B, C, D and in those
 functions will be calls to functions R,S,T and so on so forth...
 making it difficult to trace what happens to a certain variable
 
 Am using ERIC4 IDE.

To help for documentation, you may test pycallgraph, eventually depgraph if 
there are multiple modules.


http://pycallgraph.slowchop.com/en/master/
http://www.tarind.com/depgraph.html

A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: Py 3.3.2, MacBookPro, segmentation fault, GCC issue?

2013-11-10 Thread Laurent Pointal
John Ladasky wrote:

 I am trying to help a student of mine install Python 3 on his MacBook Pro.
zip
 Follow-up questions: if I need a more current GCC for my student's Mac,
 how do I obtain it?  And are there any backwards-compatibility issues I
 might need to worry about if I do upgrade?  From my Linux experience,
 upgrading GCC has never caused problems.  But I want to be cautious, since
 this isn't my computer I'll be playing with, but someone else's.

AFAIK Apple stop delivering new gcc when it goes to GPL3 licence. 
In place, they use llvm compiler tool.

See discussions and links in
http://stackoverflow.com/questions/9353444/how-to-use-install-gcc-on-mac-os-x-10-8-xcode-4-4

There may be other solutions, but you should prefer ask in a specific MacOS
usenet group.

A+

 
 Thanks for any advice you may have.
-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: Aide pour bien démarrer en Python

2013-09-29 Thread Laurent Pointal
note pour les francophones il existe le newsgroup fr.comp.lang.python
ainsi que la liste Python de l'AFUL https://listes.aful.org/wws/info/python
et l'AFPY...

jonathan.corriv...@gmail.com wrote:

 Je sais qu'il y a plein d'information à lire un peu partout, mais j'ai
 vraiment du mal à voir pourquoi Python est si fantastique...
 
 Je m'explique
 
 Pour moi python c'est un langage de script très cryptique avec des noms de
 méthodes courts, pas claire, dans une identation pas toujours facile à
 lire et qui me rappel (mauvais souvenir) le positionnement obligatoire des
 instructions en COBOL... 

L'indentation remplace les {} ou begin/end  Co - et se trouve être ce que 
font la pluspart des développeurs: placer le code graphiquement pour savoir 
au premier coup d'œil où ça commence et où ça s'arrête.

Bon, faut utiliser un éditeur bien configuré pour s'assurer de ne plus avoir 
de caractère tabulation (ou que ça, mais c'est difficile).

 Je viens d'un monde .Net où les noms de méthodes
 disent exactement, très précisemment ce que fait le code (quite à avoir un
 nom de 30 caractères)...

Question de goût. Là je trouve que ça fait un peu long.

 Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit,
 c'est facile de comprendre pourquoi c'est comme ça. Mais, il y a plein de
 cas où, personnelement et pour probablement plusieurs développeurs qui
 viennent du monde JAVA ou .Net, c'est très illisible et même
 contre-intuitif...

Ne t'inquiètes pas, c'est la même chose pour les programmeurs Python qui ont 
a faire du Java ou .Net, ils trouvent ça lourd et contre-intuitif.

Et le PEP8 n'est pas une obligation, juste des conseils de bonnes pratiques.

 Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain
 et dans un seul fichier, très mal découpés et ça devient très difficile de
 se retrouver pour savoir qui fait quoi...

Rien n'oblige à tout mettre dans un fichier, mais pour juste un exemple 
c'est souvent plus facile.

 On voit partout Python est orienté objet, tout le tralala, mais dans ma
 tête, j'ai bien du mal à voir du code Python qui suit certaine règle à la
 Clean Code avec des patterns bien établient (IoC, DI, Repository,
 UnitOfWork)...

Le fait de pouvoir faire de la POO n'oblige en rien à utiliser certains 
patterns - que l'on trouve parfois pour contourner les contraintes des 
langages.
Et Python permet la POO mais ne l'oblige pas.

 J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui
 dépendent de la terre entière avec aucune réél separation of concern...
 
 Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le
 faire... Pourriez-vous m'indiquer des bonnes ressources, documentation qui
 pourrait répondre à mes intérogations ?

http://w2.syronex.com/jmr/python-paradox

http://dirtsimple.org/2004/12/python-is-not-java.html

Et deux textes dont on a l'impression qu'ils résultent d'un traducteur 
automatique:
http://fr.softuses.com/231303
http://fr.softuses.com/144363

Et si ça peut servir: 
Le mémento (fr / en) http://perso.limsi.fr/pointal/python:memento
L'abrégé (fr / en) http://perso.limsi.fr/pointal/python:abrege

 
 Merci!
-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: Do you consider Python a 4GL? Why (not)?

2013-06-11 Thread Laurent Pointal
Dennis Lee Bieber wrote:

 On Tue, 4 Jun 2013 18:17:33 -0700, Dan Stromberg drsali...@gmail.com
 declaimed the following in gmane.comp.python.general:
 
 
 Perhaps Scripting language is the best general category we have that
 Python fits into.  But I hope not.
 
 Heh... Having encountered ARexx (the Amiga version of REXX), Python
 is NOT a scripting language... The ARexx implementation (along with the
 Amiga's interprocess communication system) allowed for scripting any
 application that opened an ARexx Port... Other than, maybe, the
 original IBM REXX, I've not seen any other REXX implementation that
 would permit embedding application specific commands into a script.
 
 Python's subprocess (and related) are all based on explicit startup
 and communication over stdin/stdout... Nothing like:
 
 address TextEditor/* a fictitious application port */
 'DN 5'/* move down five lines *?:
 'MARK'/* start a selection*/
 'RW 5'/* move right five words */
 'COPY'/* copy selection to operation result */
 string = result
 address PageSetter/* fictitious here, but a real program */
 'PASTE' string/* insert selected string into page document /*
 
 Yes, maybe the above could be done as two sessions of subprocess --
 presuming both programs had a command line interface. But what if the
 script was going to switch between the two of them throughout one
 session.

For me this is not a DSL, but an external API of an application, like you 
have with COM under Windows, DBUS under Linux. Unix streams are just an 
ancestor way of communication, you could have local-RPC also, or CORBA.

So, as this is just inter-process communication procotol, if you have the 
Amigaes interprocess communication system tool written for Python, you could 
easily write things using a Python syntax:

te = TextEditor()
te.dn(5)
te.mark()
te.rw(5)
te.copy()
string = te.result()
ps = PageSetter()
ps.paste(string)

Python is a scripting language, and a nice one to use as glue between 
different components, eventually of different technologies.

(note: if you have more than one process to control via streams, you can 
open more than one pipe)

And... here http://www.solie.ca/articles/pythonmod/pythonmod.html
you could find modules for using Python with Amiga APIs and combining it 
with ARexx.

 The C compiler suites used this ability to read the error log from a
 compile, and move to the line/column in the source file associated with
 each error. (Before integrated development environments)

This is a + for compiled environments that you effectively cannot have with 
Python, non-syntaxic errors found at runtime.

A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


New version of (french) Une introduction à Python 3

2013-04-05 Thread Laurent Pointal
Hello,

a new version of B.Cordeau book, for which i was invited to participate, is 
now online here:
http://perso.limsi.fr/pointal/_media/python:cours:courspython3.pdf

This (french) book is for people intending to learn Python as first 
programming language.

A+
L.Pointal.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Update to Python 3 Cheat Sheet for students

2013-01-02 Thread Laurent Pointal
Hello and happy year 2013,

I just updated my Python 3 Cheat Sheet for students leaning programming, to 
version 1.2.1 (fix with open() as f syntax, add enumerate() in loops).

Its available here, in english and in french:

http://perso.limsi.fr/pointal/python:memento

A+
Laurent.

PS. The (longer) Python 3.2 reference card is here:
http://perso.limsi.fr/pointal/python:abrege

-- 
Laurent POINTAL - laurent.poin...@laposte.net


-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Printing a text over an image

2012-11-07 Thread Laurent Pointal
Martha Morrigan wrote:

 
 3) Any more simple approach or module to deals with printers (paper
 and/or pdf) will be welcome.

For pdf, you can take a look at ReportLab's Toolkit. I used it to build a 
trombinoscope (ie an employee directory with each member's photo on top of 
his name and room number).

http://www.reportlab.com/software/opensource/

Once created the pdf, you must find a solution to send it to the printer...

 
 Thanks in advance,
 
 Martha

A+
Laurent.

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


Updated version of Python 3 cheat sheet

2012-09-03 Thread Laurent Pointal
Hello,

My Python3 cheat sheet for students leaning programming has been lightly 
updated to 1.2.0 (added loop control keywords).

See http://perso.limsi.fr/pointal/python:memento

French and english versions available.

A+
Laurent

-- 
Laurent POINTAL - laurent.poin...@laposte.net

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: how can I implement cd like shell in Python?

2012-06-28 Thread Laurent Pointal
Sergi Pasoev wrote:

 Do you mean to implement the cd command ? To what extent do you want to
 implement it ? if what you want is just to have a script to change the
 current working directory, it is as easy as this:
 
 
 import sys
 import os
 os.chdir(sys.argv[1])
 
 plus you could add some error-handling code.

To have a shell / python script interaction for cwd management, you can take 
a look at autojump

https://github.com/joelthelion/autojump/wiki

Its a Python script + different shells glue.

A+
Laurent.


-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: use Python to post image to Facebook

2012-06-24 Thread Laurent Pointal
davecotef...@gmail.com wrote:

 On Monday, 9 April 2012 20:24:54 UTC-7, CM  wrote:
 Shot in the dark here:  has any who reads this group been successful
 with getting Python to programmatically post an image to Facebook?
 
 I've tried using fbconsole[1] and facepy[2], both of which apparently
 work fine for their authors and others and although I have an
 authorization code, publish permissions, a Facebook app, I get back
 these unhelpful errors when I try this (like an unknown  error
 occurred).
 
 If anyone has been able to do this, maybe you can help me figure out
 what I am doing wrong.
 
 Hi, I am not sure, but have a similar question.  How can I post (upload)
 an image to google images and return the resulting page..?  In python? If
 you can help I would appreciate it ever so much, Dave:)

Note: if you develop such a tool, make it a Web Out Of Browser module.

http://weboob.org/


-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: English version for Mémento Python 3 (draft, readers needed)

2012-06-06 Thread Laurent Pointal
Paul Rubin wrote:

 Laurent Pointal laurent.poin...@free.fr writes:
 There are a few other things like that, and I'll try to look more
 carefully tonight, I can't spend more time on it right now.
 I updated the document into 1.0.5a (and fix some other errors).
 
 A few more things:
 
zip: done (thanks)

 In Files
   don't miss to close file = don't forget to close the file
 [but you might mention the with statement]

I put it as a note (I want students to have file closing in mind, they may 
practice other languages without such constructions).

 In Function definition
   bloc = block
   (« black box »)  = (black box)
 [English speakers may not recognize « » symbols]

I switched them to . 
Its here to remember students that they can't access to functions internal 
variables from outside (and should try to limit access to outside world from 
inside functions) - a common error during practice. In lecture class, I try 
to show them only two access points to functions: parameters and return 
value, and a black box blocking all other informations.

 In Generator of int sequences
   You might mention that range makes a generator only in Python 3.
   In Python 2 it makes an actual list and xrange makes a generator.

We teach with Python3 as several modifications in the language are better 
for leaning programming basics (like 1/2 = 0.5).

Thanks for all your corrections, I'll continue with other posters.

A+
L.Pointal.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: English version for Mémento Python 3 (draft, readers needed)

2012-06-06 Thread Laurent Pointal
Ulrich Eckhardt wrote:

 Am 05.06.2012 19:32, schrieb Laurent Pointal:
 I started a first translation of my document originally in french. Could
 some fluent english people read it and indicate errors or bad english
 expressions.
 
 Just one note up front: Languages or nationalities are written with
 uppercase letters, like English and French. Other common faults of that
 category are days of the week (Monday..) and month names (January..),
 although that's irrelevant for your doc.

I modified slightly the page, to have first links in the page for document 
downloading (and other links deeper in the page).

 Another thing I noticed that was missing was that the in keyword can
 not only be used to iterate over a sequence (for i in seq:...) but also
 to test if something is contained in a sequence (if i in seq:...).

I reworked the second page to have less informations about string formating 
(nice, but less important than operations on containers), and add sections 
on containers, lists, dictionaries and set.

 don't miss to close file after use: Use a with statement.

Added as a note.

 see verso for string formatting... - what is verso?

Modified with Paul indications (its the other side in french - from 
latin).

 dont - don't

Done.

 char strings - strings (in the context of indexing, byte strings
 have the same syntax)

Modified (even if I dont teach byte strings with my students).

 with several else if, else if... - there is no else if but elif.

Modified (it was originally a translation from french, but the 
correcpondance between english version and keywords can be confusing).

 block else for other cases - this sounds as if it was blocking the
 else. Maybe else-block for other cases, but English hyphenation is
 complicated and I'm not sure.

Modified to else block...

Thanks for your reading and comments.

A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


English version for Mémento Python 3 (draft, readers needed)

2012-06-05 Thread Laurent Pointal
Hello,

I started a first translation of my document originally in french. Could 
some fluent english people read it and indicate errors or bad english 
expressions.

http://perso.limsi.fr/pointal/python:memento

Thanks.
A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Re: English version for Mémento Python 3 (draft, readers needed)

2012-06-05 Thread Laurent Pointal
Paul Rubin wrote:

 Laurent Pointal laurent.poin...@free.fr writes:
 I started a first translation of my document originally in french. Could
 some fluent english people read it and indicate errors or bad english
 expressions.

 http://perso.limsi.fr/pointal/python:memento
 
 It looks nice.  It took me a minute to find the English version:
 
   http://perso.limsi.fr/pointal/_media/python:cours:mementopython3-
english.pdf
 
 A few minor things:
 
 1) We would usually call this a reference card rather than memento
 
 2) In the dictionary example,
{clé:valeur} =  {key:value}
{1:un,3:trois,2:deux,3.14:} = {1:one, etc. }
 
 3) bloc in a few places should be block
 
 4) On side 2, the part about writing files is still mostly in French
 
 There are a few other things like that, and I'll try to look more
 carefully tonight, I can't spend more time on it right now.
 
 Thanks for writing it and sharing it.
 
 --Paul

Thanks,

I updated the document into 1.0.5a (and fix some other errors).

A+
Laurent.

-- 
Laurent POINTAL - laurent.poin...@laposte.net

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


Mémento Python 3

2012-05-31 Thread Laurent Pointal
Hello,

Here is an announce for a Mémento Python 3 (in French - English version will 
come later). It targets students learning basics of algorithmic and 
programming, some remarks are related to common errors we can see in 
practical courses. It dont cover object oriented programming.

http://perso.limsi.fr/pointal/python:memento


For a heavier document, the Abrégé Dense Python 3.1 is still here:

http://perso.limsi.fr/pointal/python:abrege

A+
L.Pointal

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-02 Thread Laurent Pointal
ksals wrote:

 On May 1, 5:29 pm, John Gordon gor...@panix.com wrote:
 In 3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com
 ksals kbsals5...@gmail.com writes:

  The original choice looks like this when I print it:
  print(choice)
  ('ksals', '', 'alsdkfj', '3', '')
  I need to submit these as defaults to a multenterbox. Each entry above
  ksals, , alsdkfj', 3 , '' need to fill the five fields in the box.
  I tried your suggestion so you must be right it is a tuple of 5
  strings.  But I need them to work in an instruction like
  fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice)
  fieldNames has 5 fields.

 If you just need to convert a tuple to a list, that's easy.  Call the
 built-in function list() and pass the tuple as an intializer:

  choice = ('ksals', '', 'alsdkfj', '3', '')
  print choice

 ('ksals', '', 'alsdkfj', '3', '') choice_list = list(choice)
  print choice_list

 ['ksals', '', 'alsdkfj', '3', '']

 --
 John Gordon   A is for Amy, who fell down the stairs
 gor...@panix.com  B is for Basil, assaulted by bears
 -- Edward Gorey, The Gashlycrumb Tinies


 This is a small excert to show you what I get
 
 for choice in easygui.multchoicebox(msg1, title,qstack):
 if choice[0] == None:
 print (No entries made)
 break
 
 
 print(CHOICE IS: ,choice). CHOICE IS:
 ('', 'ksals', '', '', '')
 c=list(choice)
 print(C IS: ,c)  .  C IS:  ['(',
 ', ', ',', ' ', ', 'k', 's', 'a', 'l', 's', ', ',', ' ', ',
 ', ',', ' ', ', ', ',', ' ', ', ',
 ')']

Looks like you have your tuple expression
('ksals', '', 'alsdkfj', '3', '')
not as a tuple, but as a string. Do you convert it somewhere ? 

If you have it as a string, you can use eval() (not safe!) on the string to 
retrieve the tuple, then list() on the tuple to get a list.


-- 
Laurent POINTAL - laurent.poin...@laposte.net
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59

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


Re: Naming future objects and their methods

2012-04-15 Thread Laurent Pointal
Stefan Schwarzer wrote:

 Hello,
 
 I wrote a `Connection` class that can be found at [1]. A
 `Connection` object has a method `put_bytes(data)` which
 returns a future [2]. The data will be sent asynchronously
 by a thread attached to the connection object.
 
 The future object returned by `put_bytes` has a `was_sent`
 method which will return `True` once the sender thread has
 actually sent the data via a socket call. An example might
 look like
 
 put_result = connection.put_bytes(data)
 if put_result.was_sent(timeout=1.0):
 print Data has been sent.
 else:
 print Data hasn't been sent within one second.
 
 However, I'm not comfortable with the combination of the
 names of the future and its method. After all, not the
 `put_result` was sent, but the data that was the argument in
 the `put_bytes` call. Maybe `data_was_sent` is better than
 `was_sent`, but `put_result.data_was_sent()` doesn't feel
 right either.
zip

Just an idea:
put_result == dataput
was_sent == sent

dataput = connection.put_bytes(data)
if dataput.sent(timeout=1.0):
print Data has been sent.
else:
print Data hasn't been sent within one second.


-- 
Laurent POINTAL - laurent.poin...@laposte.net
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59

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


[ANN] Abrégé Dense Python 3.1 in english

2010-11-10 Thread Laurent Pointal
Hello,

I'm pleased to announce the translation of the quick reference for Python 3.1 
in english. It is a one recto-verso page filled with language basics and 
advanced constructions. 

Web page for all versions and source document download:
http://perso.limsi.fr/pointal/python:abrege

Direct english PDF download: 
http://perso.limsi.fr/pointal/_media/python:cours:abregepython-english.pdf

Direct english ODT download:
http://perso.limsi.fr/pointal/_media/python:cours:abregepython-english.odt

A+
L.Pointal

PS. “Abrégé Dense” may be translated to “Heavy Summary”.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: webcam (usb) access under Ubuntu

2008-04-15 Thread Laurent Pointal
Le Tue, 15 Apr 2008 05:21:54 -0700, Berco Beute a écrit :

 I've been trying to access my webcam using Python, but I failed
 miserably. The camera works fine under Ubuntu (using camora and skype),
 but I am unable to get WebCamSpy or libfg to access my webcam.
 
 First I tried webcamspy (http://webcamspy.sourceforge.net/). That
 requires pySerial and pyParallel, and optionally pyI2C. Runing WebCamSpy
 results in:
 
 Exception exceptions.AttributeError: Parallel instance has no attribute
 '_fd' in bound method Parallel.__del__ of
 parallel.parallelppdev.Parallel instance at 0x83326ac ignored
 
 This seems to come from importing I2C. The application window opens, but
 there's an error message:
 
 NO VIDEO SOURCE FOUND
 
 Next I tried libfg (http://antonym.org/libfg). I built it, made the
 Python bindings and installed it. Unfortunately the following:
 
import fg
grabber = fg.Grabber()
 
 results in:
 
 fg_open(): open video device failed: No such file or directory
 
 Since the camera works fine in Ubuntu itself my guess is that the
 problem is with the python libraries (or even likelier, my usage of
 them). Is there anybody here that was successful in accessing their
 webcam on linux using Python? Else I have to reside to Windows and
 VideoCapture (which relies on the win32 api and thus is Windows-only),
 something I'd rather not do.
 
 Thanks for any help,

I dont know if this resolve your problem, but to get snapshots from a 
camera under linux, using V4L2 API, I wrote a small wrapper around this 
API.
Its called pyvideograb, and its here:
http://laurent.pointal.org/python/projets/pyvideograb/index.pih

Note: there is no automatic thing in this library, just a wrapper to 
V4L2, so you must know what options and image format your camera support 
and use these (you may have to convert image by yourself - see PIL and 
Numpy for quick data processing functions). To find the supported options 
you can use xawtv and give it ad-hoc cli option to make it verbose.

A+

Laurent.

-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python in High School

2008-04-01 Thread Laurent Pointal
Le Tue, 01 Apr 2008 12:35:46 -0700, Paddy a écrit :

 On Apr 1, 6:27 pm, sprad [EMAIL PROTECTED] wrote:
zip

 I want to believe. Evangelize away.
 
 How proficient are you in Flash/Actionscript? I suggest you try out
 Python/Pygame and extrapolate from that, given your available time,
 would you be proficient enough to teach it?

And if you want to do easy and simple 3D graphics programming, look at 
VPython

http://www.vpython.org/





-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Where can I find :

2008-03-31 Thread Laurent Pointal
Le Sat, 29 Mar 2008 20:15:59 -0700, pythonnubie a écrit :

 Hi  All :
 Does anyone know where I  can find  either a book or a website  that
 explains  beginning  python  by actually  building a  project  line by
 line and explaining  it indepth . I  am primarily interested in
 understading  flowcontrol as well  as syntax .
 
 If it was related to  netwoprking  then that would be a great addition 
 although not required  because that is my primary field of interest .
 
 All help greatly appreciated !
 
 Mark

You may look at Dive into Python, there is an online version, 
translation in some languages other than english (if needed). It propose 
a line by line explanation on many scripts targetting language and 
libraries usage.

http://www.diveintopython.org/



-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: dream hardware

2008-02-13 Thread Laurent Pointal
Le Tue, 12 Feb 2008 10:05:59 -0800, castironpi a écrit :

 What is dream hardware for the Python interpreter?

Dream... I dont know, but hardware for the Python interpreter, yes.

http://www.telit.co.it/product.asp?productId=96



-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pythonland documentation

2008-01-19 Thread Laurent Pointal
Le Fri, 18 Jan 2008 18:51:19 +, Simon Pickles a écrit :

 Hi
 
 I am new to python (fairly) but can't stop pythonning.
 
 c++ seems so far away now from here it looks like a horrid scribble
 :)
 
 Anyway my question is really about doc tools. I've been used to
 doxygen in c++ land, and although it makes a reasonable stab with a
 python project in java mode, the output is a bit messy.
 
 Can any one suggest a more tailored tool? or do I risk a flamewar? :)

You can take a look at epydoc

http://epydoc.sourceforge.net/


 
 Thanks
 
 SiPi





-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Importing java within python

2008-01-17 Thread Laurent Pointal
Le Thu, 17 Jan 2008 08:36:59 -0800, Henry Chang a écrit :

 www.jython.org
 
 On Jan 17, 2008 8:06 AM, Osthaus, Christopher (Mission Systems)
 [EMAIL PROTECTED] wrote:


 Hi All,

 This is an easy one - I'm new to Python and working on a script where I
 need to use some java swing classes.  I'm running Python on Windows.

 I've got an import statement that looks something like:

 from java.lang import System
 from javax.swing import JPasswordField from javax.swing import
 JOptionPane


 How do I get Python to recognize the java module?  I assume I need to
 set one of my environment variables?  I realize this is probably very
 obvious but I can't seem to figure it out :)

 Thanks everyone...
 --
 http://mail.python.org/mailman/listinfo/python-list


To complement Henry Chang reply, you can also take a look at:

http://jpype.sourceforge.net/ (Java To Python Integration)
http://jepp.sourceforge.net/  (Java Embeded Python)

See my other Python/Java links at 
http://www.limsi.fr/Individu/pointal/python.html#liens-intautlang-java 

A+

Laurent.


-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Some python syntax that I'm not getting

2007-12-07 Thread Laurent Pointal
Chris a écrit :
 On Dec 7, 2:31 pm, waltbrad [EMAIL PROTECTED] wrote:
 I understand how D['say'] gets you 5,  But I still don't understand
 the line after the 5.

 How is the character 's' some special code?  And I don't get what is
 going on with the % character.  I'm used to it's use in c-style
 formatting, but this just seems so bizarre.  I can tell that the key
 is being replaced by it's value in the string, but I don't know how
 that is being done.

 TIA
 
 http://docs.python.org/lib/typesseq-strings.html
 
 The '%' invokes the formatter, the 's' specifies string type.

And the (name) specify to find the value to format (following %s rules) 
in a dictionnary given as % operator parameter, under the name key.

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


Re: Generating API documentation as a textfile

2007-12-04 Thread Laurent Pointal
MonkeeSage a écrit :
 On Dec 3, 8:58 am, Samuel [EMAIL PROTECTED] wrote:
 On Mon, 03 Dec 2007 06:45:45 -0800, Giampaolo Rodola' wrote:
 dir.__doc__
 This contains only the docstring one object (module, class,
 function, ...). I was thinking more of the complete API documentation
 that can be found in a file, and formatted in a readable way.

 -Samuel
 
 Sounds like you want pydoc.
 
 http://docs.python.org/lib/module-pydoc.html

Or epydoc http://epydoc.sourceforge.net/
Or pudge http://pudge.lesscode.org/
Or apydia http://apydia.ematia.de/

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


Re: Lib for audio?

2007-11-29 Thread Laurent Pointal
Dave a écrit :
 I need to read microphone input and determine frequency. Is there a lib
 for that?
 
 Thanks,
 Dave

Another possible solution, the PortAudio binding (pyportaudio).

http://people.csail.mit.edu/hubert/pyaudio/

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


Re: How python writes text into another windows application

2007-10-30 Thread Laurent Pointal
Le Mon, 29 Oct 2007 21:53:47 +, Meitham a écrit :

 Hi,
 
 I am trying to write a simple program that reads data from a source file
 (Excel sheet, XML file or text file) and then write the data into
 another application by pasting the data into the applications fields,
 and jumps from one field to another by writing \t tab.
 
 My question is, how do I write the data into another application fields.
 My target application is the TNT consignment manager. I asked TNT for
 their API to make my life easier but they refused to release it :(. I
 have a software that uses the same way I am looking after to fill in
 application fields, it is the QuickAddress. Any idea how to achieve
 that?
 
 Thanks
 
 Meitham

If you run Windows, try with pywinauto, it should have the tools you need 
to control an external application via its gui.


http://sourceforge.net/projects/pywinauto





-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parallel insert to postgresql with thread

2007-10-26 Thread Laurent Pointal
Le Thu, 25 Oct 2007 13:27:40 +0200, Diez B. Roggisch a écrit :

 DB modules aren't necessarily thread-safe. Most of the times, a
 connection (and of course their cursor) can't be shared between threads.
 
 So open a connection for each thread.
 
 Diez

DB modules following DBAPI2 must define the following attribute:


  threadsafety

Integer constant stating the level of thread safety the
interface supports. Possible values are:

0 Threads may not share the module.
1 Threads may share the module, but not connections.
2 Threads may share the module and connections.
3 Threads may share the module, connections and
  cursors.


http://www.python.org/dev/peps/pep-0249/



-- 
Laurent POINTAL - [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ANN: magnitude 0.9.1

2007-10-16 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 I am happy to announce the first release of magnitude, a
 library for computing with physical quantities. It is
 released under the Apache v. 2 license.
 
 A physical quantity is a number with a unit, like 10
 km/h. Units can be any of the SI units, plus a bunch of
 non-SI, bits, dollars, and any combination of them. They can
 include the standard SI prefixes. Magnitude can operate with
 physical quantities, parse their units, and print them. You
 don't have to worry about unit consistency or conversions;
 everything is handled transparently. By default output is
 done in basic SI units, but you can specify any output unit,
 as long as it can be reduced to the basic units of the
 phisical quantity.
 
 Home page: http://juanreyero.com/magnitude/ 
 
 Feedback is appreciated.

How does it compare to the scalar module ?
(see http://russp.us/scalar.htm )

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


Re: Fwd: Using fractions instead of floats

2007-10-01 Thread Laurent Pointal
Andres Riofrio a écrit :
zip
 Well, then I have
 a question: Is there a way to make 5/2 return something other than an
 integer? 

  from __future__ import division
  5/2
2.5


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


Re: Converting numbers to unicode charaters

2007-09-24 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 Here's how I'm doing this right now, It's a bit slow. I've just got
 the code working. I was wondering if there is a more efficient way of
 doing this... simple example from interactive Python:
 
 word = ''
 hexs = ['42', '72', '61', '64']
 for h in hexs:
 ...   char = unichr(int(h, 16))
 ...   word += char
 ...   print char
 ...
 B
 r
 a
 d
 print word
 Brad
 
 
 Each hex_number is two digits. unichr converts that to a character
 that I append to previous ints that have been converted to chars. In
 this way, I convert a string of hex numbers to ints to letters, to
 words.
 
 Perhaps I'm doing it wrong... any tips?

You have to go by int conversion to get codes, and by unichr to get 
corresponding unicode chars, so this seem the solution.

You may eventually use a more condensed expression and avoid n 
concatenation of n chars using join, like this:

  u''.join(unichr(int(x,16)) for x in ['42','72','61','64'])
u'Brad'

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


Re: Extracting xml from html

2007-09-19 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 On Sep 18, 1:56 am, Stefan Behnel [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
 I am attempting to extract some XML from an HTML document that I get
 returned from a form based web page. For some reason, I cannot figure
 out how to do this.
 Here's a sample of the html:
 html
 body
 lots of screwy text including divs and spans
 Row status=o
 RecordNum1126264/RecordNum
 MakeMitsubishi/Make
 ModelMirage DE/Model
 /Row
 /body
 /html
 What's the best way to get at the XML? Do I need to somehow parse it
 using the HTMLParser and then parse that with minidom or what?
 lxml makes this pretty easy:

 parser = etree.HTMLParser()
 tree = etree.parse(the_file_or_url, parser)

 This is actually a tree that can be treated as XML, e.g. with XPath, XSLT,
 tree iteration, ... You will also get plain XML when you serialise it to XML:

 xml_string = etree.tostring(tree)

 Note that this doesn't add any namespaces, so you will not magically get 
 valid
 XHTML or something. You could rewrite the tags by hand, though.

 Stefan
 
 I got it to work with lxml. See below:
 
 def Parser(filename):
 parser = etree.HTMLParser()
 tree = etree.parse(r'path/to/nextpage.htm', parser)
 xml_string = etree.tostring(tree)
 events = (recordnum, primaryowner, customeraddress)
 context = etree.iterparse(StringIO(xml_string), tag='')
 for action, elem in context:
   tag = elem.tag
   if tag == 'primaryowner':
 owner = elem.text
 elif tag == 'customeraddress':
 address = elem.text
 else:
 pass
 
 print 'Primary Owner: %s' % owner
 print 'Address: %s' % address
 
 Does this make sense? It works pretty well, but I don't really
 understand everything that I'm doing.
 
 Mike
 

Q? Once you get your document into an XML tree in memory, while do you 
go to event-based handling to extract your data ?

Try to directly manipulate the tree.

parser = etree.HTMLParser()
tree = etree.parse(r'path/to/nextpage.htm', parser)
myrows = tree.findall(.//Row)

# Then work with the sub-elements.
for r in myrows :
rnumelem = r.find(RecordNum)
makeeleme = r.find(Make)
modelelem = r.find(Model)

 co.

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


lxml codespeak pages empty ?

2007-09-19 Thread Laurent Pointal
I can no longer get codespeak's lxml page at http://codespeak.net/lxml/ 
(get an empty HTML document !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 
Transitional//ENhtmlheadtitle/title/headbody/body/html)...

Am-I alone in this case ?
Any codespeaker reading ?

A+

Laurent.

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


Re: lxml codespeak pages empty ? Come back.

2007-09-19 Thread Laurent Pointal
Laurent Pointal a écrit :
 I can no longer get codespeak's lxml page at http://codespeak.net/lxml/ 
 (get an empty HTML document !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 
 Transitional//ENhtmlheadtitle/title/headbody/body/html)... 
 
 
 Am-I alone in this case ?
 Any codespeaker reading ?

It magically come-back
-- 
http://mail.python.org/mailman/listinfo/python-list


lxml and identification of elements in source

2007-09-19 Thread Laurent Pointal
Hello,

I use lxml to parse a document, modify some elements in the tree, run
xinclude on it (thanks to Stefan Behnel for the pointer), and finally use
the data to feed my sax-aware tool.

To report warnings/errors to the user (not related to XML itself, but to
things like missing source for a cross-reference by example), is there a
way to get the source-file and line/column of an element ?

[note: these informations are available when lxml parse the source, but are
they kept anywhere in the document tree ?]

Thanks.

Laurent.

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


Re: The meaning of a = b in object oriented languages

2007-09-18 Thread Laurent Pointal
Summercool a écrit :
 
 
 The meaning of  a = b  in object oriented languages.
 
zip

Oups, reading the subject I thought it was a Xah Lee post.


;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question

2007-09-18 Thread Laurent Pointal
 [EMAIL PROTECTED] wrote:

 If I have a file name: AVC1030708.14.  How do I strip out certain
 characters from the file name?  I am so used to using MID, LEFT, and
 RIGHT functions, that I have no idea how to do this in python?  I have
 had trouble as well with most newbies on finding the help.  But I have
 used the command line built in help, but with no luck.  Thanks.
 
 Kou

As you seem to know about mid, left, right functions, you may have already
programmed with languages such as Basic.

Learning Python is usually easy, see Python tutorials in several places:
* http://docs.python.org/tut/tut.html
* http://www.awaretek.com/tutorials.html
* http://effbot.org/pytut/


Once you have the language basics, you can look after the standard library
documentation:
* http://docs.python.org/lib/lib.html

For a very quick overview of the language and the libraries, you may take a
look at R.Gruet Python Quick Reference or at my Python Quick Reference
Card - these are refs, not learning tools.
* http://rgruet.free.fr/
* http://www.limsi.fr/Individu/pointal/python/pqrc/ (still for Python 2.4 -
working on 2.5)


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


Re: Python with

2007-09-17 Thread Laurent Pointal
Ivan Voras a écrit :
zip
 I know it can be almost always done by using a temporary variable:
 
 tmp = some.big.structure.or.nested.objects.element
 tmp.member1 = something
 tmp.member2 = something
 
 but this looks ugly to me.)

The ugly part is the 'tmp' name, try to choose a name with a proper 
meaning about what it is really, and it become clean and readable:

filerefs = some.big.structure.or.nested.object.with.file.references
filerefs.encoding = utf-8
filerefs.name = MyFileName.txt
filerefs.use_quotes = True

Isn't it ?

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


Re: SVG to raster conversion.

2007-09-17 Thread Laurent Pointal
J. Cliff Dyer a écrit :
 Does anybody know a good solution (preferably in python) for rasterizing
 SVG or other vector graphics.
 
 I'm thinking something like
 
 vector_image = SVGFile(path_to_image)
 raster_image = vector_image.rasterize(format, (width, height), dpi)
 raster_image.write(out_file)
 
 Thanks for any pointers you might have.

Another link to complement other replies:

Maybe witgh Cairo:

Library:
http://cairographics.org/

SVG support:
http://cairographics.org/manual/cairo-SVG-Surfaces.html

Python binding:
http://cairographics.org/bindings/


A+

Laurent.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python with

2007-09-17 Thread Laurent Pointal
Ivan Voras a écrit :
 Laurent Pointal wrote:
 
 The ugly part is the 'tmp' name, try to choose a name with a proper 
 meaning about what it is really, and it become clean and readable:

 filerefs = some.big.structure.or.nested.object.with.file.references
 filerefs.encoding = utf-8
 filerefs.name = MyFileName.txt
 filerefs.use_quotes = True

 Isn't it ?
 
 Well, no, but this might be due to personal tastes. At least, I don't 
 think it's better then some other alternatives. For example, in C99 you 
 can do:
 
 static struct option_s foo_option = {
 .name = foo,
 .type = O_STRING,
 .def_value = default
 };
 
 At least to me, this looks even better than the Pascal's syntax.

If its at construction time, you can do the same with Python:

class option_s(object) :
 def __init__(self,**initializers) :
 self.__dict__.update(initializers)

foo_option = option_s(
 name = foo,
 type_ = O_STRING,
 def_value = default
 )


And if the class has no such construction idiom, you can play like this:

x = X()
x.__dict__.update(dict(
 name = foo,
 type_ = O_STRING,
 def_value = default
))


Note: this directly manipulate objects attributes - some times its 
preffered to use ad-hoc methods.

Note2: I prefer the namespace.name = value solution, more readable.

Note3: Its funny to see how Python users tries to change the language, 
does this occure with C, C++, Java, C# ?

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

Re: Saving parameters between Python applications?

2007-09-17 Thread Laurent Pointal
Stodge a écrit :
 I'm trying to do the following. I have a Python application that is
 run:
 
 python app1.py --location=c:\test1
 
 What I want to do is save the location parameter, so I can then do (in
 the same window):
 
 python app2.py
 
 And have app2.py automatically have access to the value of location.
 
 Now, the difficult part is, that in another window I want to do:
 
 python app1.py --location=c:\test2
 python app2.py
 
 And have app2.py automatically get c:\test2 as the location. So the
 two windows (consoles) are isolated from each other.
 
 I thought I could use os.environ, but that doesn't save the variable
 for applications that are run afterwards in the same window.
 
 Any suggestions?

May use simple file in known place:
$HOME/.myprefs
$HOME/.conf/myprefs

Or host specific configuration API:
WindowsRegistry HKEY_CURRENT_USER\Software\MySociety\MyApp\myprefs


See os.getenv, and _winreg Windows specific module.
See also standard ConfigParser module
Hope you know how to read/write files.

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


Re: read part of jpeg file by pure python

2007-09-13 Thread Laurent Pointal
Pacino a écrit :
 Hi, everyone,
 
 I am wondering whether it's possible to read part (e.g. 1000*1000) of
 a huge jpeg file (e.g. 3*3) and save it to another jpeg file
 by pure python. I failed to read the whole file and split it, because
 it would cost 2GB memory.
 
 Can anyone help me? Any comments would be appreciated.
 
 Thanks.
 
 Robert
 

Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.

A+

Laurent.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Get the complete command line as-is

2007-09-12 Thread Laurent Pointal
wangzq a écrit :
 Hello,
 
 I'm passing command line parameters to my browser, I need to pass the
 complete command line as-is, for example:
 
 test.py abc def xyz
 
 If I use ' '.join(sys.argv[1:]), then the double quotes around abc
 def is gone, but I need to pass the complete command line (abc def
 xyz) to the browser, how can I do this?
 
 I'm on Windows.

As Windows command-line parsing seem to remove some chars, maybe you can 
try to use the GetCommandLine() function from Win32 API (I dont know if 
it is available in pywin32 package - you may need to write a wrapper 
with ctypes).

See http://msdn2.microsoft.com/en-us/library/ms683156.aspx


A+

Laurent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML: SAX and XInclude

2007-09-11 Thread Laurent Pointal
Stefan Behnel a écrit :
 Laurent Pointal wrote:
 does anybody know about an XML parser usable with the sax API (xml.sax)
 and with XInclude feature support (directly or via hacks).
 
 Try lxml.etree.
 
 http://codespeak.net/lxml/
 
 http://codespeak.net/lxml/tutorial.html
 http://codespeak.net/lxml/api.html#xinclude-and-elementinclude
 http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk
 
 It's not half as complicated as SAX, BTW.
 
 Stefan

I've already used ElementTree for XML tree manipulations in some 
projects... will try to adapt my sax based processing to lxml using 
those links.

Thanks,

Laurent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: memcpy

2007-09-11 Thread Laurent Pointal
Tim a écrit :
zip
 Can I initialize something in Python that I can get access to it's
 pointer?

No, there is no pointer in Python semantic (they exist behind the scene 
in C-Python).

 How about:
 
 self.data =
 TOTAL_OUTPUT_PARMETERS*[TOTAL_PARAMETER_ENTRIES*[c_float()]
 
 or
 
 self.data = TOTAL_OUTPUT_PARMETERS*[c_char_p(temp)]
 
 or
 
 self.data = [TOTAL_OUTPUT_PARMETERS*1.0]*TOTAL_PARAMETER_ENTRIES
 
 I need to be able to copy the contents of a pointer to shared memory
 into an array of floats so I can index into that array and see my
 data. I have a pointer to shared meory but I don't know how to access
 it.

See module ctypes (14.14 in library reference manual).

A+

Laurent.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >