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

2017-02-15 Thread Makoto Kuwata
Thanks Irmen and Steven,

I'm sorry that my explanation is not enough.
I'm looking for bad python code, not refactoring examples.
I can do (and want to do) refactor bad code by myself.

Is there any bad python code (or project) with proper size?

# I found a lot of bad PHP code in github, but didn't find bad Python code.

--
regards,
makoto kuwata


On Wed, Feb 15, 2017 at 3:28 PM, Steven D'Aprano 
wrote:

> On Wed, 15 Feb 2017 07:44:03 +0900, Makoto Kuwata wrote:
>
> > Hi,
> >
> > Is there any *just right* python code to refactor?
> > In other words, I'm finding bad code example in python.
>
>
> Try looking at the ActiveState website for recipes in Python. Especially
> look at the ones with negative ratings, but even positively rated recipes
> are often nonsense.
>
> E.g. http://code.activestate.com/recipes/580750
>
> does nothing more that define
>
> echo = sys.stdout.write
>
> Why not use sys.stdout.write directly? Or print? If I saw somebody using
> this recipe in production code, in the way shown, I'd refactor it to just
> use print. There's no advantage to re-inventing the wheel this way.
>
>
>
> --
> Steve
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon
In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains 
the line


/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it 
should be possible to write


import tau4

in my programs. But it isn't. Despite the fact that 
/home/poseidon/tau4/swr/py3/src is in sys.path, I get a ModuleNotFoundError.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the 
site-packages dir:


ln -s /home/poseidon/tau4/swr/py3/src /usr/lib/python3.6/site-packages/tau4

https://docs.python.org/3.6/library/site.html suggests that PTH files 
only work relative to the site-packages dir. But digging around in e.g. 
StackOverflow I got the impression that absolute paths should work as 
well. If so, what am I doing wrong?


I'm on Arch Linux, Python 3.6.

Kind regards
Paul


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


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

2017-02-15 Thread Antoon Pardon
Op 15-02-17 om 07:28 schreef Steven D'Aprano:
> On Wed, 15 Feb 2017 07:44:03 +0900, Makoto Kuwata wrote:
>
>> Hi,
>>
>> Is there any *just right* python code to refactor?
>> In other words, I'm finding bad code example in python.
>
> Try looking at the ActiveState website for recipes in Python. Especially 
> look at the ones with negative ratings, but even positively rated recipes 
> are often nonsense.
>
> E.g. http://code.activestate.com/recipes/580750
>
> does nothing more that define
>
> echo = sys.stdout.write
>
> Why not use sys.stdout.write directly? Or print? If I saw somebody using 
> this recipe in production code, in the way shown, I'd refactor it to just 
> use print. There's no advantage to re-inventing the wheel this way.

On reason to use this is for some easy "logging", you use echo to help
in debugging and afterwards you can either define echo as an empty
function or something easy to find to comment out.

-- 
Antoon Pardon.

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


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

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

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

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

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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread Wolfgang Maier

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the 
package/module search path stored in sys.path. That is, in your example, 
if you put a file tau4.py or a tau4 directory with the __init__.py file 
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import tau4.



It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src /usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4 
package (i.e., a directory with that name and an __init__.py file 
inside) in /usr/lib/python3.6/site-packages. The .pth file is not 
involved in this at all.



https://docs.python.org/3.6/library/site.html suggests that PTH files
only work relative to the site-packages dir. But digging around in e.g.
StackOverflow I got the impression that absolute paths should work as
well. If so, what am I doing wrong?

I'm on Arch Linux, Python 3.6.

Kind regards
Paul




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


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

2017-02-15 Thread Steve D'Aprano
On Wed, 15 Feb 2017 09:49 pm, Antoon Pardon wrote:

> Op 15-02-17 om 07:28 schreef Steven D'Aprano:
[...]
>> Why not use sys.stdout.write directly? Or print? If I saw somebody using
>> this recipe in production code, in the way shown, I'd refactor it to just
>> use print. There's no advantage to re-inventing the wheel this way.
> 
> On reason to use this is for some easy "logging", you use echo to help
> in debugging and afterwards you can either define echo as an empty
> function or something easy to find to comment out.

In Python 3 you can always add 

def print(*args, **kw):
pass

in your module to disable printing. But a better way, in my opinion, is to
use your editor to search for:

print(

and replace with:

#print(



But even better, once you get to the point of putting print calls in more
than two or three places in your code, you should probably invest the time
to learn how to use the logging module.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon

On 15/02/17 12:16, Wolfgang Maier wrote:

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the
package/module search path stored in sys.path. That is, in your example,
if you put a file tau4.py or a tau4 directory with the __init__.py file
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import tau4.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src
/usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4
package (i.e., a directory with that name and an __init__.py file
inside) in /usr/lib/python3.6/site-packages. The .pth file is not
involved in this at all.



Yes, removed it (symlink still there) and it still works. But then, what 
are pth files for? I'd just place a symlink to the package and am done 
with. The path doesn't seem to be needed in sys.path (where it would go 
if placed in a pth file). If I write


from tau4 import datalogging

that works, too. So no need for the path being in sys.path (i.e. in a 
pth file)?




https://docs.python.org/3.6/library/site.html suggests that PTH files
only work relative to the site-packages dir. But digging around in e.g.
StackOverflow I got the impression that absolute paths should work as
well. If so, what am I doing wrong?

I'm on Arch Linux, Python 3.6.

Kind regards
Paul







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


Create ordering of points

2017-02-15 Thread spiess.benjamin--- via Python-list
Hello !:)
I've got a problem which I would really like to solve. 
I got a cloud of points (in the simplest example its a 2-dimensional cloud of 
points). 
First, I want to set one of the points as the initial (or middle) point. 
Starting from there, the next points with the closest distance to the initial 
points are to be found. Afterwards, the closest points to these points are to 
be written out. These points shall be connected like it is depicted in this 
figure http://fs5.directupload.net/images/170215/b835zixm.jpg

With this approach, the "fastest" path from every point to the defined initial 
point are specified by this pattern. 

Does somebody know a good technique for this problem? or can even give a hint 
to a existing python procedure?
I would be really grateful!


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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread Wolfgang Maier

On 15.02.2017 13:42, poseidon wrote:

On 15/02/17 12:16, Wolfgang Maier wrote:

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the
package/module search path stored in sys.path. That is, in your example,
if you put a file tau4.py or a tau4 directory with the __init__.py file
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import
tau4.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src
/usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4
package (i.e., a directory with that name and an __init__.py file
inside) in /usr/lib/python3.6/site-packages. The .pth file is not
involved in this at all.



Yes, removed it (symlink still there) and it still works. But then, what
are pth files for? I'd just place a symlink to the package and am done
with. The path doesn't seem to be needed in sys.path (where it would go
if placed in a pth file). If I write

from tau4 import datalogging

that works, too. So no need for the path being in sys.path (i.e. in a
pth file)?



I guess a major point of .pth files is that you only have one or a small 
number of files with a clear purpose polluting the containing directory. 
Of course, you could put symlinks to all your packages and modules into 
site-packages, but what's the point of putting them somewhere else in 
the first place? Also, you cannot create symlinks across devices, but 
.pth files will work.


Best,
Wolfgang

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


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

2017-02-15 Thread Antoon Pardon
Op 15-02-17 om 13:24 schreef Steve D'Aprano:
> On Wed, 15 Feb 2017 09:49 pm, Antoon Pardon wrote:
>
>> Op 15-02-17 om 07:28 schreef Steven D'Aprano:
> [...]
>>> Why not use sys.stdout.write directly? Or print? If I saw somebody using
>>> this recipe in production code, in the way shown, I'd refactor it to just
>>> use print. There's no advantage to re-inventing the wheel this way.
>> On reason to use this is for some easy "logging", you use echo to help
>> in debugging and afterwards you can either define echo as an empty
>> function or something easy to find to comment out.
> In Python 3 you can always add 
>
> def print(*args, **kw):
> pass
>
> in your module to disable printing. But a better way, in my opinion, is to
> use your editor to search for:
>
> print(
>
> and replace with:
>
> #print(

You don't seem to understand, I don't want to disable all printing, only the
diagnostics. That is easier to do if I use a different name for printing
diagnostics than for regular I/O. Whether I disable it by defining an empty
function or by commenting them out, doesn't really matter with this regard.

> But even better, once you get to the point of putting print calls in more
> than two or three places in your code, you should probably invest the time
> to learn how to use the logging module.

I know how to use the logging module. It is my experience that for a lot
of rather small projects, the hassle of setting it up, is not worth it.
YMMV.

-- 
Antoon Pardon

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


Re: Create ordering of points

2017-02-15 Thread duncan smith
On 15/02/17 13:27, spiess.benja...@googlemail.com wrote:
> Hello !:)
> I've got a problem which I would really like to solve. 
> I got a cloud of points (in the simplest example its a 2-dimensional cloud of 
> points). 
> First, I want to set one of the points as the initial (or middle) point. 
> Starting from there, the next points with the closest distance to the initial 
> points are to be found. Afterwards, the closest points to these points are to 
> be written out. These points shall be connected like it is depicted in this 
> figure http://fs5.directupload.net/images/170215/b835zixm.jpg
> 
> With this approach, the "fastest" path from every point to the defined 
> initial point are specified by this pattern. 
> 
> Does somebody know a good technique for this problem? or can even give a hint 
> to a existing python procedure?
> I would be really grateful!
> 
> 
> Regards
> Benny
> 

Maybe https://en.wikipedia.org/wiki/Shortest-path_tree?

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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon

On 15/02/17 14:34, Wolfgang Maier wrote:

On 15.02.2017 13:42, poseidon wrote:

On 15/02/17 12:16, Wolfgang Maier wrote:

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It
contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the
package/module search path stored in sys.path. That is, in your example,
if you put a file tau4.py or a tau4 directory with the __init__.py file
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import
tau4.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src
/usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4
package (i.e., a directory with that name and an __init__.py file
inside) in /usr/lib/python3.6/site-packages. The .pth file is not
involved in this at all.



Yes, removed it (symlink still there) and it still works. But then, what
are pth files for? I'd just place a symlink to the package and am done
with. The path doesn't seem to be needed in sys.path (where it would go
if placed in a pth file). If I write

from tau4 import datalogging

that works, too. So no need for the path being in sys.path (i.e. in a
pth file)?



I guess a major point of .pth files is that you only have one or a small
number of files with a clear purpose polluting the containing directory.
Of course, you could put symlinks to all your packages and modules into
site-packages, but what's the point of putting them somewhere else in
the first place? Also, you cannot create symlinks across devices, but
.pth files will work.


Thank you, Wolfgang.

Did the following: Put a symlink tau4 in /home/poseidon/tau4/swr/py3/src 
pointing to this directory. Removed the symlink in the site-packages. 
Restore the pth file tau4.pth containing the line 
/home/poseidon/tau4/swr/py3/src.


Worx! Thank you for sheding light on this!

Paul




Best,
Wolfgang




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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread Steve D'Aprano
On Wed, 15 Feb 2017 11:42 pm, poseidon wrote:

> Yes, removed it (symlink still there) and it still works. But then, what
> are pth files for? 


Good question. I don't actually know anyone that uses pth files, so perhaps
they're unnecessary.

But the principle behind them is that they can be used to customize the
search path Python uses for locating modules. There are (at least) six ways
to customize this path:


(1) Have your application import sys and modify sys.path on startup.

(2) Set the environment variable PYTHONPATH.

(3) For those building and distributing their own Python environment, e.g.
Linux distros, you can customise the site.py file.

(4) For site-wide customization, create a sitecustomize.py file in (for
example) /usr/local/lib/python3.5/site-packages/ or the equivalent for your
system, and modify sys.path.

(5) For a per-user customization, create usercustomize.py in (for example)
~/.local/lib/python3.5/site-packages/ or the equivalent for your system.
Again, import sys and modify sys.path.

(6) Or place a pth file in one of the site-packages locations.

See the documentation for the site module for more detail:

https://docs.python.org/3/library/site.html



> I'd just place a symlink to the package and am done 
> with. The path doesn't seem to be needed in sys.path (where it would go
> if placed in a pth file). If I write
> 
> from tau4 import datalogging
> 
> that works, too. So no need for the path being in sys.path (i.e. in a
> pth file)?

Where are you placing the symlink? Python will follow symlinks, but they
have to be in the PYTHONPATH to be found in the first place. And not all
platforms support symlinks. (Windows, I think.)




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Create ordering of points

2017-02-15 Thread Ben Bacarisse
spiess.benja...@googlemail.com writes:

> I've got a problem which I would really like to solve. 
> I got a cloud of points (in the simplest example its a 2-dimensional
> cloud of points).
> First, I want to set one of the points as the initial (or middle)
> point. Starting from there, the next points with the closest distance
> to the initial points are to be found. Afterwards, the closest points
> to these points are to be written out. These points shall be connected
> like it is depicted in this figure
> http://fs5.directupload.net/images/170215/b835zixm.jpg
>
> With this approach, the "fastest" path from every point to the defined
> initial point are specified by this pattern.

The fastest path will be a direct line -- every point connected to the
root (you are building a tree).  Are you perhaps looking for what is
call the minimum spanning tree?

This is not really a Python question.  Some language Usenet groups and
mailing lists (this is both) don't like general programming questions
and some don't mind.  I'm not sure what comp.lang.python's view is on
these things, but groups like comp.programming and even comp.theory are,
on the surface, better places to ask.  Unfortunately they are full of
cranks. though they can be ignored.


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


Re: Create ordering of points

2017-02-15 Thread Pavol Lisy
On 2/15/17, spiess.benjamin--- via Python-list  wrote:
> Hello !:)
> I've got a problem which I would really like to solve.
> I got a cloud of points (in the simplest example its a 2-dimensional cloud
> of points).
> First, I want to set one of the points as the initial (or middle) point.
> Starting from there, the next points with the closest distance to the
> initial points are to be found. Afterwards, the closest points to these
> points are to be written out. These points shall be connected like it is
> depicted in this figure
> http://fs5.directupload.net/images/170215/b835zixm.jpg
>
> With this approach, the "fastest" path from every point to the defined
> initial point are specified by this pattern.
>
> Does somebody know a good technique for this problem? or can even give a
> hint to a existing python procedure?
> I would be really grateful!

Something like 
https://networkx.github.io/documentation/networkx-1.10/reference/algorithms.shortest_paths.html
could help?

Or maybe this 
https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.algorithms.mst.minimum_spanning_tree.html?highlight=minimum_spanning_tree
?

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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread gst
Le mercredi 15 février 2017 10:34:42 UTC-5, Steve D'Aprano a écrit :
> On Wed, 15 Feb 2017 11:42 pm, poseidon wrote:
> 
> > Yes, removed it (symlink still there) and it still works. But then, what
> > are pth files for? 
> 
> 
> Good question. I don't actually know anyone that uses pth files, so perhaps
> they're unnecessary.
> 

when used with the "import " mechanism they can be used as a startup hook for 
instance, which can be pretty useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-02-15 Thread Chris Angelico
On Thu, Feb 16, 2017 at 12:37 AM, Antoon Pardon
 wrote:
>> But a better way, in my opinion, is to
>> use your editor to search for:
>>
>> print(
>>
>> and replace with:
>>
>> #print(
>
> You don't seem to understand, I don't want to disable all printing, only the
> diagnostics. That is easier to do if I use a different name for printing
> diagnostics than for regular I/O. Whether I disable it by defining an empty
> function or by commenting them out, doesn't really matter with this regard.
>
>> But even better, once you get to the point of putting print calls in more
>> than two or three places in your code, you should probably invest the time
>> to learn how to use the logging module.
>
> I know how to use the logging module. It is my experience that for a lot
> of rather small projects, the hassle of setting it up, is not worth it.
> YMMV.

Once you get to the point of saying either "but #print( might comment
out only the first line, so I can't wrap it" or "but #print( would
comment out too much, I only want to toggle some of the statements",
it's time to set up logging. Also, if you're building a daemon that
should play nicely with a larger system (eg a system process on
Unix/Linux), the logging module makes that work a lot easier, since
you can easily redirect it to a file or whatever you want.

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


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

2017-02-15 Thread jladasky
On Wednesday, February 15, 2017 at 2:52:55 AM UTC-8, Antoon Pardon wrote:
> Op 15-02-17 om 07:28 schreef Steven D'Aprano:

> > E.g. http://code.activestate.com/recipes/580750
> >
> > does nothing more that define
> >
> > echo = sys.stdout.write
> >
> > Why not use sys.stdout.write directly? Or print? If I saw somebody using 
> > this recipe in production code, in the way shown, I'd refactor it to just 
> > use print. There's no advantage to re-inventing the wheel this way.
> 
> On reason to use this is for some easy "logging", you use echo to help
> in debugging and afterwards you can either define echo as an empty
> function or something easy to find to comment out.
> 
> -- 
> Antoon Pardon.

Agreed, I have done things like this myself, but within functions, not at the 
global level.  The "echo" name could be assigned to some other function 
elsewhere in the code.  I use the name reassignment to direct the function's 
logging information -- to a console, to a GUI, or to "/dev/null" by creating an 
empty function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess problem

2017-02-15 Thread Andreas Paeffgen

On 2017-02-11 02:23:12 +, Cameron Simpson said:


  def your_function(...):
with open('/path/to/your/logfile.txt', 'a') as logfp:
  print("PATH=".os.environ['PATH'], file=logfp)
  p=Popen(...)
  p.communicate(...)
  print("p.returncode=%r" % (p.returncode))

and any other interesting values that occur to you. This is really simple, and
doesn't require a terminal or using the logging module.

You can 'tail -f /path/to/your/logfile.txt' in another terminal to watch stuff
happen as you exercise the program.


Thanks for the great advice.
I found out, that the frozen app does not pass the normal path 
variable. All the tricks with passing the correct environment did not 
work. I just hardcoded the existing standard path. After that it worked.


I think it is a problem with frozen apps in general. Cx_Freeze has 
other problems than Pyinstaller. But all need some workarounds for the 
problems.




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


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

2017-02-15 Thread Dotan Cohen
I think that we can help each other! This is my own code, back when I
was writing Python like PHP:
https://github.com/dotancohen/burton

It is badly in need of a Pythonic refactor! Have at it, and I'll be
happy to accept any pull requests.

On Wed, Feb 15, 2017 at 12:44 AM, Makoto Kuwata  wrote:
> Hi,
>
> Is there any *just right* python code to refactor?
> In other words, I'm finding bad code example in python.
>
> (background)
> I'm teaching Python to some novice programmer, and
> want to show refactoring example to them.
>
> (required)
> * not good code
> * not too large (for novice programmer)
> * not too complex (for novice programmer)
> * released under open source license
>
> If you know good material in github or bitbucket to refactor,
> let me know it.
>
> --
> regards,
> kwatch
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2017-02-15 Thread Erik

Hi,

On 15/02/17 09:36, Makoto Kuwata wrote:

I'm sorry that my explanation is not enough.
I'm looking for bad python code, not refactoring examples.


I think you need to explain what you mean by "bad". Do you mean 
something like:


i = 0
data = ["bad", "example", "of", "python", "code"]
while i < len(data):
process(data[i])
i = i + 1

... which could be better expressed as:

data = ["good", "example", "of", "python", "code"]
for d in data:
process(data)

?

If so, then you're asking for "unpythonic" code examples (code that is 
written in the style of a different language that doesn't have some of 
Python's syntactic sugar and underlying mechanisms).


I suspect that you can find many short examples like the above on sites 
like StackOverflow, but finding a substantial code-base example (which 
is what I think you mean by "proper size") is unlikely, as anyone 
writing a large project in Python is almost certainly going to have 
learned and adopted the "pythonic" idioms long before their project 
became as large as you appear to be asking for.


If you _don't_ mean what I suggested above, please explain further 
(Python code examples of what you think is "bad" vs "good" would be useful).


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


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

2017-02-15 Thread Erik

On 15/02/17 21:53, Erik wrote:

process(data)


Before I get jumped on by a pack of rabid wolves, I of course meant:

process(d)

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


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread Ned Batchelder
On Wednesday, February 15, 2017 at 8:34:45 AM UTC-5, Wolfgang Maier wrote:
> On 15.02.2017 13:42, poseidon wrote:
> > On 15/02/17 12:16, Wolfgang Maier wrote:
> >> On 15.02.2017 10:33, poseidon wrote:
> >>> In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains
> >>> the line
> >>>
> >>> /home/poseidon/tau4/swr/py3/src
> >>>
> >>> In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
> >>> should be possible to write
> >>>
> >>> import tau4
> >>>
> >>> in my programs.
> >>
> >>
> >> No, that's not what you should expect!
> >> A path file contains paths to be added at interpreter startup to the
> >> package/module search path stored in sys.path. That is, in your example,
> >> if you put a file tau4.py or a tau4 directory with the __init__.py file
> >> inside into /home/poseidon/tau4/swr/py3/src, *then* you could import
> >> tau4.
> >>
> >>> It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
> >>> site-packages dir:
> >>>
> >>> ln -s /home/poseidon/tau4/swr/py3/src
> >>> /usr/lib/python3.6/site-packages/tau4
> >>>
> >>
> >> Well this works because now Python finds (following the symlink) a tau4
> >> package (i.e., a directory with that name and an __init__.py file
> >> inside) in /usr/lib/python3.6/site-packages. The .pth file is not
> >> involved in this at all.
> >>
> >
> > Yes, removed it (symlink still there) and it still works. But then, what
> > are pth files for? I'd just place a symlink to the package and am done
> > with. The path doesn't seem to be needed in sys.path (where it would go
> > if placed in a pth file). If I write
> >
> > from tau4 import datalogging
> >
> > that works, too. So no need for the path being in sys.path (i.e. in a
> > pth file)?
> >
> 
> I guess a major point of .pth files is that you only have one or a small 
> number of files with a clear purpose polluting the containing directory. 
> Of course, you could put symlinks to all your packages and modules into 
> site-packages, but what's the point of putting them somewhere else in 
> the first place? Also, you cannot create symlinks across devices, but 
> .pth files will work.

Also, not all operating systems support symlinks.

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


Crappy Python code of the day

2017-02-15 Thread Steven D'Aprano
This has been in production for months, the writer of the code has left 
and the new maintainer has been asked to find out why it has been 
crashing with UnboundLocalError:


try:
result = future.result()
except requests.exceptions.ConnectionError as e:
pass
resp = self.client.service.GetModifiedTerminals(
__inject={'reply': result.content})


Traceback (most recent call last):
[incriminating details removed for the protection of the guilty]
UnboundLocalError: local variable 'result' referenced before assignment


https://realpython.com/blog/python/the-most-diabolical-python-antipattern/



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


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

2017-02-15 Thread Paul Rubin
Antoon Pardon  writes:
> On reason to use this is for some easy "logging"

I think it's better to use the actual logging module.  I generally start
a new program with print statements but convert them to logging after
there's enough code to want to be more organized about it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create ordering of points

2017-02-15 Thread Paul Rubin
spiess.benja...@googlemail.com writes:
> Does somebody know a good technique for this problem? or can even give
> a hint to a existing python procedure?

You're asking about nearest neighbor search, which is the topic of a
huge literature:

https://en.wikipedia.org/wiki/Nearest_neighbor_search
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Crappy Python code of the day

2017-02-15 Thread Chris Angelico
On Thu, Feb 16, 2017 at 1:25 PM, Steven D'Aprano  wrote:
> This has been in production for months, the writer of the code has left
> and the new maintainer has been asked to find out why it has been
> crashing with UnboundLocalError:
>
>
> try:
> result = future.result()
> except requests.exceptions.ConnectionError as e:
> pass
> resp = self.client.service.GetModifiedTerminals(
> __inject={'reply': result.content})
>
>
> Traceback (most recent call last):
> [incriminating details removed for the protection of the guilty]
> UnboundLocalError: local variable 'result' referenced before assignment
>

Without even looking at the link 'except pass' around an
assignment. Unless there's a preceding "result = some-other-object",
that's going to annoyingly fail. Maybe "except return None"?

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


Re: Crappy Python code of the day

2017-02-15 Thread Steven D'Aprano
On Thu, 16 Feb 2017 14:28:57 +1100, Chris Angelico wrote:

> On Thu, Feb 16, 2017 at 1:25 PM, Steven D'Aprano 
> wrote:
>> This has been in production for months, the writer of the code has left
>> and the new maintainer has been asked to find out why it has been
>> crashing with UnboundLocalError:
[...]

> Without even looking at the link 'except pass' around an assignment.
> Unless there's a preceding "result = some-other-object",
> that's going to annoyingly fail. Maybe "except return None"?

Oh, we know why the code is failing. We don't need help diagnosing the 
UnboundLocalError exception. You're right: there's an except pass around 
an assignment, so if the assignment fails, `result` never gets set.

But the real WTF is that the ConnectionError is just thrown away. There's 
no attempt to recover from it, or log it, or try connecting again... the 
end result is that the application dies with an unhelpful 
UnboundLocalError, and (until today) we had no idea what the actual cause 
of the failure was.


[Name changed to protect the guilty]

Thanks Aloysius!!!




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