To Change A Pdf Ebook To Kindle

2015-03-24 Thread jeffreyciross
PDF Converter for Mac is a fantastic and easyto-use instrument for converting
PDF documents on Macos. Macintosh PDF Converter can pdf to excel converter
to Word, Shine, PowerPoint, EPUB, Text format for Mac. With PDF Converter
Mac, the PDF documents, select certain websites of the PDF files etc that
are huge can be also previewed by Mac users.

https://sourceforge.net/projects/pdftoexcelconverter/



--
View this message in context: 
http://python.6.x6.nabble.com/To-Change-A-Pdf-Ebook-To-Kindle-tp5090337.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread CHIN Dihedral
On Tuesday, March 24, 2015 at 6:54:20 AM UTC+8, Terry Reedy wrote:
> On 3/23/2015 2:44 PM, Dave Angel wrote:
> 
> > ## Example 2: Using recursion with caching
> > cache = [0, 1]
> > def fib4(n):
> >  if len(cache) <= n:
> >  value = fib4(n-2) + fib4(n-1)
> >  cache.append(value)
> >  return cache[n]
> >
> > This one takes less than a millisecond up to n=200 or so.
> 
> Iteration with caching, using a mutable default arg to keep the cache 
> private and the function self-contained.  This should be faster.
> 
> def fib(n, _cache=[0,1]):
>  '''Return fibonacci(n).
> 
>  _cache is initialized with base values and augmented as needed.
>  '''
>  for k in range(len(_cache), n+1):
>  _cache.append(_cache[k-2] + _cache[k-1])
>  return _cache[n]
> 
> print(fib(1), fib(3), fib(6), fib(5))
> # 1 2 8 5
> 
> Either way, the pattern works with any matched pair of base value list 
> and recurrence relation where f(n), n a count, depends on one or more 
> f(k), k < n.  'Matched' means that the base value list is as least as 
> long as the maximum value of n - k.  For fib, the length and max are both 2.
> 
> -- 
> Terry Jan Reedy
How about adding a new type of 
numbers of the form:
 (a+sqrt(r0)+ swrt(r1))/b with proper operations, and  then one can compute 
the Fib term directly in a 
field. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread Gregory Ewing

Chris Angelico wrote:

Commenting is like dieting. You can always start tomorrow.


I've been meaning to become a procrastinator, but
I think I'll start tomorrow.

In the meantime, since we seem to be having a
fibbing competition, here's my contribution, that
uses neither recursion nor (explicit) iteration:

from numpy import array, dot

a = array([[0,1],[1,1]])
b = array([0,1])

def fib(n):
   return reduce(dot,[a]*n+[b])[1]

for i in range(10):
   print(fib(i))

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


ANN: eGenix pyOpenSSL Distribution 0.13.8

2015-03-24 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

Version 0.13.8

An easy-to-install and easy-to-use distribution
of the pyOpenSSL Python interface for OpenSSL -
   available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.8.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution includes the
following updates:


New in eGenix pyOpenSSL
---

 * Added FreeBSD as supported platform.

 * Updated the Mozilla CA root bundle to version 2015-02-19.


New in OpenSSL
--

 * Updated included OpenSSL libraries from OpenSSL 1.0.1k to
   1.0.1m.

   We had skipped OpenSSL 1.0.1l, since the 1.0.1l release
   only included a patch for Windows we had already included in our
   0.13.7 release. See https://www.openssl.org/news/secadv_20150319.txt
   for a complete list of changes. The following fixes are relevant for
   pyOpenSSL applications:

   - CVE-2015-0286: Segmentation fault in ASN1_TYPE_cmp.

   - CVE-2015-0287: ASN.1 structure reuse memory corruption.

   - CVE-2015-0289: PKCS#7 NULL pointer dereference.

   - CVE-2015-0292: A vulnerability existed in previous versions of
 OpenSSL related to the processing of base64 encoded data. Any
 code path that reads base64 data from an untrusted source could
 be affected (such as the PEM processing routines). Already fixed
 in OpenSSL 1.0.1h, but wasn't listed, so repeated here for
 completeness.

   - CVE-2015-0293: Denial-of-Service (DoS) via reachable assert in
 SSLv2 servers.

   - CVE-2015-0209: Use After Free following d2i_ECPrivatekey error. A
 malformed EC private key file consumed via the d2i_ECPrivateKey
 function could cause a use after free condition.

 * The FREAK Attack (CVE-2015-0204) patch was already available in our
   last release with OpenSSL 1.0.1k.

Please see the product changelog for the full set of changes:

http://www.egenix.com/products/python/pyOpenSSL/changelog.html


pyOpenSSL / OpenSSL Binaries Included
-

In addition to providing sources, we make binaries available that
include both pyOpenSSL and the necessary OpenSSL libraries for all
supported platforms: Windows, Linux, Mac OS X and now FreeBSD, for x86
and x64.

To simplify installation, we have uploaded a web installer to PyPI
which will automatically choose the right binary for your platform, so
a simple

pip install egenix-pyopenssl

will get you the package with OpenSSL libraries installed. Please see
our installation instructions for details:

http://www.egenix.com/products/python/pyOpenSSL/#Installation

We have also added .egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/


UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___
SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.


MORE INFORMATION

For more information about the eGenix pyOpenSSL Distribution, licensing
and download instructions, please visit our web-site or write to
sa...@egenix.com.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source 

module attributes and docstrings

2015-03-24 Thread Mario Figueiredo
Reading PEP 257 and 258 I got the impression that I could document
module attributes and these would be available in the __doc__
attribute of the object.

So things like the one below are something I got used to do, but that
don't work after all, as I learned today:

value_factory = lambda _, row: row[0]
"""Row factory. To be used with single-column queries."""

There are other things I could possibly do, like turning that lambda
into a function, or document attributes in the module docstring. They
are fair responses.

But did I read docstring extraction rules in PEP 258 wrong by assuming
that the above example would make into the __doc__ attribute? And if
so, short of documenting attributes in the module docstring, is there
another way I can document individual attributes?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: module attributes and docstrings

2015-03-24 Thread Chris Angelico
On Tue, Mar 24, 2015 at 7:55 PM, Mario Figueiredo  wrote:
> So things like the one below are something I got used to do, but that
> don't work after all, as I learned today:
>
> value_factory = lambda _, row: row[0]
> """Row factory. To be used with single-column queries."""
>
> There are other things I could possibly do, like turning that lambda
> into a function, or document attributes in the module docstring. They
> are fair responses.

They certainly are. Any time you assign a lambda function directly to
a simple name, it's probably worth replacing with a def function:

def value_factory(_, row):
"""Row factory. To be used with single-column queries."""
return row[0]

(Though I'd be inclined to give the first parameter a proper name here)

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


Re: module attributes and docstrings

2015-03-24 Thread Steven D'Aprano
On Tue, 24 Mar 2015 07:55 pm, Mario Figueiredo wrote:

> Reading PEP 257 and 258 I got the impression that I could document
> module attributes and these would be available in the __doc__
> attribute of the object.

PEP 258 is rejected, so you can't take that as definitive.

PEP 257 has this definition very early in the document:

A docstring is a string literal that occurs as the first 
statement in a module, function, class, or method definition.


Nothing there about documenting arbitrary attributes.

The PEP does go on to say:

String literals occurring elsewhere in Python code may also 
act as documentation. They are not recognized by the Python
bytecode compiler and are not accessible as runtime object
attributes (i.e. not assigned to  __doc__  ), but two types
of extra docstrings may be extracted by software tools: ...

so if I write this:

class K:
x = something()
"""Documentation for x"""

then the string *may* be extracted by certain third-party tools, but it will
not be recognised as a docstring by the Python interpreter and will not be
available as the __doc__ attribute of K.x.


> So things like the one below are something I got used to do, but that
> don't work after all, as I learned today:
> 
> value_factory = lambda _, row: row[0]
> """Row factory. To be used with single-column queries."""
> 
> There are other things I could possibly do, like turning that lambda
> into a function, or document attributes in the module docstring. They
> are fair responses.


For the record, the lambda is already a function. lambda is just an
alternative syntax for creating functions, not a different kind of object.


> But did I read docstring extraction rules in PEP 258 wrong by assuming
> that the above example would make into the __doc__ attribute? And if
> so, short of documenting attributes in the module docstring, is there
> another way I can document individual attributes?

In a word, no.

Even if there was support from the compiler to extract the docstring, where
would it be stored? Consider:

spam = None
"""Spammy goodness."""
eggs = None
"""Scrambled, not fried."""

There's only one None object, and even if it could take a docstring (and it
can't), which docstring would it get? Presumably the second, which would
make help(spam) confusing, but when we say eggs = 23 the docstring would
disappear too.

Python's data model is not compatible with the idea of associating
docstrings with arbitrary attributes or variables. The docstring has to be
associated with an object, and only certain objects at that.

That applies to documentation which is introspectable at runtime. But of
course you can do anything you like by parsing the source code! It may be
that the docutils library will parse the source code and extract
docstrings, associating them to their variable or attribute. If not,
perhaps some other third-party library, or you can write your own.



-- 
Steven

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


Monkey patch an entire file in a python package

2015-03-24 Thread enjoyaol
This question is about python 2.7 on Windows 7

I am trying to use multiprocessing with freeze. It appears there is some bug 
when using multiprocessing on freezed python code on windows platforms. There 
is this patch which made its way to python 3.2, and works in 2.7:

http://bugs.python.org/file20603/issue10845_mitigation.diff

I would like to monkey patch it.

Problem is, this patch is for "forking.py", used by multiprocessing.Pools 
Multiprocessing is using forking.py to launch processes. I would like to monkey 
patch this way :

import multiprocessing
import multiprocessing_fixed
multiprocessing_fixed:

import multiprocessing.forking as mpf
def prepare(data):
[include fixed code for this method]
mpf.prepare = prepare_pyz
It's not working because forking.py is launched like a python module.

How to solve this problem ?

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


Re: Monkey patch an entire file in a python package

2015-03-24 Thread Chris Angelico
On Tue, Mar 24, 2015 at 10:50 PM,   wrote:
> I am trying to use multiprocessing with freeze. It appears there is some bug 
> when using multiprocessing on freezed python code on windows platforms. There 
> is this patch which made its way to python 3.2, and works in 2.7:
>
> http://bugs.python.org/file20603/issue10845_mitigation.diff
>
> I would like to monkey patch it.

Do you have to monkey-patch at run-time? It might be better to simply
patch your Python installation once, and then have the change deployed
globally. Given that it was applied to 3.2, I doubt it's going to
break much, so you can probably afford to just edit the file and have
done with it.

Alternatively, you may be able to put your own forking.py earlier in
PYTHONPATH, and thus shadow the stdlib module. That might require you
to shadow all of multiprocessing, though.

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


Re: To Change A Pdf Ebook To Kindle

2015-03-24 Thread alister
On Tue, 24 Mar 2015 00:05:46 -0700, jeffreyciross wrote:

> PDF Converter for Mac is a fantastic and easyto-use instrument for
> converting PDF documents on Macos. Macintosh PDF Converter can pdf to
> excel converter to Word, Shine, PowerPoint, EPUB, Text format for Mac.
> With PDF Converter Mac, the PDF documents, select certain websites of
> the PDF files etc that are huge can be also previewed by Mac users.
> 
> https://sourceforge.net/projects/pdftoexcelconverter/

Calibre does a very god job as well.



-- 
Most people want either less corruption or more of a chance to
participate in it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Monkey patch an entire file in a python package

2015-03-24 Thread enjoyaol
Le mardi 24 mars 2015 13:11:33 UTC+1, Chris Angelico a écrit :
> On Tue, Mar 24, 2015 at 10:50 PM,   wrote:
> > I am trying to use multiprocessing with freeze. It appears there is some 
> > bug when using multiprocessing on freezed python code on windows platforms. 
> > There is this patch which made its way to python 3.2, and works in 2.7:
> >
> > http://bugs.python.org/file20603/issue10845_mitigation.diff
> >
> > I would like to monkey patch it.
> 
> Do you have to monkey-patch at run-time? It might be better to simply
> patch your Python installation once, and then have the change deployed
> globally. Given that it was applied to 3.2, I doubt it's going to
> break much, so you can probably afford to just edit the file and have
> done with it.
> 
> Alternatively, you may be able to put your own forking.py earlier in
> PYTHONPATH, and thus shadow the stdlib module. That might require you
> to shadow all of multiprocessing, though.
> 
> ChrisA

Unfortunately, I would need to do it at runtime.
I will look into the PYTHONPATH idea, thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread Ganesh Pal
On Tue, Mar 24, 2015 at 5:41 AM, Steven D'Aprano
 wrote:

> Python does not automatically print all return statements. If you want it to
> print the intermediate values produced, you will need to add print before
> each return:
>
>
> py> def fib(n):
> ... if n == 0:
> ... result = 0
> ... elif n == 1:
> ... result = 1
> ... else:
> ... result = fib(n-1) + fib(n-2)
> ... print result,  # trailing comma means no newline
> ... return result
> ...
> py> fib(3)
> 1 0 1 1 2
> 2
> py> fib(5)
> 1 0 1 1 2 1 0 1 3 1 0 1 1 2 5
> 5
>
>
> If you want to print a list of Fibonnaci values, you need to call the
> function in a loop. Removing the "print result" line again, you can do
> this:
>
> py> for i in range(6):
> ... print fib(i),
> ...
> 0 1 1 2 3 5


Thanks you Steven and others ( Dave, Chris and Terry ) , for having
such good discussion on this topic and benefiting me in more than one
way's. Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To Change A Pdf Ebook To Kindle

2015-03-24 Thread Michael Torrie
On 03/24/2015 01:05 AM, jeffreyciross wrote:
> probable spam

I'm wondering whether this is appropriate use of sourceforge.  Hosting a
proprietary program on SF's web site for free, doesn't seem honest to
me.  Should I report this to SF as inappropriate content?

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


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread Ian Kelly
On Tue, Mar 24, 2015 at 12:20 AM, Rustom Mody  wrote:
> On Tuesday, March 24, 2015 at 10:51:11 AM UTC+5:30, Ian wrote:
>> Iteration in log space. On my desktop, this calculates fib(1000) in
>> about 9 us, fib(10) in about 5 ms, and fib(1000) in about 7
>> seconds.
>>
>> def fib(n):
>> assert n >= 0
>> if n == 0:
>> return 0
>>
>> a = b = x = 1
>> c = y = 0
>> n -= 1
>>
>> while True:
>> n, r = divmod(n, 2)
>> if r == 1:
>> x, y = x*a + y*b, x*b + y*c
>> if n == 0:
>> return x
>> b, c = a*b + b*c, b*b + c*c
>> a = b + c
>
> This is rather arcane!
> What are the identities used above?

It's essentially the same matrix recurrence that Gregory Ewing's
solution uses, but without using numpy (which doesn't support
arbitrary precision AFAIK) and with a couple of optimizations.

The Fibonacci recurrence can be expressed using linear algebra as:

F_1 = [ 1 0 ]

T = [ 1 1 ]
[ 1 0 ]

F_(n+1) = F_n * T

I.e., given that F_n is a vector containing fib(n) and fib(n-1),
multiplying by the transition matrix T results in a new vector
containing fib(n+1) and fib(n). Therefore:

F_n = F_1 * T ** (n-1)

The code above evaluates this expression by multiplying F_1 by powers
of two of T until n-1 is reached. x and y are the two elements of the
result vector, which at the end of the loop are fib(n) and fib(n-1).
a, b, and c are the three elements of the (symmetric) transition
matrix T ** p, where p is the current power of two.

The last two lines of the loop updating a, b, and c could equivalently
be written as:

a, b, c = a*a + b*b, a*b + b*c, b*b + c*c

A little bit of algebra shows that if a = b + c before the assignment,
the equality is maintained after the assignment (in fact the elements
of T ** n are fib(n+1), fib(n), and fib(n-1)), so the two
multiplications needed to update a can be optimized away in favor of a
single addition.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To Change A Pdf Ebook To Kindle

2015-03-24 Thread Mark Lawrence

On 24/03/2015 14:23, Michael Torrie wrote:

On 03/24/2015 01:05 AM, jeffreyciross wrote:

probable spam


I'm wondering whether this is appropriate use of sourceforge.  Hosting a
proprietary program on SF's web site for free, doesn't seem honest to
me.  Should I report this to SF as inappropriate content?



Yes.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: To Change A Pdf Ebook To Kindle

2015-03-24 Thread Michael Torrie
On 03/24/2015 08:27 AM, Mark Lawrence wrote:
> On 24/03/2015 14:23, Michael Torrie wrote:
>>  Should I report this to SF as inappropriate content?
>
> Yes.

Done.

And yes I agree with alister, Calibre is an amazing program and it's all
100% python! And a large-scale app at that.  GPLv3.  Putting a link here
for the search engines.  Hopefully if anyone finds this thread they'll
find this instead of the spammy SF link.

http://calibre-ebook.com/


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


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread CHIN Dihedral
On Tuesday, March 24, 2015 at 10:24:59 PM UTC+8, Ian wrote:
> On Tue, Mar 24, 2015 at 12:20 AM, Rustom Mody  wrote:
> > On Tuesday, March 24, 2015 at 10:51:11 AM UTC+5:30, Ian wrote:
> >> Iteration in log space. On my desktop, this calculates fib(1000) in
> >> about 9 us, fib(10) in about 5 ms, and fib(1000) in about 7
> >> seconds.
> >>
> >> def fib(n):
> >> assert n >= 0
> >> if n == 0:
> >> return 0
> >>
> >> a = b = x = 1
> >> c = y = 0
> >> n -= 1
> >>
> >> while True:
> >> n, r = divmod(n, 2)
> >> if r == 1:
> >> x, y = x*a + y*b, x*b + y*c
> >> if n == 0:
> >> return x
> >> b, c = a*b + b*c, b*b + c*c
> >> a = b + c
> >
> > This is rather arcane!
> > What are the identities used above?
> 
> It's essentially the same matrix recurrence that Gregory Ewing's
> solution uses, but without using numpy (which doesn't support
> arbitrary precision AFAIK) and with a couple of optimizations.
> 
> The Fibonacci recurrence can be expressed using linear algebra as:
> 
> F_1 = [ 1 0 ]
> 
> T = [ 1 1 ]
> [ 1 0 ]
> 
> F_(n+1) = F_n * T
> 
> I.e., given that F_n is a vector containing fib(n) and fib(n-1),
> multiplying by the transition matrix T results in a new vector
> containing fib(n+1) and fib(n). Therefore:
> 
> F_n = F_1 * T ** (n-1)
> 
> The code above evaluates this expression by multiplying F_1 by powers
> of two of T until n-1 is reached. x and y are the two elements of the
> result vector, which at the end of the loop are fib(n) and fib(n-1).
> a, b, and c are the three elements of the (symmetric) transition
> matrix T ** p, where p is the current power of two.
> 
> The last two lines of the loop updating a, b, and c could equivalently
> be written as:
> 
> a, b, c = a*a + b*b, a*b + b*c, b*b + c*c
> 
> A little bit of algebra shows that if a = b + c before the assignment,
> the equality is maintained after the assignment (in fact the elements
> of T ** n are fib(n+1), fib(n), and fib(n-1)), so the two
> multiplications needed to update a can be optimized away in favor of a
> single addition.

Well, solving a  homogeneous difference equation of 2 degrees 
and generating the solution sequence 
for a particular one like the Finbnaci series is a good programming practice.

A more general programming practice 
is to generate the solution series 
of an arbitrary   homogeneous 
difference euqation of integer coefficients when a real or complex solution 
does exist.

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


Regex Python Help

2015-03-24 Thread gdotoli
I am creating a tool to search a filesystem for one simple string.
I cannot get the syntax correct.
Thank you in advance for your help.

import sys
import re
import os
path='/'
viewfiles=os.listdir(path)
for allfiles in viewfiles:
file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
if re.match("DECRYPT_I", line):
print line, 

--
This should search every file for the simple regex "DECRYPT_I"
This is from the root down.

The error is:

SyntaxError: Missing parentheses in call to 'print'

Please help.
Gregg Dotoli
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 1:13 PM,  wrote:

> SyntaxError: Missing parentheses in call to 'print'


It appears you are attempting to use a Python 2.x print statement with
Python 3.x Try changing the last line to

print(line.rstrip())

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


Re: Regex Python Help

2015-03-24 Thread Gary Herron

On 03/24/2015 11:13 AM, gdot...@gmail.com wrote:

I am creating a tool to search a filesystem for one simple string.
I cannot get the syntax correct.
Thank you in advance for your help.

import sys
import re
import os
path='/'
viewfiles=os.listdir(path)
for allfiles in viewfiles:
 file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
 if re.match("DECRYPT_I", line):
 print line,

--
This should search every file for the simple regex "DECRYPT_I"
This is from the root down.

The error is:

SyntaxError: Missing parentheses in call to 'print'

Please help.
Gregg Dotoli


You appear to be using Python3, but have written code for Python2.

There are a number of differences between the two, but your particular 
error runs into the different syntax for prints.


Python2: print line # This is a statement
Python3  print(line)  # This is a procedure call



--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


subprocess and stdin.write(), stdout.read()

2015-03-24 Thread Tobiah

The docs for the subprocess.Popen() say:

Use communicate() rather than .stdin.write, .stdout.read
or .stderr.read to avoid deadlocks due to any of the other
OS pipe buffers filling up and blocking the child process

But if I want to send a string to stdin, how can I do that without
stdin.write()?

This seems to work:

import subprocess as s

thing = """
hey
there
foo man is here
hey foo
man is there
so foo
"""
p = s.Popen(['grep', 'foo'], stdin = s.PIPE, stdout = s.PIPE)
p.stdin.write(thing)
print p.communicate()

##

('\they foo\n \tfoo there\n', None)


Will this always avoid the deadlock problem?

This also works:

p = s.Popen(['grep', 'foo'], stdin = s.PIPE, stdout = s.PIPE)
p.stdin.write(thing)
p.stdin.close()
print p.stdout.read()

Is that vulnerable to deadlock?  Is there a better way
to write to and read from the same process?

Thanks!

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


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you Gary, that got rid of the error, but now there is no tree walk, it 
runs and immediatley finishes. I just need to grep each file. I have this 
working with the windows "for /r %a and redirecting that to Python, but want to 
use Python only. I do have dummy files with the regex string.

Thanks again,
Gregg




On Tuesday, March 24, 2015 at 2:34:20 PM UTC-4, Gary Herron wrote:
> On 03/24/2015 11:13 AM, gdot...@gmail.com wrote:
> > I am creating a tool to search a filesystem for one simple string.
> > I cannot get the syntax correct.
> > Thank you in advance for your help.
> >
> > import sys
> > import re
> > import os
> > path='/'
> > viewfiles=os.listdir(path)
> > for allfiles in viewfiles:
> >  file= os.path.join(path, allfiles)
> > text=open(file, "r")
> > for line in text:
> >  if re.match("DECRYPT_I", line):
> >  print line,
> >
> > --
> > This should search every file for the simple regex "DECRYPT_I"
> > This is from the root down.
> >
> > The error is:
> >
> > SyntaxError: Missing parentheses in call to 'print'
> >
> > Please help.
> > Gregg Dotoli
> 
> You appear to be using Python3, but have written code for Python2.
> 
> There are a number of differences between the two, but your particular 
> error runs into the different syntax for prints.
> 
> Python2: print line # This is a statement
> Python3  print(line)  # This is a procedure call
> 
> 
> 
> -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

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


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you! But

The print error is gone, but now the script quickly finishes and doesnt walk
the OS tree or search.

Gregg 



On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote:
> I am creating a tool to search a filesystem for one simple string.
> I cannot get the syntax correct.
> Thank you in advance for your help.
> 
> import sys
> import re
> import os
> path='/'
> viewfiles=os.listdir(path)
> for allfiles in viewfiles:
> file= os.path.join(path, allfiles)
> text=open(file, "r")
> for line in text:
> if re.match("DECRYPT_I", line):
> print line, 
> 
> --
> This should search every file for the simple regex "DECRYPT_I"
> This is from the root down.
> 
> The error is:
> 
> SyntaxError: Missing parentheses in call to 'print'
> 
> Please help.
> Gregg Dotoli

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


Re: module attributes and docstrings

2015-03-24 Thread Terry Reedy

On 3/24/2015 4:55 AM, Mario Figueiredo wrote:

Reading PEP 257 and 258 I got the impression that I could document
module attributes and these would be available in the __doc__
attribute of the object.

So things like the one below are something I got used to do, but that
don't work after all, as I learned today:

 value_factory = lambda _, row: row[0]
 """Row factory. To be used with single-column queries."""

There are other things I could possibly do, like turning that lambda
into a function,


You have discovered one of advantages of a def statement over a 
name=lambda assignment statement.  In Python, there is no good reason to 
use the latter form and PEP 8 specifically discourages it: "Always use a 
def statement instead of an assignment statement that binds a lambda 
expression directly to an identifier."


--
Terry Jan Reedy

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


Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre

Le 24/03/2015 20:38, Vincent Vande Vyvre a écrit :

Le 24/03/2015 20:22, Gregg Dotoli a écrit :

Thank you! But

The print error is gone, but now the script quickly finishes and 
doesnt walk

the OS tree or search.

Gregg



On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote:

I am creating a tool to search a filesystem for one simple string.
I cannot get the syntax correct.
Thank you in advance for your help.

import sys
import re
import os
path='/'
viewfiles=os.listdir(path)
for allfiles in viewfiles:
 file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
 if re.match("DECRYPT_I", line):
 print line,

--
This should search every file for the simple regex "DECRYPT_I"
This is from the root down.

The error is:

SyntaxError: Missing parentheses in call to 'print'

Please help.
Gregg Dotoli

Your indentation is wrong.

for allfiles in viewfiles:
file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
if re.match("DECRYPT_I", line):
print line,


Vincent

... and me too

for allfiles in viewfiles:
file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
if re.match("DECRYPT_I", line):
print line,
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 2:22 PM, Gregg Dotoli  wrote:

> The print error is gone, but now the script quickly finishes and doesnt
> walk
> the OS tree or search.
>

You need to walk the directory tree recursively. Take a look at os.walk().

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


Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:10:24 -0700, Gregg Dotoli wrote:
> 
> Thank you Gary, that got rid of the error, but now there is no tree
> walk, it runs and immediatley finishes. I just need to grep each file. I
> have this working with the windows "for /r %a and redirecting that to
> Python, but want to use Python only. I do have dummy files with the
> regex string.
> 
> Thanks again,
> Gregg
> 

Gregg --

First, please don't top-post.  Secondly, os.listdir only does exactly 
that; it lists everything on one directory.  You're looking for os.walk.

-- Rob

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
This works fine , but I have to pipe the filename to the script python stool 
 I am creating a tool to search a filesystem for one simple string.
> I cannot get the syntax correct.
> Thank you in advance for your help.
> 
> import sys
> import re
> import os
> path='/'
> viewfiles=os.listdir(path)
> for allfiles in viewfiles:
> file= os.path.join(path, allfiles)
> text=open(file, "r")
> for line in text:
> if re.match("DECRYPT_I", line):
> print line, 
> 
> --
> This should search every file for the simple regex "DECRYPT_I"
> This is from the root down.
> 
> The error is:
> 
> SyntaxError: Missing parentheses in call to 'print'
> 
> Please help.
> Gregg Dotoli

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


Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre

Le 24/03/2015 20:22, Gregg Dotoli a écrit :

Thank you! But

The print error is gone, but now the script quickly finishes and doesnt walk
the OS tree or search.

Gregg



On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote:

I am creating a tool to search a filesystem for one simple string.
I cannot get the syntax correct.
Thank you in advance for your help.

import sys
import re
import os
path='/'
viewfiles=os.listdir(path)
for allfiles in viewfiles:
 file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
 if re.match("DECRYPT_I", line):
 print line,

--
This should search every file for the simple regex "DECRYPT_I"
This is from the root down.

The error is:

SyntaxError: Missing parentheses in call to 'print'

Please help.
Gregg Dotoli

Your indentation is wrong.

for allfiles in viewfiles:
file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
if re.match("DECRYPT_I", line):
print line,


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


Re: subprocess and stdin.write(), stdout.read()

2015-03-24 Thread Chris Kaynor
On Tue, Mar 24, 2015 at 12:08 PM, Tobiah  wrote:
> The docs for the subprocess.Popen() say:
>
> Use communicate() rather than .stdin.write, .stdout.read
> or .stderr.read to avoid deadlocks due to any of the other
> OS pipe buffers filling up and blocking the child process
>
> But if I want to send a string to stdin, how can I do that without
> stdin.write()?
>
> This seems to work:
>
> import subprocess as s
>
> thing = """
> hey
> there
> foo man is here
> hey foo
> man is there
> so foo
> """
> p = s.Popen(['grep', 'foo'], stdin = s.PIPE, stdout = s.PIPE)
> p.stdin.write(thing)
> print p.communicate()
>
> ##
>
> ('\they foo\n \tfoo there\n', None)
>
>
> Will this always avoid the deadlock problem?

What you should do is use "print p.communicate(thing)". That will
always avoid the deadlock issue.

Your code MAY deadlock in some cases as the stdin pipe could fill up
fully, but the other process is not reading it as it is waiting for
you to read output. What this means is that, you must be reading from
stdout AND stderr if you are possibly waiting for the process (such as
when writing to stdin or using .wait() or looping on .poll()).

subprocess.communicate() takes care of that issue internally, however
you can write your own variations (useful if you need to process
stdout to produce stdin, for example), however you must either be
using a select or threads to be sure to be reading stdout and stderr.
You should also pay attention to the note on communicate - if
potentially large amounts of data will be produced, you may need to
write your own method to avoid memory paging/OOM issues due to
communicate filling up the system's RAM.

In the example you provide, you will probably never hit the deadlock
as the data being written is small enough that it should never fill
the buffers (typically, they are ~2k). Additionally, if you know the
process never produces output on stdout or stderr, you can ignore them
(but then, why would you pipe them?).

>
> This also works:
>
> p = s.Popen(['grep', 'foo'], stdin = s.PIPE, stdout = s.PIPE)
> p.stdin.write(thing)
> p.stdin.close()
> print p.stdout.read()
>
> Is that vulnerable to deadlock?  Is there a better way
> to write to and read from the same process?

This is more likely to cause deadlocks as, if the process writes too
much to stderr, it may stall waiting for you to read it, while you are
waiting for it to close stdout.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Terry Reedy

On 3/24/2015 2:13 PM, gdot...@gmail.com wrote:

I am creating a tool to search a filesystem for one simple string.
I cannot get the syntax correct.
Thank you in advance for your help.

import sys
import re
import os
path='/'
viewfiles=os.listdir(path)


listdir is not recursive, so this code will only search files in the one 
directory, not the whole filesystem.  You need to use os.walk and modify 
the code to do the latter.



for allfiles in viewfiles:
 file= os.path.join(path, allfiles)
text=open(file, "r")
for line in text:
 if re.match("DECRYPT_I", line):
 print line,


You appear to have used a mixture of spaces and tabs for indents.  That 
works in 2.x, but not in 3.x.  You open but do not close files, which 
could be a problem if you open and search 10 files in a filesystem. 
 Use a with statememt.  'allfiles' is a bad name because it get bound 
to a single file.


for file in viewfiles:
with open(os.path.join(path, file)) as text:
for line in text:
if re.match("DECRYPT_I", line):
print(line)

--
Terry Jan Reedy

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


Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote:

> [context snipped due to top posting]
>
> All I need is a loop, should I bag Python and use a simple shell for 
loop?

Honestly, yes.  You're not even using a regular expression, just a fixed 
string you're trying to search for.  You can do the entire thing as

$ find . -type f | xargs grep DECRYPT_I

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Pillow bug?

2015-03-24 Thread kai . peters
Judging from the message archive, the image-sig list is (just about) dead?

Disclaimer: Am a newbie - so anything is possible


using 'RGB' works fine

img = Image.new('RGB', (inktile[0], inktile[1]), bgcolor)   

using '1' or 'L' does not (see trace below)

img = Image.new('L', (inktile[0], inktile[1]), bgcolor)   


I change nothing else but the first parameter. If I switch the 'L' back to 
'RGB' it works again.


img  = Image.new('L', (inktile[0], inktile[1]), bgcolor)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2015, in new
return Image()._new(core.fill(mode, size, color))
TypeError: an integer is required

The docs say that '1' and 'L' are supported - something broken? Something I do 
not understand?

Thanks for any pointers,

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


Re: Pillow bug?

2015-03-24 Thread Ian Kelly
On Tue, Mar 24, 2015 at 1:52 PM,   wrote:
> Judging from the message archive, the image-sig list is (just about) dead?
>
> Disclaimer: Am a newbie - so anything is possible
>
>
> using 'RGB' works fine
>
> img = Image.new('RGB', (inktile[0], inktile[1]), bgcolor)
>
> using '1' or 'L' does not (see trace below)
>
> img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
>
>
> I change nothing else but the first parameter. If I switch the 'L' back to 
> 'RGB' it works again.
>
>
> img  = Image.new('L', (inktile[0], inktile[1]), bgcolor)
>   File "C:\Python27\lib\site-packages\PIL\Image.py", line 2015, in new
> return Image()._new(core.fill(mode, size, color))
> TypeError: an integer is required
>
> The docs say that '1' and 'L' are supported - something broken? Something I 
> do not understand?

What is the value of bgcolor that you're passing in? Per the docs: "If
given, this should be a single integer or floating point value for
single-band modes, and a tuple for multi-band modes (one value per
band)." So if you're changing from a multi-band mode to a single-band
mode, you would need to change the color argument as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pillow bug?

2015-03-24 Thread Terry Reedy

On 3/24/2015 3:52 PM, kai.pet...@gmail.com wrote:

Judging from the message archive, the image-sig list is (just about) dead?


PIL and/or pillow should have their own lists.

--
Terry Jan Reedy

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


Re: Pillow bug?

2015-03-24 Thread kai . peters
On Tuesday, 24 March 2015 13:15:42 UTC-7, Ian  wrote:
> On Tue, Mar 24, 2015 at 1:52 PM,  Kai wrote:
> > Judging from the message archive, the image-sig list is (just about) dead?
> >
> > Disclaimer: Am a newbie - so anything is possible
> >
> >
> > using 'RGB' works fine
> >
> > img = Image.new('RGB', (inktile[0], inktile[1]), bgcolor)
> >
> > using '1' or 'L' does not (see trace below)
> >
> > img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
> >
> >
> > I change nothing else but the first parameter. If I switch the 'L' back to 
> > 'RGB' it works again.
> >
> >
> > img  = Image.new('L', (inktile[0], inktile[1]), bgcolor)
> >   File "C:\Python27\lib\site-packages\PIL\Image.py", line 2015, in new
> > return Image()._new(core.fill(mode, size, color))
> > TypeError: an integer is required
> >
> > The docs say that '1' and 'L' are supported - something broken? Something I 
> > do not understand?
> 
> What is the value of bgcolor that you're passing in? Per the docs: "If
> given, this should be a single integer or floating point value for
> single-band modes, and a tuple for multi-band modes (one value per
> band)." So if you're changing from a multi-band mode to a single-band
> mode, you would need to change the color argument as well.

Good catch - that was it.

Thanks much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli

Here you go. Windows shell was easier!!!

for /f %a in (c:\gonow) do echo %a | c:\Python34\python c:\python34\unopy.py %a

Now I can use any regex pattern, I need.


On Tuesday, March 24, 2015 at 3:54:25 PM UTC-4, Rob Gaddi wrote:
> On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote:
> 
> > [context snipped due to top posting]
> >
> > All I need is a loop, should I bag Python and use a simple shell for 
> loop?
> 
> Honestly, yes.  You're not even using a regular expression, just a fixed 
> string you're trying to search for.  You can do the entire thing as
> 
> $ find . -type f | xargs grep DECRYPT_I
> 
> -- 
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.

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


Daylight savings time question

2015-03-24 Thread Dan Stromberg
Is there a way of "adding" 4 hours and getting a jump of 5 hours on
March 8th, 2015 (due to Daylight Savings Time), without hardcoding
when to spring forward and when to fall back?  I'd love it if there's
some library that'll do this for me.

#!/usr/bin/python

import pytz
import datetime

def main():
# On 2015-03-08, 2:00 AM to 2:59AM Pacific time does not exist -
the clock jumps forward an hour.
weird_naive_datetime = datetime.datetime(2015, 3, 8, 1, 0,
0).replace(tzinfo=pytz.timezone('US/Pacific'))
weird_tz_aware_datetime =
weird_naive_datetime.replace(tzinfo=pytz.timezone('US/Pacific'))
print(weird_tz_aware_datetime)
four_hours=datetime.timedelta(hours=4)
print('Four hours later is:')
print(weird_tz_aware_datetime + four_hours)
print('...but I want numerically 5 hours later, because of
Daylight Savings Time')

main()


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


Re: Daylight savings time question

2015-03-24 Thread Gary Herron

On 03/24/2015 03:24 PM, Dan Stromberg wrote:

Is there a way of "adding" 4 hours and getting a jump of 5 hours on
March 8th, 2015 (due to Daylight Savings Time), without hardcoding
when to spring forward and when to fall back?  I'd love it if there's
some library that'll do this for me.

#!/usr/bin/python

import pytz
import datetime

def main():
 # On 2015-03-08, 2:00 AM to 2:59AM Pacific time does not exist -
the clock jumps forward an hour.
 weird_naive_datetime = datetime.datetime(2015, 3, 8, 1, 0,
0).replace(tzinfo=pytz.timezone('US/Pacific'))
 weird_tz_aware_datetime =
weird_naive_datetime.replace(tzinfo=pytz.timezone('US/Pacific'))
 print(weird_tz_aware_datetime)
 four_hours=datetime.timedelta(hours=4)
 print('Four hours later is:')
 print(weird_tz_aware_datetime + four_hours)
 print('...but I want numerically 5 hours later, because of
Daylight Savings Time')

main()


Thanks!


The pyzt module (which you've imported) has lots to say about this. Look 
at its procedures "localize' and 'normalize' and all the rest of the 
pyzt documentation.




--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Daylight savings time question

2015-03-24 Thread Chris Angelico
On Wed, Mar 25, 2015 at 9:24 AM, Dan Stromberg  wrote:
> Is there a way of "adding" 4 hours and getting a jump of 5 hours on
> March 8th, 2015 (due to Daylight Savings Time), without hardcoding
> when to spring forward and when to fall back?  I'd love it if there's
> some library that'll do this for me.

Fundamentally, this requires knowledge of timezone data. That means
you have to select a political time zone, which basically means you
want the Olsen database (tzdata) which primarily works with city
names. I'm not sure whether "US/Pacific" is suitable; I usually use
"America/Los_Angeles" for Pacific US time.

But that aside, what Gary said is what I would recommend.

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


Re: subprocess and stdin.write(), stdout.read()

2015-03-24 Thread Nobody
On Tue, 24 Mar 2015 12:08:24 -0700, Tobiah wrote:

> But if I want to send a string to stdin, how can I do that without
> stdin.write()?

p.communicate(string)

> This seems to work:

Only because the amounts of data involved are small enough to avoid
deadlock.

If both sides write more data in one go than will fit into a pipe buffer,
you will get deadlock. The parent will be blocked waiting for the child to
consume the input, which doesn't happen because the child will be blocked
waiting for the parent to consume its output, which doesn't happen because
he parent will be blocked waiting for the child to consume the input, ...

That's a textbook example of deadlock: each side waiting forever for the
other side to make the first move.

This is exactly why POSIX' popen() function lets you either write to stdin
(mode=="w") or read from stdout (mode=="r") but not both.

> Will this always avoid the deadlock problem?

No.

> This also works:

Again, only because the amounts of data involved are small enough to avoid
deadlock.

> Is that vulnerable to deadlock?

Yes.

> Is there a better way to write to and read from the same process?

Use threads; one for each descriptor (stdin, stdout, stderr).

Non-blocking I/O is an alternative (and that's what .communicate() uses on
Unix), but threads will work on all common desktop and server platforms.

If you need to support platforms which lack threads, either

a) have the parent first write to a file (instead of .stdin), then have
the child read from the file while the parent reads .stdout and .stderr,
or

b) have the parent write to .stdin while the child writes its
stdout/stderr to files (or a file). Once the child completes, have
the parent read the file(s).

Using files allows for potentially gigabytes of data to be buffered. With
pipes, the amount may be as low as 512 bytes (the minimum value allowed by
POSIX) and will rarely be much more (a typical value is 4096 bytes, i.e.
one "page" on x86).

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


OpenID + Python 3.4

2015-03-24 Thread Juan C.
I was looking on the Internet regarding the use of OpenID in Python apps
but I only found Flask/web related stuff.

Is there any module that provides OpenID implementation for desktop level?

I currently have a Python desktop script that needs to authenticate in a
OpenID server, but I don't know how to implement it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Daylight savings time question

2015-03-24 Thread Dan Stromberg
This appears to do what I wanted:

#!/usr/bin/python

from __future__ import print_function

import pytz
import datetime

# Is there a good way of jumping ahead 5 hours instead of 4 on 2015-03-08?

def main():
# On 2015-03-08, 2:00 AM to 2:59AM Pacific time does not exist -
the clock jumps forward an hour.
us_pacific = pytz.timezone('US/Pacific')

weird_naive_datetime = datetime.datetime(2015, 3, 8, 1, 0, 0)
print('weird_naive_datetime:  ', weird_naive_datetime)

weird_tz_aware_datetime = us_pacific.localize(weird_naive_datetime)
print('weird_tz_aware_datetime', weird_tz_aware_datetime)

four_hours=datetime.timedelta(hours=4)
print('Four hours later is:   ',
us_pacific.normalize(weird_tz_aware_datetime + four_hours))

print('...we want numerically 5 hours later (so 6AM), because of
Daylight Savings Time')

main()


On Tue, Mar 24, 2015 at 3:24 PM, Dan Stromberg  wrote:
> Is there a way of "adding" 4 hours and getting a jump of 5 hours on
> March 8th, 2015 (due to Daylight Savings Time), without hardcoding
> when to spring forward and when to fall back?  I'd love it if there's
> some library that'll do this for me.
>
> #!/usr/bin/python
>
> import pytz
> import datetime
>
> def main():
> # On 2015-03-08, 2:00 AM to 2:59AM Pacific time does not exist -
> the clock jumps forward an hour.
> weird_naive_datetime = datetime.datetime(2015, 3, 8, 1, 0,
> 0).replace(tzinfo=pytz.timezone('US/Pacific'))
> weird_tz_aware_datetime =
> weird_naive_datetime.replace(tzinfo=pytz.timezone('US/Pacific'))
> print(weird_tz_aware_datetime)
> four_hours=datetime.timedelta(hours=4)
> print('Four hours later is:')
> print(weird_tz_aware_datetime + four_hours)
> print('...but I want numerically 5 hours later, because of
> Daylight Savings Time')
>
> main()
>
>
> Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To Change A Pdf Ebook To Kindle

2015-03-24 Thread Steven D'Aprano
On Tue, 24 Mar 2015 11:32 pm, alister wrote:

> On Tue, 24 Mar 2015 00:05:46 -0700, jeffreyciross wrote:
[off-topic spam]
> 
> Calibre does a very god job as well.

Please don't reply to spam. Unless the product is a Python library, or is
given in direct reply to an explicit request for an application which is
usable by Python, it is off-topic and spam.

I see Calibre is a Python application, not sure if it is importable by
Python scripts though.

Thank you,


-- 
Steven

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


Re: Best way to calculate fraction part of x?

2015-03-24 Thread Jason Swails
On Mon, Mar 23, 2015 at 8:38 PM, Emile van Sebille  wrote:

> On 3/23/2015 5:52 AM, Steven D'Aprano wrote:
>
>  Are there any other, possibly better, ways to calculate the fractional
>> part
>> of a number?
>>
>
> float (("%6.3f" % x)[-4:])


​In general you lose a lot of precision this way...​
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Steven D'Aprano
On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote:

> The error is:
> 
> SyntaxError: Missing parentheses in call to 'print'


I cannot imagine how the message could be more explicit: the call to print
is missing parentheses. If you're not going to read the error messages you
are given, you are truly going to struggle as a programmer.

Read the error message.  If you don't understand the error message, please
say so.

And choose a relevant subject line: this has nothing to do with regexes. You
might as well have called it "Import Python Help".


-- 
Steven

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


test1

2015-03-24 Thread Tiglath Suriol


body {color:black;}
h1 {text-align:center;color:maroon;font-size:30px;font-style:normal;}
td {font-size:12;font-style:monospace;}
}

{% block title %}{% endblock %}




IPDB Data Input Window


 



 
Address:{{ form.address }}

 
Filename:{{ form.filename }}



   





{{ form.box }}
Delete Selected


   









Description:{{ form.description }}


Expiry date:{{ form.expiry }}











function submitReset()
{
document.getElementById("frm1").reset();
}

function add()
{
window.location.replace="http://127.0.0.1:8000/add/";
}

function clearForms() 
{
// variable declaration
var x, y, z, type = null;
// loop through forms on HTML page
for (x = 0; x < document.forms.length; x++) {
// loop through each element on form
for (y = 0; y < document.forms[x].elements.length; y++) {
// define element type
type = document.forms[x].elements[y].type;
// alert before erasing form element
//alert('form='+x+' element='+y+' type='+type);
// switch on element type
switch (type) {
case 'text':
case 'textarea':
case 'password':
//case "hidden":
document.forms[x].elements[y].value = '';
break;
case 'radio':
case 'checkbox':
document.forms[x].elements[y].checked = '';
break;
case 'select-multiple':
for (z = 0; z < 
document.forms[x].elements[y].options.length; z++) {
document.forms[x].elements[y].options[z].selected = 
false;
}
case 'iframe' 
} // end switch
} // end for y
} // end for x
//x = window.frames["frame1"]; 
//x.document.body.innerHTML = "";
}




---


body {
font-size:10px;
color:black;
backgrounc:CC; 
}
h1 { 
text-align:center;
color:maroon;
font-size:30px;
font-style:normal;
}
td {
font-size:12;
font-style:monospace;
}
select {
background: transparent;
width: 500; 
height: 300; 
padding: 5px;
font-size: 16px;
border: 1px solid #ccc;
height: 34px;
} 
#righty {
float:right ;
width:20% ;
}
#des {
float:right ;
width:50% ;
}
#tab {
font-size:12;font-style:normal;
}
#msg {
font-size:12;font-style:monospace;background:FFCC66;
}
#id_box {
width:300px;height:150;border:1px solid 
black;background-color:ivory;padding:8px;
}


IPDB Asset Input