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 
> 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


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: 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: 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


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.


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


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  wrote:
>> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
>> ksals  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


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  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


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

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

> Laurent Pointal  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:
> 


> 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


[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


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&W 
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


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: 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: 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: 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: 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: 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: 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: 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: 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: 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: Writing big XML files where beginning depends on end.

2005-11-28 Thread Laurent Pointal
Magnus Lycka wrote:
> We're using DOM to create XML files that describes fairly
> complex calculations. The XML is structured as a big tree,
> where elements in the beginning have values that depend on
> other values further down in the tree. Imagine something
> like below, but much bigger and much more complex:
> 
> 
> 
> 7
> 
> 2
> 1
> 
> 
> 
> 5
> 
> 
> 
> We have to stick with this XML structure for now.
> 
> In some cases, building up a DOM tree in memory takes up
> several GB of RAM, which is a real showstopper. The actual
> file is maybe a magnitute smaller than the DOM tree. The
> app is using libxml2. It's actually written in C++. Some
> library that used much less memory overhead could be
> sufficient.
> 
> We've thought of writing a file that looks like this...
> 
> 
> 
> 7
> 
> 2
> 1
> 
> 
> 
> 5
> 
> 
> 
> ...and store {"#": "15", "#1.1", "10" ... } in a map
> and then read in a piece at a time and performs some
> simple change and replace to get the correct values in.
> Then we need something that allows parts of the XML file
> to be written to file and purged from RAM to avoid the
> memory problem.
> 
> Suggestions for solutions are appreciated.

An idea.

Put spaces in your names 
Store { "#1":  }.

When you have collected all your final data, go throught your stored #,
seek at their position in the file, and replace the data (writting same
amount of chars than reserved).

A kind of direct access to nodes in an XML document file.

A+

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


Re: appending messages in imaplib

2005-12-05 Thread Laurent Pointal
[EMAIL PROTECTED] wrote:
> So I have the unfortunate task of migrating several hundred users from
> local mail (mbox and mh) up to an exchange server as part of wearisome
> SOX compliance nonsense.
> 
> I thought the best path through this thicket would be to knock up a
> quick python script using imaplib to replicate folder structures on the
> IMAP server and copy the mails accross.

[zip]


Have you tried to search for mbox2imap ?

On google the first link is... a Python script.

http://home.tiscali.cz:8080/~cz210552/distfiles/mbox2imap.py

And there are other entries...



Looking for mh2imap seem quasi unproductive.

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


Re: Creating referenceable objects from XML

2005-12-05 Thread Laurent Pointal
Michael Williams wrote:
> Hi All,
> 
> I'm looking for a quality Python XML implementation.  All of the DOM 
> and SAX implementations I've come across so far are rather  convoluted. 
> Are there any quality implementations that will (after  parsing the XML)
> return an object that is accessible by name? Such as  the following:
> 
> 
> 
> 
> xml = """
> 
> MyBook
> the author
> 
> """
> 
> 
> 
> 
> 
> And after parsing the XML allow me to access it as so:
> 
> book.title
> 
> I need it to somehow convert my XML to intuitively referenceable 
> object.  Any ideas?  I could even do it myself if I knew the  mechanism
> by which python classes do this (create variables on the fly).
> 
> Thanks in advance!

Another tool (ElementsTree already quoted): Amara
( http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/ )

[never tested but bookmarked as it seem interresting]

A+

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


Re: Unpacking Binary Data - not using struct module

2004-12-16 Thread Laurent Pointal
Geoffrey wrote:
My questions ...
1) Does anyone recognize this numeric format ?
Seem to be some decimal coded binary, where you only use hexa from 0 to 
9, coding corresponding decimal digits.
The trailing hexa F may be used to indicate the end of the number (if 
number can have variable length) as it is normally not used as a digit 
in this coding.

3) I think that the trailing "f" is sometimes used to indicate the
sign of the number and perhaps even the number of decimal places ...
but am not sure.
Maybe... but have you an example of a negative number ?
A+
Laurent.
--
http://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: 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: 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


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: 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
>  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: 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-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: 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


[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: 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: 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: 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: 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: 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.

> 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: 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'''

> 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
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


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 "", 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: 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: 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: 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: 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.


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: 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 "", line 1, in 
> 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.



A+
Laurent.

-- 
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:


> -
 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:
r"C:\Beautiful Soup\ecologicalpyramid.html"




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: 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


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: Regular expression and substitution, unexpected duplication

2015-08-19 Thread Laurent Pointal
MRAB wrote:

> On 2015-08-18 22:42, Laurent Pointal wrote:
>> Hello,

>> 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


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


[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 

-- 
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: 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


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: 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 
> hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)
> AttributeError: function 'HLLAPI' not found
 Traceback (most recent call last):
>   File "", line 1, in 

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: 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: Programming newbie coming from Ruby: a few Python questions

2006-08-02 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
...
> Ideally, I'd like a whole series of projects where I'm walked through
> how to go about writing real Python. The way I look at it, nobody
> learnt to build a house just from reading about building materials!

Take a look at "Dive Into Python" from Mark Pilgrim, good examples with
comments.

http://diveintopython.org/

Its available as paper-print or as electronic reading.

A+

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


Re: how to stop python

2006-08-02 Thread Laurent Pointal
victor a écrit :
> or if u want explicit exit of program then use:
> 
> import sys
> sys.exit(1)
> 
> or
> 
> raise SystemExit, 'message'

There is also the (not recommanded - see docs, but it exists)
os._exit(n)  function.

A+

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


Re: Unicode/utf-8 data in SQL Server

2006-08-09 Thread Laurent Pointal
John Machin a écrit :
> The customer should be very happy if you do
> text.decode('utf-8').encode('cp1252') -- not only should the file
> import into Excel OK, he should be able to view it in
> Word/Notepad/whatever.

+
text.decode('utf-8').encode('cp1252',errors='replace')

As cp1252 may not cover all utf8 chars.

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


Re: Reference Variables In Python Like Those In PHP

2006-08-16 Thread Laurent Pointal
Chaos a écrit :
> Is It possible to have reference variables like in PHP
> 
> ex.
> 
>  
> $x = 1;
> $y =& $x;
> 
> $y += 1;
> 
> echo $x;
> echo "\n"
> echo $y;
> 
> ?>
> 
> This would show
> 
> 2
> 2
> 
> Is this available in python?

See other replies (ie. in Python all variables are names refering to
objects).

You may achieve same result using an object as a namespace, like this:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class Dummy(object) : pass
...
>>> x=Dummy()
>>> x.val = 1
>>> y = x   <-- here x and y refer to *same* Dummy object
>>> y.val += 1
>>> x.val
2
>>> y.val
2

A+

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


Re: Subprocess confusion: how file-like must stdin be?

2006-08-18 Thread Laurent Pointal
Cameron Laird a écrit :
> In article <[EMAIL PROTECTED]>,
> Nick Craig-Wood  <[EMAIL PROTECTED]> wrote:
>> Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>>>  On Thu, 17 Aug 2006 17:16:25 +, [EMAIL PROTECTED] (Cameron Laird)
>>>  declaimed the following in comp.lang.python:
>>>
 Question:
   import subprocess, StringIO

   input = StringIO.StringIO("abcdefgh\nabc\n")
>>> Here you override the builtin function "input()"
   # I don't know of a compact, evocative, and
   # cross-platform way to exhibit this behavior.
   # For now, depend on cat(1).
   p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, 
stdin = response)
>>> Here you specify the non-existant "response" 
>> Assume the OP meant to write this
>>
> import subprocess, StringIO
> inp = StringIO.StringIO("abcdefgh\nabc\n")
> p = subprocess.Popen(["cat"], stdout = subprocess.PIPE, stdin = inp)
>> Traceback (most recent call last):
>>  File "", line 1, in ?
>>  File "/usr/lib/python2.4/subprocess.py", line 534, in __init__
>>(p2cread, p2cwrite,
>>  File "/usr/lib/python2.4/subprocess.py", line 830, in _get_handles
>>p2cread = stdin.fileno()
>> AttributeError: StringIO instance has no attribute 'fileno'
>   .
>   .
>   .
> Yes; my apologies for the confusion I introduced by "editing
> for publication", and doing it badly.
> 
> Your interactive session does indeed exhibit the behavior that
> puzzles me.  My expectation was that StringIO and the std* 
> parameters to Popen() were made for each other; certainly there
> are many cases where stdout and stderr can be redirected *to* a
> StringIO.  Is it simply the case that stdin demands a more
> file-like object?  While that disappoints me, I certainly can
> program around it.  My question, then:  does stdin effectively
> require something really in the filesystem, or perhaps the
> stdout of a previous subprocess?  Is there no built-in way to
> feed it an in-memory construct?

As this is a pipe at OS level, there may be no other way than using
os-level tools (ie. real files with fileno), maybe creating an anonymous
pipe, writing to it (relying on pipe buffering by the OS to avoid the
creation of a writer thread), and giving this pipe (which should have a
fileno) to the subprocess.Popen stdin parameter.
Such a construction (pipe/writer thread) would be welcome as standard
subprocess tool.


A+

Laurent.

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


Re: What do you want in a new web framework?

2006-08-21 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
> Hello Everyone,
> 
> Now, I'm working on a new web framework. I tried many test on the other
> programming languages. Then i decided to use python on my web framework
> project.
> 
> Now i want to listen all of you. What do you want in that web
> framework(Easy use of Database, Easy use of XML, GUI Designer, etc...)?
> 
> I'm wating your answers. Thank you for all answers...!

Look at http://wiki.python.org/moin/WebFrameworks

Do you *really* need to develop a *new* framework (maybe a scholl
exercise - it that case, KISS)?

Personnally I use Karrigell at home, simple, nice.

A+

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


Re: Looking for assignement operator

2006-10-17 Thread Laurent Pointal
Alexander Eisenhuth a écrit :
> Hello,
> 
> is there a assignement operator, that i can overwrite?

Adding to Simon Brunning reply (assignment is a statement).

> class MyInt:
> def __init__(self, val):
> assert(isinstance(val, int))
> self._val = val
> 
> a = MyInt(10)
> 
> # Here i need to overwrite the assignement operator
> a = 12

Here you bind the 12 (Python int value) to name 'a', then 'a' has the
int type, not your MyInt (which value has been lost).

You may define a 'set' method, and write:
a = MyInt(10)
a.set(12)

And, if a is a member of another class, you may define an accessor for
that 'a' member in that class, which automatically call your set method
when giving an int value.

b.a = MyInt(10)
b.a = 12---> b.a.set(12)

A+

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


Re: I would like write some data recovery software

2006-10-17 Thread Laurent Pointal
gel a écrit :
> I would like to write some data recovery software as a learning thing.
> The sort of thing that you would use to recover data from a currupt HDD
> or floppy etc.  I would like to be pointed in the right direction as
> far as modules to use and suggested approaches.
> 

Once you get a way to access the bytes to recover... the Hachoir library
can be interresting as a model to map structures on these data.

http://hachoir.org/


A+

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


Re: Python 2.5 ; Effbot console ; thank ; pb release.

2006-10-24 Thread Laurent Pointal
Thomas Heller a écrit :
> Ben Finney schrieb:
>> "Hendrik van Rooyen" <[EMAIL PROTECTED]> writes:
>>
>> [quoting problems fixed]
>>
>>>  "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:
 some days, I ask myself why I shouldn't just use GPL for
 everything I do, and ship it as source code only.
>>> because then you would deny your work to thousands of ungrateful,
>>> unmotivated lazy buggers like me...
>> Not necessarily. All it needs is one person (with the same platform
>> you want to use) to take the source, build it for that platform, and
>> make it available. All the other "ungrateful, unmotivated lazy
>> buggers" can then take advantage of that -- and reward the person with
>> whatever praise they require :-)
>>
> I wonder if it would be possible to setup a windows box which provides
> a (web-)service that allows to build Python packages.

You will have the problem of third-party libraries dependancies (and
installation).

> Any ideas how this could be made secure?
> 
> Thomas
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyFAQ: help wanted with thread article

2006-11-14 Thread Laurent Pointal
Fredrik Lundh a écrit :
> this FAQ item talks about using sleep to make sure that threads run
> properly:
> 
> http://effbot.org/pyfaq/none-of-my-threads-seem-to-run-why.htm
> 
> I suspect it was originally written for the "thread" module, but as
> far as I know, the "threading" module takes care of the issues described
> here all by itself.
> 
> so, should this item be removed?
> 
> or can anyone suggest a rewrite that's more relevant for "threading"
> users.  feel free to post suggestions (or better, an updated text) to
> this thread, or over at the PyFAQ staging site.

Maybe it could be modified to indicate (for threading) existence of
daemon and non-daemon threads.


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


Re: graphical class diagram tool?

2006-11-14 Thread Laurent Pointal
nic a écrit :
> Hi all
> Some years ago I saw a graphical class diagram generated by
> examining a python program. I *thought* that this was done with Boa
> Constructor, but I may be wrong. I've download a recent version of BC
> and can't find reference to this feature. Can anyone point me at other
> tools to do this?

Maybe pyreverse  :
http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%202560


I have other links here:
http://www.limsi.fr/Individu/pointal/python.html#liens-metaprog


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


Re: Python-2.5.exe?

2006-11-15 Thread Laurent Pointal
Andrew Burton wrote:

> What Python is best for installing to a USB Drive?  I've actually got
> 2.5 on a drive, but I forget which installation package I used. 

Maybe this one ? http://www.voidspace.org.uk/python/movpy/

> It 
> seems to me that it was an EXE file, but I cannot seem to find one of
> those today.
> 
> Can the Python-2.5.msi installation files from python.org be installed
> so as not to touch the registry, to make them portable?

It seems movpy can install Python2.5 on an USB Key.

A+

Laurent.

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


Re: os.lisdir, gets unicode, returns unicode... USUALLY?!?!?

2006-11-17 Thread Laurent Pointal
gabor a écrit :
> hi,
> 
> from the documentation (http://docs.python.org/lib/os-file-dir.html) for
> os.listdir:
> 
> "On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
> will be a list of Unicode objects."

Maybe, for each filename, you can test if it is an unicode string, and
if not, convert it to unicode using the encoding indicated by
sys.getfilesystemencoding().

Have a try.

A+

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


Re: Running Python scripts under a different user

2006-05-29 Thread Laurent Pointal
Bernard Lebel a écrit :
> On 5/26/06, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>> For Windows, you can use the 'runas.exe' program. But it requires a
>> password too.
>>
>>  From what you wrote, I think that you need to change architecture. You
>> should write your own service rather than write tricky programs. This
>> way you can develop your own security system, and restrict access to
>> specific files/programs. You can write tools that can connect to your
>> service. The service program can be ran on the background, with
>> sufficient privileges. How does it sound?
> 
> [Bermard] Any ressource you could point me to as to write services?
> I'm totally unexperienced with that.

As you run under Unix, you may be interrested into the daemon.py script.

See Unix Daemon in page http://homepage.hispeed.ch/py430/python/index.html

And too: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731


See also google links for python + daemon

A+

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


Re: How to format datetime values

2006-06-02 Thread Laurent Pointal
A.M a écrit :
> "BartlebyScrivener" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Are you trying to get banned, or what?
>>
>> It's the equivalent of me asking you:
>>
>> Hey, does Ruby have anything like dictionaries and will you teach me
>> about strings?  Oh, and what's an object?
>>
>> Go read the bleeping tutorial.
>>
>> rd
>>
> 
> Well, I did investigate all tutorial and google and I wasn't able to find 
> any built-in way for datetime formatting in Python. 

Really ?

For time formating... have you really really looked at module... 'time'?

> In fact I cannot find
> any way to format a long integer into 99,999, format. I know how
> to format strings with C printf like formatter, but I am sure what I
> am trying to do can't be done with C printf formatting.

For long integer formating like your example, its not direct - maybe
look at locale formating of numbers (module... 'locale').


And I recently annouce the PQRC (on clp.announce), which can gives you
some directions:
http://www.limsi.fr/Individu/pointal/python/pqrc/


A+

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


Re: Python for Visual Basic or C# programmers

2006-06-02 Thread Laurent Pointal
A.M a écrit :
> Hi,
> 
> 
> 
> I am trying to find the equivalent functions  such as vb's str or asc in 
> Python. Is there any resource that help me to find these kinds of functions 
> in Python faster?



I've written the PQRC for that purpose:
http://www.limsi.fr/Individu/pointal/python/pqrc/



A+

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


ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-03 Thread Laurent Pointal
[for those who dont read clp.announce]

The Python Quick Reference Card (PQRC) aims to provide a printable quick
reference documentation for the Python language and some of its main
standard libraries (currently for Python 2.4).

PQRC tries to group informations about same/similar subject to avoid
searching in multiple places.

It is published under a Creative Common [by nc sa] license.

It is still a work in progress, but currently usable, you can get it at:

http://www.limsi.fr/Individu/pointal/python/pqrc/


And I'll maintain a fixed URL at

http://laurent.pointal.org/python/pqrc/


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


Re: ANN: PQRC - Python Quick Reference Card - v 0.55

2006-06-04 Thread Laurent Pointal
Kent Johnson wrote:

> Laurent Pointal wrote:
>> And I'll maintain a fixed URL at
>> 
>> http://laurent.pointal.org/python/pqrc/
> 
> Broken at the moment.

Its back.

Its at my home ADSL, normally online, but my provider reset the connexion
each 24h and its home maintained... the page contains only a link to the
other URL which has the data and is beyond a larger bandwidth server.

A+

Laurent.

> 
> Kent

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


Re: Python is fun (useless social thread) ;-)

2006-06-16 Thread Laurent Pointal
John Salerno a écrit :
...
> I do, however, think the docs are pretty good, although I sometimes find
> myself just wishing that a function definition was simply laid out in an
> easy to read format that included all of its parameters, so I would know
> exactly what to pass to it (I guess help() is good for this though).


http://www.limsi.fr/Individu/pointal/python/pqrc/


A+

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


Re: [OT] code is data

2006-06-19 Thread Laurent Pointal
bruno at modulix a écrit :
> Anton Vredegoor wrote:
>> bruno at modulix wrote:
>>
>>> I still don't get the point.
>>
>> Well, I've got to be careful here, lest I'd be associated with the
>> terr.., eh, the childp..., eh the macro-enablers.
>>
>> The idea is to have a way to transform a Python (.py) module into XML
>> and then do source code manipulations in XML-space using ElementTree.
> 
> My my my... I'm not against the idea of dynamic source code
> transformation, but for heaven's sake, *why* would one put XML in the
> mix ???

Because its "à la mode", and is better for a commercial point of view,
even if inefficient for this problem.


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


Re: [OT] code is data

2006-06-20 Thread Laurent Pointal
Fredrik Lundh a écrit :
> Laurent Pointal wrote:
> 
>>>> The idea is to have a way to transform a Python (.py) module into XML
>>>> and then do source code manipulations in XML-space using ElementTree.
>>>
>>> My my my... I'm not against the idea of dynamic source code
>>> transformation, but for heaven's sake, *why* would one put XML in the
>>> mix ???
> 
> because lots of people know how to describe XML transformations, and
> there are plenty of tools that implement such transformations efficiently ?
> 
>> Because its "à la mode", and is better for a commercial point of view,
>> even if inefficient for this problem.
> 
> why would XML be inefficient ?

As a storage tool, its nice, and as you says, there are many tools to
deal with.

But as an internal representation for an AST, I certainly prefer an
ad-hoc classes definitions with well defined members.
Just have a wrapper between both representations.


Laurent

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


Re: How to truncate/round-off decimal numbers?

2006-06-20 Thread Laurent Pointal
Girish Sahani a écrit :
> Hi,
> 
> I want to truncate every number to 2 digits after the decimal point. I
> tried the following but it doesnt work.
> 
 a = 2
 b = 3
 round(a*1.0 / b,2)
> 0.67004
> 
> Inspite of specifying 2 in 2nd attribute of round, it outputs all the
> digits after decimal.

There are two operations:

1) calculate of round(), which return a float number result, with the
well known problem of floating point numbers represantation (see the FAQ).

2) print that number, where default printing of last expression result
in the cli interpreter displays up to the highest precision, print
statement works differently:

>>> a=2
>>> b=3
>>> c=round(a*1.0/b,2)
>>> c
0.67004
>>> print c
0.67
>>>

A+

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


Re: Problem with sets and Unicode strings

2006-06-28 Thread Laurent Pointal
Dennis Benzinger a écrit :
> No, byte strings contain characters which are at least 8-bit wide
> . But I don't understand what
> Python is trying to decode and why the exception says something about
> the ASCII codec, because my file is encoded with UTF-8.

[addendum to others replies]

The file encoding directive is used by Python to convert u"xxx" strings
into unicode objects using right conversion rules when compiling the code.
When a string is written simply with "xxx", its a 8 bits string with NO
encoding data associated. When these strings must be converted they are
considered to be using sys.getdefaultencoding() [generally ascii -
forced ascii in python 2.5]

So a short reply: the utf8 directive has no effect on 8 bits strings,
use unicode strings to manage correctly non-ascii texts.

A+

Laurent.

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


Re: best small database?

2006-09-11 Thread Laurent Pointal
David Isaac a écrit :
> I have no experience with database applications.
> This database will likely hold only a few hundred items,
> including both textfiles and binary files.
> 
> I would like a pure Python solution to the extent reasonable.
> 
> Suggestions?

May take a look at buzhug (very pythonic way to manipulate data in the
base).

http://buzhug.sourceforge.net/

> 
> Thank you,
> Alan Isaac
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythondocs.info : collaborative Python documentation project

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

> Hi,
> 
> I am a bit disapointed with the current Python online documentation. I
> have read many messages of people complaining about the documentation,
> it's lack of examples and the use of complicated sentences that you
> need to read 10 times before understanding what it means.

I agree in some ways, Python docs could have better organization (more links
between related things).

> That's why I have started a collaborative project to make a user
> contributed Python documentation. The wiki is online here:
> http://www.pythondocs.info
> 
> This is a fresh new website, so there's not much on it, but I hope to
> make it grow quickly. Help and contributions are welcome; Please
> register and start posting your own documentation on it.
> 
> Regards,
> 
> Nicolas.
> -
> http://www.pythondocs.info

Here is another URL of such a project, i bookmarked some times:
http://www.simisen.com/jmg/cpd/
And there is nothing beyond this URL, like many of such projects.

AFAIR there is a starting of Wiki documentation - like PHP docs, one page
per function, contributors comments & Co, from one main Python developers
(dont remember who start this neither what is the URL).

In all case, dont setup another new system, use
http://wiki.python.org/moin/, at least your work will not be lost.

A+

Laurent.



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


Re: Pythondocs.info : collaborative Python documentation project

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

> Hi,
> 
> I am a bit disapointed with the current Python online documentation. I
> have read many messages of people complaining about the documentation,
> it's lack of examples and the use of complicated sentences that you
> need to read 10 times before understanding what it means.
> 
> That's why I have started a collaborative project to make a user
> contributed Python documentation. The wiki is online here:
> http://www.pythondocs.info
> 
> This is a fresh new website, so there's not much on it, but I hope to
> make it grow quickly. Help and contributions are welcome; Please
> register and start posting your own documentation on it.
> 
> Regards,
> 
> Nicolas.
> -
> http://www.pythondocs.info

You're realy nor the first one, see
http://mail.python.org/pipermail/python-list/2004-May/219580.html
(and following thread)

Other (never achieved) projects... http://www.pythondocs.org/

Even Skip Montanaro python-glossary site seem to not have been continued...
http://mail.python.org/pipermail/python-list/2004-May/219682.html


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


Re: python threading and timing

2006-10-02 Thread Laurent Pointal
Dennis Lee Bieber a écrit :
> On Sun, 1 Oct 2006 22:28:10 +0200, "Oeyvind Brandtsegg"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> Also, I wonder what method I should be using to get a precise timing
>> in my automation thread (acting as a sequencer).
>>
>   Use a real-time OS (which neither M$ Windows nor Linux/UNIX claim to
> be).
> 
>   All non-deterministic, multi-tasking, OS's (like Windows, Linux,
> Solaris, AmigaOS) only guarantee that, for example, a sleep() call will
> not return /before/ the time specified. There is no specification for
> how much time /over/ the duration actually takes place.
> 
>   And setting the task priority into the Windows "real-time" category
> is not sufficient -- I had an application that had to put out data on
> six pins of the parallel port (acting as three discrete RS-422 style
> balanced signals) in time with a (1KHz, as I recall) clock signal coming
> in on another pin of the parallel port. The data was still getting
> glitches every ~256 clocks as the OS did something in the background.
> (the application was written in VC++6, and even disabled the GUI during
> the data output operation.
> 

+++

realtime OSes != high level priority threads

And for a sound production using a sequencer, it looks like to need real
realtime.


And dont use Python threads for realtime multithreading, even on a
realtime OS (because of the GIL - Global Interpreter Lock).

May use Python for some -non realtime- parts, but I would not use any
scripting language (not specific to Python) for real-time work (prefer
C, ADA, maybe Java with ad-hoc extensions).

You may go to Python by writing a Python C extension module (doing
realtime work on its own - but never relying on python GIL in critical
times), communicating with normal python scripts (shared memory...
things which dont need the GIL if possible).

A+

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


Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-27 Thread Laurent Pointal
Fred Bayer a écrit :
> 
> Tony Belding wrote:
>> I'm interested in using an off-the-shelf interpreted language as a
>> user-accessible scripting language for a MUCK.  I'm just not sure if I
>> can find one that does everything I need.  The MUCK must be able to
>> call the interpreter and execute scripts with it, but the interpreter
>> must also be able to call functions in the MUCK code.  And then
>> there's the security issue that really worries me. . .  I have to be
>> able to limit what the interpreter can execute.  I can't have my users
>> running scripts that access the console, access the filesystem or
>> sockets directly, or call libraries or other binaries outside the MUCK.
>>
>> Is this practical?  I'm thinking of Ruby or Python for this, if they
>> can meet the requirements.
>>
> 
> Don't forget Lua: www.lua.org
> It fulfills your requirements and is easily embedable.
> 

I Agree with F.Bayer, when reading OP post, I immediatly think about Lua.



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


Re: PythonTidy

2006-11-30 Thread Laurent Pointal
Roberto Bonvallet a écrit :
> Chuck Rhode wrote:
>> I couldn't find a routine to clean up, regularize, and reformat Python
>> code, so I wrote one:
>>
>>  http://www.lacusveris.com/PythonTidy/PythonTidy.python
>>
>> Now, I'm looking for beta-testers.  Compensation is a bit on the low
>> side.  In fact it's limited to the satisfaction of helping out.
> 
...
> # vim: set fileencoding=utf-8 :
...
> # -*- coding: utf-8 -*-
...
> About changing the shebang line:  I'll take it as a bug.
> About changing the encoding declaration from vim-style to emacs-style:
> I'll take it as an insult :)

This is not "emacs-style", this is Python normalized source encoding
directive for correct interpretation of u"..." strings by Python
interpreter.

See http://www.python.org/dev/peps/pep-0263/


A+

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


Re: PythonTidy

2006-11-30 Thread Laurent Pointal
Laurent Pointal a écrit :

> See http://www.python.org/dev/peps/pep-0263/

Aye, sorry for my missreading...

[seem I hurt the emacs guy]

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


Re: Ruby/Python/REXX as a MUCK scripting language

2006-12-01 Thread Laurent Pointal
Cameron Laird a écrit :
> In article <[EMAIL PROTECTED]>,
> Laurent Pointal  <[EMAIL PROTECTED]> wrote:
>> Fred Bayer a écrit :
>>> Tony Belding wrote:
>>>> I'm interested in using an off-the-shelf interpreted language as a
>>>> user-accessible scripting language for a MUCK.  I'm just not sure if I
>   .
>   .
>   .
>>>> there's the security issue that really worries me. . .  I have to be
>>>> able to limit what the interpreter can execute.  I can't have my users
>>>> running scripts that access the console, access the filesystem or
>>>> sockets directly, or call libraries or other binaries outside the MUCK.
>>>>
>>>> Is this practical?  I'm thinking of Ruby or Python for this, if they
>>>> can meet the requirements.
>>>>
>>> Don't forget Lua: www.lua.org
>>> It fulfills your requirements and is easily embedable.
>>>
>> I Agree with F.Bayer, when reading OP post, I immediatly think about Lua.
> 
> Does Lua have an appropriate security model--a sandbox or such?
> Fond though I am of Lua, such would be news to me.

I dont think of a security model like in Java, but in the possibility to
limit the accessible libraries for interpreted code.

http://www.lua.org/manual/5.1/manual.html#5

If OP just need some computation logic, he could limit external world
communication libraries (these libraries must be loaded by the C host
program before being usable by scripts).
Need to look more precisely to the minimum library set to load and to
available functions in this set. Maybe it is possible to remove some
undesired functions from Lua symbol tables just after loading libraries.


[note: I have still not used Lua, but I look at it for futur use in a
current development where an embedded Python would be too heavy and make
problems relative to the GIL - but I'm still a Python fan in other use
cases]

A+

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


Re: RAD for python

2006-12-04 Thread Laurent Pointal
progman a écrit :
> is there a  VB-alike  tool for python to create forms??

Maybe take a look at DaboDev http://dabodev.com/

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


Re: About the 79 character line recommendation

2006-12-06 Thread Laurent Pointal
Olivier Langlois a écrit :
> Hi,
> 
> There was a coding standard where I worked and the intention behind this
> requirement was to make the code printer friendly. Printing code source
> with lines longer than 80 chars greatly hinder readability on paper.

Try using size 10 font in place of size 12 when printing.
Still readable, print correctly longer lines.

[ :-) but I try to keep lines under the 80 columns too :-) ]

> 
> Greetings,
> Olivier Langlois
> http://www.olivierlanglois.net
>> I also think that limiting code to 80 columns often hinders
>> readability. I personally try to limit my code to 100 columns. The end
>> result is pretty nice.
>>
>> However, I'm all for the "flat is better than nested" philosophy, even
>> when nested is under 100 columns.
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Am I stupid or is 'assert' broken in Python 2.5??

2006-12-06 Thread Laurent Pointal
antred a écrit :
> I've noticed something odd in Python 2.5, namely that the 2 argument
> version of 'assert' is broken. Or at least it seems that way to me.
> 
> Run the following code in your Python interpreter:
> 
> myString = None
> 
> assert( myString, 'The string is either empty or set to the None type!'
> )
> assert( myString )
> 
> You'll notice that the first assert doesn't do anything, whereas the
> second assert correctly recognizes that myString does not evaluate to
> true. That doesn't seem right. Surely Python should have raised an
> assertion error on the first assert statement, right??

What you see is correct. Here is a test under Python 2.4:

>>> myString  = None
>>> assert myString, "It is empty"
Traceback (most recent call last):
  File "", line 1, in ?
AssertionError: It is empty
>>> assert (myString, "It is empty")

If you use parenthesis to group the condition to test and the error
message, then the whole created tuple is used as a condition to test...
and this condition is true so assert dont raise any exception.

So, just remove your parenthesis and all will go the expected way.

A+

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


Re: concatenating strings

2006-12-15 Thread Laurent Pointal
EHC a écrit :
> hello!
> 
> since i am a py noob, please bear with me ; )
> 
> how is it possible to concat a string and an integer in a
> print-command? i've tried
> 
> print "This robot is named %s. The current speed setting is %d, and %s
> has a lifetime of %d" % (self.name , self.speed , self.name)

Four % formating with only three arguments to format. It cannot work...

print "This robot is named %s. The current speed setting is %d, and %s
has a lifetime of %d" % (self.name , self.speed , self.name, self.lifetime)

...

> background is a class named Robot with members speed, name, etc...

May try this too:
print "This robot is named %(name)s. The current speed setting is
%(speed)d, and %(name)s has a lifetime of %(lifetime)d" % self.__dict__

[note: liftefime may be a dynamically calculated value, and should be
providen via an accessor attribute]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which "GUI module" you suggest me to use?

2007-06-06 Thread Laurent Pointal
ZioMiP a écrit :
...
> I think is like a "live browser"... not only render HTML because the 
> webpage got a bit of javascript inside...

Does the rendering absolutely need to be in your own GUI ?

Else you can use the *webbrowser* module and simply call user preffered 
browser to display data and run javascript. Less integrated, simpler to 
setup.

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


Re: launching default browser

2007-06-08 Thread Laurent Pointal
alf wrote:

> Hi,
> 
> I wonder how to launch from python default Windows browser? In fact I
> have the same question for Linux.
> 
> thx in advancve,

Via webbrowser module

http://docs.python.org/lib/module-webbrowser.html

(note: its in top five in google search for Python + launch + browser...)


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


Re: IndentationError: unexpected indent

2007-06-14 Thread Laurent Pointal
desktop a écrit :
> I have this class:
> 
> class case(blop.case):
>   def __init__(self, n, a, b):
> blop.case.__init__(self)
> print 'Monty Python's Flying Circus has a ' within it...'
> ...
> ...
> 
> But I get an error when I run the .py script from shell saying:
> 
> print 'Monty Python's Flying Circus has a ' within it...'
> ^
> IndentationError: unexpected indent
> 
> I have tried to indent the print statement 8 blanks but that does not 
> help. Any hints?

You have also another error:

 >>> print 'Monty Python's Flying Circus has a ' within it...'
   File "", line 1
 print 'Monty Python's Flying Circus has a ' within it...'
 ^
SyntaxError: invalid syntax

Better:
 >>> print "Monty Python's Flying Circus has a ' within it..."
Monty Python's Flying Circus has a ' within it...



Note: for your indentation problem, try to use an editor allowing to 
display tab and spaces and then identify the problem location, or 
replace all tabs by 4 spaces and configure the editor to only use spaces.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >