Discussion:
[Pydev-users] Python program running twice
Gary Roach
2016-02-14 23:24:50 UTC
Permalink
I've had several occasions when a python program seems to loop through
twice. Below is an example:

from os import walk
import subprocess

f = []
x = ""
for (dirpath, dirnames, filenames) in walk('.'):
f.extend(filenames)
f.sort()

for x in f:
if x[-3:]=='JPG':
print(x)
args = "convert " + x + " -rotate " + "-90 " + x
subprocess.call(args, shell=True)

This program should rotate a jpg file by 90 degrees left. It actually
rotates the file 180 degrees and the print(x) function prints the file
name twice. What am I doming wrong.

I run it as python rotate.py from the command line.

Gary R.
Fabio Zadrozny
2016-02-16 18:20:01 UTC
Permalink
I don't think this is an issue in PyDev (I can't reproduce it and if
something as grave was happening, I'm pretty sure there'd be other reports
from it too).

My guess is that you're doing an os.walk() which walks recursively and it's
finding the name of the file more than once in a subdir and you're always
applying it to the local file later on (you can just print your 'f'
variable to know what it's finding).

Best Regards,

Fabio
Post by Gary Roach
I've had several occasions when a python program seems to loop through
from os import walk
import subprocess
f = []
x = ""
f.extend(filenames)
f.sort()
print(x)
args = "convert " + x + " -rotate " + "-90 " + x
subprocess.call(args, shell=True)
This program should rotate a jpg file by 90 degrees left. It actually
rotates the file 180 degrees and the print(x) function prints the file
name twice. What am I doming wrong.
I run it as python rotate.py from the command line.
Gary R.
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Pydev-users mailing list
https://lists.sourceforge.net/lists/listinfo/pydev-users
Gary Roach
2016-02-16 21:00:33 UTC
Permalink
Thanks Fabio

Your subdirectory suggestion was dead on. A good thing you pointed this
out since the subdirectory was holding the backup copies of the files
which I did not want changed. I changed the directory to chmod 700 and
cleared the problem. Thanks

Gary R.
Post by Fabio Zadrozny
I don't think this is an issue in PyDev (I can't reproduce it and if
something as grave was happening, I'm pretty sure there'd be other
reports from it too).
My guess is that you're doing an os.walk() which walks recursively and
it's finding the name of the file more than once in a subdir and
you're always applying it to the local file later on (you can just
print your 'f' variable to know what it's finding).
Best Regards,
Fabio
I've had several occasions when a python program seems to loop through
from os import walk
import subprocess
f = []
x = ""
f.extend(filenames)
f.sort()
print(x)
args = "convert " + x + " -rotate " + "-90 " + x
subprocess.call(args, shell=True)
This program should rotate a jpg file by 90 degrees left. It actually
rotates the file 180 degrees and the print(x) function prints the file
name twice. What am I doming wrong.
I run it as python rotate.py from the command line.
Gary R.
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Pydev-users mailing list
https://lists.sourceforge.net/lists/listinfo/pydev-users
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Pydev-users mailing list
https://lists.sourceforge.net/lists/listinfo/pydev-users
Loading...