RE: ghostscripts in python with watchdog

2020-02-14 Thread legaulph
I'm not sure what happens, when I'm testing and suddenly I will start
getting this error.
Error: /undefinedfilename in (1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--
--nostringval--  
 false   1   %stopped_push
Dictionary stack:
   --dict:732/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.50: Unrecoverable error, exit code 1


-Original Message-
From: Python-list  On
Behalf Of Bheesham Persaud
Sent: Friday, February 14, 2020 1:26 AM
To: [email protected]
Subject: Re: ghostscripts in python with watchdog

Hey!

If you change the "-sOutputFile` parameter you pass into gswin64c.

For example, something like:

 output_directory = os.path.join(os.path.dirname(input_src), "out")

And then you should be able to modify the call to `os.system` to something
like:

 os.system(
 "gswin64c -q -dBATCH -dNOPAUSE"
 "-sOutputFile={output_directory}/page{page:04d}.pdf"
 " -dFirstPage={page} -dLastPage={page}"
 " -sDEVICE=pdfwrite {input_pdf}"
 .format(
 page=i,
 input_pdf=input_pdf,
 output_directory=output_directory
 )
 )
--
https://mail.python.org/mailman/listinfo/python-list

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


RE: ghostscripts in python with watchdog

2020-02-14 Thread legaulph
I see it does not like spaces in the file name

-Original Message-
From: [email protected]  
Sent: Friday, February 14, 2020 7:55 AM
To: 'Bheesham Persaud' ; [email protected]
Subject: RE: ghostscripts in python with watchdog

I'm not sure what happens, when I'm testing and suddenly I will start
getting this error.
Error: /undefinedfilename in (1)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--
--nostringval--  
 false   1   %stopped_push
Dictionary stack:
   --dict:732/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory GPL Ghostscript 9.50: Unrecoverable
error, exit code 1


-Original Message-
From: Python-list  On
Behalf Of Bheesham Persaud
Sent: Friday, February 14, 2020 1:26 AM
To: [email protected]
Subject: Re: ghostscripts in python with watchdog

Hey!

If you change the "-sOutputFile` parameter you pass into gswin64c.

For example, something like:

 output_directory = os.path.join(os.path.dirname(input_src), "out")

And then you should be able to modify the call to `os.system` to something
like:

 os.system(
 "gswin64c -q -dBATCH -dNOPAUSE"
 "-sOutputFile={output_directory}/page{page:04d}.pdf"
 " -dFirstPage={page} -dLastPage={page}"
 " -sDEVICE=pdfwrite {input_pdf}"
 .format(
 page=i,
 input_pdf=input_pdf,
 output_directory=output_directory
 )
 )
--
https://mail.python.org/mailman/listinfo/python-list


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


RE: ghostscripts in python with watchdog

2020-02-14 Thread Peter Otten
[email protected] wrote:

> os.system("... {input_pdf} ...".format(..., input_pdf=input_pdf))

> I see it does not like spaces in the file name

Use subprocess.call(), not os.system(), then:

>>> filename = "hello world.txt"
>>> with open(filename, "w") as f: print("Hello, world!", file=f)
... 
>>> import os, subprocess

Wrong, uses shell, and file name is not properly escaped:

>>> os.system("cat " + filename)
cat: hello: No such file or directory
cat: world.txt: No such file or directory
256

Right, does not use shell, no escaping needed:

>>> subprocess.call(["cat", filename])
Hello, world!
0


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


Re: first time python learner

2020-02-14 Thread Terry Reedy

On 2/13/2020 11:38 PM, Marty Konopko wrote:

Win 10
Anti Virus  off
[image: image.png]

Any idea?


Cameron already suggested a better title and question.  If it is about 
IDLE startup, read

https://docs.python.org/3/library/idle.html#startup-failure


--
Terry Jan Reedy

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


Re: What I learned today

2020-02-14 Thread Dan Stromberg
On Fri, Feb 14, 2020 at 3:10 PM Stefan Ram  wrote:

>   By trial and error (never read documentation!) I found
>   that you can count the number of e's in a text by just
>
> Counter( text ).get( 'e' )
>
>   (after »from collections import Counter« that is).
>
Even simpler, though not suitable for all situations:
"abcbdbe".count("b")

  The other thing I read in a book. I already knew that one
>   can zip using ... »zip«. E.g.,
>
Neat.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What I learned today

2020-02-14 Thread duncan smith
On 14/02/2020 23:21, Dan Stromberg wrote:
> On Fri, Feb 14, 2020 at 3:10 PM Stefan Ram  wrote:
> 
>>   By trial and error (never read documentation!) I found
>>   that you can count the number of e's in a text by just
>>
>> Counter( text ).get( 'e' )
>>
>>   (after »from collections import Counter« that is).
>>
> Even simpler, though not suitable for all situations:
> "abcbdbe".count("b")
> 

[snip]

And by far the quickest way (that I've found) for counting the number of
set bits in an int.

>>> def popcount(n):
cnt = 0
while n:
n &= n-1
cnt += 1
return cnt

>>> import timeit
>>> timeit.timeit("popcount(19847998494279)", "from __main__ import
popcount", number=1)

0.034410387044772506
>>> timeit.timeit("bin(19847998494279).count('1')", number=1)

0.004501901799812913
>>>

OK, things turn around for large integers with very few set bits. But
for my use case bin(n).count('1') wins hands down (which surprised me a
little).

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