Which way is best to execute a Python script in Excel?

2012-07-05 Thread Maurizio Spadaccino
Hi all

I'm new to Python but soon after a few days of studying its features I find
it my favourite mean of programming scripts to allow for data storing and
mining. My idea would be to inplement python scripts from inside an excel
sheet that would store and fetch data from a Mysql database. So i need the
script to be launched, say, by pressing a button in excel and, for
instance, retrieve immediately data from the mysql table. For what I found
in the net, it seems there are three ways to control python from excel:
1) run my python script via shell using the Run command in VBA, which seems
to me the easiest (but maybe slower?) way;
2) creating a COM server, for which I need more training since it doesnt
appear that easy;
3) via Microsoft Script Control, for which I saw some example around where
It looks like I can 'simulate' a python shell via the 'executeStatement'
command.

What would you suggest would be the more performing way to achieve my goals
as described above?

Thanks for you help
Maurizio


-- 
Maurizio


www.mauriziospadaccino.com
---
If you can avoid printing this e-mail, you are only doing good for our
planet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Karim

Le 05/07/2012 09:22, Maurizio Spadaccino a écrit :

Hi all

I'm new to Python but soon after a few days of studying its features I 
find it my favourite mean of programming scripts to allow for data 
storing and mining. My idea would be to inplement python scripts from 
inside an excel sheet that would store and fetch data from a Mysql 
database. So i need the script to be launched, say, by pressing a 
button in excel and, for instance, retrieve immediately data from the 
mysql table. For what I found in the net, it seems there are three 
ways to control python from excel:
1) run my python script via shell using the Run command in VBA, which 
seems to me the easiest (but maybe slower?) way;
2) creating a COM server, for which I need more training since it 
doesnt appear that easy;
3) via Microsoft Script Control, for which I saw some example around 
where It looks like I can 'simulate' a python shell via the 
'executeStatement' command.


What would you suggest would be the more performing way to achieve my 
goals as described above?


Thanks for you help
Maurizio


--
Maurizio


www.mauriziospadaccino.com 
---
If you can avoid printing this e-mail, you are only doing good for our 
planet.




Look at PyUNO from OpenOffice very large API:
http://www.openoffice.org/api/docs

I use to create all my documention (Excell, Writer, etc...) on this API.

Cheers
Karim

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


Re: Discussion on some Code Issues

2012-07-05 Thread Peter Otten
[email protected] wrote:

> On Thursday, July 5, 2012 4:51:46 AM UTC+5:30, (unknown) wrote:
>> Dear Group,
>> 
>> I am Sri Subhabrata Banerjee trying to write from Gurgaon, India to
>> discuss some coding issues. If any one of this learned room can shower
>> some light I would be helpful enough.
>> 
>> I got to code a bunch of documents  which are combined together.
>> Like,
>> 
>> 1)A Mumbai-bound aircraft with 99 passengers on board was struck by
>> lightning on Tuesday evening that led to complete communication failure
>> in mid-air and forced the pilot to make an emergency landing. 2) The
>> discovery of a new sub-atomic particle that is key to understanding how
>> the universe is built has an intrinsic Indian connection. 3) A bomb
>> explosion outside a shopping mall here on Tuesday left no one injured,
>> but Nigerian authorities put security agencies on high alert fearing more
>> such attacks in the city.
>> 
>> The task is to separate the documents on the fly and to parse each of the
>> documents with a definite set of rules.
>> 
>> Now, the way I am processing is:
>> I am clubbing all the documents together, as,
>> 
>> A Mumbai-bound aircraft with 99 passengers on board was struck by
>> lightning on Tuesday evening that led to complete communication failure
>> in mid-air and forced the pilot to make an emergency landing.The
>> discovery of a new sub-atomic particle that is key to understanding how
>> the universe is built has an intrinsic Indian connection. A bomb
>> explosion outside a shopping mall here on Tuesday left no one injured,
>> but Nigerian authorities put security agencies on high alert fearing more
>> such attacks in the city.
>> 
>> But they are separated by a tag set, like,
>> A Mumbai-bound aircraft with 99 passengers on board was struck by
>> lightning on Tuesday evening that led to complete communication failure
>> in mid-air and forced the pilot to make an emergency landing.$ The
>> discovery of a new sub-atomic particle that is key to understanding how
>> the universe is built has an intrinsic Indian connection.$ A bomb
>> explosion outside a shopping mall here on Tuesday left no one injured,
>> but Nigerian authorities put security agencies on high alert fearing more
>> such attacks in the city.
>> 
>> To detect the document boundaries, I am splitting them into a bag of
>> words and using a simple for loop as, for i in range(len(bag_words)):
>> if bag_words[i]=="$":
>> print (bag_words[i],i)
>> 
>> There is no issue. I am segmenting it nicely. I am using annotated corpus
>> so applying parse rules.
>> 
>> The confusion comes next,
>> 
>> As per my problem statement the size of the file (of documents combined
>> together) won’t increase on the fly. So, just to support all kinds of
>> combinations I am appending in a list the “I” values, taking its length,
>> and using slice. Works perfect. Question is, is there a smarter way to
>> achieve this, and a curious question if the documents are on the fly with
>> no preprocessed tag set like “$” how may I do it? From a bunch without
>> EOF isn’t it a classification problem?
>> 
>> There is no question on parsing it seems I am achieving it independent of
>> length of the document.
>> 
>> If any one in the group can suggest how I am dealing with the problem and
>> which portions should be improved and how?
>> 
>> Thanking You in Advance,
>> 
>> Best Regards,
>> Subhabrata Banerjee.
> 
> 
> Hi Steven, It is nice to see your post. They are nice and I learnt so many
> things from you. "I" is for index of the loop. Now my clarification I
> thought to do "import os" and process files in a loop but that is not my
> problem statement. I have to make a big lump of text and detect one chunk.
> Looping over the line number of file I am not using because I may not be
> able to take the slices-this I need. I thought to give re.findall a try
> but that is not giving me the slices. Slice spreads here. The power issue
> of string! I would definitely give it a try. Happy Day Ahead Regards,
> Subhabrata Banerjee.

Then use re.finditer():

start = 0
for match in re.finditer(r"\$", data):
end = match.start()
print(start, end)
print(data[start:end])
start = match.end()

This will omit the last text. The simplest fix is to put another "$" 
separator at the end of your data.

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


Re: Using a CMS for small site?

2012-07-05 Thread Dieter Maurer
Gilles  writes:

> The site is just...
> - a few web pages that include text (in four languages) and pictures
> displayed in a Flash slide show
> - a calendar to show availability
> - a form to send e-mail with anti-SPAM support
> - (ASAP) online payment
>
> Out of curiosity, are there CMS/frameworks in Python that can do this?
> Django? Other?

There is also "Plone" ("http://plone.org";) -- easy to set up.

You likely need third party extensions for the "anti-SPAM" support
and the onlie payment.

Unfortunately, "Plone" is quite resource hungry -- especially it wants
quite some memory.

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


Re: adding a simulation mode

2012-07-05 Thread Dieter Maurer
andrea crotti  writes:

> I'm writing a program which has to interact with many external
> resources, at least:
> - mysql database
> - perforce
> - shared mounts
> - files on disk
>
> And the logic is quite complex, because there are many possible paths to
> follow depending on some other parameters.
> This program even needs to run on many virtual machines at the same time
> so the interaction is another thing I need to check...
>
> Now I successfully managed to mock the database with sqlalchemy and only
> the fields I actually need, but I now would like to simulate also
> everything else.

There is a paradigm called "inversion of control" which can be used
to handle those requirements.

With "inversion of control", the components interact on the bases
of interfaces. The components themselves do not know each other, they
know only the interfaces they want to interact with. For the interaction
to really take place, a component asks a registry "give me a component
satisfying this interface", gets it and uses the interface.

If you follow this paradigm, it is easy to switch components: just
register different alternatives for the interface at hand.


"zope.interface" and "zope.component" are python packages that
support this paradigm. Despite the "zope" in their name, they can be
used outside of "Zope".

"zope.interface" models interfaces, while "zope.component" provides
so called "utilities" (e.g. "database utility", "filesystem utility", ...)
and "adapters" and the corresponding registries.


Of course, they contain only the infrastructure for the "inversion of control"
paradigm. Up to you to provide the implementation for the various
mocks.

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


Re: Question about weakref

2012-07-05 Thread Dieter Maurer
Frank Millman  writes:

> I have a situation where I thought using weakrefs would save me a bit
> of effort.

Instead of the low level "weakref", you might use a "WeakKeyDictionary".

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


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Thomas Jollans
On 07/05/2012 09:26 AM, Karim wrote:
> Look at PyUNO from OpenOffice very large API:
> http://www.openoffice.org/api/docs
> 
> I use to create all my documention (Excell, Writer, etc...) on this API.

Note that this API is for OpenOffice, not Microsoft Excel. However, as
you probably know, you can open most Excel files in OpenOffice's Calc.

I urge you to consider LibreOffice, a fork of OpenOffice that is now
broadly considered its successor. Its API can also be used in Python
http://api.libreoffice.org/

If you want to program Microsoft Office, your only option is, as far as
I know, VBA, but it may be possible to call Python from VBA using the
Windows Script Host. I assume that the Windows Script Control uses this,
but I doubt that's much easier to use than the standard WScript API.
(then again, I wouldn't know)

All in all, if you're going to script Microsoft office, by far the
easiest way is to simply stick to VBA and forget about Python in this
particular environment. If it's an option, try LibreOffice.

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: adding a simulation mode

2012-07-05 Thread andrea crotti
2012/7/5 Dieter Maurer :
>
> There is a paradigm called "inversion of control" which can be used
> to handle those requirements.
>
> With "inversion of control", the components interact on the bases
> of interfaces. The components themselves do not know each other, they
> know only the interfaces they want to interact with. For the interaction
> to really take place, a component asks a registry "give me a component
> satisfying this interface", gets it and uses the interface.
>
> If you follow this paradigm, it is easy to switch components: just
> register different alternatives for the interface at hand.
>
>
> "zope.interface" and "zope.component" are python packages that
> support this paradigm. Despite the "zope" in their name, they can be
> used outside of "Zope".
>
> "zope.interface" models interfaces, while "zope.component" provides
> so called "utilities" (e.g. "database utility", "filesystem utility", ...)
> and "adapters" and the corresponding registries.
>
>
> Of course, they contain only the infrastructure for the "inversion of control"
> paradigm. Up to you to provide the implementation for the various
> mocks.
>


Thanks that's a good point, in short I could do something like:


class FSActions:
  @classmethod
  def copy_directories(cls, src, dest)
  raise NotImplementedError

  @classmethod
  

And then have different implementations of this interface.  This would
work, but I don't really like the idea of constructing interfaces that
provide only the few things I need.

Instead of being good APIs they might become just random
functionalities put together to make my life easier, and at that point
maybe just some clear mocking might be even better..
-- 
http://mail.python.org/mailman/listinfo/python-list


Creating an instance when the argument is already an instance.

2012-07-05 Thread Olive
I am learning python -:)

I am creating a new class: package (to analyse the packages database in
some linux distros). I have created a class package such that
package("string") give me an instance of package if string is a correct
representation of a package. I would like that if pack is already an
instance of package then package(pack) just return pack.

This is exactly the behaviour of many of the built-in types. For
example:

[code]
[oesser@pcolivier ~]$ python2
Python 2.7.3 (default, Apr 24 2012, 00:06:13) 
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=complex(2,3)
>>> b=complex(a)
>>> a is b
True
[/code]

I note here that b is not a new instance of complex, it is another name
for a (as we can see with a is b). I would like to implement such
behaviour but I do not not how.

Olive
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an instance when the argument is already an instance.

2012-07-05 Thread Chris Angelico
On Thu, Jul 5, 2012 at 8:29 PM, Olive  wrote:
> I am creating a new class: package (to analyse the packages database in
> some linux distros). I have created a class package such that
> package("string") give me an instance of package if string is a correct
> representation of a package. I would like that if pack is already an
> instance of package then package(pack) just return pack.

One way would be to make the name "package" actually a wrapper
function, not the class itself:

>>> class _package:
def __init__(self,arg):
# blah blah
self.asdf=arg

>>> def package(arg):
if isinstance(arg,_package): return arg
return _package(arg)

>>> a=package("Test")
>>> b=package(a)
>>> a is b
True

The leading underscore is a common convention meaning "private
implementation detail".

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about weakref

2012-07-05 Thread Frank Millman

On 05/07/2012 10:46, Dieter Maurer wrote:

Frank Millman  writes:


I have a situation where I thought using weakrefs would save me a bit
of effort.


Instead of the low level "weakref", you might use a "WeakKeyDictionary".



Thanks, Dieter. I could do that.

In fact, a WeakSet suits my purposes better. I tested it with my 
original example, and it works correctly. It also saves me the step of 
deleting the weak reference once the original object is deleted, as it 
seems to do that automatically.


I just need to double-check that I would never have the same 
listener-object try to register itself with the publisher twice, as that 
would obviously fail with a Set, as it would with a Dict.


I would still like to know why weakref.proxy raised an exception. I have 
re-read the manual several times, and googled for similar problems, but 
am none the wiser. Naturally I feel a bit uneasy using a feature of the 
language which sometimes fails mysteriously, so if anyone has an 
explanation, I would really appreciate it.


Frank

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


Re: Creating an instance when the argument is already an instance.

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 12:29:24 +0200, Olive wrote:

> I am learning python -:)
> 
> I am creating a new class: package (to analyse the packages database in
> some linux distros). I have created a class package such that
> package("string") give me an instance of package if string is a correct
> representation of a package. I would like that if pack is already an
> instance of package then package(pack) just return pack.

The built-in types only do this for immutable objects, those which cannot 
be modified.

py> a = float('42.5')
py> b = float(a)
py> a is b
True


But note carefully that this is not a guarantee of the language. Other 
versions of Python may not do this.

Also note carefully that it is only immutable objects which do this. 
Mutable objects do not behave this way:

py> a = ['a', 1, None]
py> b = list(a)
py> a is b
False


By default, most custom-made classes are mutable, and so re-using 
instances is the wrong thing to do. Unfortunately, it is moderately 
tricky to make mutable classes in Python. One way is described here:

http://northernplanets.blogspot.com.au/2007/01/immutable-instances-in-python.html

You can also look at the source code for Decimal (warning: it's BIG) or 
Fraction:

http://hg.python.org/cpython/file/2.7/Lib/decimal.py
http://hg.python.org/cpython/file/2.7/Lib/fractions.py


But suppose you make your class immutable. Then it's quite safe, and 
easy, to get the behaviour you want:


class Package(object):
def __new__(cls, argument):
if isinstance(argument, Package):
return argument
return object.__new__(cls, argument)


or similar, I haven't actually tested the above. But the important trick 
is to use __new__, the constructor, rather than __init__, which runs 
after the instance is already created, and to use an isinstance test to 
detect when you already have an instance.


Good luck!



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a CMS for small site?

2012-07-05 Thread Gilles
On Wed, 4 Jul 2012 17:09:40 -0700 (PDT), alex23 
wrote:
>Not necessarily! There are several static site generators written in
>Python :)
>
>One that I see being updating a lot is Nikola: http://nikola.ralsina.com.ar/

I'll check it out, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a CMS for small site?

2012-07-05 Thread Gilles
On Thu, 05 Jul 2012 10:27:40 +0200, Dieter Maurer
 wrote:
>There is also "Plone" ("http://plone.org";) -- easy to set up.
>
>You likely need third party extensions for the "anti-SPAM" support
>and the onlie payment.

I'll see what extensions it offers. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Vlastimil Brom
Many thanks to all for your suggestions!

@ChrisA
Yes, the calculations with seconds since the Unix epoch is very
convenient for real times, but trying to make it dateless seemed to
make it more complicated for me.

The expected output for the increments asked by Jason was already
correctly stated by Devin; i.e.: 12:45 plus 12 hours is 0:45 and 12:45
minus 13 hours is 23:45.

Thanks for reminding me of dateutil.relativedelta, Mark, I didn't
think of it in this context (I always thought, the "relative" stands
for time and date calculations with regard to the current time and
date). There doesn't seem to be a way to use dateless time either
(unless I missed it),
however, it turns out, that one can probably work with this naive
"times" like with deltas (possibly ignoring other units than hours and
minutes in the result):

>>> td = dateutil.relativedelta.relativedelta(hours=9, minutes=45) + 
>>> dateutil.relativedelta.relativedelta(minutes=30)
>>> "%s.%s" % (td.hours, td.minutes)
'10.15'
>>>
Which is probably the simplest and the most robust way, I found sofar.
It likely isn't the expected use case for relativedelta, but it seems
to work ok. (Are there maybe some drawbacks I am missing?)
(Well I just found one possible pitfall , if floats are passed:
>>> td = dateutil.relativedelta.relativedelta(hours=9, minutes=45) + 
>>> dateutil.relativedelta.relativedelta(minutes=30.5)
>>> "%s.%s" % (td.hours, td.minutes)
'10.0.15.5'
, but its beyond my current use case, and the validation can always be added.)


The same would be doable using the built in timedelta too, but there
are no hours and minutes in its output, hence these are to be
converted from the seconds count.

>>> dttd=datetime.timedelta(hours=9, minutes=45) + 
>>> datetime.timedelta(minutes=30)
>>> dttd
datetime.timedelta(0, 36900)
>>> dttd.seconds
36900
>>> s = dttd.seconds
>>> h,s = divmod(s,3600)
>>> m,s = divmod(s,60)
>>> h,m,s
(10, 15, 0)
>>> "%s.%s" % (h, m)
'10.15'
>>>

Any thoughts?
 thanks again,

   vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Thu, Jul 5, 2012 at 11:18 PM, Vlastimil Brom
 wrote:
> Yes, the calculations with seconds since the Unix epoch is very
> convenient for real times, but trying to make it dateless seemed to
> make it more complicated for me.
>
> The expected output for the increments asked by Jason was already
> correctly stated by Devin; i.e.: 12:45 plus 12 hours is 0:45 and 12:45
> minus 13 hours is 23:45.

I'm not familiar with the Python classes (I tend to think in terms of
language-agnostic algorithms first, and specific libraries/modules/etc
second), but if you're working with simple integer seconds, your
datelessness is just modulo arithmetic.

time1 + time2  --> (time1 + time2) % 86400
time1 - time2  --> (time1 + 86400 - time2) % 86400

Or alternatively, bounding afterward:

if time > 86400: time-=86400
if time < 86400: time+=86400

(The "magic number" 86400 is a well-known number, being seconds in a
day. Feel free to replace it with 24*60*60 if it makes you feel
better; I'm pretty sure Python will translate it into a constant at
parse time. Or alternatively, have a module-level constant
SECONDS_IN_A_DAY = 86400, in case that number should ever change.)

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


Re: 2 + 2 = 5

2012-07-05 Thread Hans Mulder
On 5/07/12 07:32:48, Steven D'Aprano wrote:
> On Wed, 04 Jul 2012 23:38:17 -0400, Terry Reedy wrote:
> 
>> If I run the script in 3.3 Idle, I get the same output you got. If I
>> then enter '5-2' interactively, I still get 3. Maybe the constant folder
>> is always on now.
> 
> Yes, I believe constant folding is always on, since Python 2.4 if I 
> remember correctly. Somebody who cares more than me can possibly check 
> the "What's New" documents :)

It's not a difference between 2.4 and 3.3; the difference is between
Idle and the command-line version of the interactive interpreter.

If I type the same code into Idle and the interactive interpreter
(both using 3.3alpha1), I get 3 in Idle and 2 in Terminal.

I don't quite understand why this difference exists.


Confused,

-- HansM

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


Re: simpler increment of time values?

2012-07-05 Thread rurpy
On Wednesday, July 4, 2012 6:29:10 PM UTC-6, Vlastimil Brom wrote:
> Hi all,
> I'd like to ask about the possibilities to do some basic manipulation
> on timestamps - such as incrementing a given time (hour.minute -
> string) by some minutes.
> Very basic notion of "time" is assumed, i.e. dateless,
> timezone-unaware, DST-less etc.
> I first thought, it would be possible to just add a timedelta to a
> time object, but, it doesn't seem to be the case.
> 
> The code I came up with (using time and datetime modules) seems rather
> convoluted and I would like to ask about some possible more
> straightforward alternatives I missed.
> The equivalent function (lacking validation) without the (date)time
> libraries seems simple enough (for this limited and individual task).
> Although it is probably mostly throw-away code, which seems to do what
> I need, I'd be interested in better/more elegant... solutions.
> 
> # # #
> import time
> import datetime
> import re
> 
> print re.sub(r"^0","", (datetime.datetime(*list(time.strptime("8.45",
> "%H.%M"))[:6]) + datetime.timedelta(minutes=30)).strftime("%H.%M"))
> # 9.15
> 
> # # # # # # # # #
> 
> def add_minutes(hour_min_str, separator=".", minutes_to_add=0):
> h, m = [int(s) for s in hour_min_str.split(separator)]
> sum_minutes = h * 60 + m + minutes_to_add
> h, m = divmod(sum_minutes, 60)
> h = h % 24
> return "%s%s%s" % (h, separator, m)
> 
> print add_minutes(hour_min_str="8.45", separator='.', minutes_to_add=30)
> # 9.15
> 
> # # # # # # # # #
> 
> Is it true, that timedelta cannot be used with dateless time values?
> (Is there some other possibility than the current one, where strptime
> actually infers 1. 1. 1900?)
> Is there some simpler way to adapt the incompatible output of strptime
> as the input of datetime?
> Is it possible to get one-digit hours formatted without the leading zero?
> 
> Thanks in advance for any suggestions or remarks;
>regards,
>   Vlastimil Brom

If it's any consolation, I had to add a small constant time 
delta to all the times in a video subtitles file and my code
ended up looking very much like yours.  What should have take
five minutes to write took several hours,

I remain surprised and disappointed that doing something so
simple (read time text into time object, add timedelta, print 
result) was so awkward in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Confusing datetime.datetime

2012-07-05 Thread Damjan
I've been struggling with an app that uses 
Postgresql/Psycopg2/SQLAlchemy  and I've come to this confusing 
behaviour of datetime.datetime.



First of all, the "Seconds since Epoch" timestamps are always in UTC, so 
shouldn't change with timezones. So I'd expect that a round trip of a 
timestamp through datetime.datetime, shouldn't change it.



Now, all is good when I use a naive datetime.datetime


-- TZ=UTC python
>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(1341446400)
>>> dt
datetime.datetime(2012, 7, 5, 0, 0)
>>> dt.strftime('%s')
'1341446400'


-- TZ=Asia/Tokyo python
>>> from datetime import datetime
>>> dt = datetime.fromtimestamp(1341446400)
>>> dt
datetime.datetime(2012, 7, 5, 9, 0)
>>> dt.strftime('%s')
'1341446400'



But when I use an timezone aware datetime.datetime objects, the 
timestamp roundtrip is destroyed. I get 2 different timestamps.
Am I missing something here, I've been reading the datetime 
documentation several times, but I can't understand what is the intended 
behaviour.



-- TZ=UTC python
>>> from datetime import datetime
>>> import pytz
>>> tz = pytz.timezone('Europe/Skopje')
>>> dt = datetime.fromtimestamp(1341446400, tz)
>>> dt
datetime.datetime(2012, 7, 5, 2, 0, tzinfo=CEST+2:00:00 DST>)

>>> dt.strftime('%s')
'1341453600'


-- TZ=Asia/Tokyo python
>>> from datetime import datetime
>>> import pytz
>>> tz = pytz.timezone('Europe/Skopje')
>>> dt = datetime.fromtimestamp(1341446400, tz)
>>> dt
datetime.datetime(2012, 7, 5, 2, 0, tzinfo=CEST+2:00:00 DST>)

>>> dt.strftime('%s')
'1341421200'



Python 2.7.3, pytz 2012c

--
damjan

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


Re: OAuth 2.0 implementation

2012-07-05 Thread Demian Brecht
FWIW, this package has undergone a major overhaul (474 LOC down to much happier 
66) and is available at https://github.com/demianbrecht/sanction. Also 
available from PyPI.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Emile van Sebille

On 7/5/2012 12:22 AM Maurizio Spadaccino said...

Hi all

I'm new to Python but soon after a few days of studying its features I
find it my favourite mean of programming scripts to allow for data
storing and mining. My idea would be to inplement python scripts from
inside an excel sheet that would store and fetch data from a Mysql
database.


Look again at the com interface -- I've created excel commands 
implemented entirely in python this way and it will do everything you're 
looking for.  Just start with some of the examples and extend from there.


See http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

I did this ten years ago so things have likely changed, but the bits of 
the python script that set up com then looked like this:



class fenxUtilities:
_public_methods_ = [ 'FirstPartInsp' ]
_reg_progid_ = "fenxDCom.Util"
_reg_clsid_ = "{3EAD7AB4-2978-4360-8F7D-33FB36E9E146}"
def FirstPartInsp(self,nomDiam, numFlutes, nomOAL, nomLOC):
return EMSpecs(nomDiam, numFlutes, nomOAL, nomLOC).retvals


if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(fenxUtilities)


HTH,

Emile





So i need the script to be launched, say, by pressing a button
in excel and, for instance, retrieve immediately data from the mysql
table. For what I found in the net, it seems there are three ways to
control python from excel:
1) run my python script via shell using the Run command in VBA, which
seems to me the easiest (but maybe slower?) way;
2) creating a COM server, for which I need more training since it doesnt
appear that easy;
3) via Microsoft Script Control, for which I saw some example around
where It looks like I can 'simulate' a python shell via the
'executeStatement' command.

What would you suggest would be the more performing way to achieve my
goals as described above?

Thanks for you help
Maurizio


--
Maurizio


www.mauriziospadaccino.com 
---
If you can avoid printing this e-mail, you are only doing good for our
planet.





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


Re: Discussion on some Code Issues

2012-07-05 Thread subhabangalore
Dear Peter,
That is a nice one. I am thinking if I can write "for lines in f" sort of code 
that is easy but then how to find out the slices then, btw do you know in any 
case may I convert the index position of file to the list position provided I 
am writing the list for the same file we are reading. 

Best Regards,
Subhabrata. 

On Thursday, July 5, 2012 1:00:12 PM UTC+5:30, Peter Otten wrote:
> [email protected] wrote:
> 
> > On Thursday, July 5, 2012 4:51:46 AM UTC+5:30, (unknown) wrote:
> >> Dear Group,
> >> 
> >> I am Sri Subhabrata Banerjee trying to write from Gurgaon, India to
> >> discuss some coding issues. If any one of this learned room can shower
> >> some light I would be helpful enough.
> >> 
> >> I got to code a bunch of documents  which are combined together.
> >> Like,
> >> 
> >> 1)A Mumbai-bound aircraft with 99 passengers on board was struck by
> >> lightning on Tuesday evening that led to complete communication failure
> >> in mid-air and forced the pilot to make an emergency landing. 2) The
> >> discovery of a new sub-atomic particle that is key to understanding how
> >> the universe is built has an intrinsic Indian connection. 3) A bomb
> >> explosion outside a shopping mall here on Tuesday left no one injured,
> >> but Nigerian authorities put security agencies on high alert fearing more
> >> such attacks in the city.
> >> 
> >> The task is to separate the documents on the fly and to parse each of the
> >> documents with a definite set of rules.
> >> 
> >> Now, the way I am processing is:
> >> I am clubbing all the documents together, as,
> >> 
> >> A Mumbai-bound aircraft with 99 passengers on board was struck by
> >> lightning on Tuesday evening that led to complete communication failure
> >> in mid-air and forced the pilot to make an emergency landing.The
> >> discovery of a new sub-atomic particle that is key to understanding how
> >> the universe is built has an intrinsic Indian connection. A bomb
> >> explosion outside a shopping mall here on Tuesday left no one injured,
> >> but Nigerian authorities put security agencies on high alert fearing more
> >> such attacks in the city.
> >> 
> >> But they are separated by a tag set, like,
> >> A Mumbai-bound aircraft with 99 passengers on board was struck by
> >> lightning on Tuesday evening that led to complete communication failure
> >> in mid-air and forced the pilot to make an emergency landing.$ The
> >> discovery of a new sub-atomic particle that is key to understanding how
> >> the universe is built has an intrinsic Indian connection.$ A bomb
> >> explosion outside a shopping mall here on Tuesday left no one injured,
> >> but Nigerian authorities put security agencies on high alert fearing more
> >> such attacks in the city.
> >> 
> >> To detect the document boundaries, I am splitting them into a bag of
> >> words and using a simple for loop as, for i in range(len(bag_words)):
> >> if bag_words[i]=="$":
> >> print (bag_words[i],i)
> >> 
> >> There is no issue. I am segmenting it nicely. I am using annotated corpus
> >> so applying parse rules.
> >> 
> >> The confusion comes next,
> >> 
> >> As per my problem statement the size of the file (of documents combined
> >> together) won’t increase on the fly. So, just to support all kinds of
> >> combinations I am appending in a list the “I” values, taking its length,
> >> and using slice. Works perfect. Question is, is there a smarter way to
> >> achieve this, and a curious question if the documents are on the fly with
> >> no preprocessed tag set like “$” how may I do it? From a bunch without
> >> EOF isn’t it a classification problem?
> >> 
> >> There is no question on parsing it seems I am achieving it independent of
> >> length of the document.
> >> 
> >> If any one in the group can suggest how I am dealing with the problem and
> >> which portions should be improved and how?
> >> 
> >> Thanking You in Advance,
> >> 
> >> Best Regards,
> >> Subhabrata Banerjee.
> > 
> > 
> > Hi Steven, It is nice to see your post. They are nice and I learnt so many
> > things from you. "I" is for index of the loop. Now my clarification I
> > thought to do "import os" and process files in a loop but that is not my
> > problem statement. I have to make a big lump of text and detect one chunk.
> > Looping over the line number of file I am not using because I may not be
> > able to take the slices-this I need. I thought to give re.findall a try
> > but that is not giving me the slices. Slice spreads here. The power issue
> > of string! I would definitely give it a try. Happy Day Ahead Regards,
> > Subhabrata Banerjee.
> 
> Then use re.finditer():
> 
> start = 0
> for match in re.finditer(r"\$", data):
> end = match.start()
> print(start, end)
> print(data[start:end])
> start = match.end()
> 
> This will omit the last text. The simplest fix is to put another "$" 
> separator at the end of your data.

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


Re: Using a CMS for small site?

2012-07-05 Thread Alex Clark

On 7/5/12 4:27 AM, Dieter Maurer wrote:

Gilles  writes:


The site is just...
- a few web pages that include text (in four languages) and pictures
displayed in a Flash slide show
- a calendar to show availability
- a form to send e-mail with anti-SPAM support
- (ASAP) online payment

Out of curiosity, are there CMS/frameworks in Python that can do this?
Django? Other?


There is also "Plone" ("http://plone.org";) -- easy to set up.

You likely need third party extensions for the "anti-SPAM" support
and the onlie payment.

Unfortunately, "Plone" is quite resource hungry -- especially it wants
quite some memory.



Actually with Plone 4 (and 4.2 in particular) that is becoming less 
true, I recently shrunk http://aclark.net to a 256MB vhost on rackspace 
cloud.








--
Alex Clark · http://pythonpackages.com



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


Re: Creating an instance when the argument is already an instance.

2012-07-05 Thread Hans Mulder
On 5/07/12 12:47:52, Chris Angelico wrote:
> On Thu, Jul 5, 2012 at 8:29 PM, Olive  wrote:
>> I am creating a new class: package (to analyse the packages database in
>> some linux distros). I have created a class package such that
>> package("string") give me an instance of package if string is a correct
>> representation of a package. I would like that if pack is already an
>> instance of package then package(pack) just return pack.
> 
> One way would be to make the name "package" actually a wrapper
> function, not the class itself:
> 
 class _package:
>   def __init__(self,arg):
>   # blah blah
>   self.asdf=arg
> 
 def package(arg):
>   if isinstance(arg,_package): return arg
>   return _package(arg)
> 
 a=package("Test")
 b=package(a)
 a is b
> True
> 
> The leading underscore is a common convention meaning "private
> implementation detail".

I think using a factory function is the right idea, but the
code above doesn't solve the problem as stated.  Olive needs
a factory function that takes a string argument and returns
a _package object.

Maybe:

class _package:
def __init__(self, name):
self.name = name
 # etc.

packages = dict()

def package(name):
if name not in packages:
packages[name] = _package(name)
return packages[name]


Hope this helps,

-- HansM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Mark Shroyer
On Thu, Jul 05, 2012 at 03:22:01AM -0400, Maurizio Spadaccino wrote:
> Hi all
> 
> I'm new to Python but soon after a few days of studying its features I
> find it my favourite mean of programming scripts to allow for data
> storing and mining. My idea would be to inplement python scripts from
> inside an excel sheet that would store and fetch data from a Mysql
> database. So i need the script to be launched, say, by pressing a
> button in excel and, for instance, retrieve immediately data from the
> mysql table. For what I found in the net, it seems there are three
> ways to control python from excel: 1) run my python script via shell
> using the Run command in VBA, which seems to me the easiest (but maybe
> slower?) way; 2) creating a COM server, for which I need more training
> since it doesnt appear that easy; 3) via Microsoft Script Control, for
> which I saw some example around where It looks like I can 'simulate' a
> python shell via the 'executeStatement' command.
> 
> What would you suggest would be the more performing way to achieve my
> goals as described above?

One thing you could check out is IronSpread: http://www.ironspread.com/

(Despite the name, it's based on CPython rather than IronPython.)

It presents a simplified interface for communicating with Excel compared
to what you get with win32com / plain OLE automation.  I'm a little hazy
on whether the Python scripts created with this plugin are saved within
the Excel file or somewhere on the local system, though...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Laszlo Nagy

On 2012-07-04 21:37, Paul Rubin wrote:

I just came across this (https://gist.github.com/1208215):

 import sys
 import ctypes
 pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
 five = ctypes.cast(id(5), pyint_p)
 print(2 + 2 == 5) # False
 five.contents[five.contents[:].index(5)] = 4
 print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)

Heh.  The author is apparently anonymous, I guess for good reason.


>>> five.contents[five.contents[:].index(5)] = 4
>>> 5
4
>>> 5 is 4
True

But this I don't understand:

>>> 5+0
4
>>> 5+1
4
>>> 5+2
6


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


Re: OAuth 2.0 implementation

2012-07-05 Thread Alec Taylor
On Fri, Jul 6, 2012 at 12:06 AM, Demian Brecht  wrote:
> FWIW, this package has undergone a major overhaul (474 LOC down to much 
> happier 66) and is available at https://github.com/demianbrecht/sanction. 
> Also available from PyPI.

Thanks for this, I've now shared it on my favourite web-framework
(which unfortunately recommends Janrain) as an alternative:
https://groups.google.com/forum/#!topic/web2py/XjUEewfP5Xg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread MRAB

On 05/07/2012 15:34, Laszlo Nagy wrote:

On 2012-07-04 21:37, Paul Rubin wrote:

I just came across this (https://gist.github.com/1208215):

 import sys
 import ctypes
 pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
 five = ctypes.cast(id(5), pyint_p)
 print(2 + 2 == 5) # False
 five.contents[five.contents[:].index(5)] = 4
 print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)

Heh.  The author is apparently anonymous, I guess for good reason.


  >>> five.contents[five.contents[:].index(5)] = 4
  >>> 5
4
  >>> 5 is 4
True

But this I don't understand:

  >>> 5+0
4


5 is interned as 4, 0 is interned as 0, 4+0 is calculated as 4 and then
interned as 4.


  >>> 5+1
4


5 is interned as 4, 1 is interned as 1, 4+1 is calculated as 5 and then
interned as 4.


  >>> 5+2
6


5 is interned as 4, 2 is interned as 2, 4+2 is calculated as 6 and then
interned and 6.

Simple really! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 23:56:37 +1000, Chris Angelico wrote:

> (The "magic number" 86400 is a well-known number, being seconds in a
> day. 

Does that include leap seconds?


> Feel free to replace it with 24*60*60 if it makes you feel better;
> I'm pretty sure Python will translate it into a constant at parse time.
> Or alternatively, have a module-level constant SECONDS_IN_A_DAY = 86400,
> in case that number should ever change.)

"In case"?

The number of seconds in a day (true solar day) varies by between 13 and 
30 seconds depending on the time of the year and the position of the sun.

The mean solar day fluctuates randomly by about 5ms due to friction 
between the core and the mantle; it is also systematically slowing due to 
tidal friction. The 2004 Indian Ocean earthquake reduced the length of a 
day by about 3ms; the 2011 Japan earthquake slowed it down by about 2ms. 
Apart from these random changes, there are systematic changes of the 
order of 1ms per year, so in a mere thousand years, the length of the 
mean solar day will be about a second longer.

Imagine how much extra work we'll be able to get done!

The stellar day (Earth's rotational period relative to the distant stars) 
is slightly more than 86164.098 seconds; the sidereal day is slightly 
more than 86164.090 seconds. Both are approximately 3 minutes 56 seconds 
shorter than the mean solar day.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Devin Jeanpierre
On Thu, Jul 5, 2012 at 10:34 AM, Laszlo Nagy  wrote:
 5+1
> 4

4 + 1 is 5 is 4.

(e.g. try 2+3 as well).

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help: PYMALLOC_DBUG and PIL

2012-07-05 Thread Roman Putilov
2012/7/5 tom z 

> Hi~ all,
> I encounter a odd problem, when i compile Python with PYMALLOC_DEBUG, the
> PIL module can't work fine, it always make core-dump like this
>
> [Switching to Thread 182897301792 (LWP 16102)]
> 0x004df264 in PyObject_Malloc (nbytes=64) at Objects/obmalloc.c:804
> 804 if ((pool->freeblock = *(block **)bp) != NULL) {
> Current language:  auto; currently c
> (gdb) bt
> #0  0x004df264 in PyObject_Malloc (nbytes=64) at
> Objects/obmalloc.c:804
> #1  0x004dfb97 in _PyObject_DebugMallocApi (id=109 'm', nbytes=32)
> at Objects/obmalloc.c:1461
> #2  0x004dfd22 in _PyObject_DebugReallocApi (api=109 'm', p=0x0,
> nbytes=32) at Objects/obmalloc.c:1523
> #3  0x004dfac0 in _PyMem_DebugRealloc (p=0x0, nbytes=32) at
> Objects/obmalloc.c:1416
> #4  0x004c68d9 in list_resize (self=0x2a988409b8, newsize=1) at
> Objects/listobject.c:62
> #5  0x004c6f63 in app1 (self=0x2a988409b8, v=0x2a958cea90) at
> Objects/listobject.c:277
> #6  0x004c6fdd in PyList_Append (op=0x2a988409b8,
> newitem=0x2a958cea90) at Objects/listobject.c:289
> #7  0x00558c7f in symtable_add_def (st=0x2a99a4ca68,
> name=0x2a958cea90, flag=4) at Python/symtable.c:910
> #8  0x0055a953 in symtable_visit_params (st=0x2a99a4ca68,
> args=0x924380, toplevel=1) at Python/symtable.c:1318
> #9  0x0055aaa7 in symtable_visit_arguments (st=0x2a99a4ca68,
> a=0x9243c8) at Python/symtable.c:1365
> #10 0x00558f3d in symtable_visit_stmt (st=0x2a99a4ca68,
> s=0x9244d0) at Python/symtable.c:1012
> #11 0x0055919e in symtable_visit_stmt (st=0x2a99a4ca68,
> s=0x924500) at Python/symtable.c:1029
> #12 0x005574d7 in PySymtable_Build (mod=0x931798,
> filename=0x7fbfffa2c0
> "../lib/python2.7/site-packages/PIL/BmpImagePlugin.py",
> future=0x2a9883aae0) at Python/symtable.c:240
> #13 0x00531f14 in PyAST_Compile (mod=0x931798,
> filename=0x7fbfffa2c0
> "../lib/python2.7/site-packages/PIL/BmpImagePlugin.py", flags=0x7fbfff9020,
> arena=0x8eedd0) at Python/compile.c:282
> #14 0x00545967 in parse_source_module (
> pathname=0x7fbfffa2c0
> "../lib/python2.7/site-packages/PIL/BmpImagePlugin.py", fp=0x91a060) at
> Python/import.c:843
> #15 0x00545e75 in load_source_module (name=0x7fbfffb3e0
> "PIL.BmpImagePlugin",
> pathname=0x7fbfffa2c0
> "../lib/python2.7/site-packages/PIL/BmpImagePlugin.py", fp=0x91a060) at
> Python/import.c:1027
>
> i've no idea about this, someone could get me help~
>
> ---
> thanks a lot
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
PYMALLOC_DEBUG requires WITH_PYMALLOC. It's enabled?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Rick Johnson
On Jul 5, 10:19 am, Steven D'Aprano  wrote:
> The number of seconds in a day (true solar day) varies by between 13 and
> 30 seconds depending on the time of the year and the position of the sun.

Indeed. Which proves that a time keeping system based on the haphazard
movements of celestial bodies is antiquated technology. Talk about job
security!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 1:19 AM, Steven D'Aprano
 wrote:
> On Thu, 05 Jul 2012 23:56:37 +1000, Chris Angelico wrote:
>
>> (The "magic number" 86400 is a well-known number, being seconds in a
>> day.
>
> Does that include leap seconds?

No it doesn't, hence...

>> Feel free to replace it with 24*60*60 if it makes you feel better;
>> I'm pretty sure Python will translate it into a constant at parse time.
>> Or alternatively, have a module-level constant SECONDS_IN_A_DAY = 86400,
>> in case that number should ever change.)
>
> "In case"?

... this not being entirely tongue-in-cheek. I believe the UTC spec
allows for a progressive increase in the number of leap seconds, from
the current "maybe one a year" at either Dec or June to having them
multiple months a year, to having a leap second optionally every day,
to having one a day and multiple leap seconds on some days. But it's
not until we're actually in that last state (or close to it) that I
would consider changing SECONDS_IN_A_DAY to 86401. Leap seconds are
largely outside the concept of "dateless time".

> The number of seconds in a day (true solar day) varies ...
> it is also systematically slowing due to tidal friction.
> ... in a mere thousand years, the length of the
> mean solar day will be about a second longer.

Yes. It's rather more likely to be an issue than, say, "PI = 3.14159"
needing to change, but you do still have to consider what your
definition of time is. If you're actually counting real
time-since-epoch, then you need to either include leap seconds in your
count (like TAI does) or ignore them (like Unix time does - divide
Unix time by 86400 and you get the number of days since 1970, but a
second's worth of Unix times "happen twice" when a positive leap
second occurs). However, I think it would only surprise people if:

23:30 + 03:45 = 03:14:59

and they'd think it was an easter egg for displaying one of a geek's
favorite numbers.

> Imagine how much extra work we'll be able to get done!

Oh, I reckon most people will waste it on sleep...

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


Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 1:39 AM, Rick Johnson
 wrote:
> On Jul 5, 10:19 am, Steven D'Aprano  [email protected]> wrote:
>> The number of seconds in a day (true solar day) varies by between 13 and
>> 30 seconds depending on the time of the year and the position of the sun.
>
> Indeed. Which proves that a time keeping system based on the haphazard
> movements of celestial bodies is antiquated technology. Talk about job
> security!

The current *time keeping system* is based atomic clocks. It's only
when you want to display this thing called "civil time" (so-called
because it causes very uncivil arguments) that you concern yourself
with astronomy, base 60, base 24, and other constructs.

Now, if you want to argue about a poor choice of standard, look at
so-called "Internet Time" that a Swiss watch company invented, which
divides a day into 1000 beats. Why use the day as your basis and make
it hard to convert to SI units reliably?

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


Re: how to interact with Windows cmd?

2012-07-05 Thread Nobody
On Wed, 04 Jul 2012 20:10:47 -0700, self.python wrote:

> 2. after this, I typed like "cd .." but I/O is already closed so I
> can't do another things..

Don't use .communicate() if you want to keep the child process alive.
Write to p.stdin and read p.stdout and p.stderr.

In general, you'll need to use a separate thread for each stream,
otherwise you risk deadlock. Look at the source code for the
.communicate() method for an example.

Also, unless you specifically need stdout and stderr to be separated, use
"stderr=subprocess.STDOUT". The problem with separating them is that
there's no way to determine the order in which data was written, so
there's no way to reconstruct the output as it would have appeared on the
console.

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


Re: 2 + 2 = 5

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 15:57:53 +0200, Hans Mulder wrote:

> On 5/07/12 07:32:48, Steven D'Aprano wrote:
>> On Wed, 04 Jul 2012 23:38:17 -0400, Terry Reedy wrote:
>> 
>>> If I run the script in 3.3 Idle, I get the same output you got. If I
>>> then enter '5-2' interactively, I still get 3. Maybe the constant
>>> folder is always on now.
>> 
>> Yes, I believe constant folding is always on, since Python 2.4 if I
>> remember correctly. Somebody who cares more than me can possibly check
>> the "What's New" documents :)
> 
> It's not a difference between 2.4 and 3.3; the difference is between
> Idle and the command-line version of the interactive interpreter.
> 
> If I type the same code into Idle and the interactive interpreter (both
> using 3.3alpha1), I get 3 in Idle and 2 in Terminal.
> 
> I don't quite understand why this difference exists.

This difference exists because you are mucking about with implementation 
details of Python, changing things which are not guaranteed by the 
language, in ways that you are not supposed to change them. Since 
changing the value of the int 2 into that of 3 is not supported, you can 
hardly expect consistent behaviour. You're lucky that you don't get a 
segfault. (In fact, if you keep playing around with it, you likely will 
get a segfault.)

Idle does many things differently to the basic Python interpreter. This 
should not surprise you. You should be surprised if it *does* work the 
same in Idle and the basic Python interpreter.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Alexander Blinne
On 05.07.2012 16:34, Laszlo Nagy wrote:
 five.contents[five.contents[:].index(5)] = 4
 5
> 4
 5 is 4
> True

That's surprising, because even after changing 5 to 4 both objects still
have different id()s (tested on Py2.7), so 5 is 4 /should/ still be
False (But isn't on my 2.7). But that's some implementation detail we
are not supposed to play with ;)

> But this I don't understand:
> 
 5+0
> 4
 5+1
> 4
 5+2
> 6

That's easy:

5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4.
5+1 is actually 4+1, which is 5, but 5 is again 4.
5+2 is 4+2 which is 6.

Greetings

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


Re: simpler increment of time values?

2012-07-05 Thread Ian Kelly
On Thu, Jul 5, 2012 at 7:56 AM, Chris Angelico  wrote:
> I'm not familiar with the Python classes (I tend to think in terms of
> language-agnostic algorithms first, and specific libraries/modules/etc
> second), but if you're working with simple integer seconds, your
> datelessness is just modulo arithmetic.
>
> time1 + time2  --> (time1 + time2) % 86400
> time1 - time2  --> (time1 + 86400 - time2) % 86400

The "+ 86400" is redundant; you'll get the same answer with or without
it.  There is nothing to fear from going negative when doing modulo
arithmetic, because unlike C, Python actually has well-defined
semantics regarding modulo division of negative numbers.

>>> (13382 + 86400 - 42597) % 86400
57185
>>> (13382 - 42597) % 86400
57185

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread Chris Angelico
On Fri, Jul 6, 2012 at 3:06 AM, Ian Kelly  wrote:
> The "+ 86400" is redundant; you'll get the same answer with or without
> it.  There is nothing to fear from going negative when doing modulo
> arithmetic, because unlike C, Python actually has well-defined
> semantics regarding modulo division of negative numbers.
>
 (13382 + 86400 - 42597) % 86400
> 57185
 (13382 - 42597) % 86400
> 57185

Ah good. There's a lot of languages like that these days, but I've
gotten so into the habit of not depending on it that I just
automatically add N first. It's redundant but insignificant.

So it's even easier than I said. And bonus lesson for the day: Try
things in the interactive interpreter before you post. :)

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


Re: simpler increment of time values?

2012-07-05 Thread John Nagle

On 7/4/2012 5:29 PM, Vlastimil Brom wrote:

Hi all,
I'd like to ask about the possibilities to do some basic manipulation
on timestamps - such as incrementing a given time (hour.minute -
string) by some minutes.
Very basic notion of "time" is assumed, i.e. dateless,
timezone-unaware, DST-less etc.
I first thought, it would be possible to just add a timedelta to a
time object, but, it doesn't seem to be the case.


   That's correct.  A datetime.time object is a time within a day.
A datetime.date object is a date without a time.  A datetime.datetime
object contains both.

  You can add a datetime.timedelta object to a datetime.datetime
object, which will yield a datetime.datetime object.

  You can also call time.time(), and get the number of seconds
since the epoch (usually 1970-01-01 00:00:00 UTC). That's just
a number, and you can do arithmetic on that.

  Adding a datetime.time to a datetime.timedelta isn't that
useful.  It would have to return a value error if the result
crossed a day boundary.

John Nagle


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


Re: Question about weakref

2012-07-05 Thread Dieter Maurer
Frank Millman  writes:
> On 05/07/2012 10:46, Dieter Maurer wrote:
>> Instead of the low level "weakref", you might use a "WeakKeyDictionary".
>>
>
> Thanks, Dieter. I could do that.
>
> In fact, a WeakSet suits my purposes better. I tested it with my
> original example, and it works correctly. It also saves me the step of
> deleting the weak reference once the original object is deleted, as it
> seems to do that automatically.
>
> I just need to double-check that I would never have the same
> listener-object try to register itself with the publisher twice, as
> that would obviously fail with a Set, as it would with a Dict.

No need to verify. A secondary subscription would be effectively
a no-operation -- with both a "set" and a "dict".


> I would still like to know why weakref.proxy raised an exception. I
> have re-read the manual several times, and googled for similar
> problems, but am none the wiser.

In fact, it is documented. Accessing a proxy will raise an exception
when the proxied object no longer exists.

What you can ask is why your proxy has been accessed after the
object was deleted. The documentation is specific: during the callback,
the object should still exist. Thus, apparently, one of your proxies
outlived an event that should have deleted it (probably a hole in
your logic).

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


Re: OAuth 2.0 implementation

2012-07-05 Thread Demian Brecht
On Thursday, 5 July 2012 08:19:41 UTC-7, Alec Taylor  wrote:
> On Fri, Jul 6, 2012 at 12:06 AM, Demian Brecht  wrote:
> > FWIW, this package has undergone a major overhaul (474 LOC down to much 
> > happier 66) and is available at https://github.com/demianbrecht/sanction. 
> > Also available from PyPI.
> 
> Thanks for this, I've now shared it on my favourite web-framework
> (which unfortunately recommends Janrain) as an alternative:
> https://groups.google.com/forum/#!topic/web2py/XjUEewfP5Xg

No worries, thanks for the interest :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: simpler increment of time values?

2012-07-05 Thread rurpy
On Thursday, July 5, 2012 11:34:16 AM UTC-6, John Nagle wrote:
>[...]
>You can also call time.time(), and get the number of seconds
> since the epoch (usually 1970-01-01 00:00:00 UTC). That's just
> a number, and you can do arithmetic on that.
> 
>Adding a datetime.time to a datetime.timedelta isn't that
> useful. 

It certainly is useful and I gave an obvious and real-
world example in my previous post.

> It would have to return a value error if the result
> crossed a day boundary.

Why?  When I turn the adjustment knob on my analog
clock it crosses the day boundary from 23:59 to 0:00
with no problem whatsoever.  Why is Python unable
to do what billions of clocks do? 

Instead I have to convert everything to seconds and
do the same math I would have done in fortran in 1980.
Phew.

Another example of Pythonic "purity beats practicality"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Hans Mulder
On 5/07/12 19:03:57, Alexander Blinne wrote:
> On 05.07.2012 16:34, Laszlo Nagy wrote:
> five.contents[five.contents[:].index(5)] = 4
> 5
>> 4
> 5 is 4
>> True

> That's surprising, because even after changing 5 to 4 both objects still
> have different id()s (tested on Py2.7), so 5 is 4 /should/ still be
> False (But isn't on my 2.7). But that's some implementation detail we
> are not supposed to play with ;)

On my 2.7, id(5) gives the same value as id(4) == id(2+2), but id(2+3)
has a different value.  The 'is' operator is consistent with 'id':

>>> 4 is 5
True
>>> 2+2 is 2+3
False

This is when using the interactive interpreter; it may be different
in Idle.

-- HansM


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


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Terry Reedy

On 7/5/2012 5:12 AM, Thomas Jollans wrote:

On 07/05/2012 09:26 AM, Karim wrote:

Look at PyUNO from OpenOffice very large API:
http://www.openoffice.org/api/docs

I use to create all my documention (Excell, Writer, etc...) on this API.


Note that this API is for OpenOffice, not Microsoft Excel. However, as
you probably know, you can open most Excel files in OpenOffice's Calc.

I urge you to consider LibreOffice, a fork of OpenOffice that is now
broadly considered its successor. Its API can also be used in Python
http://api.libreoffice.org/


Can you explain or point to a document that explains how to actually do 
that? (use the LibreOffice api from Python?)


The only mention of Python on that page is under examples. (and there is 
no mention of python in the installation guide, even as an option, nor 
in the development tools doc, ).


On the example page, there is only one example and unlike all the other 
sections, no 'Additional information' linking to a 'Python Language 
binding'.


In toolpanel.py of the example, there is

import uno
import unohelper

from com.sun.star.ui import XUIElementFactory
from com.sun.star.ui import XUIElement
from com.sun.star.ui.UIElementType import TOOLPANEL as unoTOOLPANEL
from com.sun.star.ui import XToolPanel

but where are the python-importable modules and com package and their 
docs and how does one get them? There are not in the example directory.


The IDL reference only covers the com.sun.star stuff.

---
Looking with Google, I see that some linux distros include 
LibreOffice-PyUno in thier package managers. Not helpful for Windows.


The LibreOffice installation includes a python2.6.1 installation under 
LO.../program/ with pyuno pre-installed. No doc that I could see. 
However, when running it


>>> import com.sun.star.ui
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named com.sun.star.ui

Oh, there is a trick to it
>>> import uno
>>> import unohelper
>>> import com.sun.star.ui
Traceback (most recent call last):
  File "", line 1, in 
  File "uno.py", line 263, in _uno_import
return _g_delegatee( name, *optargs, **kwargs )
ImportError: No module named com.sun.star.ui
>>> from com.sun.star.ui import XToolPanel

So import uno and unohelper and one can import objects from the 
non-existent com.sun.star.ui module. Still, a lot more is needed to 
understand even the example.


--
Terry Jan Reedy



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


Re: Re: 2 + 2 = 5

2012-07-05 Thread Evan Driscoll

On 01/-10/-28163 01:59 PM, Alexander Blinne wrote:

5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4.
5+1 is actually 4+1, which is 5, but 5 is again 4.
5+2 is 4+2 which is 6.


Now all I can think is "Hoory for new math, new-hoo-hoo math" :-)

Evan
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Rhodri James
On Wed, 04 Jul 2012 20:37:25 +0100, Paul Rubin   
wrote:



I just came across this (https://gist.github.com/1208215):

import sys
import ctypes
pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
five = ctypes.cast(id(5), pyint_p)
print(2 + 2 == 5) # False
five.contents[five.contents[:].index(5)] = 4
print(2 + 2 == 5) # True (must be sufficiently large values of 2  
there...)


Heh.  The author is apparently anonymous, I guess for good reason.


Someone's been writing FORTRAN again :-)

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Andrew Cooper
On 05/07/2012 22:46, Evan Driscoll wrote:
> On 01/-10/-28163 01:59 PM, Alexander Blinne wrote:
>> 5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4.
>> 5+1 is actually 4+1, which is 5, but 5 is again 4.
>> 5+2 is 4+2 which is 6.
> 
> Now all I can think is "Hoory for new math, new-hoo-hoo math" :-)
> 
> Evan

It wont do you a bit of good to read new math!

(My mind was on exactly the same track)

~Andrew

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


Re: Confusing datetime.datetime

2012-07-05 Thread Damjan

On 05.07.2012 16:10, Damjan wrote:

I've been struggling with an app that uses
Postgresql/Psycopg2/SQLAlchemy  and I've come to this confusing
behaviour of datetime.datetime.



Also this:

#! /usr/bin/python2
# retardations in python's datetime

import pytz
TZ = pytz.timezone('Europe/Skopje')

from datetime import datetime

x1 = datetime.now(tz=TZ)
x2 = datetime(x1.year, x1.month, x1.day, tzinfo=TZ)

assert x1.tzinfo == x2.tzinfo


WHY does the assert throw an error???

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


Re: Confusing datetime.datetime

2012-07-05 Thread Steven D'Aprano
On Fri, 06 Jul 2012 00:55:48 +0200, Damjan wrote:

> Also this:
> 
> #! /usr/bin/python2
> # retardations in python's datetime
> 
> import pytz
> TZ = pytz.timezone('Europe/Skopje')
>
> from datetime import datetime
> 
> x1 = datetime.now(tz=TZ)
> x2 = datetime(x1.year, x1.month, x1.day, tzinfo=TZ)
> 
> assert x1.tzinfo == x2.tzinfo
> 
> 
> WHY does the assert throw an error???

I don't have pytz, so I can't test your exact code. But using my own time 
zone class, it seems to work fine in Python 2.5, 2.6 and 2.7:

from datetime import datetime, timedelta, tzinfo
ZERO = timedelta(0)
HOUR = timedelta(hours=1)

class UTC(tzinfo):
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO

utc = UTC()
t1 = datetime.now(tz=utc)
t2 = datetime(t1.year, t1.month, t1.day, tzinfo=utc)
assert t1.tzinfo == t2.tzinfo


No assertion error at all.

This makes me think that the "retardation" as you put it is not in 
Python's datetime module at all, but in pytz.

What does TZ == TZ give? If it returns False, I recommend you report it 
as a bug against the pytz module.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 2 + 2 = 5

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 16:46:48 -0500, Evan Driscoll wrote:

> On 01/-10/-28163 01:59 PM, Alexander Blinne wrote:
>> 5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4. 5+1 is actually
>> 4+1, which is 5, but 5 is again 4. 5+2 is 4+2 which is 6.
> 
> Now all I can think is "Hoory for new math, new-hoo-hoo math" :-)

+1 QOTW 



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confusing datetime.datetime

2012-07-05 Thread Damjan

from datetime import datetime, timedelta, tzinfo
ZERO = timedelta(0)
HOUR = timedelta(hours=1)

class UTC(tzinfo):
 def utcoffset(self, dt):
 return ZERO
 def tzname(self, dt):
 return "UTC"
 def dst(self, dt):
 return ZERO

utc = UTC()
t1 = datetime.now(tz=utc)
t2 = datetime(t1.year, t1.month, t1.day, tzinfo=utc)
assert t1.tzinfo == t2.tzinfo


No assertion error at all.

This makes me think that the "retardation" as you put it is not in
Python's datetime module at all, but in pytz.

What does TZ == TZ give? If it returns False, I recommend you report it
as a bug against the pytz module.


It returns True, so it seems to be changed in the datetime object??

I tried both 2.7 and 3.2

--
damjan

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


Apology for OT posts (was: code review)

2012-07-05 Thread John O'Hagan
On Tue, 03 Jul 2012 23:39:20 -0600
"Littlefield, Tyler"  wrote:

> On 7/3/2012 10:55 PM, Simon Cropper wrote:
> > Some questions to Tyler Littlefield, who started this thread.
> >
> > Q1 -- Did you get any constructive feedback on your code?
> 
> I did get some, which I appreciated. someone mentioned using PyLint. 
>  From reading, I found it was really really pedantic, so I used PyFlakes 
> instead.
> >
> > Q2 -- Did you feel that the process of submitting your code for review 
> > met your expectation?
> 
> There wasn't much more to review, so yes. The info I got was helpful and 
> farther than it was before I started.
> 
> > Q3 -- Would you recommend others doing this either on this forum or 
> > other fora?
> >
> > It appears to me - third party watching the ongoing dialog - that the 
> > tread has gone right off topic (some time ago) and someone should 
> > really start a new thread under a new title/subject. Most of what I 
> > have read does not appear to be discussing your code or how you could 
> > improve your code.
> >
> I basically just stopped after a while. It got into a my language is 
> better than your language, so I didn't see much constructive info. I've 
> started reading from the bottom though, where it looks like it's back, 
> and I do appreciate the rest of the info given, as well. Thanks again 
> for the feedback.
> 

As one of the perpetrators, I did apologise for being OT within the body of my
replies to OT posts, but I see the irony. I guess I just thought somebody else
would do it eventually. I hereby apologise for not taking the correct action,
and vow to do so in future: to change the subject line regardless of who
initially went OT, starting now.

Regards,
--
John

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


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Karim

Le 05/07/2012 23:20, Terry Reedy a écrit :

On 7/5/2012 5:12 AM, Thomas Jollans wrote:

On 07/05/2012 09:26 AM, Karim wrote:

Look at PyUNO from OpenOffice very large API:
http://www.openoffice.org/api/docs

I use to create all my documention (Excell, Writer, etc...) on this 
API.


Note that this API is for OpenOffice, not Microsoft Excel. However, as
you probably know, you can open most Excel files in OpenOffice's Calc.

I urge you to consider LibreOffice, a fork of OpenOffice that is now
broadly considered its successor. Its API can also be used in Python
http://api.libreoffice.org/


Can you explain or point to a document that explains how to actually 
do that? (use the LibreOffice api from Python?)


The only mention of Python on that page is under examples. (and there 
is no mention of python in the installation guide, even as an option, 
nor in the development tools doc, ).


On the example page, there is only one example and unlike all the 
other sections, no 'Additional information' linking to a 'Python 
Language binding'.


In toolpanel.py of the example, there is

import uno
import unohelper

from com.sun.star.ui import XUIElementFactory
from com.sun.star.ui import XUIElement
from com.sun.star.ui.UIElementType import TOOLPANEL as unoTOOLPANEL
from com.sun.star.ui import XToolPanel

but where are the python-importable modules and com package and their 
docs and how does one get them? There are not in the example directory.


The IDL reference only covers the com.sun.star stuff.

---
Looking with Google, I see that some linux distros include 
LibreOffice-PyUno in thier package managers. Not helpful for Windows.


The LibreOffice installation includes a python2.6.1 installation under 
LO.../program/ with pyuno pre-installed. No doc that I could see. 
However, when running it


>>> import com.sun.star.ui
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named com.sun.star.ui

Oh, there is a trick to it
>>> import uno
>>> import unohelper
>>> import com.sun.star.ui
Traceback (most recent call last):
  File "", line 1, in 
  File "uno.py", line 263, in _uno_import
return _g_delegatee( name, *optargs, **kwargs )
ImportError: No module named com.sun.star.ui
>>> from com.sun.star.ui import XToolPanel

So import uno and unohelper and one can import objects from the 
non-existent com.sun.star.ui module. Still, a lot more is needed to 
understand even the example.




Hi Terry,

You are right it was the warrior path at the beginning to be able to 
produce some code but it is working pretty well.
I add to gather many pieces and examples. In fact, you should take the 
OOo Basic langage example (API) and convert it
(sometimes for python some cases have been changed but mainly you have 
to use ones from original API namely OOo Basic

language). They only did python wrapper around the native API.

An excellent link to derived all code example to python: 
http://www.pitonyak.org/AndrewMacro.sxw.


On latest ubuntu you get no error if you are importing:
import uno
import unohelper

BUT IN OTHER ENVIRONMENT if the version of python is different from the 
one embedded inside OpenOffice (LibreOffice) namely 2.6.X
You are obliged to recompile a OOo version with you python version. BUT 
there is a way to hack this. I did it, just do the following:


LD_LIBRARY_PATH=:/usr/lib/openoffice.org/ure/lib:/usr/lib/openoffice.org/basis3.3/program 


PYTHONPATH=:/usr/lib/openoffice.org3/basis-link/program/
UNO_PATH=/usr/lib/openoffice.org/basis3.3/program
URE_BOOTSTRAP=vnd.sun.star.pathname:/usr/lib/openoffice.org/basis3.3/program/fundamentalbasisrc 



Jut set these env variables according to your OOo installation and you 
will get no error by importing uno and unohelper.



One article to begin with:
 
http://www.linuxjournal.com/content/starting-stopping-and-connecting-openoffice-python

And to finish basic code to get started and some functions I adapted 
from Andrew 's Macro book in python to search string and update a table 
inside writer document (work or MSW ord or SW format):


Start up code
---
import uno
import unohelper

# 1.  Get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# 2.  Create the UnoUrlResolver
resolver = 
localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", 
localContext )

# 3.  Get the central desktop object
smgr  = resolver.resolve( 
"uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" )

# 4.  Declare the ServiceManager
remoteContext = smgr.getPropertyValue( "DefaultContext" )

# 5.  Get the central desktop object
desktop = smgr.createInstanceWithContext( 
"com.sun.star.frame.Desktop",remoteContext)


"""
!!! Document text creation !!!
"""
# open a writer document
#doc = desktop.loadComponentFromURL('private:factory/swriter','_blank', 
0, ())
#document = desktop

Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 11:15:04 -0700, rurpy wrote:

> On Thursday, July 5, 2012 11:34:16 AM UTC-6, John Nagle wrote:
>>[...]
>>You can also call time.time(), and get the number of seconds
>> since the epoch (usually 1970-01-01 00:00:00 UTC). That's just a
>> number, and you can do arithmetic on that.
>> 
>>Adding a datetime.time to a datetime.timedelta isn't that
>> useful.
> 
> It certainly is useful and I gave an obvious and real- world example in
> my previous post.

Agreed.

A timedelta of less than one day magnitude should be usable with time 
objects, and wrap around at midnight. That's a clear and useful extension 
to the current functionality.

I can't see a feature request (rejected or otherwise) on the bug tracker. 
Perhaps you should raise one for Python 3.4. It will have a better chance 
of being accepted if you include a patch, or at least tests.

http://bugs.python.org/



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help: PYMALLOC_DBUG and PIL

2012-07-05 Thread tom z
Thanks  Roman. of course, i use PYMALLOC_DEBUG with PYMALLOC.
-- 
http://mail.python.org/mailman/listinfo/python-list


tkFileDialogs

2012-07-05 Thread brandon harris
I'm wanting to allow users to select hidden directories in windows and it seems 
that using the tkFileDialog.askdirectory() won't allow for that.  It's using 
the tkFileDialog.Directory class which calls an internal command 
'tk_chooseDirectory' .  However the file selector dialogs (askopenfilename, 
asksaveasfilename, etc) has the common windows dialog which supports showing 
hidden folders.  It's using the tkFileDialog.Open class which is calling an 
internal command of 'tk_getOpenFile'.

Can anyone shed light on why these two dialogs are so very different and 
possibly give me a solution to this hidden directory issue.  I have found that 
you can't really use the Open class because it's going to require a file be 
selected, not a directory and the Directory class won't navigate to or have an 
initialdir that is hidden (on windows the %APPDAT% folder is hidden by default)

Windows Example Code.

import tkFileDialog
# Won't start in or allow navigation to APPDATA
test = tkFileDialog.askdirectory(initialdir='%APPDATA%')
# Will start in and navigate to APPDATA
test = tkFileDialog.askopenfile(initialdir='%APPDATA%')

Thanks in advance for any help given!


Brandon L. Harris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apology for OT posts

2012-07-05 Thread Simon Cropper

On 06/07/12 12:06, John O'Hagan wrote:

On Tue, 03 Jul 2012 23:39:20 -0600
"Littlefield, Tyler"  wrote:


On 7/3/2012 10:55 PM, Simon Cropper wrote:

Some questions to Tyler Littlefield, who started this thread.

Q1 -- Did you get any constructive feedback on your code?


I did get some, which I appreciated. someone mentioned using PyLint.
  From reading, I found it was really really pedantic, so I used PyFlakes
instead.


Q2 -- Did you feel that the process of submitting your code for review
met your expectation?


There wasn't much more to review, so yes. The info I got was helpful and
farther than it was before I started.


Q3 -- Would you recommend others doing this either on this forum or
other fora?

It appears to me - third party watching the ongoing dialog - that the
tread has gone right off topic (some time ago) and someone should
really start a new thread under a new title/subject. Most of what I
have read does not appear to be discussing your code or how you could
improve your code.


I basically just stopped after a while. It got into a my language is
better than your language, so I didn't see much constructive info. I've
started reading from the bottom though, where it looks like it's back,
and I do appreciate the rest of the info given, as well. Thanks again
for the feedback.



As one of the perpetrators, I did apologise for being OT within the body of my
replies to OT posts, but I see the irony. I guess I just thought somebody else
would do it eventually. I hereby apologise for not taking the correct action,
and vow to do so in future: to change the subject line regardless of who
initially went OT, starting now.

Regards,
--
John



thanks :)

bet this kills the conservation though...

Simon

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


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Karim

Le 06/07/2012 07:09, Terry Reedy a écrit :


On 7/5/2012 10:30 PM, Karim wrote:


An excellent link to derived all code example to python:
http://www.pitonyak.org/AndrewMacro.sxw.


Even though he only writes in OOBasic, you are right that he explains 
the basic concepts needed for accessing the api from any language. He 
is also honest. Writing non-api code is relatively easy; accessing the 
OO/LO api is harder. I made a start. When I get further, I will look 
at the examples that are close to some things I want to do. I will 
also study your Python examples. Thanks for the help.


Terry



NP you are welcome to ask me any question.


Cheers
Karim

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


Re: Which way is best to execute a Python script in Excel?

2012-07-05 Thread Terry Reedy


On 7/5/2012 10:30 PM, Karim wrote:


An excellent link to derived all code example to python:
http://www.pitonyak.org/AndrewMacro.sxw.


Even though he only writes in OOBasic, you are right that he explains 
the basic concepts needed for accessing the api from any language. He is 
also honest. Writing non-api code is relatively easy; accessing the 
OO/LO api is harder. I made a start. When I get further, I will look at 
the examples that are close to some things I want to do. I will also 
study your Python examples. Thanks for the help.


Terry


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