os.system vs subrocess.call

2019-11-28 Thread Ulrich Goebel

Hi,

I have to call commands from inside a python skript. These commands are 
in fact other python scripts. So I made


os.system('\.Test.py')

That works.

Now I tried to use

supprocess.call(['.\', 'test.py'])

That doesn't work but ends in an error:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

Using

subprocess.call(['./', 'Test.py'], shell=True)

I get

Test.py: 1: Test.py: ./: Permission denied

Is there a simple way to use subprocess in this usecase?

Best regards
Ulrich

--
Ulrich Goebel
Am Büchel 57, 53173 Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Re: os.system vs subrocess.call

2019-11-28 Thread Peter Otten
Ulrich Goebel wrote:

> Hi,
> 
> I have to call commands from inside a python skript. These commands are
> in fact other python scripts. So I made
> 
>  os.system('\.Test.py')
> 
> That works.
> 
> Now I tried to use
> 
>  supprocess.call(['.\', 'test.py'])

Remember to use cut and paste for code and traceback.
The above triggers a syntax error because the backslash escapes the ending ' 
of the first argument. Also: is it Test.py or test.py?

> 
> That doesn't work but ends in an error:
> 
> Traceback (most recent call last):
>File "", line 1, in 
>File "/usr/lib/python3.5/subprocess.py", line 557, in call
>  with Popen(*popenargs, **kwargs) as p:
>File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
>  restore_signals, start_new_session)
>File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
>  raise child_exception_type(errno_num, err_msg)
> PermissionError: [Errno 13] Permission denied
> 
> Using
> 
>  subprocess.call(['./', 'Test.py'], shell=True)
> 
> I get
> 
> Test.py: 1: Test.py: ./: Permission denied
> 
> Is there a simple way to use subprocess in this usecase?

You must not split the path into directory and name.
If you are on Linux or similar, your script is executable, and your file 
system is case sensitive:

$ echo -e '#!/usr/bin/python3\nprint("hello")' > test.py
$ chmod u+x test.py
$ cat test.py
#!/usr/bin/python3
print("hello")
$ python3
Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(["./test.py"])
hello
0


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


Re: os.system vs subrocess.call

2019-11-28 Thread Ulrich Goebel

Sorry for the wrong spelling. In fact

subprocess.call('./Test.py')

works.

The raising error was my error too, using ['./', 'Test.py'] instead of 
'./Test.py'


Sorry...

Am 28.11.19 um 11:05 schrieb Ulrich Goebel:

Hi,

I have to call commands from inside a python skript. These commands are 
in fact other python scripts. So I made


     os.system('\.Test.py')

That works.

Now I tried to use

     supprocess.call(['.\', 'test.py'])

That doesn't work but ends in an error:

Traceback (most recent call last):
   File "", line 1, in 
   File "/usr/lib/python3.5/subprocess.py", line 557, in call
     with Popen(*popenargs, **kwargs) as p:
   File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
     restore_signals, start_new_session)
   File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
     raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

Using

     subprocess.call(['./', 'Test.py'], shell=True)

I get

Test.py: 1: Test.py: ./: Permission denied

Is there a simple way to use subprocess in this usecase?

Best regards
Ulrich



--
Ulrich Goebel
Am Büchel 57, 53173 Bonn
--
https://mail.python.org/mailman/listinfo/python-list


Re: os.system vs subrocess.call

2019-11-28 Thread Pieter van Oostrum
Ulrich Goebel  writes:

> Hi,
>
> I have to call commands from inside a python skript. These commands are
> in fact other python scripts. So I made
>
> os.system('\.Test.py')
>
> That works.

In a string \. is the same as . So this should execute the command '.Test.py'. 
Is that really what you did? Or did you mean os.system('./Test.py') which is 
much more probable.
NOTE: Never retype the commands that you used, but copy and paste them.

>
> Now I tried to use
>
> supprocess.call(['.\', 'test.py'])
>
That can't have given the error below, as it would have to be subprocess.call,
not supprocess.call.
And then also '.\' would have given a syntax error.
NOTE: Never retype the commands that you used, but copy and paste them.

> That doesn't work but ends in an error:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python3.5/subprocess.py", line 557, in call
> with Popen(*popenargs, **kwargs) as p:
>   File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
> restore_signals, start_new_session)
>   File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
> raise child_exception_type(errno_num, err_msg)
> PermissionError: [Errno 13] Permission denied
>
> Using
>
> subprocess.call(['./', 'Test.py'], shell=True)
>
> I get
>
> Test.py: 1: Test.py: ./: Permission denied
>
Why would you do that, splitting './Test.py' in two parts? That doesn't work.
> Is there a simple way to use subprocess in this usecase?
>

subprocess.call(['./Test.py'])

-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Madhavan Bomidi
Hi,

I have the following IDL program lines. I want to write equivalent Python 
program lines. Can anyone suggest me equivalent Pythons program lines?

# --- 1 --- #
How to handle the format in IDL to Python?

IDL program line:

print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)'


Python program line written by me:

print('Column '+str(j)+' of product matrix A*AINV:')


#---2  #
How the JMP can be transformed in Python?

IDL program lines:

  FOR K=1,M DO BEGIN
FOR I=1,M DO BEGIN
  IF I NE K THEN BEGIN
IF WK(K-1,K-1) EQ 0 THEN BEGIN
  L=1
JMP:  IF WK(L-1,K-1) EQ 0 THEN BEGIN
L=L+1
GOTO, JMP
  ENDIF
  FOR J=K,2*M DO BEGIN
WK(K-1,J-1)=WK(K-1,J-1)+WK(L-1,J-1)
  ENDFOR
ENDIF
U=-WK(I-1,K-1)/WK(K-1,K-1)
FOR J=K+1,2*M DO BEGIN
  WK(I-1,J-1)=WK(I-1,J-1)+U*WK(K-1,J-1)
ENDFOR
  ENDIF
ENDFOR
  ENDFOR

JMP: RETURN

Python program lines:

for k in np.arange(1,M+1,dtype=int):
for i in np.arange(1,M+1,dtype=int):
if (i != k):
if (WK[k-1,k-1] == 0):
L = 1
if (WK[k-1,L-1] == 0):# JMP
L = L+1
for j in np.arange(k,2*M+1,dtype=int):
WK[j-1,k-1] = WK[j-1,k-1] + WK[j-1,L-1]
U = -WK[k-1,i-1]/WK[k-1,k-1]
for j in np.arange(k+1,2*M+1,dtype=int):
WK[j-1,i-1] = WK[j-1,i-1]+U*WK[j-1,k-1]



Can someone provide their feedback on whether I have done the correct 
transformation of the above IDL program lines to python program lines?

Look forward to the suggestions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Ben Bacarisse
Madhavan Bomidi  writes:

> I have the following IDL program lines. I want to write equivalent
> Python program lines. Can anyone suggest me equivalent Pythons program
> lines?
>
> # --- 1 --- #
> How to handle the format in IDL to Python?
>
> IDL program line:
>
> print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)'
>
>
> Python program line written by me:
>
> print('Column '+str(j)+' of product matrix A*AINV:')

You could just use

  print('Column', j, 'of product matrix A*AINV:')

but if you need to copy the I3 format:

  print('Column {0:3} of product matrix A*AINV:'.format(j))

I don't know what the 1X format does.  The A7 and A27 formats just seem
to involve the programmer counting the strings.  Very odd.

> #---2  #
> How the JMP can be transformed in Python?
>
> IDL program lines:
>
>   FOR K=1,M DO BEGIN
> FOR I=1,M DO BEGIN
>   IF I NE K THEN BEGIN
> IF WK(K-1,K-1) EQ 0 THEN BEGIN
>   L=1
> JMP:  IF WK(L-1,K-1) EQ 0 THEN BEGIN
> L=L+1
> GOTO, JMP
>   ENDIF
>   FOR J=K,2*M DO BEGIN
> WK(K-1,J-1)=WK(K-1,J-1)+WK(L-1,J-1)
>   ENDFOR
> ENDIF
> U=-WK(I-1,K-1)/WK(K-1,K-1)
> FOR J=K+1,2*M DO BEGIN
>   WK(I-1,J-1)=WK(I-1,J-1)+U*WK(K-1,J-1)
> ENDFOR
>   ENDIF
> ENDFOR
>   ENDFOR
>
> JMP: RETURN

This is very odd.  What does it mean when a label is duplicated in IDL?
If the second one were not there, this:

  JMP:  IF WK(L-1,K-1) EQ 0 THEN BEGIN
  L=L+1
  GOTO, JMP
ENDIF

would just be a while loop:

while WK[L-1,K-1] == 0:
  L=L+1



By the way, all those -1s suggest that the IDL was itself a translation
from a language with 1-based array indexing.  All that might be able to
be tidied up.

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


install software

2019-11-28 Thread alberto
Hi, 
I'm trying to install a python source

https://github.com/peteboyd/lammps_interface

when I run the example test I receive this error


AttributeError: 'NoneType' object has no attribute 'copy'

How could I fix it?

regards


lammps-interface 
/home/alberto/Scaricati/lammps_interface-master/test_struct/IRMOF-1.cif
fatal: Not a git repository (or any of the parent directories): .git
No bonds reported in cif file - computing bonding..
Molecules found in the framework, separating.
Traceback (most recent call last):
  File "/usr/local/bin/lammps-interface", line 4, in 
__import__('pkg_resources').run_script('lammps-interface==0.1.1', 
'lammps-interface')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 719, in 
run_script
self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1504, 
in run_script
exec(code, namespace, namespace)
  File 
"/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/EGG-INFO/scripts/lammps-interface",
 line 13, in 
sim.split_graph()
  File 
"/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py",
 line 398, in split_graph
sg = self.cut_molecule(molecule)
  File 
"/usr/local/lib/python3.5/dist-packages/lammps_interface-0.1.1-py3.5.egg/lammps_interface/lammps_main.py",
 line 1535, in cut_molecule
mgraph.distance_matrix = self.graph.distance_matrix.copy()
AttributeError: 'NoneType' object has no attribute 'copy'


the installetion seems completed correctly

sudo python3 setup.py install 
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution 
option: 'long_description_content_type'
  warnings.warn(msg)
running install
Checking .pth file support in /usr/local/lib/python3.5/dist-packages/
/usr/bin/python3 -E -c pass
TEST PASSED: /usr/local/lib/python3.5/dist-packages/ appears to support .pth 
files
running bdist_egg
running egg_info
creating lammps_interface.egg-info
writing requirements to lammps_interface.egg-info/requires.txt
writing dependency_links to lammps_interface.egg-info/dependency_links.txt
writing lammps_interface.egg-info/PKG-INFO
writing top-level names to lammps_interface.egg-info/top_level.txt
writing manifest file 'lammps_interface.egg-info/SOURCES.txt'
reading manifest file 'lammps_interface.egg-info/SOURCES.txt'
writing manifest file 'lammps_interface.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/lammps_interface
copying lammps_interface/mof_sbus.py -> build/lib/lammps_interface
copying lammps_interface/Dubbeldam.py -> build/lib/lammps_interface
copying lammps_interface/gas_models.py -> build/lib/lammps_interface
copying lammps_interface/lammps_main.py -> build/lib/lammps_interface
copying lammps_interface/structure_data.py -> build/lib/lammps_interface
copying lammps_interface/Molecules.py -> build/lib/lammps_interface
copying lammps_interface/water_models.py -> build/lib/lammps_interface
copying lammps_interface/lammps_potentials.py -> build/lib/lammps_interface
copying lammps_interface/BTW.py -> build/lib/lammps_interface
copying lammps_interface/dreiding.py -> build/lib/lammps_interface
copying lammps_interface/CIFIO.py -> build/lib/lammps_interface
copying lammps_interface/__init__.py -> build/lib/lammps_interface
copying lammps_interface/generic_raspa.py -> build/lib/lammps_interface
copying lammps_interface/atomic.py -> build/lib/lammps_interface
copying lammps_interface/ccdc.py -> build/lib/lammps_interface
copying lammps_interface/uff_nonbonded.py -> build/lib/lammps_interface
copying lammps_interface/MOFFF.py -> build/lib/lammps_interface
copying lammps_interface/uff.py -> build/lib/lammps_interface
copying lammps_interface/InputHandler.py -> build/lib/lammps_interface
copying lammps_interface/uff4mof.py -> build/lib/lammps_interface
copying lammps_interface/ForceFields.py -> build/lib/lammps_interface
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/mof_sbus.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/Dubbeldam.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/gas_models.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/lammps_main.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/structure_data.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/Molecules.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/water_models.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/lammps_interface/lammps_potentials.py -> 
build/bdist.linux-x86_64/egg/lammps_interface
copying build/lib/la

Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Bev In TX


> On Nov 28, 2019, at 9:35 AM, Dennis Lee Bieber  wrote:
> 
> Channeling ancient FORTRAN, I'd interpret it as
> 
> 1XSkip one space
> A7Seven character alpha
> I3Three digit integer
> A2727 character alpha
> 
> and it is rather painful when the arguments are literals of those sizes.
> Makes more sense if the arguments are strings of various widths yet column
> alignment is required.
> 
>Since I still favor string interpolation for formatting, I'd probably
> just end up with
> 
> print(" Column %3d of product matrix A*AINV:")
> 
> {Odd that the original uses a 1X format, when the literals have white space
> at the adjoining ends... Why not " Column " with A8 format?}

Still channeling Fortran, 1X ensured a blank in column 1, which was used 
strictly for carriage control on a line printer.  A8 may, or may not leave a 
blank in column 1, which could have caused erroneous carriage controls.

Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread MRAB

On 2019-11-28 15:35, Dennis Lee Bieber wrote:

On Thu, 28 Nov 2019 12:45:27 +, Ben Bacarisse 
declaimed the following:


Madhavan Bomidi  writes:


print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)'





I don't know what the 1X format does.  The A7 and A27 formats just seem
to involve the programmer counting the strings.  Very odd.



Channeling ancient FORTRAN, I'd interpret it as

1X  Skip one space
A7  Seven character alpha
I3  Three digit integer
A27 27 character alpha

and it is rather painful when the arguments are literals of those sizes.
Makes more sense if the arguments are strings of various widths yet column
alignment is required.

Since I still favor string interpolation for formatting, I'd probably
just end up with

print(" Column %3d of product matrix A*AINV:")

{Odd that the original uses a 1X format, when the literals have white space
at the adjoining ends... Why not " Column " with A8 format?}

In Fortran, if the first character printed is a space, then the 
remainder is printed on a new line, else the remainder is printed as a 
continuation of the previous line. Thus, the initial 1X is making it 
start on a new line.






This is very odd.  What does it mean when a label is duplicated in IDL?
If the second one were not there, this:

 JMP:  IF WK(L-1,K-1) EQ 0 THEN BEGIN
 L=L+1
 GOTO, JMP
   ENDIF

would just be a while loop:

   while WK[L-1,K-1] == 0:
 L=L+1




Did you notice that "JMP:" occurs twice? Very strange!


By the way, all those -1s suggest that the IDL was itself a translation
from a language with 1-based array indexing.  All that might be able to
be tidied up.


Heck -- the IDL could be tidied up... All those loop indices could be
configured to run 0..n-1, rather than 1..n

Looks a lot like a garbaged form of FORTRAN that has removed the . from
relational operators, and tried to use blocked syntax.

EQ  =>   .eq.
NE  =>   .ne.

FOR i = s, e DO BEGIN

=>
DO lbl i=s, e
stuff
lbl CONTINUE



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


Re: os.system vs subrocess.call

2019-11-28 Thread Stephan Lukits


> On 28. Nov 2019, at 12:05, Ulrich Goebel  wrote:
> 
> Hi,
> 
> I have to call commands from inside a python skript. These commands are in 
> fact other python scripts. So I made
> 
>os.system('\.Test.py')
> 
> That works.
> 
> Now I tried to use
> 
>supprocess.call(['.\', 'test.py'])

[ins] In [1]: from os import system

[ins] In [2]: system('./test.py')
hallo world
Out[2]: 0

[ins] In [3]: from subprocess import call

[ins] In [4]: call('./test.py')
hallo world
Out[4]: 0

In the first call you call ’.Test.py’
In the second call you call ’test.py’

“supprocess” doesn’t exist

How about

subprocess.call(‘\.Test.py’)

Or

subprocess.call([‘\.Test.py’])

Whereas the later makes more sense if you want to pass arguments to Test.py

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


Does module socketserver using epoll in python3?

2019-11-28 Thread lampahome
As title,

I want to use socketserver to replace my own server code to
maintain ealsier.

But I don't found any info about tech. detail of socketserver, epoll is
important.

Can anyone tell me?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does module socketserver using epoll in python3?

2019-11-28 Thread Michael Torrie
On 11/28/19 8:46 PM, lampahome wrote:
> As title,
> 
> I want to use socketserver to replace my own server code to
> maintain ealsier.
> 
> But I don't found any info about tech. detail of socketserver, epoll is
> important.
> 
> Can anyone tell me?

The source code is here:
https://github.com/python/cpython/blob/master/Lib/socketserver.py .  You
should find all the technical details you are looking for in it.

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


Re: Does module socketserver using epoll in python3?

2019-11-28 Thread lampahome
>
> The source code is here:
> https://github.com/python/cpython/blob/master/Lib/socketserver.py .  You
> should find all the technical details you are looking for in it.
>
>
# poll/select have the advantage of not requiring any extra file
> descriptor,# contrarily to epoll/kqueue (also, they require a single
> syscall).
> if hasattr(selectors, 'PollSelector'):
>  _ServerSelector = selectors.PollSelector
> else:
>  _ServerSelector = selectors.SelectSelector

 Oh..no It uses poll or select ranther than epoll. Maybe it suffer some
performance degrading.

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


Re: tab replace to space 4

2019-11-28 Thread Pankaj Jangid
황병희  writes:
> usally i write python code in gnu emacs on ubuntu 18.04 sometimes i
> re-edit the code vim in same machine so often when i do run the code in
> shell like as ./test.py i meet consol error -- which line wrong!
>
> so i am considering how can i replace all tab to space 4 within python
> code. if there is solution in google i am very sorry.

In Emacs, use "M-x untabify". And "M-x tabify" if you want to do the
reverse.

Regards,
-- 
Pankaj Jangid
-- 
https://mail.python.org/mailman/listinfo/python-list