Re: Importing module from another subdirectory

2019-04-23 Thread Rich Shepard
On Tue, 23 Apr 2019, dieter wrote: I use "virtualenv" (for "VIRTUAL ENVironmet") to separate projects. Dieter, I know about virtualenv and tried using them. Found conflicting information and didn't know if I really needed them. I'll re-learn how to activate and use them. One project is for m

Re: Better ways for implementing two situations

2019-04-23 Thread Paulo da Silva
Às 19:42 de 21/04/19, Stefan Ram escreveu: > Paulo da Silva writes: >> I have a list of objects and want to split it in a list of groups. >> "equal objects" is based on an id we can get from the object. > > main.py > > input = [ 'abc', 'ade', 'bcd' ] > > for group, list in \ > __import__( 'ite

Re: Better ways for implementing two situations

2019-04-23 Thread Paulo da Silva
Às 20:10 de 21/04/19, MRAB escreveu: > On 2019-04-21 19:23, Paulo da Silva wrote: >> Hi all. >> ... > Have you compared the speed with an implementation that uses > defaultdict? Your code always creates an empty list for each item, even > though it might not be needed. I never used defaultdict. I'

Re: Better ways for implementing two situations

2019-04-23 Thread Paulo da Silva
Às 20:41 de 21/04/19, DL Neil escreveu: > Olá Paulo, > ... > > Given that we're talking "big data", which Python Data Science tools are > you employing? eg NumPy. Sorry. I misused the term "big data". I should have said a big amount of data. It is all about objects built of text and some number

Re: Better ways for implementing two situations

2019-04-23 Thread Paulo da Silva
Às 22:21 de 21/04/19, Paul Rubin escreveu: > Paulo da Silva writes: >> splitter={} >> for f in Objs: >> splitter.setdefault(f.getId1,[]).append(f) >> groups=[gs for gs in splitter.values() if len(gs)>1] > > It's easiest if you can sort the input list and then use > itertools.groupby. Yes, so

How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre
Hi, In a CPython lib I have an _init() method wich take one argument, a file name.     char *fname;     if (!PyArg_ParseTuple(args, "s", &fname))     return NULL; So, if I instanciate my object with a bad argument I've a good error message: tif = ImgProc(123) TypeError: argument 1 mus

Re: How to catch a usefull error message ?

2019-04-23 Thread Chris Angelico
On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre wrote: > > Hi, > > In a CPython lib I have an _init() method wich take one argument, a file > name. > > char *fname; > > if (!PyArg_ParseTuple(args, "s", &fname)) > return NULL; > > So, if I instanciate my object with a bad arg

Re: How to catch a usefull error message ?

2019-04-23 Thread MRAB
On 2019-04-23 10:56, Vincent Vande Vyvre wrote: Hi, In a CPython lib I have an _init() method wich take one argument, a file name.     char *fname;     if (!PyArg_ParseTuple(args, "s", &fname))     return NULL; So, if I instanciate my object with a bad argument I've a good error mes

Re: How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre
Le 23/04/19 à 19:23, Chris Angelico a écrit : On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre wrote: Hi, In a CPython lib I have an _init() method wich take one argument, a file name. char *fname; if (!PyArg_ParseTuple(args, "s", &fname)) return NULL; So, if I inst

Re: How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre
Le 23/04/19 à 19:27, MRAB a écrit : On 2019-04-23 10:56, Vincent Vande Vyvre wrote: Hi, In a CPython lib I have an _init() method wich take one argument, a file name.       char *fname;       if (!PyArg_ParseTuple(args, "s", &fname))       return NULL; So, if I instanciate my object with

Re: How to catch a usefull error message ?

2019-04-23 Thread Chris Angelico
On Wed, Apr 24, 2019 at 4:47 AM Vincent Vande Vyvre wrote: > > Le 23/04/19 à 19:23, Chris Angelico a écrit : > > On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre > > wrote: > >> Hi, > >> > >> In a CPython lib I have an _init() method wich take one argument, a file > >> name. > >> > >> ch

Re: How to catch a usefull error message ?

2019-04-23 Thread Chris Angelico
On Wed, Apr 24, 2019 at 4:51 AM Vincent Vande Vyvre wrote: > > Le 23/04/19 à 19:27, MRAB a écrit : > > On 2019-04-23 10:56, Vincent Vande Vyvre wrote: > >> Hi, > >> > >> In a CPython lib I have an _init() method wich take one argument, a file > >> name. > >> > >> char *fname; > >> > >>

Re: How to catch a usefull error message ?

2019-04-23 Thread MRAB
On 2019-04-23 19:21, Vincent Vande Vyvre wrote: Le 23/04/19 à 19:23, Chris Angelico a écrit : On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre wrote: Hi, In a CPython lib I have an _init() method wich take one argument, a file name. char *fname; if (!PyArg_ParseTuple(args, "s

Re: need help understanding: converting text to binary

2019-04-23 Thread Eli the Bearded
In comp.lang.python, Chris Angelico wrote: > Have you checked to see if Python can already do this? You mention I'm sure there's a library already. I'm trying to mix library usage with my own code to get practice writing in python. In this case, I want code to deal with MIME encoding in email he

Re: need help understanding: converting text to binary

2019-04-23 Thread Eli the Bearded
In comp.lang.python, Paul Rubin wrote: > Eli the Bearded <*@eli.users.panix.com> writes: >> # decode a single hex digit >> def hord(c): ... > >def hord(c): return int(c, 16) That's a good method, thanks. > > # decode quoted printable, specifically the MIME-encoded words > > # variant which

Re: need help understanding: converting text to binary

2019-04-23 Thread Cameron Simpson
On 23Apr2019 20:35, Eli the Bearded <*@eli.users.panix.com> wrote: In comp.lang.python, Chris Angelico wrote: Is there a more python-esque way to convert what should be plain ascii What does "plain ASCII" actually mean, though? ASCII encoded binary data. ASCII is code points that fit in 7-b

Re: How to catch a usefull error message ?

2019-04-23 Thread Gregory Ewing
Vincent Vande Vyvre wrote: static int ImgProc_init(ImgProc *self, PyObject *args, PyObject *kwds) { PyObject *tmp; char *fname; if (!PyArg_ParseTuple(args, "s", &fname)) return NULL; You should be returning -1 here, not NULL. -- Greg -- https://mail.python.org/mailman/list

Re: need help understanding: converting text to binary

2019-04-23 Thread Gregory Ewing
Cameron Simpson wrote: If you don't know the encoding then you don't know you're looking at a hex digit. OTOH, if the binary data contain ASCII data then you do know the encoding: it is ASCII. Not necessarily, it could be a superset of ASCII such as latin-1 or utf-8. You do need to know that

Re: need help understanding: converting text to binary

2019-04-23 Thread Eli the Bearded
In comp.lang.python, Cameron Simpson wrote: > On 23Apr2019 20:35, Eli the Bearded <*@eli.users.panix.com> wrote: >> That feels entirely wrong. I don't know what b'\x9A' means without >> knowing the character set and character encoding. If the encoding is a >> multibyte one, b'\x9A' doesn't mean a

Re: Importing module from another subdirectory

2019-04-23 Thread dieter
Rich Shepard writes: > On Tue, 23 Apr 2019, dieter wrote: > ... > One project is for my own use and I understand now that a virtualenv with > its own sys.path appendices would work. Those are two separate approaches: With a "virtualenv", there is usually no need to tweak "sys.path" -- you simply