Re: simple string format question

2012-10-15 Thread Adrien

Le 15/10/2012 14:12, Neal Becker a écrit :

Is there a way to specify to format I want a floating point written with no more
than e.g., 2 digits after the decimal?  I tried {:.2f}, but then I get all
floats written with 2 digits, even if they are 0:

2.35 << yes, that's what I want
2.00 << no, I want just 2 or 2.


Maybe you're looking for "{:.3g}"

print "{:.3g}".format(2)
# '2'

print "{:.3g}".format(2.00)
# '2'

print "{:.3g}".format(2.35)
# '2.35'

print "{:.3g}".format(2.356)  # this rounds up
# '2.36'

Cheers,

-- Adrien

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


Re: Imaging libraries in active development?

2012-11-29 Thread Adrien

Hey Alasdair,

I believe OpenCV might do the trick for you:
- it contains everything you seem to need (+ much much more);
- it is efficient;
- it is cross-platform;
- it has a usable python interface since version 2.4;
- it is not going away any time soon and is constantly improved;
- it has an active user base.

But (there is always a but), it also has some issues:
- (the main one for me) documentation is often incomplete or even 
sometimes cryptic: the website (http://docs.opencv.org/) is great, but, 
IIRC, the docstrings are automatically generated from the C++ prototypes 
using Boost.Python; some trial & error is often necessary to find out 
what the parameters of a function should be;
- it may be overkill if you just want to do some basic image processing 
(maybe scikits-image is a better choice there?).


Hope this helps,

Adrien

Le 29/11/2012 07:53, Alasdair McAndrew a écrit :

I take your point that not being actively developed doesn't necessarily mean 
that the software is bad - but in general healthy software is continuously 
updated and expanded to meet the needs of its users, or to take advantage of 
new algorithms or hardware.

And in its current form PIL has a number of limitations: it doesn't allow 
linear filters of arbitrary size or shape, or non-linear filters (such as 
median filter) of arbitrary size. There doesn't seem to be built in support for 
standard imaging filters: Gaussian, Laplacian, LoG, edge detection, unsharp 
masking and so on.  It doesn't seem to have support for color space conversions 
(RGB, YIQ, HSV etc).  There don't seem to be standard edge detection routines 
(Laplacian of Gaussian, Canny, etc).  And so on.  Now maybe some of these can 
be found in other Python libraries, but I can't imagine I'm the only person who 
would ever want them in an imaging library.  Other libraries (scipy.ndimage, 
scikits-image) do go a long way to addressing my concerns.

Anyway, I was curious to know why PIL is lacking so much of what I would 
consider fairly fundamental imaging facilities, and why development seems to 
have stalled since 2009.

On Thursday, 29 November 2012 05:14:30 UTC+11, Michael Torrie  wrote:

On 11/28/2012 05:30 AM, Alasdair McAndrew wrote:


I'm investigating Python for image processing (having used Matlab,
then Octave for some years).  And I'm spoiled for choice: PIL and its
fork pillow, scipy.ndimage, scikits-image, mahotas, the Python
interface to openCV...
However, PIL doesn't seem to be in active development.  What I want
to know is - what are the current "standard" libraries for image
processing in Python which are in active development?
I have quite a few image processing student notes which I'm thinking
of converting to Python, but I'd like to use the most up-to-date
library.



I'm curious.  What features do you need that pil doesn't have?  Other

than updating pil to fix bugs, support new image types or new versions

of Python, what kind of active development do you think it needs to

have? Maybe pil has all the features the original author wanted and is

pretty stable.  To judge a package on how fast it's changing seems a bit

odd to me.  Obviously you want to know that bugs can get fixed of

course.  Perhaps none have been reported recently.


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


Re: Combining sets/dictionaries

2009-09-22 Thread Adrien
Hi,

Did you try the list.update() builtin function ?

Regards

Peter Otten a écrit :
> Alfons Nonell-Canals wrote:
> 
>> I have different sets/dictionaries/lists (whatever you want because I
>> can convert them easily) and I would like to combine them. I don't want
>> a consensus and something like it. I'd need to combine all elements of
>> the first one with the all elements of the second one and third,... the
>> numbers of dictionaries/sets/lists is variable as the number of elements
>> for each one.
>>
>> For example, i have the following sets and I would like to obtain all
>> possible combinations...
>>
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['I', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['I', 'O', 'N', 'P', 'S', 'C']
>> ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']
>>
>> And it should be flexible because as I've said, the number of
>> dictionaries/lists/sets is not always the same, as the number of elements.
>>
>> I don't like to ask this kid of questions but... today I'm totally lost
>> and I need it to close one part of a nice project...
> 
> Using one common definition of "combinations":
> 
 from pprint import pprint
 pprint(items)
> [['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'N', 'P', 'S', 'C'],
>  ['I', 'N', 'P', 'S', 'C'],
>  ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['I', 'O', 'N', 'P', 'S', 'C'],
>  ['F', 'I', 'L', 'O', 'N', 'P', 'S', 'R', 'C']]
 import itertools
 for c in itertools.combinations(items, 2):
> ... print c
> ...
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'O', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])
> (['I', 'O', 'N', 'P', 'S', 'C'], ['I', 'N', 'P', 'S', 'C'])
> 
> 
> If you mean something else (likely) please give a more detailed description 
> or provide some examples with both input and desired output.
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for a scalable Python cloud platform ? Go try Clever Cloud!

2013-06-20 Thread Adrien Cretté
If you'are looking for hosting some Python in the cloud, let me introduce you 
to http://python-cloud.com/ 

This PaaS platform can automatically scale up and down your application   
regarding your traffic. You can also finely customize if you want vertical, 
horizontal or both types of scalability. The consequence of this scaling is 
that you pay as you go: you only pay for your real consumption and not the 
potential one.

Deployment via git.

Non AWS, hosted in tier-4+ datacenters.

Free trial!

Disclosure: I work at Clever Cloud.
-- 
http://mail.python.org/mailman/listinfo/python-list


A question related to the PYTHONPATH

2018-03-25 Thread adrien oyono
Hello everyone,

This is my first email to the python list, I'll try my best to do it well.

TL;DR

I have recently read the documentation about how imports work on python,
and I was wondering why, when you execute a python file, the current
directory is not added by default to the PYTHONPATH ?

Extended:

Let's assume we have this directory structure for a python package:

$ tree A
A
├── B1
│   ├── b1.py
│   ├── C1
│   │   ├── c1_1.py
│   │   ├── c1.py
│   │   └── __init__.py
│   └── __init__.py
├── B2
│   ├── b2.py
│   ├── C2
│   │   ├── c2.py
│   │   └── __init__.py
│   └── __init__.py
├── __init__.py
└── toto.py

4 directories, 11 files


with the file A/B2/C2/c2.py content being:

import sys
print(sys.path)

import A

from A.B2.b2 import PLOP
from A.B1.C1.c1 import TOTO

print(TOTO)


If I do, from the top level directory containing the package A:

$ python A/B2/C2/c2.py

I get an :

['/tmp/A/B2/C2', '/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/cris/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-
packages/gtk-2.0']
Traceback (most recent call last):
  File "A/B2/C2/c2.py", line 9, in 
import A
ImportError: No module named A

Which is normal according to the documentation of Python 2
(https://docs.python.org/2/tutorial/modules.html#the-module-search-path):

When a module named spam is imported, the interpreter first searches for a
> built-in module with that name. If not found, it then searches for a file
> named spam.py in a list of directories given by the variable sys.path
> <https://docs.python.org/2/library/sys.html#sys.path>. sys.path
> <https://docs.python.org/2/library/sys.html#sys.path> is initialized from
> these locations:
>
>- the directory containing the input script (or the current directory).
>- PYTHONPATH
><https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH> (a
>list of directory names, with the same syntax as the shell variable
>PATH).
>- the installation-dependent default.
>
> After initialization, Python programs can modify sys.path
> <https://docs.python.org/2/library/sys.html#sys.path>. The directory
> containing the script being run is placed at the beginning of the search
> path, ahead of the standard library path. This means that scripts in that
> directory will be loaded instead of modules of the same name in the library
> directory. This is an error unless the replacement is intended. See section 
> Standard
> Modules
> <https://docs.python.org/2/tutorial/modules.html#tut-standardmodules> for
> more information.
>

Meanwhile when I do:

$ python -m A.B2.C2.c2

I get the script running correctly:

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/cris/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0']
42

An empty string is now pre-pended to the value of sys.path, which means, if
I correctly interpret the documentation of Python 3, that the current
directory is added to the PYTHONPATH (https://docs.python.org/3/
reference/import.html#path-entry-finders):

The current working directory – denoted by an empty string – is handled
> slightly differently from other entries on sys.path
> <https://docs.python.org/3/library/sys.html#sys.path>. First, if the
> current working directory is found to not exist, no value is stored in
> sys.path_importer_cache
> <https://docs.python.org/3/library/sys.html#sys.path_importer_cache>.
> Second, the value for the current working directory is looked up fresh for
> each module lookup. Third, the path used for sys.path_importer_cache
> <https://docs.python.org/3/library/sys.html#sys.path_importer_cache> and
> returned by importlib.machinery.PathFinder.find_spec()
> <https://docs.python.org/3/library/importlib.html#importlib.machinery.PathFinder.find_spec>
> will be the actual current working directory and not the empty string.
>


What I am interested in is what is the reason of this difference ?


P.S.:

   - My english may suck a bit, please blame it on me being a French native
   speaker
   - Sorry if the colours hurt 😅


*Adrien OYONO*
-- 
https://mail.python.org/mailman/listinfo/python-list


PyGILState API and Py_Main

2014-12-18 Thread Adrien Bruneton

Hello all,

I am having a hard time understanding what is the proper use of 
PyGILState_Ensure/Release.
My understanding is that one should always be matched with the other, 
and that this high level API auto-magically deals with the ThreadState 
creation.


However the following piece of code (executed with a simple "print 
'hello world' " script as argv) triggers the message:


Fatal Python error: auto-releasing thread-state, but no 
thread-state for this thread


Minimal code:

void initPython(int initsigs)
{
  if (Py_IsInitialized() == 0)
{
  Py_InitializeEx(initsigs);
  // Put default SIGINT handler back after 
Py_Initialize/Py_InitializeEx.

  signal(SIGINT, SIG_DFL);
}

  int threadInit = PyEval_ThreadsInitialized();
  PyEval_InitThreads(); // safe to call this multiple time

  if(!threadInit)
PyEval_SaveThread(); // release GIL
}

int main(int argc, char ** argv)
{
  initPython(1);
  PyGILState_STATE _gstate_avoid_clash = PyGILState_Ensure();
  int ret = Py_Main(argc, argv);
  PyGILState_Release(_gstate_avoid_clash);  // this one triggers the 
Fatal error

  Py_Finalize();
  return ret;
}


Removing the last PyGILState_Release works, but I have a bad feeling 
about it :-)

Any help would be welcome! Thanks in advance.
Adrien.

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


uninstall 3.5

2015-11-16 Thread Adrien Viala
Hello,

Thank you for your work. Just discovering python.

My issue steps were  :
- 3.5 installed
- friend codes in 2.7
- server scripts can t run on my laptop (cant find module 0o)
- whatever, must be 3.5 / 2.7 issues
- let's try virtualenv
- can t download virtualenvwrapper-powershell : error X that i can t find
info about on googl
- whatever let's uninstall 3.5

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


Re: uninstall 3.5

2015-11-16 Thread Adrien Viala
Hi again, Correct guess, virtualenvwrapper-powershell correctly installed
under 2.7 :)

On Sun, 15 Nov 2015 at 12:31 Adrien Viala <
[email protected]> wrote:

> Hello,
>
> Thank you for your work. Just discovering python.
>
> My issue steps were  :
> - 3.5 installed
> - friend codes in 2.7
> - server scripts can t run on my laptop (cant find module 0o)
> - whatever, must be 3.5 / 2.7 issues
> - let's try virtualenv
> - can t download virtualenvwrapper-powershell : error X that i can t find
> info about on googl
> - whatever let's uninstall 3.5
>
> :/
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list