Re: Execute a python script with CGI ?

2014-06-26 Thread gregor
Hi,

Am Thu, 26 Jun 2014 08:24:56 -0700 (PDT)
schrieb dandrigo :

> I coded a python script (web service with query postgresql/postgis).
> Up to now, i did several test on my local laptop station (windows). 
> 
> Now i want to execute this python script on our remote server (Web
> server : Apache;OS :  Linux). 
> 
> How to write a CGI template please? 
> 
> Could you throw light for me? 

https://docs.python.org/2/library/cgi.html

--
Greg 

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


Re: Everything you did not want to know about Unicode in Python 3

2014-05-13 Thread gregor
Am 13 May 2014 01:18:35 GMT
schrieb Steven D'Aprano :

> 
> - have a simple way to write bytes to stdout and stderr.

there is the underlying binary buffer:

https://docs.python.org/3/library/sys.html#sys.stdin

greg

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


Re: How to check the date validity?

2013-12-24 Thread gregor
Am Mon, 23 Dec 2013 16:30:35 -0800
schrieb Igor Korot :

> 
> Now, it looks that the python way of validating the date/time of the
> string is to call strptime(). However looking at the docs and trying
> to use the function I didn't find a way to check for the milliseconds.
> Now the dates can be formatted differently I think according to the
> locale under which the csv is generated.

you can also use an validator package like formencode:

http://www.formencode.org/en/latest/Validator.html

It has an TimeConverter but it does not understand milliseconds either.
But it should be trivial to implement it based on TimeConverter.

Using formencode the validation / conversion is seperated and therefore 
reusable.
You also get nice human readable validation messages in different languages.
It supports also Schemas to validate complete records.

--
Greg

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


Re: In defence of 80-char lines

2013-04-03 Thread gregor
Am Wed, 3 Apr 2013 21:32:33 -0700 (PDT)
schrieb llanitedave :

> I would hate to have to break up this line, for instance:
> 
> self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD,
> faceName = "FreeSans"))

I think this is much more readable:

self.mainLabel.SetFont(wx.Font(12,
   wx.DEFAULT,
   wx.NORMAL,
   wx.BOLD,
   faceName = "FreeSans"))  

Emacs for example does this indentation with the TAB key automatically.

--
Greg 

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


Re: Making module content available in parent module

2010-11-23 Thread Gregor Horvath
Hi,

On Tue, 23 Nov 2010 11:36:05 +0100
Ulrich Eckhardt  wrote:

> Now, my problem is I have a directory containing test scripts which I
> all want to run. I used to run them individually and manually, but
> want to avoid this overhead in the future.
> 
>  tests/
>foo.py # defines TestFoo1 and TestFoo2
>bar.py # defines TestBar1 and TestBar2

Nose does what you want:

http://packages.python.org/nose/

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



Re: polymorphic function question

2010-09-21 Thread Gregor Horvath
Am Tue, 21 Sep 2010 11:35:14 -0700 (PDT)
schrieb joblack :

> Let's say I've got a function with
> 
> def doesSomething(A='bla'):
> ...
> 
> and I try to call it with a non existent variable with
> 
> doesSomething(DoesNotExist)
> 
> What will happen? Will it throw an exception or will it take the
> defautl value?

The interpreter is omniscient, just ask him:

Python 2.6.6 (r266:84292, Aug 29 2010, 12:36:23) 
[GCC 4.4.5 20100824 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> def doesSomething(A='bla'):
... pass
... 
>>> doesSomething(DoesNotExist)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'DoesNotExist' is not defined


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


Re: Encode HTML CDATA name token

2010-09-20 Thread Gregor Horvath
Am Mon, 20 Sep 2010 21:36:46 +1200
schrieb Lawrence D'Oliveiro :

> In message <20100920104546.3699e...@valun>, Gregor Horvath wrote:
> 
> > Is there a encoder / decoder in Python that can convert arbitrary
> > text to and from this encoding in an readable manner?
> 
> Not sure if this is already in Python, but 
> <http://en.wikipedia.org/wiki/Base32>.

Thanks for the suggestion.

Yes it is in Python: base64.b32encode

2 Problems: 

a) "=" is used as padding char
b) The special case of a base32 encoding with a leading digit is not
handled.
c) It's not readbale

But I can easly work around this. 
Thanks.

--
Greg


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


Encode HTML CDATA name token

2010-09-20 Thread Gregor Horvath
Hi,

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods ("."). [1]

Is there a encoder / decoder in Python that can convert arbitrary text
to and from this encoding in an readable manner?

base64 is not readable:

In [31]: base64.encodestring("/TEST")
Out[31]: 'L1RFU1Q=\n'

quopri does not encode for example "/".

In [25]: quopri.encodestring("/test")
Out[25]: '/test'

Anything else?

--
Greg

[1] http://www.w3.org/TR/html4/types.html#type-cdata
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 put-downs: What's the point?

2010-07-06 Thread Gregor Horvath
Am Mon, 05 Jul 2010 14:32:13 -0500
schrieb Tim Chase :

> On 07/05/2010 02:50 AM, Gregor Horvath wrote:
> > Am Sun, 04 Jul 2010 18:51:54 -0500
> > schrieb Tim Chase:
> >
> >> I think it's the same venting of frustration that caused veteran
> >> VB6 developers to start calling VB.Net "Visual Fred" -- the
> >> language was too different and too non-backwards-compatible.
> >>
> >
> > VB6 ->  VB.NET and Python 2 ->  3 is not a valid comparison.
> >
> > VB6 and VB.NET are totally different languages and technologies,
> > with some similarity in syntax. This is not true for Python 2->3.
> > This is an healthy organic language growth, not an abandon of a
> > language.
> 
> The quintessential example is Py3's breaking of Hello World. 
> It's a spectrum of language changes -- Visual Fred just happens 
> to be MUCH further down the same spectrum having more dramatic 
> changes.  Only a subset of $OLD_VER (whether Py2 or VB6) code 
> will run unmodified under $NEW_VER (whether Py3 or VB.Net).  It 

Don't you think that there is a really huge difference in an
evolutionary development of a language with some well founded
incompatibilities due to some muck outs on one side and and on the other
side stopping the development of a language and replacing it with one
derived from a completely different one and giving it a related name
and syntax?

And that such a big difference forbids any comparison, although there
are some superficial similarities?

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


Re: Python 3 put-downs: What's the point?

2010-07-05 Thread Gregor Horvath
Am Sun, 04 Jul 2010 18:51:54 -0500
schrieb Tim Chase :

> I think it's the same venting of frustration that caused veteran 
> VB6 developers to start calling VB.Net "Visual Fred" -- the 
> language was too different and too non-backwards-compatible.
> 

VB6 -> VB.NET and Python 2 -> 3 is not a valid comparison.

VB6 and VB.NET are totally different languages and technologies, with
some similarity in syntax. This is not true for Python 2->3. 
This is an healthy organic language growth, not an abandon of a
language.

--
Greg

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


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl



kirby urner schrieb:

I'm glad turtle graphics intersected my thinking re extended precision
decimals (Decimal type) on edu-sig just now.

I've updated my tmods.py to contain a turtle rendering the plane-net of a T-mod:

http://www.4dsolutions.net/ocn/python/tmod.py (runnable source)
http://www.flickr.com/photos/17157...@n00/4147429781/  (GUI view)
  

Nice tiny app! Albeit not an example for using the if statement ;-)
Just to show you how turtle.py enables you to implement this
using quite different approaches to doing geometry, I'd like to add
two more implementations.

Besides you may notice that these do not rely on rather complicated
calculations of distances and angles, using the Pythagorean theorem
and trigonometrics but only on a few more fundamental properties of
the figure.

# Version 2 - using coordinate geometry without coordinates ;-)
# a different implementation for Kirby's "Plane Net for T-module"

from turtle import *
from math import sqrt

PHI = (sqrt(5)-1)/2

def planeNet(h=500): 
  setup(560,560)

  title("Plane Net for T-module")
  penup()
  back(h/2); left(90); back(h/2); right(90)
  pendown()

  forward(h); left(90)
  forward(h*PHI); A = pos(); forward(h-h*PHI); left(90)
  forward(h*PHI); B = pos(); forward(h-h*PHI); left(90)
  forward(h); C = pos()

  for P in A, B, C:
 goto(P)


# Version 3 - stamping simple transforms of the shape of
#  an isosceles rectangular triangle:

from turtle import Screen, Turtle
from math import sqrt

GOLDEN_RATIO = (sqrt(5)-1)/2

def planeNet(h=500.0, phi=GOLDEN_RATIO): 
  s = Screen(); s.setup(560,560); s.title("Plane Net for T-module")

  s.register_shape("recttriangle", ((0, 0), (h, 0), (0, h)))
  designer = Turtle(shape="recttriangle")
  designer.color("black","")
  designer.penup()
  designer.goto(-h/2, h/2)

  for width, height in ((1, 1-phi), (phi, 1-phi), (phi, 1)):
 designer.shapesize(width, height)
 designer.stamp()
 designer.forward(h)
 designer.right(90)
  designer.hideturtle()

Hoping, you will find this a bit interesting,
best regards

Gregor




Here's the graphical output:

http://www.flickr.com/photos/17157...@n00/4148139184/in/photostream/
(Python 3.1)

If you actually wanna fold the T, you need to snip off the cap and
reverse it, per this diagram:

http://www.rwgrayprojects.com/synergetics/s09/figs/f86515.html

120 of them, 60 folded left, 60 folded right, all of volume 1/24, make
the volume 5 rhombic triacontahedron.

http://www.rwgrayprojects.com/synergetics/s09/figs/f86419.html

If you blow up the volume by 3/2, to 7.5, the radius becomes phi /
sqrt(2) -- what we're showing with Decimals.

The reason this seems unfamiliar is the unit of volume is the
tetrahedron formed by any four equi-radiused balls in inter-tangency.

I'm spinning this as Martian Math these days, yakking on
math-thinking-l about it, learned it from Bucky Fuller, Dave Koski et
al.

Kirby

  

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


Re: [Edu-sig] teaching python using turtle module

2009-11-30 Thread Gregor Lingl

Hello Brian,

I think the most natural use of the if statement (using turtle
graphics) occurs in recursive functions drawing trees,
fractals and the like. This is well known from Logo, where
recursion is the canonical way of doing repetitions. (But
note, that Logo has tail recursion optimizaton!)

If you are not yet ready to use recursion with your students,
probably many  of the problems coming to your mind that need
the examination of conditions  can be solved better by using
a conditional loop (i. e. a while -loop in Python) than by
using mere if statements.

That is not the case however, if you have to perform actions in
the body of a loop, that depend on the current situation.
I did a quick search in my repository of examples and found
a fairly short and simple script that demonstrates, what I mean:
a drunken turtle collecting coins (or whatever) on its random walk.


# Python script using turtle graphics

from turtle import Screen, Turtle
from random import randint

s = Screen()
s.setup(560,560)
s.title("A drunken turtle collecting ...")

s.tracer(False)
writer = Turtle(visible=False)
writer.penup()
writer.goto(0, -275)

coins = []
for i in range(-4,5):
   for j in range(-4, 5):
   if i == j == 0:
   continue
   c = Turtle(shape="circle")
   c.color("", "orange")
   c.shapesize(0.5)
   c.goto(40*i, 40*j)
   coins.append(c)
s.tracer(True)

DRUNKENNESS = 45   
t = Turtle(shape="turtle")

t.color("black","")
points = 0
while abs(t.xcor()) < 200 and abs(t.ycor()) < 200:
   t.forward(5)
   t.right(randint(-DRUNKENNESS, DRUNKENNESS))
   found = None
   for c in coins:
   if t.distance(c) < 10:
   found = c
   break
   if found:
   found.hideturtle()
   coins.remove(found)
   t.shapesize(1+points/5., outline=1+points)
   points += 1

writer.write("{0} points".format(points),
align="center", font=('Arial', 24, 'bold'))

## End of script


You can see a screenshot of a run of this script here:

http://www.dropbox.com/gallery/2016850/1/TurtleCollector?h=6b370a

The script could be expanded in several ways, e. g. for
doing statistical investigations or examinig how the
result depends on different parameters like drunkenness etc.
Or you distribute the coins randomly ... Does that alter
the average "harvest"?

Just a suggestion ...

Regards,
Gregor


Brian Blais schrieb:

Hello,

I was just playing with the turtle module, and thought it was an 
interesting way to augment the introduction to python (I teach college 
students, who haven't had any programming).  It's a great way to 
introduce functions, for-loops, and general program structures.


After a bit of playing, I realized that I couldn't think of many 
examples which use turtle with conditional structures (if- and while- 
statements), or functions that return values, as opposed to 
"procedures" like:


def square(length):
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)
forward(length)
right(90)


If-statements could possibly be used with some sort of random behavior 
(if rand()<0.5 ...).  Are there any other situations, using turtle, 
that these structures would be natural? 




thanks,

Brian Blais

--
Brian Blais
bbl...@bryant.edu <mailto:bbl...@bryant.edu>
http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>





___
Edu-sig mailing list
edu-...@python.org
http://mail.python.org/mailman/listinfo/edu-sig
  

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


Re: How to pass a global variable to a module?

2009-09-29 Thread Gregor Horvath
Hi,

Am Tue, 29 Sep 2009 09:40:29 -0700 (PDT)
schrieb Mars creature :

>   I just start to use python and love this language. I met this
> problem when I try to save my functions in a separate file.
> The question is how I can pass a global variable to a function which
> is saved in another file. If I save the function I defined in the same
> file with the main program, there is no problem after I declare the
> global variable. But problem comes out when I save all the function is
> a separate file. Help is very much appreciated! Thanks!
> Jinbo

http://mail.python.org/pipermail/tutor/2002-November/018353.html

--
Gregor
http://gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Business issues regarding adapting Python

2009-09-27 Thread Gregor Horvath
Hi,

Am Sun, 27 Sep 2009 00:13:47 -0700 (PDT)
schrieb Nash :

> I'm a big time python fan and it has helped me write code fast and
> push it out quickly. We have a medium sized telecom product written
> 90% in Python and 10% in Java. The problem is, in the place where we
> work (Pakistan), we can't find Python developers. I asked HR to send

[...]

> 4. Any suggestions or idea? Related posts, articles etc would
> certainly help!

http://www.paulgraham.com/pypar.html

--
Gregor
http://gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


logging sound / speech handler?

2009-09-09 Thread Gregor Horvath
Hi,

For an application in an industrial environment where the workers are
not always sitting in front of the monitor, but are within earshot of
the PC I would need an sound / speech handler for the standard logging
system. It should beep or better say the logging message. (with
standard filtering etc.)
I google search was not successfull.
Does anybode know of such a handler?

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


Re: win32ui DLL Load Failed

2009-09-01 Thread Gregor Horvath
Am Mon, 31 Aug 2009 12:43:04 -0700 (PDT)
schrieb MikeC :

> I have a python executable that's failing to load on a user's machine
> running Windows XP. My developer machine is also running Windows XP. I
> have determined that it is failing when it attempts to load win32ui.
> 
> I have Python 2.6 on my developer machine and am using the pywin
> support (Mark Hammonds???) for Python 2.6.

Try to install:

http://www.microsoft.com/downloads/details.aspx?familyid=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en

2.6 is linked against VS8 dlls, which are missing on some machines.

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


Re: Splitting a string into substrings of equal size

2009-08-17 Thread Gregor Lingl

Simon Forman schrieb:

On Aug 14, 8:22 pm, candide  wrote:

Suppose you need to split a string into substrings of a given size (except
possibly the last substring). I make the hypothesis the first slice is at the
end of the string.
A typical example is provided by formatting a decimal string with thousands
separator.

What is the pythonic way to do this ?


...

Thanks


FWIW:

def chunks(s, length=3):
stop = len(s)
start = stop - length
while start > 0:
yield s[start:stop]
stop, start = start, start - length
yield s[:stop]


s = '1234567890'
print ','.join(reversed(list(chunks(s
# prints '1,234,567,890'


or:

>>> def chunks(s, length=3):
i, j = 0, len(s) % length or length
while i < len(s):
yield s[i:j]
i, j = j, j + length

>>> print(','.join(list(chunks(s
1,234,567,890
>>> print(','.join(list(chunks(s,2
12,34,56,78,90
>>> print(','.join(list(chunks(s,4
12,3456,7890

Regards,
Gregor
--
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into substrings of equal size

2009-08-16 Thread Gregor Lingl

Mark Tolonen schrieb:


"Gregor Lingl"  wrote in message 
news:4a87036a$0$2292$91cee...@newsreader02.highway.telekom.at...

Emile van Sebille schrieb:

On 8/14/2009 5:22 PM candide said...

...

What is the pythonic way to do this ?


I like list comps...

 >>> jj = '1234567890123456789'
 >>> ",".join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
 >>>

Emile



Less beautiful but more correct:

>>> ",".join([jj[max(ii-3,0):ii] for ii in
     range(len(jj)%3,len(jj)+3,3)])
'1,234,567,890,123,456,789'

Gregor


Is it?


jj = '234567890123456789'
",".join([jj[max(ii-3,0):ii] for ii in range(len(jj)%3,len(jj)+3,3)])

',234,567,890,123,456,789'


Schluck!

Even more ugly:

 ",".join([jj[max(ii-3,0):ii] for ii in
   range(len(jj)%3,len(jj)+3,3)]).strip(",")
'234,567,890,123,456,789'

Gregor



At least one other solution in this thread had the same problem.

-Mark



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


Re: getting the fractional part of a real?

2009-08-15 Thread Gregor Lingl

Christian Heimes schrieb:

Roy Smith schrieb:
What's the best way to get the fractional part of a real?  The two 
ways I can see are r % 1 and r = int(r), but both seem a bit hokey.  
Is there something more straight-forward that I'm missing, like 
fraction(r)?



import math
math.modf(1.5)

(0.5, 1.0)

Christian


Or without the need to import something:

>>> divmod(1.5, 1)
(1.0, 0.5)
>>>

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl

Emile van Sebille schrieb:

On 8/14/2009 5:22 PM candide said...

...

What is the pythonic way to do this ?


I like list comps...

 >>> jj = '1234567890123456789'
 >>> ",".join([jj[ii:ii+3] for ii in range(0,len(jj),3)])
'123,456,789,012,345,678,9'
 >>>

Emile



Less beautiful but more correct:

>>> ",".join([jj[max(ii-3,0):ii] for ii in
     range(len(jj)%3,len(jj)+3,3)])
'1,234,567,890,123,456,789'

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl



What is the pythonic way to do this ?


For my part, i reach to this rather complicated code:


# --

def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
print z+" --> ", comaSep(z)



Just if you are interested, a recursive solution:

>>> def comaSep(z,k=3,sep=","):
return comaSep(z[:-3],k,sep)+sep+z[-3:] if len(z)>3 else z

>>> comaSep("7")
'7'
>>> comaSep("2007")
'2,007'
>>> comaSep("12024")
'12,024'
>>> comaSep("509")
'509'
>>> comaSep("75096042068045")
'75,096,042,068,045'
>>>

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


Re: Splitting a string into substrings of equal size

2009-08-15 Thread Gregor Lingl



What is the pythonic way to do this ?


For my part, i reach to this rather complicated code:


# --

def comaSep(z,k=3, sep=','):
z=z[::-1]
x=[z[k*i:k*(i+1)][::-1] for i in range(1+(len(z)-1)/k)][::-1]
return sep.join(x)

# Test
for z in ["75096042068045", "509", "12024", "7", "2009"]:
print z+" --> ", comaSep(z)



Just if you are interested, a recursive solution:

>>> def comaSep(z,k=3,sep=","):
return comaSep(z[:-3],k,sep)+sep+z[-3:] if len(z)>3 else z

>>> comaSep("7")
'7'
>>> comaSep("2007")
'2,007'
>>> comaSep("12024")
'12,024'
>>> comaSep("509")
'509'
>>> comaSep("75096042068045")
'75,096,042,068,045'
>>>

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


Re: Turtle Graphics are incompatible with gmpy

2009-08-05 Thread Gregor Lingl

Mensanator schrieb:

On Aug 5, 5:31 pm, Mensanator  wrote:

I fixed this to produce the actual image I'm looking
for instead of that stupid black square. All I did was
use up() & dowm() in place of penup(), pendown() and
replace dot(2) with forward(1).

I'll be posting a followup report later.



http://www.mensanator.com/mensanator/PythonTurtle/turtle.htm


Hi Mansanator,

Thanks for that thorough investigations.
I hope I'll soon find time to study it in detail.

I've just one idea, but I don't know if you might
be intersted in it or if it's rewarding at all:

What would be the results when using the old turtle
module with Python 3.1 (it will certainly not run
out of the box, but perhaps 2to3 might do it?)

That would clarify the question if there is some
impact of new division or some changes in Tkinter.

Best regards,
Gregor
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turtle Graphics are incompatible with gmpy

2009-08-05 Thread Gregor Lingl

Mensanator schrieb:

It didn't form 2.5 to 2.6 (at least not intentionally). But with the
indroduction of the TurtleScreen class and the Screen class/object
(singleton) a few of the turtle methods were also implemented as screen
methods and as turtle methods declared deprecated (see docs of Python
2.6). These deprecated turtle methods do not occur as turtle methods any
more in Python 3.x.


More info.

Yes, there is no tracer attribute...when the object is created.

But watch this (Python 3.1):


import turtle
tooter = turtle.Turtle()
tooter.tracer

Traceback (most recent call last):
  File "", line 1, in 
tooter.tracer
AttributeError: 'Turtle' object has no attribute 'tracer'

tooter.hideturtle()
tooter.speed('fast')
turtle.update()
turtle.tracer



Now, after setting hide, speed, update, a tracer exists.


No,

>>> import turtle
>>> turtle.tracer

>>> help(turtle.tracer)
Help on function tracer in module turtle:

tracer(n=None, delay=None)
Turns turtle animation on/off and set delay for update drawings.

Optional arguments:
n -- nonnegative  integer
delay -- nonnegative  integer

If n is given, only each n-th regular screen update is really 
performed.

(Can be used to accelerate the drawing of complex graphics.)
Second arguments sets delay value.)

Example:
>>> tracer(8, 25)
>>> dist = 2
>>> for i in range(200):
fd(dist)
rt(90)
dist += 2

>>>

The reason for this is, that the turtle module (the new one as well as 
the old one) has a vers special design: The methods of class Turtle are 
also available as functions (which are in fact methods calls of an 
anonymous turtle). The same holds for the methods of TurtleScreen.


The intention behind this design is that you can use the module in an 
OOP way as well as with procedural programming (especially for beginners).


When using objects I normally use

from turtle import Turtle, Screen
screen = Screen()
# that creates  singleton object, the screen the turtle acts on
and I create as many turtles as I need from the Turtle class

So turtle.tracer() doesn't make sense anymore



Is that supposed to happen? That explains why there was no error
when I set the turtle attribute instead of the screen attribute.


You do not 'set the turtle attribute', you call the tracer function of 
the turtle module



And, of course, setting the turtle attribute accomplishes nothing,
as actual tracing is controlled by the screen attribute as you say.


Among them is the tracer method, which in fact does not control single
turtle objects but all the turtles on a given screen.

So there is an icompatibility beween 2.6 and 3.x

But as far as I have understood, this doesn't concern the problem
reported by mensator.


Only that the problem is hidden when tracing is off, as the nhops
variable is never evaluated when trace is off.


Nevertheless I'd like to see a working Python 2.5 version of your script.

Regards,
Gregor
--
http://mail.python.org/mailman/listinfo/python-list


Re: Turtle Graphics are incompatible with gmpy

2009-08-05 Thread Gregor Lingl

Steven D'Aprano schrieb:

On Wed, 5 Aug 2009 03:49 pm Mensanator wrote:


In 3.1, tracing is now a screen attribute, not a turtle atribute.
I have no idea why

  tooter = turtle.Turtle()
  tooter.tracer(False)

doesn't give me an error (I thought silent errors were a bad thing).


What makes it an error? Do you consider the following an error?


class Test:

... pass
...

t = Test()
t.tracer = 5



Perhaps you mean, it's an API change you didn't know about, and you wish to
protest that Turtle Graphics made an incompatible API change without
telling you?



It didn't form 2.5 to 2.6 (at least not intentionally). But with the 
indroduction of the TurtleScreen class and the Screen class/object 
(singleton) a few of the turtle methods were also implemented as screen 
methods and as turtle methods declared deprecated (see docs of Python 
2.6). These deprecated turtle methods do not occur as turtle methods any 
more in Python 3.x.


Among them is the tracer method, which in fact does not control single 
turtle objects but all the turtles on a given screen.


So there is an icompatibility beween 2.6 and 3.x

But as far as I have understood, this doesn't concern the problem 
reported by mensator.


Regards,
Gregor




Naturally, having tracing on caused my program to crash. 


It seg faulted or raised an exception?


[...] 

Unfortunately, that calculation of nhops is illegal if diffsq is
an .mpf (gmpy floating point). Otherwise, you get


How does diffsq get to be a mpf? Are gmpy floats supposed to be supported?




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


Re: Turtle Graphics are incompatible with gmpy

2009-08-05 Thread Gregor Lingl

Mensanator schrieb:

I hadn't noticed this before, but the overhaul of Turtle Graphics
dating
back to 2.6 has been broken as far as gmpy is concerned.

I hadn't noticed because I usually have tracing turned off (tracing
off
takes 3-4 seconds, tracing on takes 6-7 minutes).

In 3.1, tracing is now a screen attribute, not a turtle atribute.
I have no idea why

  tooter = turtle.Turtle()
  tooter.tracer(False)

doesn't give me an error (I thought silent errors were a bad thing).



Hi,

on my machine I get:

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit 
(Intel)] on win32

Type "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> tooter = turtle.Turtle()
>>> tooter.tracer(False)
Traceback (most recent call last):
  File "", line 1, in 
tooter.tracer(False)
AttributeError: 'Turtle' object has no attribute 'tracer'
>>>

I'd like to help with your problem but I'd much better be
able to analyze it, if I had a version of your script,
which works as you intended with Python 2.5 and the old
turtle module. Could you please post it?

(The one you posted below uses some commands of the
turtle 2.6 module which are not present in 2.5, so it
doesn't run with Python 2.5)

Regards,
Gregor



Had to change to

  tooter = turtle.Turtle()
  tooter.screen.tracer(False) # tracer now a screen attribute

to turn tracing off in 3.1.

Naturally, having tracing on caused my program to crash. The 2.6
version
seemed to work, but only because turning off tracing as a turtle
attribute
works in 2.6.

So I turned it back on and it crashed too.

2.5 worked okay.

The reason is that code in turtle.py was chabged from

v2.5
if self._drawing:
if self._tracing:
dx = float(x1 - x0)
dy = float(y1 - y0)
distance = hypot(dx, dy)
nhops = int(distance)

to

v3.1
   if self._speed and screen._tracing == 1:
diff = (end-start)
diffsq = (diff[0]*screen.xscale)**2 + (diff[1]
*screen.yscale)**2
nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)
*self._speed))

Unfortunately, that calculation of nhops is illegal if diffsq is
an .mpf (gmpy
floating point). Otherwise, you get

Traceback (most recent call last):
  File "K:\user_python26\turtle\turtle_xy_Py3.py", line 95, in

tooter.goto(the_coord)
  File "C:\Python31\lib\turtle.py", line 1771, in goto
self._goto(Vec2D(*x))
  File "C:\Python31\lib\turtle.py", line 3165, in _goto
nhops = 1+int((diffsq**0.5)/(3*(1.1**self._speed)*self._speed))
ValueError: mpq.pow fractional exponent, inexact-root

So when using gmpy, you have to convert the .mpz to int before calling
turtle
functions. (if tracing is on).

demo code (fixed code commented out)

import gmpy

##   (even) hi|
##|
##lo (odd)
## or
##
##   (even) lo
##   |
##   |
##   hi (odd)
##
##
##
##

import turtle

tooter = turtle.Turtle()

tooter.hideturtle()
tooter.speed('fast')
turtle.update()
# make tracer false and it works
#tooter.screen.tracer(False) # tracer now a screen attribute
tooter.penup()
tooter.color('black')

s = ['1','0']
while len(s[0])<1:
s = [''.join(s), s[0]]


origin = [0,0]
if s[0] == '0':
  tooter.goto(origin)
  tooter.dot(1)
if s[1] == '0':
  tooter.goto([1,0])
  tooter.dot(1)

print(len(s[0]))

for i,j in enumerate(s[0]):
  the_coord=[]
  cur_root = gmpy.sqrt(i)
  lo__root = gmpy.sqrt(i)**2
  hi__root = ((gmpy.sqrt(i)+1)**2)
##  cur_root = int(gmpy.sqrt(i))
##  lo__root = int(gmpy.sqrt(i)**2)
##  hi__root = int(((gmpy.sqrt(i)+1)**2))

  if hi__root%2==0:
side = 'northeast'
  else:
side = 'southwest'

  elbow = (hi__root - lo__root)//2 + lo__root + 1

  if i>= elbow:

side_len = i - elbow
elbow_plus = True
  else:
side_len = elbow - i
elbow_plus = False

  if side == 'northeast':
elbow_offset = [(gmpy.sqrt(elbow)-1)//2 +1,-((gmpy.sqrt(elbow)-1)//
2) +1]
  else:
elbow_offset = [-((gmpy.sqrt(elbow)-1)//2 +1),((gmpy.sqrt
(elbow)-1)//2 +1)]
##  if side == 'northeast':
##elbow_offset = [int((gmpy.sqrt(elbow)-1)//2 +1),-int(((gmpy.sqrt
(elbow)-1)//2) +1)]
##  else:
##elbow_offset = [-int(((gmpy.sqrt(elbow)-1)//2 +1)),int
(((gmpy.sqrt(elbow)-1)//2 +1))]

  elbow_coord = [origin[0]+elbow_offset[0],origin[1]+elbow_offset[1]]

  if i != hi__root and i != lo__root:
if i == elbow:
  the_coord = elbow_coord
else:
  if elbow_plus:
if side == 'northeast':
  the_coord = [elbow_coord[0]-side_len,elbow_coord[1]]
else:
  the_coord = [elbow_coord[0]+side_len,elbow_coord[1]]
  else:
if side == 'northeast':
   

Re: Overlap in python

2009-08-04 Thread Gregor Lingl

Gregor Lingl schrieb:


As my proposed solution shows this approach can
be done with on board means of Python (namely
the set type). This would be quite different though,
if you had floating point boundaries of the intervals.


... or if the intgers involved were very big  :-(


Regards,
Gregor



Duane

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


Re: Overlap in python

2009-08-04 Thread Gregor Lingl

DuaneKaufman schrieb:

On Aug 4, 1:15 pm, Jay Bird  wrote:

...

For instance the interval module found at: 
http://members.cox.net/apoco/interval/
can be put to use:

Given your data above:

part name   location
a  5-9
b  7-10
c  3-6


from interval import Interval

a_int=Interval(5,9)
b_int=Interval(7,10)
c_int=Interval(3,6)
a_int.overlaps(b_int)

True

a_int.overlaps(c_int)

True

b_int.overlaps(c_int)

False


As my proposed solution shows this approach can
be done with on board means of Python (namely
the set type). This would be quite different though,
if you had floating point boundaries of the intervals.

Regards,
Gregor



Duane

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


Re: Overlap in python

2009-08-04 Thread Gregor Lingl

Jay Bird schrieb:

Hi everyone,

I've been trying to figure out a simple algorithm on how to combine a
list of parts that have 1D locations that overlap into a non-
overlapping list.  For example, here would be my input:

part name   location
a  5-9
b  7-10
c  3-6
d  15-20
e  18-23

And here is what I need for an output:
part name   location
c.a.b3-10
d.e   15-23



Suppose you have your data given as a dictionary:

data = {'a':(5,9),
'b':(7,10),
'c':(3,6),
'd':(15,20),
'e':(18,23)}

Then the following not particularly elegant
but very simple and straight forward
algorithm will solve your problem:

def values(key):
return set(range(data[key][0], data[key][1]+1))

keys = list(data.keys())
result = []
while keys:
k = [keys[0]]
keys = keys[1:]
v = values(k[0])
for l in keys[:]:
if v.intersection(values(l)):
v.update(values(l))
k.append(l)
keys.remove(l)
result.append((k,v))

# print(result) ## if you like

for k, v in result:
print(".".join(sorted(k)), "%d-%d" % (min(v), max(v)))

Regards,
Gregor



I've tried various methods, which all fail.  Does anyone have an idea
how to do this?

Thank you very much!
Jay

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


Re: Announcing PythonTurtle

2009-08-04 Thread Gregor Lingl

cool-RR schrieb:

Hi Ram,

that's indeed a nice starting point for kids to doing turtle graphics,
although currently it seems to implement only a very small subset of
Python's turtle module's capabilities, even less than those of the old
turtle module (that shipped with Python upto 2.5).

...

A text editor would be a good feature for future versions.
Regarding the naming of functions: I named them in the way that seemed
best to me. You seem not to agree, you like the way your functions are
named better, and there's little point in arguing over which
convention is truly better. The convention I chose is the one that
seemed ideal to me.
I did consider naming the functions the same way you did for
consistency, but I decided not to compromise the quality of
PythonTurtle just to be compatible with a module that my users may not
even use.


That's the advantage of not developing for the standard library. In fact 
those elementary commands you use were present already in the old turtle 
module. When I decided to extend the old turtle module a primary 
requirement was that it remains 100% compatible to the old one. New 
versions of a module in the standard library must not break code of 
previous users of that module. In short: I did not name these functions 
but I had to use the names that already were there.


Nevertheless I'd prefer left and right over turn even today, especially 
for kids as I argued before.


Regards,
Gregor




It would be certainly a good thing if one had a similar environment
using Tkinter, preferably also as part of the standard distribution of
Python accompanying the turtle module. I think it should not be that
difficult to create a GUI of this sort combining IDLE's shell window,
its editor and turtle.py. Alas, at the moment I'm too busy with some
othr work to start a project like this. Perhaps someone else might be
interested? I'd enjoy to join a team doing it.


I agree that it shouldn't be difficult; The question is whether
someone will step up and do it.


Finally I'd like to stress, that the aims of PythonTurtle and Python's
turtle module are quite different - as one could grasp easily by trying
out the collection of examples at python-turtle-demo.googlecode.com that
I posted in another posting. Anyway they could very well complement one
another in some more mature state of development.

Best regards,
Gregor


Thank you for your feedback Gregor.

Ram Rachum.

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


Re: Announcing PythonTurtle

2009-08-04 Thread Gregor Lingl

cool-RR schrieb:

On Aug 4, 7:12 am, John Posner  wrote:

... I would also venture to say a key-map



...

If you're asking WHY I put it in a wxPython application, the answer is
pretty much what "r" said: To make it like any other "over the
counter" Windows application, making people feel more comfortable with
it.
Also, not requiring them to install Python+packages, but just
PythonTurtle.
Fortunately it's not necessary to install 'packages' to use Python's 
turtle module as it is one of it's 'batteries included'. And I think 
it's not so a bad idea to install Python if one want's to learn it, anyway.


Regards,
Gregor



Ram.

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


Re: Announcing PythonTurtle

2009-08-04 Thread Gregor Lingl

cool-RR schrieb:

Hello,

I wanted to announce that I have just released my little side project,
PythonTurtle.
Here is its website:
http://pythonturtle.com

Its goal is to be the lowest-threshold way to learn (or teach) Python.
You can read more about it and download it on the website.

Ram.


Hi Ram,

that's indeed a nice starting point for kids to doing turtle graphics, 
although currently it seems to implement only a very small subset of 
Python's turtle module's capabilities, even less than those of the old 
turtle module (that shipped with Python upto 2.5).


Moreover I have to complain that you decided to use different commands 
for the turtle's actions - go instead of forward, turn instead of left 
and right etc. First I think left and right are more intuitive than turn 
as they do not need negative angles as arguments, which might matter for 
young children. Also I cannot see the advantage of cammands like 
visible() or invisible() over showturtle() and hideturtle()


But second even kids - when learning how to program - will arrive at a 
point where it's no more problem to use an editor like IDLE so they
could easily switch to Python's turtle module. That would be even easier 
if they had not to learn a new command set.


Moreover a learning environment like PythonTurtle needs something like 
an editor - at least a simple one - in order to create programs that can 
be run repeatedly. Coding, that's creating programs - not only issuing

a sequence of cammands interactively.

It would be certainly a good thing if one had a similar environment 
using Tkinter, preferably also as part of the standard distribution of 
Python accompanying the turtle module. I think it should not be that 
difficult to create a GUI of this sort combining IDLE's shell window, 
its editor and turtle.py. Alas, at the moment I'm too busy with some 
othr work to start a project like this. Perhaps someone else might be 
interested? I'd enjoy to join a team doing it.


Finally I'd like to stress, that the aims of PythonTurtle and Python's
turtle module are quite different - as one could grasp easily by trying
out the collection of examples at python-turtle-demo.googlecode.com that 
I posted in another posting. Anyway they could very well complement one 
another in some more mature state of development.


Best regards,
Gregor





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


ANN: Python's turtle module: collection of examples + demoViewer

2009-08-04 Thread Gregor Lingl

Hi all,

A few days ago I've created a repository of turtle graphics 
demos/applications, that use Python's new turtle module.

You can find it at at google code:

http://python-turtle-demo.googlecode.com

There are two versions of the collection: one for use with Python 3.1
and one for use with Python 2.5 / 2.6. The latter contains a

***  backport of version 1.1 of the turtle module  ***
***  (from Python 3.1) to Python 2.5 / 2.6 *** 



Among others it contains all the examples I have demonstrated
at Pycon 2009 and at EuroPython 2009.

Moreover it contains the demoViewer (which is also in the source
distribution of CPython) that lets you select the examples via a menu,
display their source code and execute them in parallel.

If you are interested to amend some of these examples, add some
explanatory material or contribute additional examples, please tell
me so I could add you as a committer to the project.

I'd be glad to expand the repository whith interesting examples
and applications using the turtle module.

If you have questions concerning the examples, feel free to ask
here or ask me directly via my email-address.

I hope this collection will prove to be useful.

Best regards,
Gregor

P.S.: I tried to announce it at comp.lang.python.announce
but for some unknown reason it was not accepted there


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


Re: Overwriting property-> can't set attribute

2008-08-22 Thread Gregor Horvath

Gregor Horvath schrieb:


why is this code failing?


OK I answer myself :-)

Because there is not fset function definied in the property.
I have to del the attr before rebinding the attributename to another object.

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


Overwriting property-> can't set attribute

2008-08-22 Thread Gregor Horvath

Hi,

why is this code failing?

class B(object):
pass

B.testattr = property(lambda s:"hallo")
b = B()
b.testattr = "test"


Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)

/tmp/python-14202ViU.py in ()
 14 B.testattr = property(lambda s:"hallo")
 15 b = B()
---> 16 b.testattr = "test"
 17
 18

: can't set attribute

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


Re: getattr nested attributes

2008-08-15 Thread Gregor Horvath

Peter Otten schrieb:


make your own function that loops over the attributes, or spell it


reduce(getattr, "a.test".split("."), B)

'test'



Thank's, but this does not work for this case:

class A(object):
test = "test"

class B(object):
a = [A(),]

In [70]: reduce(getattr, "a[0].test".split("."), B)
---
Traceback (most recent call last)

/ in ()

: type object 'B' has no attribute 'a[0]'

Seems that I have to use eval ?
I have a mapping text file (data) which contains such attributes strings 
and those attributes should be read.


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


getattr nested attributes

2008-08-15 Thread Gregor Horvath

Hi,

class A(object):
test = "test"

class B(object):
a = A()


In [36]: B.a.test
Out[36]: 'test'

In [37]: getattr(B, "a.test")
---
Traceback (most recent call last)

/ in ()

: type object 'B' has no attribute 
'a.test'


???

Documentation says B.a.test and getattr(B, "a.test") should be equivalent.

http://docs.python.org/lib/built-in-funcs.html

any help?

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


Re: Why is None <= 0

2008-04-25 Thread Gregor Horvath

D'Arcy J.M. Cain schrieb:

On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <[EMAIL PROTECTED]> wrote:

 >>> None <= 0
True

Why?


Why not?


Because, from http://www.python.org/dev/peps/pep-0020/ :

Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

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


Why is None <= 0

2008-04-25 Thread Gregor Horvath

Hi,

>>> None <= 0
True

Why?
Is there a logical reason?

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


Re: Python code-writing for the blind. Was (Re: newbie: stani's python editor if-else)

2007-09-11 Thread Gregor Horvath
madzientist schrieb:

> 
> Is Python a bad choice for the blind programmer, as a result of a
> tight linkage between visual aspects of the code and its function ? I
> wish the site blindprogramming.com weren't so lifeless...

There was a thread regarding blind people and python indentation shortly:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/80654a87bfa89e3b

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


Re: newbie: stani's python editor if-else

2007-09-11 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> I agree with Steve. I have yet to see an IDE for Python (or anything
> else) that unindents statements. Even IDLE, the Official IDE for
> Python, doesn't do that.


emacs in python-mode

Just hit TAB and it unindents "else" in the given example.
Hit TAB again and it cylces in the possible indentations.

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


Re: Class design (information hiding)

2007-09-09 Thread Gregor Horvath
Alex Martelli schrieb:
> 
> Why, thanks for the pointer -- I'm particularly proud of having written
> """
> The only really workable way to develop large software projects, just as
> the only really workable way to run a large business, is a state of
> controlled chaos.
> """

Yes, indeed a good saying.
The problem is that we do not understand those complex systems, despite 
the fact that some megalomaniacal people think they do.

Declaring a method as private, public or protected assumes that the 
author fully understands the uses of this class by other programmers or 
even himself later on.
But if the software is complex enough, chances are good that he does 
*NOT* understand it fully at the time he writes "Protected".

Programming means attempting. Attempt implies failure. Flexible systems 
that are built for easy correction are therefore superior.

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


Re: Class design (information hiding)

2007-09-07 Thread Gregor Horvath
Alexander Eisenhuth schrieb:
> 
> I'm wodering how the information hiding in python is ment. As I 
> understand there  doesn't exist public / protected / private  mechanism, 
> but a '_' and '__' naming convention.
> 
> As I figured out there is only public and private possible as speakin in 
> "C++ manner". Are you all happy with it. What does "the zen of python" 
> say to that design? (protected is useless?)

My favourite thread to this FAQ:

http://groups.google.at/group/comp.lang.python/browse_thread/thread/2c85d6412d9e99a4/b977ed1312e10b21#b977ed1312e10b21

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


pickle error/instancemethod

2007-09-04 Thread Gregor Kling
Hello,

I have some of these nefarious pickle errors I do not understand,
maybe some of you have a clue.

This is what I get
(nd is the object which I want to pickle [cPickle.dumps(nd,2)], with
the printout of nd.__dict__):

 ERROR Error: Can't pickle : attribute lookup
__builtin__.instancemethod failed, nd: {'dvzLogger':
, '_DVZnetzDataBase__netzentries':
[], '_DVZnetzDataBase__option_fqdn_alias':
set(['a.b.c']), '_DVZnetzDataBase__admins': set([]),
'_DVZnetzDataBase__aliasentries': []}


I follow the hints on http://docs.python.org/lib/node318.html, so I
do not understand the source of the problem. I do not try to pickle
an instancemethod directly. The dict does apparently contains only
top level tuples, lists, sets, and dictionaries, classes/instances.

So if more Data is needed to analyse the problem - demand.

gfk

-- 
gfk


smime.p7s
Description: S/MIME Cryptographic Signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: advice about `correct' use of decorator

2007-09-03 Thread Gregor Horvath
Gerardo Herzig schrieb:
> 
> @is_logued_in
> def change_pass():
>bla
>bla
> 
> And so on for all the other functions who needs that the user is still 
> loged in.
> 
> where obviosly the is_logued_in() function will determine if the dude is 
> still loged in, and THEN execute change_pass(). If the dude is not loged 
> in, change_pass() is NOT executed at all. Instead, it will be redirected 
> to the `login' screen.
> 
> Something in my mind tells me that this is not the pythonic way...But i 
> like the idea, so please tell me that im in the right way :)
> 

That's how turbogears does it.
See:

http://docs.turbogears.org/1.0/UsingIdentity?highlight=%28identity%29


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


Re: Why PHP is so much more popular for web-development

2007-07-25 Thread Gregor Horvath
walterbyrd schrieb:

> Don't get me wrong: I am not saying that PHP is better than Python for
> web-development. But, I sometimes think that Python could learn a few
> things from PHP.

Yes, indeed we can learn that popularity is not superiority. ;-)

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


Re: The best platform and editor for Python

2007-07-05 Thread Gregor Horvath
Kay Schluehr schrieb:

> The problem is simply that the Python community has failed in this
> respect. There are many platform dependent and ideology driven ways to
> do deal with code editing / debugging but not actually a recommend or
> "pythonic" way. Other than Smalltalk, Python has not created an own

Again, that's how Open Source or a Toolkit driven development (Unixy) 
works.
For every problem there are 5 solutions. One size does not fit all.

It's no fault that for example Linux Distributions do not have only one 
GUI but a lot of them. It's a great fortune.

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


Re: The best platform and editor for Python

2007-07-05 Thread Gregor Horvath
kimiraikkonen schrieb:

> My another aim is: Can i develop graphical applications (like in
> Windows) which contain menus, interactive dialog boxes etc. using
> Ptyhon?
> 
> I got it quite but not sure. I don't know Ptyhon's capability skills
> for creating interactive softwares like in Windows's created by C++ or
> Delphi.
> 

have a look at Dabo

http://www.dabodev.com/

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


Re: The best platform and editor for Python

2007-07-05 Thread Gregor Horvath
Kay Schluehr schrieb:

> That's what I love most about the Python community. Whenever there is
> just a non-standard, platform-dependent or crappy implementation of a
> feature you get told that you don't need it. When printf was good for
> little David print is good enough for me.
> 

That's a property of open source projects.
Features nobody really needs are not implemented.

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


Re: What's the best way to iniatilize a function

2007-05-28 Thread Gregor Horvath
Jack schrieb:

> I didn't call del explicitly. I'm expecting Python to call it when
> the program exits. I put a logging line in __del__() but I never
> see that line printed. It seems that __del__() is not being called
> even when the program exits. Any idea why?
> 
> 

http://effbot.org/pyfaq/my-class-defines-del-but-it-is-not-called-when-i-delete-the-object.htm

better solutions:

http://docs.python.org/ref/try.html
http://docs.python.org/whatsnew/pep-343.html

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> opposed.  But dismissing the fact that Outlook and other quite common
> tools may have severe problems with code seems naive (or disingenuous,
> but I don't think that's the case here).

Of course there is broken software out there. There are even editors 
that mix tabs and spaces ;-) Python did not introduce braces to solve 
this problem but encouraged to use appropriate tools. It seems to work 
for 99% of us. Same here.
It is the 21st century. Tools that destroy Unicode byte streams are 
seriously broken. Face it. You can not halt progress because of some 
broken software. Fix or drop it instead.

I do not think that this will be a big problem because only a very small 
fraction of specialized local code will use Unicode identifiers anyway.

Unicode strings and comments are allowed today and I didn't heard of a 
single issue of destroyed strings because of bad editors, although I 
guess that Unicode strings in code are way more common than Unicode 
identifiers would ever be.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Gregor Horvath
Paul Boddie schrieb:

> Perhaps, but the treatment by your mail/news software plus the
> delightful Google Groups of the original text (which seemed intact in
> the original, although I don't have the fonts for the content) would
> suggest that not just social or cultural issues would be involved.

I do not see the point.
If my editor or newsreader does display the text correctly or not is no 
difference for me, since I do not understand a word of it anyway. It's a 
meaningless stream of bits for me.
It's save to assume that for people who are finding this meaningful 
their setup will display it correctly. Otherwise they could not work 
with their computer anyway.

Until now I did not find a single Computer in my German domain who 
cannot display: ß.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Gregor Horvath
Istvan Albert schrieb:
> On May 17, 2:30 pm, Gregor Horvath <[EMAIL PROTECTED]> wrote:
> 
>> Is there any difference for you in debugging this code snippets?
> 
>> class Türstock(object):
> 
> Of course there is, how do I type the ü ? (I can copy/paste for
> example, but that gets old quick).
> 

I doubt that you can debug the code without Unicode chars. It seems that 
you do no understand German and therefore you do not know what the 
purpose of this program is.
Can you tell me if there is an error in the snippet without Unicode?

I would refuse to try do debug a program that I do not understand. 
Avoiding Unicode does not help a bit in this regard.

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Gregor Horvath
Hendrik van Rooyen schrieb:

> I suppose that this "one language track" - mindedness of mine
> is why I find the mix of keywords and German or Afrikaans so 
> abhorrent - I cannot really help it, it feels as if I am eating a 
> sandwich, and that I bite on a stone in the bread. - It just jars.

Please come to Vienna and learn the local slang.
You would be surprised how beautiful and expressive a language mixed up 
of a lot of very different languages can be. Same for music. It's the 
secret of success of the music from Vienna. It's just a mix up of all 
the different cultures once living in a big multicultural kingdom.

A mix up of Python key words and German identifiers feels very natural 
for me. I live in cultural diversity and richness and love it.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-17 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> With the second one, all my standard tools would work fine.  My user's
> setups will work with it.  And there's a much higher chance that all
> the intervening systems will work with it.
> 

Please fix your setup.
This is the 21st Century. Unicode is the default in Python 3000.
Wake up before it is too late for you.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-17 Thread Gregor Horvath
Istvan Albert schrieb:
> 
> After the first time that your programmer friends need fix a trivial
> bug in a piece of code that does not display correctly in the terminal
> I can assure you that their mellow acceptance will turn to something
> entirely different.
> 

Is there any difference for you in debugging this code snippets?

class Türstock(object):
   höhe = 0
   breite = 0
   tiefe = 0

   def _get_fläche(self):
 return self.höhe * self.breite

   fläche = property(_get_fläche)

#---

class Tuerstock(object):
   hoehe = 0
   breite = 0
   tiefe = 0

   def _get_flaeche(self):
 return self.hoehe * self.breite

   flaeche = property(_get_flaeche)


I can tell you that for me and for my costumers this makes a big difference.

Whether this PEP gets accepted or not I am going to use German 
identifiers and you have to be frightened to death by that fact ;-)

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-17 Thread Gregor Horvath
Martin v. Löwis schrieb:

> I've reported this before, but happily do it again: I have lived many
> years without knowing what a "hub" is, and what "to pass" means if
> it's not the opposite of "to fail". Yet, I have used their technical
> meanings correctly all these years.

That's not only true for computer terms.
In the German Viennese slang there are a lot of Italian, French, 
Hungarian, Czech, Hebrew and Serbocroatien words. Nobody knows the exact 
meaning in their original language (nor does the vast majority actually 
speak those languages), but all are used in the correct original context.

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

Re: Declaring variables

2007-05-17 Thread Gregor Horvath
HMS Surprise schrieb:

> 
> #~~
> createdIncidentId = 0
> .
> .
> .
> #attempt to change varialbe
> createdIncidentID = 1
> .
> .
> .
> if createdIncidentId == 1:
>...
> 

test.py is your code above

$ pychecker -v test.py
Processing test...

Warnings...

test.py:7: Variable (createdIncidentID) not used


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


Re: Sending a JavaScript array to Python script?

2007-05-17 Thread Gregor Horvath
placid schrieb:

> Just wondering if there is any way of sending a JavaScript array to a
> Python cgi script? A quick Google search didn't turn up anything
> useful.

http://mochikit.com/doc/html/MochiKit/Base.html#json-serialization
http://svn.red-bean.com/bob/simplejson/tags/simplejson-1.3/docs/index.html

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-17 Thread Gregor Horvath
Hendrik van Rooyen schrieb:

> I can sympathise a little bit with a customer who tries to read code.
> Why that should be necessary, I cannot understand - does the stuff
> not work to the extent that the customer feels he has to help you?
> You do not talk as if you are incompetent, so I see no reason why 
> the customer should want to meddle in what you have written, unless
> he is paying you to train him to program, and as Eric Brunel has 
> pointed out, this mixing of languages is all right in a training environment.

That is highly domain and customer specific individual logic, that the 
costumer knows best. (For example variation logic of window and door 
manufacturers)
He has to understand the code, so that he can verify it's correct.
We are in fact developing it together.
Some costumers even are coding this logic themselves. Some of them are 
not fluent in English especially not in the computer domain.

Translating the logic into a documentation is a waste of time if the 
code is self documenting and easy to grasp. (As python usually is) But 
the code can only be self documenting if it is written in the domain 
specific language of the customer. Sometimes these are words that are 
not even used in general German. Even in German different customers are 
naming the same thing with different words. Talking and coding in the 
language of the customer is a huge benefit.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> On May 16, 12:54 pm, Gregor Horvath <[EMAIL PROTECTED]> wrote:
>> Istvan Albert schrieb:
>>
>> So the solution is to forbid Chinese XP ?
>>
> 
> It's one solution, depending on your support needs.
> 

That would be a rather arrogant solution.
You would consider dropping the language and culture of millions of 
users because a small number of support team staff does not understand 
it? I would recommend to drop the support team and the management that 
even considers this.

This PEP is not a technical question.
Technically it would no change much.

The underlying question is a philosophical one.
Should computer programming only be easy accessible to a small fraction 
of privileged individuals who had the luck to be born in the correct 
countries?

Should the unfounded and maybe xenophilous fear of loosing power and 
control of a small number of those already privileged be a guide for 
development?

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

>> 2) Create a way to internationalize the standard library (and possibly
>> the language keywords, too). Ideally, create a general standardized way
>> to internationalize code, possibly similiar to how people
>> internationalize strings today.
> 
> Why?  Or more acurately why before adopting the PEP?
> The library is very usable by non-english speakers as long as
> there is documentation in their native language.  It would be

Microsoft once translated their VBA to foreign languages.
I didn't use it because I was used to "English" code.
If I program in mixed cultural contexts I have to use to smallest 
dominator. Mixing the symbols of the programming language is confusing.

Long time ago at the age of 12 I learned programming using English 
Computer books. Then there were no German books at all. It was not easy. 
It would have been completely impossible if our schools system would not 
have been wise enough to teach as English early.

I think millions of people are handicapped because of this.
Any step to improve this, is a good step for all of us. In no doubt 
there are a lot of talents wasted because of this wall.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
Istvan Albert schrieb:

> Here is something that just happened and relates to this subject: I
> had to help a student run some python code on her laptop, she had
> Windows XP that hid the extensions. I wanted to set it up such that
> the extension is shown. I don't have XP in front of me but when I do
> it takes me 15 seconds to do it. Now her Windows was set up with some
> asian fonts (Chinese, Korean not sure), looked extremely unfamiliar
> and I had no idea what the menu systems were. We have spent quite a
> bit of time figuring out how to accomplish the task. I had her read me
> back the options, but something like "hide extensions" comes out quite
> a bit different. Surprisingly tedious and frustrating experience.
> 

So the solution is to forbid Chinese XP ?

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
Eric Brunel schrieb:
> 
> The point is that today, I have a reasonable chance of being able to 
> read, understand and edit any Python code. With PEP 3131, it will no 
> more be true. That's what bugs me.

That's just not true. I and others in this thread have stated that they 
use German or other languages as identifiers today but are forced to 
make a stupid and unreadable translation to ASCII.

> 
> Same question again and again: how does he know that non-Russian 
> speakers will *ever* get in touch with his code and/or need to update it?

If you didn't get non English comments and identifiers until now, you 
will not get any with this PEP either. And if you do get them today or 
with the PEP it doesn't make a difference for you to get some glyphs not 
properly displayed, doesn't it?

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
Eric Brunel schrieb:

> Highly improbable in the general context. If I stumble on a source code 
> in Chinese, Russian or Hebrew, I wouldn't be able to figure out a single 
> sound.

If you get source code in a programming language that you don't know you 
can't figure out a single sound too.
How is that different?

If someone decides to make *his* identifiers in Russian he's taking into 
account that none-Russian speakers are not going to be able to read the 
code.
If someone decides to program in Fortran he takes into account that the 
average Python programmer can not read the code.

How is that different?

It's the choice of the author.
Taking away the choice is not a good thing.
Following this logic we should forbid all other programming languages 
except Python so everyone can read every code in the world.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
Hendrik van Rooyen schrieb:

> It is not so much for technical reasons as for aesthetic 
> ones - I find reading a mix of languages horrible, and I am
> kind of surprised by the strength of my own reaction.

This is a matter of taste.
In some programs I use German identifiers (not unicode). I and others 
like the mix. My customers can understand the code better. (They are 
only reading it)

> 
> "Beautiful is better than ugly"

Correct.
But why do you think you should enforce your taste to all of us?

With this logic you should all drive Alfa Romeos!

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> code on the (GUI-less) production servers over a terminal link.  They
> have to use all kinds of environments where they can't install the
> latest and greatest fonts.  Promoting code that becomes very hard to
> read and debug in real situations seems like a sound negative to me.

If someone wants to debug a Chinese program, he has in almost all cases 
obviously already installed the correct fonts and his machine can handle 
unicode.

Maybe yours and mine not, but I doubt that we are going to debug a 
chinese program.

I have debugged German programs (not python) with unicode characters in 
it for years and had no problem at all, because all customers and me 
have obviously German machines.

Gregor


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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
René Fleschenberg schrieb:

>> I love Python because it does not dictate how to do things.
>> I do not need a ASCII-Dictator, I can judge myself when to use this
>> feature and when to avoid it, like any other feature.
> 
> *That* logic can be used to justify the introduction of *any* feature.
> 

No. That logic can only be used to justify the introduction of a feature 
that brings freedom.

Who are we to dictate the whole python world how to spell an identifier?

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Gregor Horvath
René Fleschenberg schrieb:

> today, to the best of my knowledge. And "in some form or another"
> basically means that the PEP would create more possibilities for things
> to go wrong. That things can already go wrong today does not mean that
> it does not matter if we create more occasions were things can go wrong
> even worse.

Following this logic we should not add any new features at all, because 
all of them can go wrong and can be used the wrong way.

I love Python because it does not dictate how to do things.
I do not need a ASCII-Dictator, I can judge myself when to use this 
feature and when to avoid it, like any other feature.

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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Gregor Horvath
Ross Ridge schrieb:

> non-ASCII identifiers.  While it's easy to find code where comments use
> non-ASCII characters, I was never able to find a non-made up example
> that used them in identifiers.

If comments are allowed to be none English, then why are identifier not?
This is inconsistent because there is a correlation between identifier 
and comment.

The best identifier is one that needs no comment, because it 
self-describes it's content. None English identifiers enhance the 
meaning of identifiers for some projects. So why forbid them? We are all 
adults.

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Gregor Horvath
René Fleschenberg schrieb:
> 
> We all know what the PEP is about (we can read). The point is: If we do
> not *need* non-English/ASCII identifiers, we do not need the PEP. If the
> PEP does not solve an actual *problem* and still introduces some
> potential for *new* problems, it should be rejected. So far, the
> "problem" seems to just not exist. The burden of proof is on those who
> support the PEP.
> 

A good product does not only react to problems but acts.

Solving current problems is only one thing. Great products are exploring 
new ways, ideas and possibilities according to their underlying vision.

Python has a vision of being easy even for newbies to programming.
Making it easier for non native English speakers is a step forward in 
this regard.

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

Re: howto check is object a func, lambda-func or something else?

2007-04-29 Thread Gregor Horvath
dmitrey schrieb:

> howto check is object Arg1
> - a func, lambda-func
> - something else?
> 
> I tried callable(Arg1), but  callable(lambda-func) returnes False

I don't understand your problem:

>>> callable(lambda:0)
True


Please post your relevant code.

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


jython: user-defined modules

2007-04-25 Thread Gregor Stich
Dear all,

I hope my question is here in the right place...
What I want to achieve is a communication between Java and Python. We
have a pretty strong framework of existing python scripts and modules.
Now I want to use jython in order to faciliate the communication
between another Java framework.

But I`m currently stuck with jython: Trying to import the user-defined
python modules, these cannot be found. I read a lot about the jython
registry and I setup a $HOME/.jython file where I created a
python.path=... resource, however, when I start the jython command
line and type
print python.path
then this property is not found. Passing it with the -D option does
not work as well, or maybe I`m too confused to make it work anyway?

Any help would be great!
 Best regards
 Greg

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


Re: How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh
Giles Brown wrote:
> Yeah.  You've cleverly decided to simplify the "smallest
> possible python service" by removing the
> if __name__ == '__main__':

Ha ha. :)
Seriously, though, I removed that long after it was failing to work, and
have since replaced it and it didn't affect a thing.


Gabriel Genellina wrote:
> Have you installed the pywin32 package from
> https://sourceforge.net/projects/pywin32/ ?
> The code skeleton looks OK to me.

Indeed, I have win32 installed. :)

I'm used to writing wxPython apps, even a small-scale video game, but
services are a new and alien direction for me. :)

Now, I did stumble upon the solution to this one this morning, after a
fresh night of sleep: I re-ran "python tester.py install" I got a message
that the service had been updated, and now it runs! Hooray!

Any insight into why that would be the case? Does pythonservice.exe keep a
cached copy or some such, so I'll have to re-install the service after
code changes?


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


Re: How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh

Giles Brown wrote:
> Yeah.  You've cleverly decided to simplify the "smallest possible
> python service" by removing the
> if __name__ == '__main__':

Ha ha. :)
Seriously, though, I removed that long after it was failing to work, and
have since replaced it and it didn't affect a thing.


Gabriel Genellina wrote:
> Have you installed the pywin32 package from
> https://sourceforge.net/projects/pywin32/ ?
> The code skeleton looks OK to me.

Indeed, I have win32 installed. I'm used to writing wx applications,
compiling into exes, etc. Services are a new direction for me.


So, both of you say that the program I sent *did* work?import win32serviceutil, win32service, win32event


class Service(win32serviceutil.ServiceFramework):
_svc_name_ = "EDMS-to-CG"
_svc_display_name_ = "EDMS-to-CG Syncer"
_svc_description_  = "Uploaded the EDMS database to Cartograph"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
pausetime = 60 * 1000
while True:
stopsignal = win32event.WaitForSingleObject(self.hWaitStop, 
pausetime)
if stopsignal == win32event.WAIT_OBJECT_0: break
self.runOneLoop()

def runOneLoop(self):
import servicemanager
servicemanager.LogInfoMsg('Running')

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(Service)-- 
http://mail.python.org/mailman/listinfo/python-list

How to build a Windows service using win32?

2007-03-07 Thread Gregor Mosheh
I'm trying to write a Win32 service. The following is straight from Python
Programming on Win32 and it doesn't work. Is that book out of date; is
there a new way to do services? I searched Google for hours trying to find
any other method, and have been beating on this one for 5 more hours.

The present error is:

C:\Tester>python tester.py debug
Debugging service Tester - press Ctrl+C to stop.
Error 0xC004 - Python could not import the service's module

: No module named service


The code is:

import win32serviceutil, win32service, win32event

class Service(win32serviceutil.ServiceFramework):
_svc_name_ = "EDMS-to-CG"
_svc_display_name_ = "EDMS-to-CG Syncer"
_svc_description_  = "Uploaded the EDMS database to Cartograph"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
pausetime = 60 * 1000
while True:
stopsignal = win32event.WaitForSingleObject(self.hWaitStop,
pausetime)
if stopsignal == win32event.WAIT_OBJECT_0: break
self.runOneLoop()

def runOneLoop(self):
import servicemanager
servicemanager.LogInfoMsg('Running')

win32serviceutil.HandleCommandLine(Service)


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


Re: Complex HTML forms

2007-02-18 Thread Gregor Horvath
George Sakkis schrieb:
> I'd like to gather advice and links to any existing solutions (e.g.
> libraries, frameworks, design patterns) on general ways of writing
> complex web forms, as opposed to the typical {name:value} flat model.
> A particular case of what I mean by complex is hierarchical forms. For

http://toscawidgets.org/
http://docs.turbogears.org/1.0/SimpleWidgetForm

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


Re: Can Python help?

2006-12-26 Thread Gregor Horvath
Lad schrieb:
> On my website I allow users to upload files. I would like a user to see
> how much time is left before a file is uploaded. So, I would like to
> have a progress bar during  a file uploading. Can Python help me with
> that?Or how can be a progress bar made? 
> Thank you for ideas.
> La.
> 

http://docs.turbogears.org/1.0/FileUploadProgressBar

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


Re: What do I look for in a shared Python host?

2006-11-17 Thread Gregor Horvath
walterbyrd schrieb:
> 
> What other "gotchas" would I look for?
> 

Maybe this is helpfull for you:

http://docs.turbogears.org/1.0/Hosting

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


Re: The fastest search

2006-10-21 Thread Gregor Horvath
Fulvio schrieb:
> 
> Is there some trick to apply the best search in wise use of resources while 
> using the above said methods?
> 

measure it:

http://docs.python.org/lib/module-timeit.html

Regarding your debugger question in the seperate thread I don't know
since I am not using a debugger at all.

Most people coming from other languages are looking for a debugger and
are overlooking that in python a interactive interpreter, a good editor,
print statements and the tracebacks are all a lot of python developers need.

Small snippets of code are developed in the interpreter and when they
are working assembled in the editor. If something goes wrong a print on
the suspect place or the traceback is all I need. (of course this is
matter of taste)

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good Form

2006-10-21 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:

> Would you normally write methods to retrive and set your class
> variables or just refrence them directly?
> 

you start by referencing them directly and ONLY if you need you can add
getters and setters later on without breaking any client code.
see the property function.

An explanation for the motivation behind this and python's thinking can
be found here:

http://tinyurl.com/wfgyw

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Webprogr: Link with automatic submit

2006-10-20 Thread Gregor Horvath
Bruno Desthuilliers schrieb:
> yes : replace the link with another submit button, then in your
> controller check which submit has been successful and take appropriate
> action.

Thanks !

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Webprogr: Link with automatic submit

2006-10-20 Thread Gregor Horvath
Hi,

As I am no expert web programmer I thought I'd better ask the experts if
there is a simpler or better solution to my problem than the one I am
thinking of. (using TurboGears)

The problem
---

I have a form. Ok. you can submit, validate it etc.
Now I have a link on that form to another page.
What I want is that the form gets automatically submitted and validated
before the browser follows the link. If the validation has errors the
link should not be followed.

My solution
---

1. client side solution

First I thought I just make a little javascript function like this:

function xy(url) {
document.form.submit();
parent.location=url;
}

The problem is that submit works ansynchronisly. I do not get a return
code to decide if to follow the url or not. Furthermore the form does
not get submitted if there is the line parent.location=url; .

2. server side solution

I thought of including a hidden field and include directives for my
controller method to raise the redirection if no validation errors are
there.



function xy(url) {
document.form.hiddenfield.value = "redirect_to: " + url;
document.form.submit();
}

@expose
def mycontroller(self, *args, **kwargs):
   #do the usual saving stuff

   if hasattr(kwargs, 'hiddenfield'):
  #parse the JSON or mini-langage and do the redirection, when no
  #validation errors


As there might be more other directives necessery for client-server
communciation I thought of setting the hiddenfield value to JSON or a
self made mini-language and parse this in the controller.

Is this a good solution?
Are there any other options?

--
Greg

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


Re: Scope of decorator argument

2006-10-17 Thread Gregor Horvath
Gregor Horvath schrieb:
> 
> Is there any other solution, probably with metaclasses ?
> 

I've found this one:

class mymeta(type):
def __new__(meta, class_name, bases, new_attrs):
new_attrs["edit"] = adecorator(new_attrs['xy'])(bases[0].edit))
return type.__new__(meta, class_name, bases, new_attrs)

class base(object):
def edit(self):
print "%s edit" % self

class child(base):
__metaclass__ = mymeta
xy = 3


Don't know if it's the best solution but it seems to work.

-- 
  Servus, Gregor

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


Scope of decorator argument

2006-10-16 Thread Gregor Horvath
Hi,

this:

class base(object):
@adecorator(xy)
def edit(self):
print "edit"

class child(base):
xy = 3


obviously fails because "xy" is not bound at class creation time of the
base object.

One solution could be delegation:

class base(object):
@classmethod
def edit(self):
print "do the real work here"

class child(object):
xy = 3
mybase = base

@adecorator(xy)
def edit(self, *args, **kwargs):
self.mybase.edit(*args, **kwargs)

But then I have the ugly boiler plate delegation code in child.

Is there any other solution, probably with metaclasses ?

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python's OOP question

2006-10-15 Thread Gregor Horvath
neoedmund schrieb:
> python use multiple inheritance.
> but "inheritance" means you must inherite all methods from super type.
> now i just need "some" methods from one type and "some" methods from
> other types,
> to build the new type.
> Do you think this way is more flexible than tranditional inheritance?
> 

Probably your problem is better solved with delegation instead of
inheritance.

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web Hosting

2006-10-15 Thread Gregor Horvath
Sir Psycho schrieb:
> 
> Im looking at making a site in Python, however, Im lost as to what ISPs
> actually support. Some ISPs say they support Python so does that mean
> if I wanted to use TurboGears It would just work anyway?

http://docs.turbogears.org/1.0/Hosting?highlight=%28hosting%29

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using SVN with Python and .pyc files

2006-10-13 Thread Gregor Horvath
James Stroud schrieb:

> project or package. How do people manage this? Do you run a script to
> find files with the .pyc extension and delete those before every commit,
> or is there a more elegant way? It seems like a lot of wasted bandwidth
> an memory on the server side to constantly be dealing with these files
> that contain no real information.

in /etc/subversion/config

global-ignores = *.pyc *~ #*#

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32 Service: path to .py script

2006-09-19 Thread Gregor Horvath
Larry Bates schrieb:

> I believe that your problem is that services run under Local
> System account.  Normally Local System account would not have
> a drive mapping Y:\.  You can change the account that a service

You are absolutly correct.
I moved the script to a local drive instead of a mapped network drive,
now it works perfectly.

Thank you a lot.

-- 
  Servus, Gregor
-- 
http://mail.python.org/mailman/listinfo/python-list


win32 Service: path to .py script

2006-09-19 Thread Gregor Horvath
Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineoption install)
The problem is that it runs only when it is in c:\windows\system32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.ImportError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceutil, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService(win32serviceutil.ServiceFramework):
_svc_name_ = "MDE Dispatcher"
_svc_display_name_ = "MDE-Dispatcher"
_svc_description_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)


def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')
)

while 1:
win32api.Sleep(2)
rc = win32event.WaitForSingleObject(self.hWaitStop, 2000)
if rc == win32event.WAIT_OBJECT_0:
break


# Write another event log record.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STOPPED,
(self._svc_name_, " TEST ")
)


if __name__=='__main__':
win32serviceutil.HandleCommandLine(TestPipeService)

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


Re: Looking for a text file based wiki system written in Python

2006-08-12 Thread Gregor Horvath
Jack schrieb:
> I'd like to set up a wiki system for a project I'm working on.
> Since I'm not good at databases, and there's really not much
> stuff to put into the wiki, I hope it is text file-based.
> I used DokuWiki before, which is very nice but it's written
> in PHP. Is there a similar system that's written in Python?
> I found pwyky but it's functionality is a bit too simple. 


http://moinmoin.wikiwikiweb.de/

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dallas One wire tempreture measurement.

2006-08-09 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:
>  a previous thread
> 
> http://mail.python.org/pipermail/python-list/2002-June/107616.html
> 
> discussed this issue, and Dave Moor kindly pointed to his solution.
> However this is no longer a current link, does anyone know if there is
> a currently available solution?
> 

I am using  digitemp with this code:


def GetActT():
"Liest aus Digittemp die temp"
digi = os.popen("digitemp -q -a -o2 -c /home/gh/.digitemprc")
f = digi.readlines()
digi.close()
return float(f[0].split()[1])

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Grammar parsing

2006-08-03 Thread Gregor Horvath
Paolo Pantaleo schrieb:

> How can I write a pareser for a certain gramamr? I found PyPy that
> does it, is thare any other tool? Maybe something built-in the python
> interpreter?
> 

http://pyparsing.wikispaces.com/

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to read, and analyze a log file?

2006-08-01 Thread Gregor Horvath
Hi,

[EMAIL PROTECTED] schrieb:

> I am reading a log file, and wondering what is the best way to read and
> analize this.

Look at:

http://pyparsing.wikispaces.com/

There is also an example for parsing an apache log.

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Interpretation of UnhandledException.rpt

2006-06-06 Thread Gregor Horvath
Hi,

in a windows server python application I receive once a week suddenly
and not reproducible the following error. UnhandledException.rpt file:


//===
Exception code: C090 FLT_INVALID_OPERATION
Program: C:\Python24\python.exe Date:  6/ 6/2006 14:36:13 (MM/DD/
HH:MM:SS)
Fault address:  00E9ADF0 01:00019DF0
C:\in4\inforCOM\Prod\InforDbCOM_Server.dll

Registers:
EAX:012BDAA0
EBX:012ADF50
ECX:B0D6
EDX:012BDAA0
ESI:012ADF50
EDI:0096A8C0
CS:EIP:001B:00DC4DC7
SS:ESP:0023:0021EF4C  EBP:02E91EF0
DS:0023  ES:0023  FS:003B  GS:
Flags:00010212

Call stack:
Address   Frame
00DC4DC7  02E91EF0  0001:3DC7 C:\Python24\DLLs\psycopg.pyd
2D36302D  36303032

*** Exception while writing report! ***


Do I read this correct, that the problem is in the InforDbCOM_Server.dll?
The call stack mentions the psycopg.pyd, can it be related to this problem?

How can I track down this problem?

-- 
  Servus, Gregor

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


Re: Install libraries only without the program itself

2006-05-11 Thread Gregor Horvath
Serge Orlov schrieb:

> I believe it's better to keep *everything* on the file server. Suppose

Certainly!

> your OS is windows and suppose you want to keep everything in s:/tools.
> The actions are:
> 3. Create little dispatcher s:/tools/win32/client.py:
> #!s:/tools/python24-win32/python.exe
> import sys
> sys.path[0] = "s:/tools/client-1.0.0"
> import client

I also had to set the paths for the imports and current directory
manually (why?). This worked for me:

#!y:/python24-win32/python24.dll
import sys
import os
sys.path =
["","y:\\","y:\\python24-win32\\lib\\site-packages","y:\\python24-win32\\DLLs","y:\\python24-win32\\lib","y:\\python24-win32\\lib\\plat-win","y:\\python24-win32\\lib\\lib-tk","y:\\python24-win32",
"y:\\python24-win32\\lib\\site-packages\\win32",
"y:\\python24-win32\\lib\\site-packages\\win32\\lib",
"y:\\python24-win32\\lib\\site-packages\\Pythonwin",
"Y:\\python24-win32\\python24.zip","y:\\python24-win32"]
os.chdir("y:\\")

import hobel300


5. I also had to copy all required dlls from the c:\winnt directory (for
example pywintypes24.dll) into the current directory.

Thanks for this solution, works great, did not know that you can run
python programs even without a python installation on the local machine!
Nice!

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Install libraries only without the program itself

2006-05-11 Thread Gregor Horvath
Hi,

My application is a client/server in a LAN. I want to keep my programs
.py files on a central File Server serving all clients. The clients
should load those over the LAN every time they start the program since I
expect that they are rapidly changing and I dont want to update each
client seperatly.

On the clients there should only be python and the necessary libraries
and third party modules (sqlobject etc.) installed.

How do I make a setup script that only installs the necessary things,
without the program itself. Is there a tool for that?

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Protocols for Python?

2006-04-27 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:
> 
> Is there a standard way to document protocols in Python? Of should I
> come up with something tailored to my needs.
> 

Write unittests or doctest strings.

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding IP address of computer

2006-04-27 Thread Gregor Horvath
Chris schrieb:
> How do I find and print to screen the IP address of the computer my
> python program is working on?
> 

IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Events in Python?

2006-04-26 Thread Gregor Horvath
[EMAIL PROTECTED] schrieb:
> 
> Does Python have a mechanism for events/event-driven programming?
> 

Probably this is something for you:

http://twistedmatrix.com/trac/

-- 
  Servus, Gregor
  http://www.gregor-horvath.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >