Must target be only one bit one such as 0001,0010,0100,1000 In supervised neural learning f(w*p+b) with perceptron rule w = w + e for linear case?

2017-01-19 Thread Ho Yeung Lee
Must target be only one bit one such as 0001,0010,0100,1000 In supervised 
neural learning f(w*p+b) with perceptron rule w = w + e for linear case?

with neural network design

does it means that can not use two or more one as target such as 
0011,0110,1100,1010, 0111,1110,1101, etc when training weight?
-- 
https://mail.python.org/mailman/listinfo/python-list


Is "two different input map to one unique target called nonlinear case " or "one unique input map to two different target called nonlinear case"? Which learning method can train these two cases or no

2017-01-19 Thread Ho Yeung Lee
Is "two different input map to one unique target called nonlinear case " or 
"one unique input map to two different target called nonlinear case"? Which 
learning method can train these two cases or no method to train one of case?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python for WEB-page !?

2017-01-19 Thread Johann Spies
It might be worth while to look at web2py (http://web2py.com).

Here is a good tutorial: http://killer-web-development.com/

Regards
Johann

-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)
-- 
https://mail.python.org/mailman/listinfo/python-list


ipython2 does not work anymore

2017-01-19 Thread Cecil Westerhof
I did not work with ipython2 for a long time. Most of my work is done
with python3. I just tried to start ipython2 and got:
Traceback (most recent call last):
  File "/usr/bin/ipython2", line 7, in 
from IPython import start_ipython
  File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 49, in 

from .terminal.embed import embed
  File "/usr/lib/python2.7/site-packages/IPython/terminal/embed.py", line 16, 
in 
from IPython.core.interactiveshell import DummyMod, InteractiveShell
  File "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py", 
line 31, in 
from pickleshare import PickleShareDB
  File "/usr/lib/python2.7/site-packages/pickleshare.py", line 40, in 
from path import path as Path
ImportError: No module named path


What could be the problem here?


Python2 does work:
Python 2.7.12 (default, Jul 01 2016, 15:36:53) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Otherwise I would have a problem. Some scripts still use it.

I am working with openSUSE 13.2

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Odd message while building Python from tip

2017-01-19 Thread Chris Angelico
I don't think I've ever seen this message before. This is just after
'hg pull -u' to get to the latest CPython (my previous build was about
a month ago). 'make' succeeded, but concluded with this message:

running build_ext
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexitpwd   time

And then proceeded to run build_scripts as normal.

It doesn't look like an error, and those three modules can happily be
imported by "./python" and by the freshly-installed "python3.7". It's
curious though. Any explanation?

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


Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
I am writing a python program to start the programs that need to be
started after logging in.

I have the following imports:
from subprocess import check_call, Popen, STDOUT
from time   import sleep, strftime

And use the following code:
check_call(tuple('wmctrl -s 10'.split()))
log_file = open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')), 
'w')
Popen(tuple('firefox'.split()), stdout = log_file, stderr = STDOUT)

The first statement is to go to the correct desktop.

Is this a good way to do things, or could I do it in a better way?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using python to start programs after logging in

2017-01-19 Thread John Gordon
In <[email protected]> Cecil Westerhof  writes:

> I am writing a python program to start the programs that need to be
> started after logging in.

> Is this a good way to do things, or could I do it in a better way?

I think using your window manager's built-in facilities for starting
programs would be better.  Why are you using Python instead?

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: ipython2 does not work anymore

2017-01-19 Thread MRAB

On 2017-01-19 15:06, Cecil Westerhof wrote:

I did not work with ipython2 for a long time. Most of my work is done
with python3. I just tried to start ipython2 and got:
Traceback (most recent call last):
  File "/usr/bin/ipython2", line 7, in 
from IPython import start_ipython
  File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 49, in 

from .terminal.embed import embed
  File "/usr/lib/python2.7/site-packages/IPython/terminal/embed.py", line 16, in 

from IPython.core.interactiveshell import DummyMod, InteractiveShell
  File "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 31, 
in 
from pickleshare import PickleShareDB
  File "/usr/lib/python2.7/site-packages/pickleshare.py", line 40, in 
from path import path as Path
ImportError: No module named path


What could be the problem here?


Python2 does work:
Python 2.7.12 (default, Jul 01 2016, 15:36:53) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.




Otherwise I would have a problem. Some scripts still use it.

I am working with openSUSE 13.2


There's no module called 'path' in Python 3. Do you mean 'pathlib'?

If you do mean 'pathlib', it was introduced in Python 3.4.

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


Re: Using python to start programs after logging in

2017-01-19 Thread MRAB

On 2017-01-19 19:08, Cecil Westerhof wrote:

I am writing a python program to start the programs that need to be
started after logging in.

I have the following imports:
from subprocess import check_call, Popen, STDOUT
from time   import sleep, strftime

And use the following code:
check_call(tuple('wmctrl -s 10'.split()))
log_file = open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')), 
'w')
Popen(tuple('firefox'.split()), stdout = log_file, stderr = STDOUT)

The first statement is to go to the correct desktop.

Is this a good way to do things, or could I do it in a better way?

Apart from the other answer, your use of .replace is odd. This would be 
better:


log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')

Even better would be to use the 'with' statement as well.

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


Re: Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
On Thursday 19 Jan 2017 20:29 CET, John Gordon wrote:

> In <[email protected]> Cecil Westerhof
>  writes:
>
>> I am writing a python program to start the programs that need to be
>> started after logging in.
>
>> Is this a good way to do things, or could I do it in a better way?
>
> I think using your window manager's built-in facilities for starting
> programs would be better.  Why are you using Python instead?

Because when you use the window managers builtin facilities then all
programs will be started on the same virtual desktop and I want to
start them on different ones.

Second reason is that I want to fetch the programs to start from a
database so I can easily change the programs to be started.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ipython2 does not work anymore

2017-01-19 Thread Cecil Westerhof
On Thursday 19 Jan 2017 21:08 CET, MRAB wrote:

> On 2017-01-19 15:06, Cecil Westerhof wrote:
>> I did not work with ipython2 for a long time. Most of my work is
>> done with python3. I just tried to start ipython2 and got:
>> Traceback (most recent call last): File "/usr/bin/ipython2", line
>> 7, in  from IPython import start_ipython File
>> "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 49, in
>>  from .terminal.embed import embed File
>> "/usr/lib/python2.7/site-packages/IPython/terminal/embed.py", line
>> 16, in  from IPython.core.interactiveshell import DummyMod,
>> InteractiveShell File
>> "/usr/lib/python2.7/site-packages/IPython/core/interactiveshell.py",
>> line 31, in  from pickleshare import PickleShareDB File
>> "/usr/lib/python2.7/site-packages/pickleshare.py", line 40, in
>>  from path import path as Path ImportError: No module named
>> path
>>
>>
>> What could be the problem here?
>>
>>
>> Python2 does work: Python 2.7.12 (default, Jul 01 2016, 15:36:53)
>> [GCC] on linux2 Type "help", "copyright", "credits" or "license"
>> for more information.
>
>>
>> Otherwise I would have a problem. Some scripts still use it.
>>
>> I am working with openSUSE 13.2
>>
> There's no module called 'path' in Python 3. Do you mean 'pathlib'?

I copied this from the output I got.


> If you do mean 'pathlib', it was introduced in Python 3.4.

It is about python2.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
On Thursday 19 Jan 2017 21:12 CET, MRAB wrote:

> On 2017-01-19 19:08, Cecil Westerhof wrote:
>> I am writing a python program to start the programs that need to be
>> started after logging in.
>>
>> I have the following imports:
>> from subprocess import check_call, Popen, STDOUT
>> from time   import sleep, strftime
>>
>> And use the following code: check_call(tuple('wmctrl -s
>> 10'.split())) log_file =
>> open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')),
>> 'w') Popen(tuple('firefox'.split()), stdout = log_file, stderr =
>> STDOUT)
>>
>> The first statement is to go to the correct desktop.
>>
>> Is this a good way to do things, or could I do it in a better way?
>>
> Apart from the other answer, your use of .replace is odd. This would
> be better:
>
> log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')

The reason is that it is ‘generic’ code. In the future instead of
string it will be a variable and only when the variable contains %T it
should be replaced.


> Even better would be to use the 'with' statement as well.

The same here. Not always has the output to be logged and then I would
use NONE for log_file.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Odd message while building Python from tip

2017-01-19 Thread INADA Naoki
Hi, Chris.

They are "builtin" module.
python executable contains the modules already.

But I don't know it's safe to remove them from setup.py.
There are so many platforms and special build of Python.


$ ./python
Python 3.7.0a0 (default:9f7d16266928, Jan 18 2017, 23:59:22)
[GCC 6.2.0 20161005] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.builtin_module_names
('_ast', '_codecs', '_collections', '_functools', '_imp', '_io',
'_locale', '_operator', '_signal', '_sre', '_stat', '_string',
'_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref',
'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools',
'marshal', 'posix', 'pwd', 'sys', 'time', 'xxsubtype', 'zipimport')



On Fri, Jan 20, 2017 at 3:21 AM, Chris Angelico  wrote:
> I don't think I've ever seen this message before. This is just after
> 'hg pull -u' to get to the latest CPython (my previous build was about
> a month ago). 'make' succeeded, but concluded with this message:
>
> running build_ext
> The following modules found by detect_modules() in setup.py, have been
> built by the Makefile instead, as configured by the Setup files:
> atexitpwd   time
>
> And then proceeded to run build_scripts as normal.
>
> It doesn't look like an error, and those three modules can happily be
> imported by "./python" and by the freshly-installed "python3.7". It's
> curious though. Any explanation?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
On Thursday 19 Jan 2017 22:21 CET, Cecil Westerhof wrote:

> On Thursday 19 Jan 2017 21:12 CET, MRAB wrote:
>
>> On 2017-01-19 19:08, Cecil Westerhof wrote:
>>> I am writing a python program to start the programs that need to
>>> be started after logging in.
>>>
>>> I have the following imports:
>>> from subprocess import check_call, Popen, STDOUT
>>> from time   import sleep, strftime
>>>
>>> And use the following code: check_call(tuple('wmctrl -s
>>> 10'.split())) log_file =
>>> open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')),
>>> 'w') Popen(tuple('firefox'.split()), stdout = log_file, stderr =
>>> STDOUT)
>>>
>>> The first statement is to go to the correct desktop.
>>>
>>> Is this a good way to do things, or could I do it in a better way?
>>>
>> Apart from the other answer, your use of .replace is odd. This
>> would be better:
>>
>> log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')
>
> The reason is that it is ‘generic’ code. In the future instead of
> string it will be a variable and only when the variable contains %T
> it should be replaced.
>
>
>> Even better would be to use the 'with' statement as well.
>
> The same here. Not always has the output to be logged and then I
> would use NONE for log_file.

I wrote a function for switching to the correct virtual desktop and
starting all the commands. I am also using with now:
def do_desktop(desktop, commands, seconds_to_wait = 10):
desktop_command = ('wmctrl -s ' + desktop).split()
check_call(tuple(desktop_command))
for command_arr in commands:
command = command_arr[0].split()
log_directory   = command_arr[1]
directory   = command_arr[2]
if (directory != ''):
chdir(directory)
if (log_directory == 'NONE'):
Popen(tuple(command.split()))
else:
log_file_name = log_directory.replace('%T', strftime('%F_%R'))
with open(log_file_name, 'w') as log_file:
Popen(tuple(command), stdout = log_file, stderr = STDOUT)
if (directory != ''):
set_default_dir()
sleep(seconds_to_wait)


The function set_default_dir:
def set_default_dir():
chdir(expanduser('~'))


The example with firefox is then done with:
commands = [
['firefox', 'Logging/firefox_%T.log', ''],
]
do_desktop('10', commands, 30)


Sometimes a command needs to be executed in a different directory,
that is done like:
commands = [
['lein run',
'NONE', 'Clojure/Quotes'],
['xfce4-terminal --maximize --execute screen -S Clojure -c 
~/.screenrcClojure', 'NONE', ''],
]
do_desktop('6', commands, 30)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Odd message while building Python from tip

2017-01-19 Thread Chris Angelico
On Fri, Jan 20, 2017 at 10:09 AM, INADA Naoki  wrote:
> Hi, Chris.
>
> They are "builtin" module.
> python executable contains the modules already.
>
> But I don't know it's safe to remove them from setup.py.
> There are so many platforms and special build of Python.

I haven't changed the code in any way, btw. This is a vanilla CPython
(at the moment - there have been times I've had patches sitting
around), and this message is, I believe, new.

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


Re: ipython2 does not work anymore

2017-01-19 Thread Steve D'Aprano
On Fri, 20 Jan 2017 02:06 am, Cecil Westerhof wrote:

> I did not work with ipython2 for a long time. Most of my work is done
> with python3. I just tried to start ipython2 and got:
> Traceback (most recent call last):
[...]
> ImportError: No module named path
> 
> 
> What could be the problem here?

Something has changed between the last time you ran IPython and now. You
have deleted something, changed something, installed something... or you
have file system corruption and files are disappearing... or your 
PYTHONPATH environment variable is not set, or is set differently to the way
it used to be...

Do you want to investigate why the error occurred, or just fix it in the
most convenient and easy way?

If the second, then you can probably fix it by running:

python2 -m pip install path

assuming that you trust that path is a legitimate module.

Looking at the traceback, I see the final call which fails is in a module
called pickleshare.py:

  File "/usr/lib/python2.7/site-packages/pickleshare.py", line 40, in 
from path import path as Path


You could try removing pickleshare and re-installing, or upgrading to the
latest version, and see whether it brings in the "path" dependency.

You could try running "locate path.py | grep python2.7" in the shell and see
whether path is installed. If it is installed, it sounds like the PYTHONPATH
is messed up. Run these and tell us what they say:

locate path.py | grep python2.7
python2.7 -c "import sys; print sys.path"
echo $PYTHONPATH



Googling for your error gives me these two relevant looking hits:

https://duckduckgo.com/html/?q=%22ImportError:%20No%20module%20named%20path%22+ipython

https://github.com/jupyter/notebook/issues/270

https://github.com/jupyter/notebook/issues/525



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


python corrupted double-linked list error

2017-01-19 Thread Xristos Xristoou
i am a python 2.7 and ubuntu 16.04 user and i have unexpected error when try to 
excute some python scripts . i use pycharm and i have the some error when i try 
to run python script from the ubuntu terminal. the error :

*** Error in `/usr/bin/python2.7': corrupted double-linked list: 0x0b83c880 ***

the error message :

=== Backtrace: =
/lib/i386-linux-gnu/libc.so.6(+0x67377)[0xb764b377]
/lib/i386-linux-gnu/libc.so.6(+0x6d2f7)[0xb76512f7]
/lib/i386-linux-gnu/libc.so.6(+0x6e2f1)[0xb76522f1]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x18)[0xb6ba9d88]
/usr/lib/libgdal.so.1(_ZN15GDALMajorObjectD0Ev+0x22)[0xb075a582]
/usr/lib/libgdal.so.1(GDALClose+0x77)[0xb074d747]
/usr/lib/qgis/plugins/libgdalprovider.so(+0xa930)[0xa4888930]
/usr/lib/qgis/plugins/libgdalprovider.so(+0xaafa)[0xa4888afa]
/usr/lib/libqgis_core.so.2.18.3(_ZN13QgsRasterPipeD1Ev+0x75)[0xb3d6a7d5]
/usr/lib/libqgis_core.so.2.18.3(_ZN14QgsRasterLayerD1Ev+0x2f)[0xb3d5cd0f]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(_ZN17sipQgsRasterLayerD1Ev+0x3b)[0xb489dd2b]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(_ZN17sipQgsRasterLayerD0Ev+0x1a)[0xb489dd5a]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(+0x43df45)[0xb4883f45]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(+0x43df8a)[0xb4883f8a]
/usr/lib/python2.7/dist-packages/sip.i386-linux-gnu.so(+0x5d49)[0xb724dd49]
/usr/lib/python2.7/dist-packages/sip.i386-linux-gnu.so(+0xc19b)[0xb725419b]
/usr/bin/python2.7[0x8144aad]
/usr/bin/python2.7[0x80fd127]
/usr/bin/python2.7(PyDict_SetItem+0x478)[0x80e9268]
/usr/bin/python2.7(_PyModule_Clear+0xba)[0x8149a1a]
/usr/bin/python2.7(PyImport_Cleanup+0x37a)[0x81495ca]
/usr/bin/python2.7(Py_Finalize+0x99)[0x8147399]
/usr/bin/python2.7(Py_Main+0x4bd)[0x80e639d]
/usr/bin/python2.7(main+0x26)[0x80e5ec6]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0xb75fc637]
/usr/bin/python2.7[0x80e5dc8]
=== Memory map: 
08048000-0838f000 r-xp  08:01 1583892/usr/bin/python2.7
0839-08391000 r--p 00347000 08:01 1583892/usr/bin/python2.7
08391000-083f1000 rw-p 00348000 08:01 1583892/usr/bin/python2.7
083f1000-08406000 rw-p  00:00 0 
0a0f7000-0ba69000 rw-p  00:00 0  [heap]
a03e-a03eb000 r-xp  08:01 1049930
/lib/i386-linux-gnu/libnss_files-2.23.so
a03eb000-a03ec000 r--p a000 08:01 1049930
/lib/i386-linux-gnu/libnss_files-2.23.so
a03ec000-a03ed000 rw-p b000 08:01 1049930
/lib/i386-linux-gnu/libnss_files-2.23.so
a03ed000-a03f3000 rw-p  00:00 0 
a03f3000-a03fe000 r-xp  08:01 1048664
/lib/i386-linux-gnu/libnss_nis-2.23.so
a03fe000-a03ff000 r--p a000 08:01 1048664
/lib/i386-linux-gnu/libnss_nis-2.23.so
a03ff000-a040 rw-p b000 08:01 1048664
/lib/i386-linux-gnu/libnss_nis-2.23.so
a040-a0421000 rw-p  00:00 0 
a0421000-a050 ---p  00:00 0 
a0509000-a052 r-xp  08:01 1048674
/lib/i386-linux-gnu/libnsl-2.23.so
a052-a0521000 r--p 00016000 08:01 1048674
/lib/i386-linux-gnu/libnsl-2.23.so
a0521000-a0522000 rw-p 00017000 08:01 1048674
/lib/i386-linux-gnu/libnsl-2.23.so
a0522000-a0524000 rw-p  00:00 0 
a0524000-a052c000 r-xp  08:01 1048675
/lib/i386-linux-gnu/libnss_compat-2.23.so
a052c000-a052d000 r--p 7000 08:01 1048675
/lib/i386-linux-gnu/libnss_compat-2.23.so
a052d000-a052e000 rw-p 8000 08:01 1048675
/lib/i386-linux-gnu/libnss_compat-2.23.so
a054a000-a054b000 ---p  00:00 0 
a054b000-a10cb000 rw-p  00:00 0 
a10cb000-a10d4000 r-xp  08:01 150141 
/usr/lib/i386-linux-gnu/qt4/plugins/iconengines/libqsvgicon.so
a10d4000-a10d5000 r--p 8000 08:01 150141 
/usr/lib/i386-linux-gnu/qt4/plugins/iconengines/libqsvgicon.so
a10d5000-a10d6000 rw-p 9000 08:01 150141 
/usr/lib/i386-linux-gnu/qt4/plugins/iconengines/libqsvgicon.so
a10d6000-a1296000 rw-p  00:00 0 
a1296000-a12a5000 r-xp  08:01 283552 
/usr/lib/python2.7/dist-packages/scipy/stats/mvn.i386-linux-gnu.so
a12a5000-a12a6000 ---p f000 08:01 283552 
/usr/lib/python2.7/dist-packages/scipy/stats/mvn.i386-linux-gnu.so
a12a6000-a12a7000 r--p f000 08:01 283552 
/usr/lib/python2.7/dist-packages/scipy/stats/mvn.i386-linux-gnu.so
a12a7000-a12a8000 rw-p 0001 08:01 283552 
/usr/lib/python2.7/dist-packages/scipy/stats/mvn.i386-linux-gnu.so
a12a8000-a139f000 rw-p  00:00 0 
a139f000-a13a8000 r-xp  08:01 283553 
/usr/lib/python2.7/dist-packages/scipy/stats/statlib.i386-linux-gnu.so
a13a8000-a13a9000 ---p 9000 08:01 283553 
/usr/lib/python2.7/dist-packages/scipy/stats/statlib.i386-linux-gnu.so
a13a9000-a13aa000 r--p 9000 08:01 283553 
/usr/lib/python2.7/dist-packages/scipy/stats/statlib.i386-linux-gnu.so
a13aa000-a13ab000 rw-p a000 08:01 283553 
/usr/lib/python2.7/dist-packages/scipy/stats/statlib.i386-linux-gnu.so
a13ab000-a13eb000 rw-p  00:0

Re: Using python to start programs after logging in

2017-01-19 Thread MRAB

On 2017-01-19 23:36, Cecil Westerhof wrote:

On Thursday 19 Jan 2017 22:21 CET, Cecil Westerhof wrote:


On Thursday 19 Jan 2017 21:12 CET, MRAB wrote:


On 2017-01-19 19:08, Cecil Westerhof wrote:

I am writing a python program to start the programs that need to
be started after logging in.

I have the following imports:
from subprocess import check_call, Popen, STDOUT
from time   import sleep, strftime

And use the following code: check_call(tuple('wmctrl -s
10'.split())) log_file =
open('Logging/firefox_%T.log'.replace('%T', strftime('%F_%R')),
'w') Popen(tuple('firefox'.split()), stdout = log_file, stderr =
STDOUT)

The first statement is to go to the correct desktop.

Is this a good way to do things, or could I do it in a better way?


Apart from the other answer, your use of .replace is odd. This
would be better:

log_file = open('Logging/firefox_%s.log' % strftime('%F_%R'), 'w')


The reason is that it is ‘generic’ code. In the future instead of
string it will be a variable and only when the variable contains %T
it should be replaced.



Even better would be to use the 'with' statement as well.


The same here. Not always has the output to be logged and then I
would use NONE for log_file.


I wrote a function for switching to the correct virtual desktop and
starting all the commands. I am also using with now:
def do_desktop(desktop, commands, seconds_to_wait = 10):
desktop_command = ('wmctrl -s ' + desktop).split()
check_call(tuple(desktop_command))


You don't have to pass a tuple to check_call; it'll also accept a list.


for command_arr in commands:
command = command_arr[0].split()
log_directory   = command_arr[1]
directory   = command_arr[2]
if (directory != ''):
chdir(directory)


There's no need for the parentheses around the 'if' condition.


if (log_directory == 'NONE'):
Popen(tuple(command.split()))
else:
log_file_name = log_directory.replace('%T', strftime('%F_%R'))
with open(log_file_name, 'w') as log_file:
Popen(tuple(command), stdout = log_file, stderr = STDOUT)
if (directory != ''):
set_default_dir()


Using 'chdir' is generally a bad idea.

'Popen' will start the process and then continue, so what you're doing 
is changing the directory, starting a process, and then changing the 
directory again, possibly before the process has truly started (i.e. 
you've told the OS to start it, but there might be a small delay before 
that happens). Popen accepts a 'cwd' argument, which sets the 'current 
working directory' for that process.



sleep(seconds_to_wait)


The function set_default_dir:
def set_default_dir():
chdir(expanduser('~'))


The example with firefox is then done with:
commands = [
['firefox', 'Logging/firefox_%T.log', ''],
]
do_desktop('10', commands, 30)


Sometimes a command needs to be executed in a different directory,
that is done like:
commands = [
['lein run',
'NONE', 'Clojure/Quotes'],
['xfce4-terminal --maximize --execute screen -S Clojure -c 
~/.screenrcClojure', 'NONE', ''],
]
do_desktop('6', commands, 30)


Why 'NONE'? Why not None?

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


Re: python corrupted double-linked list error

2017-01-19 Thread MRAB

On 2017-01-20 00:03, Xristos Xristoou wrote:

i am a python 2.7 and ubuntu 16.04 user and i have unexpected error when try to 
excute some python scripts . i use pycharm and i have the some error when i try 
to run python script from the ubuntu terminal. the error :

*** Error in `/usr/bin/python2.7': corrupted double-linked list: 0x0b83c880 ***

the error message :

=== Backtrace: =
/lib/i386-linux-gnu/libc.so.6(+0x67377)[0xb764b377]
/lib/i386-linux-gnu/libc.so.6(+0x6d2f7)[0xb76512f7]
/lib/i386-linux-gnu/libc.so.6(+0x6e2f1)[0xb76522f1]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x18)[0xb6ba9d88]
/usr/lib/libgdal.so.1(_ZN15GDALMajorObjectD0Ev+0x22)[0xb075a582]
/usr/lib/libgdal.so.1(GDALClose+0x77)[0xb074d747]
/usr/lib/qgis/plugins/libgdalprovider.so(+0xa930)[0xa4888930]
/usr/lib/qgis/plugins/libgdalprovider.so(+0xaafa)[0xa4888afa]
/usr/lib/libqgis_core.so.2.18.3(_ZN13QgsRasterPipeD1Ev+0x75)[0xb3d6a7d5]
/usr/lib/libqgis_core.so.2.18.3(_ZN14QgsRasterLayerD1Ev+0x2f)[0xb3d5cd0f]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(_ZN17sipQgsRasterLayerD1Ev+0x3b)[0xb489dd2b]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(_ZN17sipQgsRasterLayerD0Ev+0x1a)[0xb489dd5a]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(+0x43df45)[0xb4883f45]
/usr/lib/python2.7/dist-packages/qgis/_core.i386-linux-gnu.so(+0x43df8a)[0xb4883f8a]
/usr/lib/python2.7/dist-packages/sip.i386-linux-gnu.so(+0x5d49)[0xb724dd49]
/usr/lib/python2.7/dist-packages/sip.i386-linux-gnu.so(+0xc19b)[0xb725419b]
/usr/bin/python2.7[0x8144aad]
/usr/bin/python2.7[0x80fd127]
/usr/bin/python2.7(PyDict_SetItem+0x478)[0x80e9268]
/usr/bin/python2.7(_PyModule_Clear+0xba)[0x8149a1a]
/usr/bin/python2.7(PyImport_Cleanup+0x37a)[0x81495ca]
/usr/bin/python2.7(Py_Finalize+0x99)[0x8147399]
/usr/bin/python2.7(Py_Main+0x4bd)[0x80e639d]
/usr/bin/python2.7(main+0x26)[0x80e5ec6]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0xb75fc637]
/usr/bin/python2.7[0x80e5dc8]

[snip]

It looks like a bug in an extension, possibly in libgdal, qgis or 
libqgis. It has written to a part of the heap that it shouldn't, perhaps 
beyond the end of an allocated block, corrupting the heap in the process.


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


Re: python corrupted double-linked list error

2017-01-19 Thread Xristos Xristoou


how to understand that ?solution ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python corrupted double-linked list error

2017-01-19 Thread Michael Torrie
On 01/19/2017 05:53 PM, Xristos Xristoou wrote:
> 
> 
> how to understand that ?solution ?

Well the problem is likely in the gdal or/and qgis modules. You'll
probably want to talk to the qgis folks about this problem.  It's not a
bug in Python itself.

If you can reproduce the problem with a minimal script, you can post it
here and maybe someone can help here.

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


Re: Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
On Friday 20 Jan 2017 01:24 CET, MRAB wrote:

>> I wrote a function for switching to the correct virtual desktop and
>> starting all the commands. I am also using with now:
>> def do_desktop(desktop, commands, seconds_to_wait = 10):
>> desktop_command = ('wmctrl -s ' + desktop).split()
>> check_call(tuple(desktop_command))
>
> You don't have to pass a tuple to check_call; it'll also accept a
> list.

I did not know that. The same for Popen.


>> for command_arr in commands:
>> command = command_arr[0].split()
>> log_directory   = command_arr[1]
>> directory   = command_arr[2]
>> if (directory != ''):
>> chdir(directory)
>
> There's no need for the parentheses around the 'if' condition.

Thanks, I always thought these were necessary.


>> if (log_directory == 'NONE'):
>> Popen(tuple(command.split()))
>> else:
>> log_file_name = log_directory.replace('%T', strftime('%F_%R'))
>> with open(log_file_name, 'w') as log_file:
>> Popen(tuple(command), stdout = log_file, stderr = STDOUT)
>> if (directory != ''):
>> set_default_dir()
>
> Using 'chdir' is generally a bad idea.
>
> 'Popen' will start the process and then continue, so what you're
> doing is changing the directory, starting a process, and then
> changing the directory again, possibly before the process has truly
> started (i.e. you've told the OS to start it, but there might be a
> small delay before that happens). Popen accepts a 'cwd' argument,
> which sets the 'current working directory' for that process.

I am using cwd now.


>> Sometimes a command needs to be executed in a different directory,
>> that is done like: commands = [ ['lein run', 'NONE',
>> 'Clojure/Quotes'], ['xfce4-terminal --maximize --execute screen -S
>> Clojure -c ~/.screenrcClojure', 'NONE', ''],
>> ]
>> do_desktop('6', commands, 30)
>>
> Why 'NONE'? Why not None?

I am using None now.


Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using python to start programs after logging in

2017-01-19 Thread Cecil Westerhof
On Friday 20 Jan 2017 00:36 CET, Cecil Westerhof wrote:

> I wrote a function for switching to the correct virtual desktop and
> starting all the commands. I am also using with now:
> def do_desktop(desktop, commands, seconds_to_wait = 10):
> desktop_command = ('wmctrl -s ' + desktop).split()
> check_call(tuple(desktop_command))
> for command_arr in commands:
> command = command_arr[0].split()
> log_directory   = command_arr[1]
> directory   = command_arr[2]
> if (directory != ''):
> chdir(directory)
> if (log_directory == 'NONE'):
> Popen(tuple(command.split()))
> else:
> log_file_name = log_directory.replace('%T', strftime('%F_%R'))
> with open(log_file_name, 'w') as log_file:
> Popen(tuple(command), stdout = log_file, stderr = STDOUT)
> if (directory != ''):
> set_default_dir()
> sleep(seconds_to_wait)


I wrote a little better version:
def do_desktop(desktop, commands, seconds_to_wait):
desktop_command = (switch_desktop + desktop).split()
if seconds_to_wait == 0:
seconds_to_wait = 10
check_call(desktop_command)
for command_arr in commands:
command = command_arr[0].split()
log_directory   = command_arr[1]
directory   = command_arr[2]
if not log_directory:
log_directory = '/dev/null'
log_file_name = log_directory.replace('%T', strftime('%F_%R'))
with open(log_file_name, 'w') as log_file:
Popen(command, stdout = log_file, cwd = directory, stderr = STDOUT)
sleep(seconds_to_wait)

When there is no log_directory I set it to '/dev/null': that makes the
code a little bit cleaner.


And everything is now fetched from the database:
for desktop in cursor.execute(select_desktops).fetchall():
desktop_name= desktop[0]
desktop_value   = desktop[1]
desktop_wait= desktop[2]
commands= cursor.execute(select_commands, [desktop_name]).fetchall()
do_desktop(desktop_value, commands, desktop_wait)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list